feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -3,5 +3,21 @@ from misc.utility.scons_hints import *
Import("env")
env.add_source_files(env.scene_sources, "*.cpp")
env.add_source_files(env.scene_sources, "skeleton/*.cpp")
env.add_source_files(env.scene_sources, "tile_set.cpp")
if not env["disable_physics_2d"]:
env.add_source_files(env.scene_sources, "capsule_shape_2d.cpp")
env.add_source_files(env.scene_sources, "circle_shape_2d.cpp")
env.add_source_files(env.scene_sources, "concave_polygon_shape_2d.cpp")
env.add_source_files(env.scene_sources, "convex_polygon_shape_2d.cpp")
env.add_source_files(env.scene_sources, "rectangle_shape_2d.cpp")
env.add_source_files(env.scene_sources, "segment_shape_2d.cpp")
env.add_source_files(env.scene_sources, "separation_ray_shape_2d.cpp")
env.add_source_files(env.scene_sources, "shape_2d.cpp")
env.add_source_files(env.scene_sources, "world_boundary_shape_2d.cpp")
if not env["disable_navigation_2d"]:
env.add_source_files(env.scene_sources, "navigation_mesh_source_geometry_data_2d.cpp")
env.add_source_files(env.scene_sources, "navigation_polygon.cpp")
env.add_source_files(env.scene_sources, "polygon_path_finder.cpp")
SConscript("skeleton/SCsub")

View file

@ -36,7 +36,7 @@
Vector<Vector2> CapsuleShape2D::_get_points() const {
Vector<Vector2> points;
const real_t turn_step = Math_TAU / 24.0;
const real_t turn_step = Math::TAU / 24.0;
for (int i = 0; i < 24; i++) {
Vector2 ofs = Vector2(0, (i > 6 && i <= 18) ? -height * 0.5 + radius : height * 0.5 - radius);

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CAPSULE_SHAPE_2D_H
#define CAPSULE_SHAPE_2D_H
#pragma once
#include "scene/resources/2d/shape_2d.h"
@ -60,5 +59,3 @@ public:
CapsuleShape2D();
};
#endif // CAPSULE_SHAPE_2D_H

View file

@ -77,7 +77,7 @@ void CircleShape2D::draw(const RID &p_to_rid, const Color &p_color) {
Vector<Vector2> points;
points.resize(24);
const real_t turn_step = Math_TAU / 24.0;
const real_t turn_step = Math::TAU / 24.0;
for (int i = 0; i < 24; i++) {
points.write[i] = Vector2(Math::cos(i * turn_step), Math::sin(i * turn_step)) * get_radius();
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CIRCLE_SHAPE_2D_H
#define CIRCLE_SHAPE_2D_H
#pragma once
#include "scene/resources/2d/shape_2d.h"
@ -54,5 +53,3 @@ public:
CircleShape2D();
};
#endif // CIRCLE_SHAPE_2D_H

View file

@ -43,7 +43,7 @@ bool ConcavePolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, do
const Vector2 *r = s.ptr();
for (int i = 0; i < len; i += 2) {
Vector2 closest = Geometry2D::get_closest_point_to_segment(p_point, &r[i]);
Vector2 closest = Geometry2D::get_closest_point_to_segment(p_point, r[i], r[i + 1]);
if (p_point.distance_to(closest) < p_tolerance) {
return true;
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CONCAVE_POLYGON_SHAPE_2D_H
#define CONCAVE_POLYGON_SHAPE_2D_H
#pragma once
#include "scene/resources/2d/shape_2d.h"
@ -51,5 +50,3 @@ public:
ConcavePolygonShape2D();
};
#endif // CONCAVE_POLYGON_SHAPE_2D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CONVEX_POLYGON_SHAPE_2D_H
#define CONVEX_POLYGON_SHAPE_2D_H
#pragma once
#include "scene/resources/2d/shape_2d.h"
@ -55,5 +54,3 @@ public:
ConvexPolygonShape2D();
};
#endif // CONVEX_POLYGON_SHAPE_2D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_2D_H
#define NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_2D_H
#pragma once
#include "core/io/resource.h"
#include "core/os/rw_lock.h"
@ -112,5 +111,3 @@ public:
NavigationMeshSourceGeometryData2D() {}
~NavigationMeshSourceGeometryData2D() { clear(); }
};
#endif // NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_2D_H

View file

@ -396,9 +396,7 @@ void NavigationPolygon::make_polygons_from_outlines() {
vertices.clear();
HashMap<Vector2, int> points;
for (List<TPPLPoly>::Element *I = out_poly.front(); I; I = I->next()) {
TPPLPoly &tp = I->get();
for (const TPPLPoly &tp : out_poly) {
Vector<int> p;
for (int64_t i = 0; i < tp.GetNumPoints(); i++) {

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef NAVIGATION_POLYGON_H
#define NAVIGATION_POLYGON_H
#pragma once
#include "scene/2d/node_2d.h"
#include "scene/resources/navigation_mesh.h"
@ -176,5 +175,3 @@ public:
VARIANT_ENUM_CAST(NavigationPolygon::SamplePartitionType);
VARIANT_ENUM_CAST(NavigationPolygon::ParsedGeometryType);
VARIANT_ENUM_CAST(NavigationPolygon::SourceGeometryMode);
#endif // NAVIGATION_POLYGON_H

View file

@ -141,12 +141,9 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector
for (const Edge &E : edges) {
const Edge &e = E;
Vector2 seg[2] = {
points[e.points[0]].pos,
points[e.points[1]].pos
};
Vector2 closest = Geometry2D::get_closest_point_to_segment(from, seg);
const Vector2 segment_a = points[e.points[0]].pos;
const Vector2 segment_b = points[e.points[1]].pos;
Vector2 closest = Geometry2D::get_closest_point_to_segment(from, segment_a, segment_b);
float d = from.distance_squared_to(closest);
if (d < closest_dist) {
@ -165,12 +162,9 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector
for (const Edge &E : edges) {
const Edge &e = E;
Vector2 seg[2] = {
points[e.points[0]].pos,
points[e.points[1]].pos
};
Vector2 closest = Geometry2D::get_closest_point_to_segment(to, seg);
const Vector2 segment_a = points[e.points[0]].pos;
const Vector2 segment_b = points[e.points[1]].pos;
Vector2 closest = Geometry2D::get_closest_point_to_segment(to, segment_a, segment_b);
float d = to.distance_squared_to(closest);
if (d < closest_dist) {
@ -301,7 +295,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector
bool found_route = false;
while (true) {
if (open_list.size() == 0) {
if (open_list.is_empty()) {
print_verbose("Open list empty.");
break;
}
@ -493,12 +487,9 @@ Vector2 PolygonPathFinder::get_closest_point(const Vector2 &p_point) const {
for (const Edge &E : edges) {
const Edge &e = E;
Vector2 seg[2] = {
points[e.points[0]].pos,
points[e.points[1]].pos
};
Vector2 closest = Geometry2D::get_closest_point_to_segment(p_point, seg);
const Vector2 segment_a = points[e.points[0]].pos;
const Vector2 segment_b = points[e.points[1]].pos;
Vector2 closest = Geometry2D::get_closest_point_to_segment(p_point, segment_a, segment_b);
float d = p_point.distance_squared_to(closest);
if (d < closest_dist) {

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef POLYGON_PATH_FINDER_H
#define POLYGON_PATH_FINDER_H
#pragma once
#include "core/io/resource.h"
@ -94,5 +93,3 @@ public:
PolygonPathFinder();
};
#endif // POLYGON_PATH_FINDER_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef RECTANGLE_SHAPE_2D_H
#define RECTANGLE_SHAPE_2D_H
#pragma once
#include "scene/resources/2d/shape_2d.h"
@ -56,5 +55,3 @@ public:
RectangleShape2D();
};
#endif // RECTANGLE_SHAPE_2D_H

View file

@ -35,8 +35,7 @@
#include "servers/rendering_server.h"
bool SegmentShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
Vector2 l[2] = { a, b };
Vector2 closest = Geometry2D::get_closest_point_to_segment(p_point, l);
Vector2 closest = Geometry2D::get_closest_point_to_segment(p_point, a, b);
return p_point.distance_to(closest) < p_tolerance;
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SEGMENT_SHAPE_2D_H
#define SEGMENT_SHAPE_2D_H
#pragma once
#include "scene/resources/2d/shape_2d.h"
@ -59,5 +58,3 @@ public:
SegmentShape2D();
};
#endif // SEGMENT_SHAPE_2D_H

View file

@ -74,7 +74,7 @@ Rect2 SeparationRayShape2D::get_rect() const {
Rect2 rect;
rect.position = Vector2();
rect.expand_to(Vector2(0, length));
rect = rect.grow(Math_SQRT12 * 4);
rect = rect.grow(Math::SQRT12 * 4);
return rect;
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SEPARATION_RAY_SHAPE_2D_H
#define SEPARATION_RAY_SHAPE_2D_H
#pragma once
#include "scene/resources/2d/shape_2d.h"
@ -57,5 +56,3 @@ public:
SeparationRayShape2D();
};
#endif // SEPARATION_RAY_SHAPE_2D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SHAPE_2D_H
#define SHAPE_2D_H
#pragma once
#include "core/io/resource.h"
@ -66,5 +65,3 @@ public:
~Shape2D();
};
#endif // SHAPE_2D_H

View file

@ -0,0 +1,16 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *
Import("env")
env.add_source_files(env.scene_sources, "skeleton_modification_2d.cpp")
env.add_source_files(env.scene_sources, "skeleton_modification_2d_ccdik.cpp")
env.add_source_files(env.scene_sources, "skeleton_modification_2d_fabrik.cpp")
env.add_source_files(env.scene_sources, "skeleton_modification_2d_lookat.cpp")
env.add_source_files(env.scene_sources, "skeleton_modification_2d_stackholder.cpp")
env.add_source_files(env.scene_sources, "skeleton_modification_2d_twoboneik.cpp")
env.add_source_files(env.scene_sources, "skeleton_modification_stack_2d.cpp")
if not env["disable_physics_2d"]:
env.add_source_files(env.scene_sources, "skeleton_modification_2d_jiggle.cpp")
env.add_source_files(env.scene_sources, "skeleton_modification_2d_physicalbones.cpp")

View file

@ -81,15 +81,15 @@ bool SkeletonModification2D::get_enabled() {
float SkeletonModification2D::clamp_angle(float p_angle, float p_min_bound, float p_max_bound, bool p_invert) {
// Map to the 0 to 360 range (in radians though) instead of the -180 to 180 range.
if (p_angle < 0) {
p_angle = Math_TAU + p_angle;
p_angle = Math::TAU + p_angle;
}
// Make min and max in the range of 0 to 360 (in radians), and make sure they are in the right order
if (p_min_bound < 0) {
p_min_bound = Math_TAU + p_min_bound;
p_min_bound = Math::TAU + p_min_bound;
}
if (p_max_bound < 0) {
p_max_bound = Math_TAU + p_max_bound;
p_max_bound = Math::TAU + p_max_bound;
}
if (p_min_bound > p_max_bound) {
SWAP(p_min_bound, p_max_bound);
@ -130,10 +130,10 @@ void SkeletonModification2D::editor_draw_angle_constraints(Bone2D *p_operation_b
float arc_angle_min = p_min_bound;
float arc_angle_max = p_max_bound;
if (arc_angle_min < 0) {
arc_angle_min = (Math_PI * 2) + arc_angle_min;
arc_angle_min = (Math::PI * 2) + arc_angle_min;
}
if (arc_angle_max < 0) {
arc_angle_max = (Math_PI * 2) + arc_angle_max;
arc_angle_max = (Math::PI * 2) + arc_angle_max;
}
if (arc_angle_min > arc_angle_max) {
SWAP(arc_angle_min, arc_angle_max);
@ -159,7 +159,7 @@ void SkeletonModification2D::editor_draw_angle_constraints(Bone2D *p_operation_b
if (p_constraint_inverted) {
stack->skeleton->draw_arc(Vector2(0, 0), p_operation_bone->get_length(),
arc_angle_min + (Math_PI * 2), arc_angle_max, 32, bone_ik_color, 1.0);
arc_angle_min + (Math::PI * 2), arc_angle_max, 32, bone_ik_color, 1.0);
} else {
stack->skeleton->draw_arc(Vector2(0, 0), p_operation_bone->get_length(),
arc_angle_min, arc_angle_max, 32, bone_ik_color, 1.0);
@ -169,7 +169,7 @@ void SkeletonModification2D::editor_draw_angle_constraints(Bone2D *p_operation_b
} else {
stack->skeleton->draw_set_transform(stack->skeleton->to_local(p_operation_bone->get_global_position()));
stack->skeleton->draw_arc(Vector2(0, 0), p_operation_bone->get_length(), 0, Math_PI * 2, 32, bone_ik_color, 1.0);
stack->skeleton->draw_arc(Vector2(0, 0), p_operation_bone->get_length(), 0, Math::PI * 2, 32, bone_ik_color, 1.0);
stack->skeleton->draw_line(Vector2(0, 0), Vector2(1, 0) * p_operation_bone->get_length(), bone_ik_color, 1.0);
}
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKELETON_MODIFICATION_2D_H
#define SKELETON_MODIFICATION_2D_H
#pragma once
#include "scene/resources/2d/skeleton/skeleton_modification_stack_2d.h"
@ -85,5 +84,3 @@ public:
SkeletonModification2D();
};
#endif // SKELETON_MODIFICATION_2D_H

View file

@ -171,13 +171,13 @@ void SkeletonModification2DCCDIK::_execute(float p_delta) {
return;
}
Node2D *target = Object::cast_to<Node2D>(ObjectDB::get_instance(target_node_cache));
Node2D *target = ObjectDB::get_instance<Node2D>(target_node_cache);
if (!target || !target->is_inside_tree()) {
ERR_PRINT_ONCE("Target node is not in the scene tree. Cannot execute modification!");
return;
}
Node2D *tip = Object::cast_to<Node2D>(ObjectDB::get_instance(tip_node_cache));
Node2D *tip = ObjectDB::get_instance<Node2D>(tip_node_cache);
if (!tip || !tip->is_inside_tree()) {
ERR_PRINT_ONCE("Tip node is not in the scene tree. Cannot execute modification!");
return;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKELETON_MODIFICATION_2D_CCDIK_H
#define SKELETON_MODIFICATION_2D_CCDIK_H
#pragma once
#include "scene/2d/skeleton_2d.h"
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
@ -50,7 +49,7 @@ private:
bool enable_constraint = false;
float constraint_angle_min = 0;
float constraint_angle_max = (2.0 * Math_PI);
float constraint_angle_max = (2.0 * Math::PI);
bool constraint_angle_invert = false;
bool constraint_in_localspace = true;
@ -112,5 +111,3 @@ public:
SkeletonModification2DCCDIK();
~SkeletonModification2DCCDIK();
};
#endif // SKELETON_MODIFICATION_2D_CCDIK_H

View file

@ -116,7 +116,7 @@ void SkeletonModification2DFABRIK::_execute(float p_delta) {
return;
}
Node2D *target = Object::cast_to<Node2D>(ObjectDB::get_instance(target_node_cache));
Node2D *target = ObjectDB::get_instance<Node2D>(target_node_cache);
if (!target || !target->is_inside_tree()) {
ERR_PRINT_ONCE("Target node is not in the scene tree. Cannot execute modification!");
return;
@ -128,7 +128,7 @@ void SkeletonModification2DFABRIK::_execute(float p_delta) {
WARN_PRINT("Bone2D cache for origin joint is out of date. Updating...");
}
Bone2D *origin_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[0].bone2d_node_cache));
Bone2D *origin_bone2d_node = ObjectDB::get_instance<Bone2D>(fabrik_data_chain[0].bone2d_node_cache);
if (!origin_bone2d_node || !origin_bone2d_node->is_inside_tree()) {
ERR_PRINT_ONCE("Origin joint's Bone2D node is not in the scene tree. Cannot execute modification!");
return;
@ -146,7 +146,7 @@ void SkeletonModification2DFABRIK::_execute(float p_delta) {
WARN_PRINT_ONCE("Bone2D cache for joint " + itos(i) + " is out of date.. Attempting to update...");
fabrik_joint_update_bone2d_cache(i);
}
Bone2D *joint_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[i].bone2d_node_cache));
Bone2D *joint_bone2d_node = ObjectDB::get_instance<Bone2D>(fabrik_data_chain[i].bone2d_node_cache);
if (!joint_bone2d_node) {
ERR_PRINT_ONCE("FABRIK Joint " + itos(i) + " does not have a Bone2D node set! Cannot execute modification!");
return;
@ -154,7 +154,7 @@ void SkeletonModification2DFABRIK::_execute(float p_delta) {
fabrik_transform_chain.write[i] = joint_bone2d_node->get_global_transform();
}
Bone2D *final_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[fabrik_data_chain.size() - 1].bone2d_node_cache));
Bone2D *final_bone2d_node = ObjectDB::get_instance<Bone2D>(fabrik_data_chain[fabrik_data_chain.size() - 1].bone2d_node_cache);
float final_bone2d_angle = final_bone2d_node->get_global_rotation();
if (fabrik_data_chain[fabrik_data_chain.size() - 1].use_target_rotation) {
final_bone2d_angle = target_global_pose.get_rotation();
@ -183,7 +183,7 @@ void SkeletonModification2DFABRIK::_execute(float p_delta) {
// Apply all of the saved transforms to the Bone2D nodes
for (int i = 0; i < fabrik_data_chain.size(); i++) {
Bone2D *joint_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[i].bone2d_node_cache));
Bone2D *joint_bone2d_node = ObjectDB::get_instance<Bone2D>(fabrik_data_chain[i].bone2d_node_cache);
if (!joint_bone2d_node) {
ERR_PRINT_ONCE("FABRIK Joint " + itos(i) + " does not have a Bone2D node set!");
continue;
@ -214,7 +214,7 @@ void SkeletonModification2DFABRIK::_execute(float p_delta) {
void SkeletonModification2DFABRIK::chain_backwards() {
int final_joint_index = fabrik_data_chain.size() - 1;
Bone2D *final_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[final_joint_index].bone2d_node_cache));
Bone2D *final_bone2d_node = ObjectDB::get_instance<Bone2D>(fabrik_data_chain[final_joint_index].bone2d_node_cache);
Transform2D final_bone2d_trans = fabrik_transform_chain[final_joint_index];
// Apply magnet position
@ -241,7 +241,7 @@ void SkeletonModification2DFABRIK::chain_backwards() {
while (i >= 1) {
Transform2D previous_pose = fabrik_transform_chain[i];
i -= 1;
Bone2D *current_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[i].bone2d_node_cache));
Bone2D *current_bone2d_node = ObjectDB::get_instance<Bone2D>(fabrik_data_chain[i].bone2d_node_cache);
Transform2D current_pose = fabrik_transform_chain[i];
// Apply magnet position
@ -266,7 +266,7 @@ void SkeletonModification2DFABRIK::chain_forwards() {
fabrik_transform_chain.write[0] = origin_bone2d_trans;
for (int i = 0; i < fabrik_data_chain.size() - 1; i++) {
Bone2D *current_bone2d_node = Object::cast_to<Bone2D>(ObjectDB::get_instance(fabrik_data_chain[i].bone2d_node_cache));
Bone2D *current_bone2d_node = ObjectDB::get_instance<Bone2D>(fabrik_data_chain[i].bone2d_node_cache);
Transform2D current_pose = fabrik_transform_chain[i];
Transform2D next_pose = fabrik_transform_chain[i + 1];

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKELETON_MODIFICATION_2D_FABRIK_H
#define SKELETON_MODIFICATION_2D_FABRIK_H
#pragma once
#include "scene/2d/skeleton_2d.h"
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
@ -104,5 +103,3 @@ public:
SkeletonModification2DFABRIK();
~SkeletonModification2DFABRIK();
};
#endif // SKELETON_MODIFICATION_2D_FABRIK_H

View file

@ -143,7 +143,7 @@ void SkeletonModification2DJiggle::_execute(float p_delta) {
update_target_cache();
return;
}
Node2D *target = Object::cast_to<Node2D>(ObjectDB::get_instance(target_node_cache));
Node2D *target = ObjectDB::get_instance<Node2D>(target_node_cache);
if (!target || !target->is_inside_tree()) {
ERR_PRINT_ONCE("Target node is not in the scene tree. Cannot execute modification!");
return;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKELETON_MODIFICATION_2D_JIGGLE_H
#define SKELETON_MODIFICATION_2D_JIGGLE_H
#pragma once
#include "scene/2d/skeleton_2d.h"
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
@ -135,5 +134,3 @@ public:
SkeletonModification2DJiggle();
~SkeletonModification2DJiggle();
};
#endif // SKELETON_MODIFICATION_2D_JIGGLE_H

View file

@ -124,7 +124,7 @@ void SkeletonModification2DLookAt::_execute(float p_delta) {
}
if (target_node_reference == nullptr) {
target_node_reference = Object::cast_to<Node2D>(ObjectDB::get_instance(target_node_cache));
target_node_reference = ObjectDB::get_instance<Node2D>(target_node_cache);
}
if (!target_node_reference || !target_node_reference->is_inside_tree()) {
ERR_PRINT_ONCE("Target node is not in the scene tree. Cannot execute modification!");
@ -399,7 +399,7 @@ SkeletonModification2DLookAt::SkeletonModification2DLookAt() {
additional_rotation = 0;
enable_constraint = false;
constraint_angle_min = 0;
constraint_angle_max = Math_PI * 2;
constraint_angle_max = Math::PI * 2;
constraint_angle_invert = false;
enabled = true;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKELETON_MODIFICATION_2D_LOOKAT_H
#define SKELETON_MODIFICATION_2D_LOOKAT_H
#pragma once
#include "scene/2d/skeleton_2d.h"
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
@ -53,7 +52,7 @@ private:
float additional_rotation = 0;
bool enable_constraint = false;
float constraint_angle_min = 0;
float constraint_angle_max = (2.0 * Math_PI);
float constraint_angle_max = (2.0 * Math::PI);
bool constraint_angle_invert = false;
bool constraint_in_localspace = true;
@ -96,5 +95,3 @@ public:
SkeletonModification2DLookAt();
~SkeletonModification2DLookAt();
};
#endif // SKELETON_MODIFICATION_2D_LOOKAT_H

View file

@ -118,7 +118,7 @@ void SkeletonModification2DPhysicalBones::_execute(float p_delta) {
continue;
}
PhysicalBone2D *physical_bone = Object::cast_to<PhysicalBone2D>(ObjectDB::get_instance(bone_data.physical_bone_node_cache));
PhysicalBone2D *physical_bone = ObjectDB::get_instance<PhysicalBone2D>(bone_data.physical_bone_node_cache);
if (!physical_bone) {
ERR_PRINT_ONCE("PhysicalBone2D not found at index " + itos(i) + "!");
return;
@ -238,7 +238,7 @@ void SkeletonModification2DPhysicalBones::_update_simulation_state() {
}
_simulation_state_dirty = false;
if (_simulation_state_dirty_names.size() <= 0) {
if (_simulation_state_dirty_names.is_empty()) {
for (int i = 0; i < physical_bone_chain.size(); i++) {
PhysicalBone2D *physical_bone = Object::cast_to<PhysicalBone2D>(stack->skeleton->get_node(physical_bone_chain[i].physical_bone_node));
if (!physical_bone) {
@ -249,7 +249,7 @@ void SkeletonModification2DPhysicalBones::_update_simulation_state() {
}
} else {
for (int i = 0; i < physical_bone_chain.size(); i++) {
PhysicalBone2D *physical_bone = Object::cast_to<PhysicalBone2D>(ObjectDB::get_instance(physical_bone_chain[i].physical_bone_node_cache));
PhysicalBone2D *physical_bone = ObjectDB::get_instance<PhysicalBone2D>(physical_bone_chain[i].physical_bone_node_cache);
if (!physical_bone) {
continue;
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKELETON_MODIFICATION_2D_PHYSICALBONES_H
#define SKELETON_MODIFICATION_2D_PHYSICALBONES_H
#pragma once
#include "scene/2d/skeleton_2d.h"
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
@ -78,5 +77,3 @@ public:
SkeletonModification2DPhysicalBones();
~SkeletonModification2DPhysicalBones();
};
#endif // SKELETON_MODIFICATION_2D_PHYSICALBONES_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKELETON_MODIFICATION_2D_STACKHOLDER_H
#define SKELETON_MODIFICATION_2D_STACKHOLDER_H
#pragma once
#include "scene/2d/skeleton_2d.h"
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
@ -60,5 +59,3 @@ public:
SkeletonModification2DStackHolder();
~SkeletonModification2DStackHolder();
};
#endif // SKELETON_MODIFICATION_2D_STACKHOLDER_H

View file

@ -124,7 +124,7 @@ void SkeletonModification2DTwoBoneIK::_execute(float p_delta) {
update_joint_two_bone2d_cache();
}
Node2D *target = Object::cast_to<Node2D>(ObjectDB::get_instance(target_node_cache));
Node2D *target = ObjectDB::get_instance<Node2D>(target_node_cache);
if (!target || !target->is_inside_tree()) {
ERR_PRINT_ONCE("Target node is not in the scene tree. Cannot execute modification!");
return;
@ -178,7 +178,7 @@ void SkeletonModification2DTwoBoneIK::_execute(float p_delta) {
// We cannot solve for this angle! Do nothing to avoid setting the rotation (and scale) to NaN.
} else {
joint_one_bone->set_global_rotation(angle_atan - angle_0 - joint_one_bone->get_bone_angle());
joint_two_bone->set_rotation(-Math_PI - angle_1 - joint_two_bone->get_bone_angle() + joint_one_bone->get_bone_angle());
joint_two_bone->set_rotation(-Math::PI - angle_1 - joint_two_bone->get_bone_angle() + joint_one_bone->get_bone_angle());
}
} else {
joint_one_bone->set_global_rotation(angle_atan - joint_one_bone->get_bone_angle());
@ -221,10 +221,10 @@ void SkeletonModification2DTwoBoneIK::_draw_editor_gizmo() {
#endif // TOOLS_ENABLED
if (flip_bend_direction) {
float angle = -(Math_PI * 0.5) + operation_bone_one->get_bone_angle();
float angle = -(Math::PI * 0.5) + operation_bone_one->get_bone_angle();
stack->skeleton->draw_line(Vector2(0, 0), Vector2(Math::cos(angle), sin(angle)) * (operation_bone_one->get_length() * 0.5), bone_ik_color, 2.0);
} else {
float angle = (Math_PI * 0.5) + operation_bone_one->get_bone_angle();
float angle = (Math::PI * 0.5) + operation_bone_one->get_bone_angle();
stack->skeleton->draw_line(Vector2(0, 0), Vector2(Math::cos(angle), sin(angle)) * (operation_bone_one->get_length() * 0.5), bone_ik_color, 2.0);
}
@ -235,7 +235,7 @@ void SkeletonModification2DTwoBoneIK::_draw_editor_gizmo() {
Vector2 target_direction = Vector2(0, 1);
if (target_node_cache.is_valid()) {
stack->skeleton->draw_set_transform(Vector2(0, 0), 0.0);
Node2D *target = Object::cast_to<Node2D>(ObjectDB::get_instance(target_node_cache));
Node2D *target = ObjectDB::get_instance<Node2D>(target_node_cache);
target_direction = operation_bone_one->get_global_position().direction_to(target->get_global_position());
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKELETON_MODIFICATION_2D_TWOBONEIK_H
#define SKELETON_MODIFICATION_2D_TWOBONEIK_H
#pragma once
#include "scene/2d/skeleton_2d.h"
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h"
@ -103,5 +102,3 @@ public:
SkeletonModification2DTwoBoneIK();
~SkeletonModification2DTwoBoneIK();
};
#endif // SKELETON_MODIFICATION_2D_TWOBONEIK_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKELETON_MODIFICATION_STACK_2D_H
#define SKELETON_MODIFICATION_STACK_2D_H
#pragma once
#include "core/io/resource.h"
@ -94,5 +93,3 @@ public:
SkeletonModificationStack2D();
};
#endif // SKELETON_MODIFICATION_STACK_2D_H

View file

@ -32,16 +32,20 @@
#include "tile_set.h"
#ifndef NAVIGATION_2D_DISABLED
Ref<NavigationPolygon> TileData::_get_navigation_polygon_bind_compat_84660(int p_layer_id) const {
return get_navigation_polygon(p_layer_id, false, false, false);
}
#endif // NAVIGATION_2D_DISABLED
Ref<OccluderPolygon2D> TileData::_get_occluder_bind_compat_84660(int p_layer_id) const {
return get_occluder_polygon(p_layer_id, 0, false, false, false);
}
void TileData::_bind_compatibility_methods() {
#ifndef NAVIGATION_2D_DISABLED
ClassDB::bind_compatibility_method(D_METHOD("get_navigation_polygon"), &TileData::_get_navigation_polygon_bind_compat_84660);
#endif // NAVIGATION_2D_DISABLED
ClassDB::bind_compatibility_method(D_METHOD("get_occluder"), &TileData::_get_occluder_bind_compat_84660);
}

View file

@ -37,7 +37,10 @@
#include "core/templates/rb_set.h"
#include "scene/gui/control.h"
#include "scene/resources/image_texture.h"
#ifndef NAVIGATION_2D_DISABLED
#include "servers/navigation_server_2d.h"
#endif // NAVIGATION_2D_DISABLED
/////////////////////////////// TileMapPattern //////////////////////////////////////
@ -305,8 +308,7 @@ void TileSet::TerrainsPattern::from_array(Array p_terrains) {
}
Array TileSet::TerrainsPattern::as_array() const {
Array output;
output.push_back(get_terrain());
Array output = { get_terrain() };
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
if (is_valid_bit[i]) {
output.push_back(bits[i]);
@ -636,6 +638,7 @@ bool TileSet::get_occlusion_layer_sdf_collision(int p_layer_index) const {
return occlusion_layers[p_layer_index].sdf_collision;
}
#ifndef PHYSICS_2D_DISABLED
int TileSet::get_physics_layers_count() const {
return physics_layers.size();
}
@ -719,6 +722,7 @@ Ref<PhysicsMaterial> TileSet::get_physics_layer_physics_material(int p_layer_ind
ERR_FAIL_INDEX_V(p_layer_index, physics_layers.size(), Ref<PhysicsMaterial>());
return physics_layers[p_layer_index].physics_material;
}
#endif // PHYSICS_2D_DISABLED
// Terrains
int TileSet::get_terrain_sets_count() const {
@ -964,6 +968,7 @@ bool TileSet::is_valid_terrain_peering_bit(int p_terrain_set, TileSet::CellNeigh
return is_valid_terrain_peering_bit_for_mode(terrain_mode, p_peering_bit);
}
#ifndef NAVIGATION_2D_DISABLED
// Navigation
int TileSet::get_navigation_layers_count() const {
return navigation_layers.size();
@ -1038,6 +1043,7 @@ bool TileSet::get_navigation_layer_layer_value(int p_layer_index, int p_layer_nu
return get_navigation_layer_layers(p_layer_index) & (1 << (p_layer_number - 1));
}
#endif // NAVIGATION_2D_DISABLED
// Custom data.
int TileSet::get_custom_data_layers_count() const {
@ -1177,42 +1183,26 @@ void TileSet::set_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_f
ERR_FAIL_COND(p_source_from == TileSet::INVALID_SOURCE || p_source_to == TileSet::INVALID_SOURCE);
ERR_FAIL_COND(p_coords_from == TileSetSource::INVALID_ATLAS_COORDS || p_coords_to == TileSetSource::INVALID_ATLAS_COORDS);
Array from;
from.push_back(p_source_from);
from.push_back(p_coords_from);
Array to;
to.push_back(p_source_to);
to.push_back(p_coords_to);
Array from = { p_source_from, p_coords_from };
Array to = { p_source_to, p_coords_to };
coords_level_proxies[from] = to;
emit_changed();
}
Array TileSet::get_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from) {
Array from;
from.push_back(p_source_from);
from.push_back(p_coords_from);
Array from = { p_source_from, p_coords_from };
ERR_FAIL_COND_V(!coords_level_proxies.has(from), Array());
return coords_level_proxies[from];
}
bool TileSet::has_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from) {
Array from;
from.push_back(p_source_from);
from.push_back(p_coords_from);
Array from = { p_source_from, p_coords_from };
return coords_level_proxies.has(from);
}
void TileSet::remove_coords_level_tile_proxy(int p_source_from, Vector2i p_coords_from) {
Array from;
from.push_back(p_source_from);
from.push_back(p_coords_from);
Array from = { p_source_from, p_coords_from };
ERR_FAIL_COND(!coords_level_proxies.has(from));
coords_level_proxies.erase(from);
@ -1224,47 +1214,27 @@ void TileSet::set_alternative_level_tile_proxy(int p_source_from, Vector2i p_coo
ERR_FAIL_COND(p_source_from == TileSet::INVALID_SOURCE || p_source_to == TileSet::INVALID_SOURCE);
ERR_FAIL_COND(p_coords_from == TileSetSource::INVALID_ATLAS_COORDS || p_coords_to == TileSetSource::INVALID_ATLAS_COORDS);
Array from;
from.push_back(p_source_from);
from.push_back(p_coords_from);
from.push_back(p_alternative_from);
Array to;
to.push_back(p_source_to);
to.push_back(p_coords_to);
to.push_back(p_alternative_to);
Array from = { p_source_from, p_coords_from, p_alternative_from };
Array to = { p_source_to, p_coords_to, p_alternative_to };
alternative_level_proxies[from] = to;
emit_changed();
}
Array TileSet::get_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) {
Array from;
from.push_back(p_source_from);
from.push_back(p_coords_from);
from.push_back(p_alternative_from);
Array from = { p_source_from, p_coords_from, p_alternative_from };
ERR_FAIL_COND_V(!alternative_level_proxies.has(from), Array());
return alternative_level_proxies[from];
}
bool TileSet::has_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) {
Array from;
from.push_back(p_source_from);
from.push_back(p_coords_from);
from.push_back(p_alternative_from);
Array from = { p_source_from, p_coords_from, p_alternative_from };
return alternative_level_proxies.has(from);
}
void TileSet::remove_alternative_level_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) {
Array from;
from.push_back(p_source_from);
from.push_back(p_coords_from);
from.push_back(p_alternative_from);
Array from = { p_source_from, p_coords_from, p_alternative_from };
ERR_FAIL_COND(!alternative_level_proxies.has(from));
alternative_level_proxies.erase(from);
@ -1306,10 +1276,7 @@ Array TileSet::get_alternative_level_tile_proxies() const {
}
Array TileSet::map_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_alternative_from) const {
Array from;
from.push_back(p_source_from);
from.push_back(p_coords_from);
from.push_back(p_alternative_from);
Array from = { p_source_from, p_coords_from, p_alternative_from };
// Check if the tile is valid, and if so, don't map the tile and return the input.
if (has_source(p_source_from)) {
@ -1334,17 +1301,11 @@ Array TileSet::map_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_a
// Source matches.
if (source_level_proxies.has(p_source_from)) {
Array output;
output.push_back(source_level_proxies[p_source_from]);
output.push_back(p_coords_from);
output.push_back(p_alternative_from);
Array output = { source_level_proxies[p_source_from], p_coords_from, p_alternative_from };
return output;
}
Array output;
output.push_back(p_source_from);
output.push_back(p_coords_from);
output.push_back(p_alternative_from);
Array output = { p_source_from, p_coords_from, p_alternative_from };
return output;
}
@ -3238,8 +3199,10 @@ void TileSet::reset_state() {
tile_filled_mesh.instantiate();
tile_meshes_dirty = true;
#ifndef PHYSICS_2D_DISABLED
// Physics
physics_layers.clear();
#endif // PHYSICS_2D_DISABLED
// Terrains
terrain_sets.clear();
@ -3423,15 +3386,8 @@ void TileSet::_compatibility_conversion() {
}
// Add to the mapping.
Array key_array;
key_array.push_back(flip_h);
key_array.push_back(flip_v);
key_array.push_back(transpose);
Array value_array;
value_array.push_back(source_id);
value_array.push_back(coords);
value_array.push_back(alternative_tile);
Array key_array = { flip_h, flip_v, transpose };
Array value_array = { source_id, coords, alternative_tile };
if (!compatibility_tilemap_mapping.has(E.key)) {
compatibility_tilemap_mapping[E.key] = RBMap<Array, Array>();
@ -3462,6 +3418,7 @@ void TileSet::_compatibility_conversion() {
tile_data->add_occluder_polygon(0);
tile_data->set_occluder_polygon(0, 0, occluder);
}
#ifndef NAVIGATION_2D_DISABLED
if (ctd->navigation.is_valid()) {
if (get_navigation_layers_count() < 1) {
add_navigation_layer();
@ -3474,9 +3431,11 @@ void TileSet::_compatibility_conversion() {
navigation->set_vertices(vertices);
tile_data->set_navigation_polygon(0, navigation);
}
#endif // NAVIGATION_2D_DISABLED
tile_data->set_z_index(ctd->z_index);
#ifndef PHYSICS_2D_DISABLED
// Add the shapes.
if (ctd->shapes.size() > 0) {
if (get_physics_layers_count() < 1) {
@ -3500,6 +3459,7 @@ void TileSet::_compatibility_conversion() {
}
}
}
#endif // PHYSICS_2D_DISABLED
}
// Update the size count.
if (!compatibility_size_count.has(ctd->region.get_size())) {
@ -3539,16 +3499,8 @@ void TileSet::_compatibility_conversion() {
}
// Add to the mapping.
Array key_array;
key_array.push_back(coords);
key_array.push_back(flip_h);
key_array.push_back(flip_v);
key_array.push_back(transpose);
Array value_array;
value_array.push_back(source_id);
value_array.push_back(coords);
value_array.push_back(alternative_tile);
Array key_array = { coords, flip_h, flip_v, transpose };
Array value_array = { source_id, coords, alternative_tile };
if (!compatibility_tilemap_mapping.has(E.key)) {
compatibility_tilemap_mapping[E.key] = RBMap<Array, Array>();
@ -3577,6 +3529,7 @@ void TileSet::_compatibility_conversion() {
tile_data->add_occluder_polygon(0);
tile_data->set_occluder_polygon(0, 0, occluder);
}
#ifndef NAVIGATION_2D_DISABLED
if (ctd->autotile_navpoly_map.has(coords)) {
if (get_navigation_layers_count() < 1) {
add_navigation_layer();
@ -3589,6 +3542,7 @@ void TileSet::_compatibility_conversion() {
navigation->set_vertices(vertices);
tile_data->set_navigation_polygon(0, navigation);
}
#endif // NAVIGATION_2D_DISABLED
if (ctd->autotile_priority_map.has(coords)) {
tile_data->set_probability(ctd->autotile_priority_map[coords]);
}
@ -3596,6 +3550,7 @@ void TileSet::_compatibility_conversion() {
tile_data->set_z_index(ctd->autotile_z_index_map[coords]);
}
#ifndef PHYSICS_2D_DISABLED
// Add the shapes.
if (ctd->shapes.size() > 0) {
if (get_physics_layers_count() < 1) {
@ -3619,6 +3574,7 @@ void TileSet::_compatibility_conversion() {
}
}
}
#endif // PHYSICS_2D_DISABLED
// -- TODO: handle --
// Those are offset for the whole atlas, they are likely useless for the atlases, but might make sense for single tiles.
@ -3641,6 +3597,7 @@ void TileSet::_compatibility_conversion() {
} break;
}
#ifndef PHYSICS_2D_DISABLED
// Offset all shapes
for (int k = 0; k < ctd->shapes.size(); k++) {
Ref<ConvexPolygonShape2D> convex = ctd->shapes[k].shape;
@ -3652,6 +3609,7 @@ void TileSet::_compatibility_conversion() {
convex->set_points(points);
}
}
#endif // PHYSICS_2D_DISABLED
}
// Update the TileSet tile_size according to the most common size found.
@ -3673,10 +3631,11 @@ void TileSet::_compatibility_conversion() {
}
Array TileSet::compatibility_tilemap_map(int p_tile_id, Vector2i p_coords, bool p_flip_h, bool p_flip_v, bool p_transpose) {
Array cannot_convert_array;
cannot_convert_array.push_back(TileSet::INVALID_SOURCE);
cannot_convert_array.push_back(TileSetAtlasSource::INVALID_ATLAS_COORDS);
cannot_convert_array.push_back(TileSetAtlasSource::INVALID_TILE_ALTERNATIVE);
Array cannot_convert_array = {
TileSet::INVALID_SOURCE,
TileSetAtlasSource::INVALID_ATLAS_COORDS,
TileSetAtlasSource::INVALID_TILE_ALTERNATIVE
};
if (!compatibility_tilemap_mapping.has(p_tile_id)) {
return cannot_convert_array;
@ -3685,21 +3644,14 @@ Array TileSet::compatibility_tilemap_map(int p_tile_id, Vector2i p_coords, bool
int tile_mode = compatibility_tilemap_mapping_tile_modes[p_tile_id];
switch (tile_mode) {
case COMPATIBILITY_TILE_MODE_SINGLE_TILE: {
Array a;
a.push_back(p_flip_h);
a.push_back(p_flip_v);
a.push_back(p_transpose);
Array a = { p_flip_h, p_flip_v, p_transpose };
return compatibility_tilemap_mapping[p_tile_id][a];
}
case COMPATIBILITY_TILE_MODE_AUTO_TILE:
return cannot_convert_array;
break;
case COMPATIBILITY_TILE_MODE_ATLAS_TILE: {
Array a;
a.push_back(p_coords);
a.push_back(p_flip_h);
a.push_back(p_flip_v);
a.push_back(p_transpose);
Array a = { p_coords, p_flip_h, p_flip_v, p_transpose };
return compatibility_tilemap_mapping[p_tile_id][a];
}
default:
@ -3789,7 +3741,9 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
if (p[0].get_type() == Variant::VECTOR2) {
last_coord = p[0];
} else if (p[0].get_type() == Variant::OBJECT) {
#ifndef NAVIGATION_2D_DISABLED
ctd->autotile_navpoly_map.insert(last_coord, p[0]);
#endif // NAVIGATION_2D_DISABLED
}
p.pop_front();
}
@ -3830,18 +3784,20 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
for (int i = 0; i < p.size(); i++) {
CompatibilityShapeData csd;
Dictionary d = p[i];
for (int j = 0; j < d.size(); j++) {
String key = d.get_key_at_index(j);
for (const KeyValue<Variant, Variant> &kv : d) {
String key = kv.key;
if (key == "autotile_coord") {
csd.autotile_coords = d[key];
csd.autotile_coords = kv.value;
} else if (key == "one_way") {
csd.one_way = d[key];
csd.one_way = kv.value;
} else if (key == "one_way_margin") {
csd.one_way_margin = d[key];
csd.one_way_margin = kv.value;
} else if (key == "shape") {
csd.shape = d[key];
#ifndef PHYSICS_2D_DISABLED
csd.shape = kv.value;
#endif // PHYSICS_2D_DISABLED
} else if (key == "shape_transform") {
csd.transform = d[key];
csd.transform = kv.value;
}
}
ctd->shapes.push_back(csd);
@ -3849,7 +3805,9 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
} else if (what == "occluder") {
ctd->occluder = p_value;
} else if (what == "navigation") {
#ifndef NAVIGATION_2D_DISABLED
ctd->navigation = p_value;
#endif // NAVIGATION_2D_DISABLED
/*
// IGNORED FOR NOW, they seem duplicated data compared to the shapes array
@ -3897,6 +3855,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
set_occlusion_layer_sdf_collision(index, p_value);
return true;
}
#ifndef PHYSICS_2D_DISABLED
} else if (components.size() == 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
// Physics layers.
int index = components[0].trim_prefix("physics_layer_").to_int();
@ -3930,6 +3889,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
set_physics_layer_physics_material(index, physics_material);
return true;
}
#endif // PHYSICS_2D_DISABLED
} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int()) {
// Terrains.
int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int();
@ -3966,6 +3926,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
}
}
} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
#ifndef NAVIGATION_2D_DISABLED
// Navigation layers.
int index = components[0].trim_prefix("navigation_layer_").to_int();
ERR_FAIL_COND_V(index < 0, false);
@ -3977,6 +3938,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
set_navigation_layer_layers(index, p_value);
return true;
}
#endif // NAVIGATION_2D_DISABLED
} else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_int()) {
// Custom data layers.
int index = components[0].trim_prefix("custom_data_layer_").to_int();
@ -4061,6 +4023,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_occlusion_layer_sdf_collision(index);
return true;
}
#ifndef PHYSICS_2D_DISABLED
} else if (components.size() == 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
// Physics layers.
int index = components[0].trim_prefix("physics_layer_").to_int();
@ -4080,6 +4043,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_physics_layer_physics_material(index);
return true;
}
#endif // PHYSICS_2D_DISABLED
} else if (components.size() >= 2 && components[0].begins_with("terrain_set_") && components[0].trim_prefix("terrain_set_").is_valid_int()) {
// Terrains.
int terrain_set_index = components[0].trim_prefix("terrain_set_").to_int();
@ -4108,10 +4072,12 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
if (index < 0 || index >= navigation_layers.size()) {
return false;
}
#ifndef NAVIGATION_2D_DISABLED
if (components[1] == "layers") {
r_ret = get_navigation_layer_layers(index);
return true;
}
#endif // NAVIGATION_2D_DISABLED
} else if (components.size() == 2 && components[0].begins_with("custom_data_layer_") && components[0].trim_prefix("custom_data_layer_").is_valid_int()) {
// Custom data layers.
int index = components[0].trim_prefix("custom_data_layer_").to_int();
@ -4189,6 +4155,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(property_info);
}
#ifndef PHYSICS_2D_DISABLED
// Physics.
p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Physics", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
for (int i = 0; i < physics_layers.size(); i++) {
@ -4215,6 +4182,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
}
p_list->push_back(property_info);
}
#endif // PHYSICS_2D_DISABLED
// Terrains.
p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Terrains", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
@ -4310,6 +4278,7 @@ void TileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_occlusion_layer_sdf_collision", "layer_index", "sdf_collision"), &TileSet::set_occlusion_layer_sdf_collision);
ClassDB::bind_method(D_METHOD("get_occlusion_layer_sdf_collision", "layer_index"), &TileSet::get_occlusion_layer_sdf_collision);
#ifndef PHYSICS_2D_DISABLED
// Physics
ClassDB::bind_method(D_METHOD("get_physics_layers_count"), &TileSet::get_physics_layers_count);
ClassDB::bind_method(D_METHOD("add_physics_layer", "to_position"), &TileSet::add_physics_layer, DEFVAL(-1));
@ -4323,6 +4292,7 @@ void TileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_physics_layer_collision_priority", "layer_index"), &TileSet::get_physics_layer_collision_priority);
ClassDB::bind_method(D_METHOD("set_physics_layer_physics_material", "layer_index", "physics_material"), &TileSet::set_physics_layer_physics_material);
ClassDB::bind_method(D_METHOD("get_physics_layer_physics_material", "layer_index"), &TileSet::get_physics_layer_physics_material);
#endif // PHYSICS_2D_DISABLED
// Terrains
ClassDB::bind_method(D_METHOD("get_terrain_sets_count"), &TileSet::get_terrain_sets_count);
@ -4341,6 +4311,7 @@ void TileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_terrain_color", "terrain_set", "terrain_index", "color"), &TileSet::set_terrain_color);
ClassDB::bind_method(D_METHOD("get_terrain_color", "terrain_set", "terrain_index"), &TileSet::get_terrain_color);
#ifndef NAVIGATION_2D_DISABLED
// Navigation
ClassDB::bind_method(D_METHOD("get_navigation_layers_count"), &TileSet::get_navigation_layers_count);
ClassDB::bind_method(D_METHOD("add_navigation_layer", "to_position"), &TileSet::add_navigation_layer, DEFVAL(-1));
@ -4350,6 +4321,7 @@ void TileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_navigation_layer_layers", "layer_index"), &TileSet::get_navigation_layer_layers);
ClassDB::bind_method(D_METHOD("set_navigation_layer_layer_value", "layer_index", "layer_number", "value"), &TileSet::set_navigation_layer_layer_value);
ClassDB::bind_method(D_METHOD("get_navigation_layer_layer_value", "layer_index", "layer_number"), &TileSet::get_navigation_layer_layer_value);
#endif // NAVIGATION_2D_DISABLED
// Custom data
ClassDB::bind_method(D_METHOD("get_custom_data_layers_count"), &TileSet::get_custom_data_layers_count);
@ -4397,7 +4369,9 @@ void TileSet::_bind_methods() {
ADD_GROUP("", "");
ADD_ARRAY("physics_layers", "physics_layer_");
ADD_ARRAY("terrain_sets", "terrain_set_");
#ifndef NAVIGATION_2D_DISABLED
ADD_ARRAY("navigation_layers", "navigation_layer_");
#endif // NAVIGATION_2D_DISABLED
ADD_ARRAY("custom_data_layers", "custom_data_layer_");
// -- Enum binding --
@ -4531,6 +4505,7 @@ void TileSetAtlasSource::remove_occlusion_layer(int p_index) {
}
}
#ifndef PHYSICS_2D_DISABLED
void TileSetAtlasSource::add_physics_layer(int p_to_pos) {
for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) {
for (KeyValue<int, TileData *> E_alternative : E_tile.value.alternatives) {
@ -4554,6 +4529,7 @@ void TileSetAtlasSource::remove_physics_layer(int p_index) {
}
}
}
#endif // PHYSICS_2D_DISABLED
void TileSetAtlasSource::add_terrain_set(int p_to_pos) {
for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) {
@ -4603,6 +4579,7 @@ void TileSetAtlasSource::remove_terrain(int p_terrain_set, int p_index) {
}
}
#ifndef NAVIGATION_2D_DISABLED
void TileSetAtlasSource::add_navigation_layer(int p_to_pos) {
for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) {
for (KeyValue<int, TileData *> E_alternative : E_tile.value.alternatives) {
@ -4626,6 +4603,7 @@ void TileSetAtlasSource::remove_navigation_layer(int p_index) {
}
}
}
#endif // NAVIGATION_2D_DISABLED
void TileSetAtlasSource::add_custom_data_layer(int p_to_pos) {
for (KeyValue<Vector2i, TileAlternativesData> E_tile : tiles) {
@ -5969,13 +5947,17 @@ void TileData::notify_tile_data_properties_should_change() {
}
occluders.resize(tile_set->get_occlusion_layers_count());
#ifndef PHYSICS_2D_DISABLED
physics.resize(tile_set->get_physics_layers_count());
#endif // PHYSICS_2D_DISABLED
for (int bit_index = 0; bit_index < 16; bit_index++) {
if (terrain_set < 0 || terrain_peering_bits[bit_index] >= tile_set->get_terrains_count(terrain_set)) {
terrain_peering_bits[bit_index] = -1;
}
}
#ifndef NAVIGATION_2D_DISABLED
navigation.resize(tile_set->get_navigation_layers_count());
#endif // NAVIGATION_2D_DISABLED
// Convert custom data to the new type.
custom_data.resize(tile_set->get_custom_data_layers_count());
@ -6017,6 +5999,7 @@ void TileData::remove_occlusion_layer(int p_index) {
occluders.remove_at(p_index);
}
#ifndef PHYSICS_2D_DISABLED
void TileData::add_physics_layer(int p_to_pos) {
if (p_to_pos < 0) {
p_to_pos = physics.size();
@ -6036,6 +6019,7 @@ void TileData::remove_physics_layer(int p_index) {
ERR_FAIL_INDEX(p_index, physics.size());
physics.remove_at(p_index);
}
#endif // PHYSICS_2D_DISABLED
void TileData::add_terrain_set(int p_to_pos) {
if (p_to_pos >= 0 && p_to_pos <= terrain_set) {
@ -6112,6 +6096,7 @@ void TileData::remove_terrain(int p_terrain_set, int p_index) {
}
}
#ifndef NAVIGATION_2D_DISABLED
void TileData::add_navigation_layer(int p_to_pos) {
if (p_to_pos < 0) {
p_to_pos = navigation.size();
@ -6131,6 +6116,7 @@ void TileData::remove_navigation_layer(int p_index) {
ERR_FAIL_INDEX(p_index, navigation.size());
navigation.remove_at(p_index);
}
#endif // NAVIGATION_2D_DISABLED
void TileData::add_custom_data_layer(int p_to_pos) {
if (p_to_pos < 0) {
@ -6176,13 +6162,17 @@ TileData *TileData::duplicate() {
output->z_index = z_index;
output->y_sort_origin = y_sort_origin;
output->occluders = occluders;
#ifndef PHYSICS_2D_DISABLED
// Physics
output->physics = physics;
#endif // PHYSICS_2D_DISABLED
// Terrain
output->terrain_set = -1;
memcpy(output->terrain_peering_bits, terrain_peering_bits, 16 * sizeof(int));
#ifndef NAVIGATION_2D_DISABLED
// Navigation
output->navigation = navigation;
#endif // NAVIGATION_2D_DISABLED
// Misc
output->probability = probability;
// Custom data
@ -6347,6 +6337,7 @@ Ref<OccluderPolygon2D> TileData::get_occluder_polygon(int p_layer_id, int p_poly
}
}
#ifndef PHYSICS_2D_DISABLED
// Physics
void TileData::set_constant_linear_velocity(int p_layer_id, const Vector2 &p_velocity) {
ERR_FAIL_INDEX(p_layer_id, physics.size());
@ -6495,6 +6486,7 @@ Ref<ConvexPolygonShape2D> TileData::get_collision_polygon_shape(int p_layer_id,
return I->value[shape_index];
}
}
#endif // PHYSICS_2D_DISABLED
// Terrain
void TileData::set_terrain_set(int p_terrain_set) {
@ -6568,6 +6560,7 @@ TileSet::TerrainsPattern TileData::get_terrains_pattern() const {
return output;
}
#ifndef NAVIGATION_2D_DISABLED
// Navigation
void TileData::set_navigation_polygon(int p_layer_id, Ref<NavigationPolygon> p_navigation_polygon) {
ERR_FAIL_INDEX(p_layer_id, navigation.size());
@ -6615,6 +6608,7 @@ Ref<NavigationPolygon> TileData::get_navigation_polygon(int p_layer_id, bool p_f
return I->value;
}
}
#endif // NAVIGATION_2D_DISABLED
// Misc
void TileData::set_probability(float p_probability) {
@ -6743,7 +6737,9 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
return true;
}
}
} else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
}
#ifndef PHYSICS_2D_DISABLED
else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
// Physics layers.
int layer_index = components[0].trim_prefix("physics_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false);
@ -6798,7 +6794,10 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
return true;
}
}
} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
}
#endif // PHYSICS_2D_DISABLED
#ifndef NAVIGATION_2D_DISABLED
else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
// Navigation layers.
int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false);
@ -6815,7 +6814,9 @@ bool TileData::_set(const StringName &p_name, const Variant &p_value) {
set_navigation_polygon(layer_index, polygon);
return true;
}
} else if (components.size() == 2 && components[0] == "terrains_peering_bit") {
}
#endif // NAVIGATION_2D_DISABLED
else if (components.size() == 2 && components[0] == "terrains_peering_bit") {
// Terrains.
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
@ -6887,7 +6888,9 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
return true;
}
}
} else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
}
#ifndef PHYSICS_2D_DISABLED
else if (components.size() >= 2 && components[0].begins_with("physics_layer_") && components[0].trim_prefix("physics_layer_").is_valid_int()) {
// Physics layers.
int layer_index = components[0].trim_prefix("physics_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false);
@ -6923,7 +6926,9 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
return true;
}
}
} else if (components.size() == 2 && components[0] == "terrains_peering_bit") {
}
#endif // PHYSICS_2D_DISABLED
else if (components.size() == 2 && components[0] == "terrains_peering_bit") {
// Terrains.
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
if (components[1] == TileSet::CELL_NEIGHBOR_ENUM_TO_TEXT[i]) {
@ -6932,7 +6937,9 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
}
}
return false;
} else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
}
#ifndef NAVIGATION_2D_DISABLED
else if (components.size() == 2 && components[0].begins_with("navigation_layer_") && components[0].trim_prefix("navigation_layer_").is_valid_int()) {
// Occlusion layers.
int layer_index = components[0].trim_prefix("navigation_layer_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false);
@ -6943,7 +6950,9 @@ bool TileData::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_navigation_polygon(layer_index);
return true;
}
} else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
}
#endif // NAVIGATION_2D_DISABLED
else if (components.size() == 1 && components[0].begins_with("custom_data_") && components[0].trim_prefix("custom_data_").is_valid_int()) {
// Custom data layers.
int layer_index = components[0].trim_prefix("custom_data_").to_int();
ERR_FAIL_COND_V(layer_index < 0, false);
@ -6976,6 +6985,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
}
}
#ifndef PHYSICS_2D_DISABLED
// Physics layers.
p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Physics", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
for (int i = 0; i < physics.size(); i++) {
@ -7018,6 +7028,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(property_info);
}
}
#endif // PHYSICS_2D_DISABLED
// Terrain data
if (terrain_set >= 0) {
@ -7034,6 +7045,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
}
}
#ifndef NAVIGATION_2D_DISABLED
// Navigation layers.
p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Navigation", ""), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP));
for (int i = 0; i < navigation.size(); i++) {
@ -7043,6 +7055,7 @@ void TileData::_get_property_list(List<PropertyInfo> *p_list) const {
}
p_list->push_back(property_info);
}
#endif // NAVIGATION_2D_DISABLED
// Custom data layers.
p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Custom Data", "custom_data_"), PROPERTY_HINT_NONE, "custom_data_", PROPERTY_USAGE_GROUP));
@ -7090,6 +7103,7 @@ void TileData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_occluder", "layer_id", "flip_h", "flip_v", "transpose"), &TileData::get_occluder, DEFVAL(false), DEFVAL(false), DEFVAL(false));
#endif // DISABLE_DEPRECATED
#ifndef PHYSICS_2D_DISABLED
// Physics.
ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "layer_id", "velocity"), &TileData::set_constant_linear_velocity);
ClassDB::bind_method(D_METHOD("get_constant_linear_velocity", "layer_id"), &TileData::get_constant_linear_velocity);
@ -7105,6 +7119,7 @@ void TileData::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_collision_polygon_one_way", "layer_id", "polygon_index"), &TileData::is_collision_polygon_one_way);
ClassDB::bind_method(D_METHOD("set_collision_polygon_one_way_margin", "layer_id", "polygon_index", "one_way_margin"), &TileData::set_collision_polygon_one_way_margin);
ClassDB::bind_method(D_METHOD("get_collision_polygon_one_way_margin", "layer_id", "polygon_index"), &TileData::get_collision_polygon_one_way_margin);
#endif // PHYSICS_2D_DISABLED
// Terrain
ClassDB::bind_method(D_METHOD("set_terrain_set", "terrain_set"), &TileData::set_terrain_set);
@ -7115,9 +7130,11 @@ void TileData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_terrain_peering_bit", "peering_bit"), &TileData::get_terrain_peering_bit);
ClassDB::bind_method(D_METHOD("is_valid_terrain_peering_bit", "peering_bit"), &TileData::is_valid_terrain_peering_bit);
#ifndef NAVIGATION_2D_DISABLED
// Navigation
ClassDB::bind_method(D_METHOD("set_navigation_polygon", "layer_id", "navigation_polygon"), &TileData::set_navigation_polygon);
ClassDB::bind_method(D_METHOD("get_navigation_polygon", "layer_id", "flip_h", "flip_v", "transpose"), &TileData::get_navigation_polygon, DEFVAL(false), DEFVAL(false), DEFVAL(false));
#endif // NAVIGATION_2D_DISABLED
// Misc.
ClassDB::bind_method(D_METHOD("set_probability", "probability"), &TileData::set_probability);

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TILE_SET_H
#define TILE_SET_H
#pragma once
#include "core/io/resource.h"
#include "core/object/object.h"
@ -37,12 +36,18 @@
#include "core/templates/rb_set.h"
#include "scene/2d/light_occluder_2d.h"
#include "scene/main/canvas_item.h"
#include "scene/resources/2d/convex_polygon_shape_2d.h"
#include "scene/resources/2d/navigation_polygon.h"
#include "scene/resources/image_texture.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/physics_material.h"
#ifndef PHYSICS_2D_DISABLED
#include "scene/resources/2d/convex_polygon_shape_2d.h"
#endif // PHYSICS_2D_DISABLED
#ifndef NAVIGATION_2D_DISABLED
#include "scene/resources/2d/navigation_polygon.h"
#endif // NAVIGATION_2D_DISABLED
#ifndef DISABLE_DEPRECATED
#include "scene/resources/shader.h"
#endif
@ -52,12 +57,6 @@ class TileSetSource;
class TileSetAtlasSource;
class TileData;
// Forward-declare the plugins.
class TileSetPlugin;
class TileSetPluginAtlasRendering;
class TileSetPluginAtlasPhysics;
class TileSetPluginAtlasNavigation;
union TileMapCell {
struct {
int16_t source_id;
@ -154,7 +153,9 @@ private:
Vector2i autotile_coords;
bool one_way;
float one_way_margin;
#ifndef PHYSICS_2D_DISABLED
Ref<Shape2D> shape;
#endif // PHYSICS_2D_DISABLED
Transform2D transform;
};
@ -175,14 +176,18 @@ private:
int autotile_spacing = 0;
HashMap<Vector2i, int> autotile_bitmask_flags;
HashMap<Vector2i, Ref<OccluderPolygon2D>> autotile_occluder_map;
#ifndef NAVIGATION_2D_DISABLED
HashMap<Vector2i, Ref<NavigationPolygon>> autotile_navpoly_map;
#endif // NAVIGATION_2D_DISABLED
HashMap<Vector2i, int> autotile_priority_map;
HashMap<Vector2i, int> autotile_z_index_map;
Vector<CompatibilityShapeData> shapes;
Ref<OccluderPolygon2D> occluder;
Vector2 occluder_offset;
#ifndef NAVIGATION_2D_DISABLED
Ref<NavigationPolygon> navigation;
#endif // NAVIGATION_2D_DISABLED
Vector2 navigation_offset;
int z_index = 0;
};
@ -323,6 +328,7 @@ private:
Ref<ArrayMesh> tile_filled_mesh;
mutable bool tile_meshes_dirty = true;
#ifndef PHYSICS_2D_DISABLED
// Physics
struct PhysicsLayer {
uint32_t collision_layer = 1;
@ -331,6 +337,7 @@ private:
Ref<PhysicsMaterial> physics_material;
};
Vector<PhysicsLayer> physics_layers;
#endif // PHYSICS_2D_DISABLED
// Terrains
struct Terrain {
@ -401,9 +408,6 @@ protected:
static void _bind_methods();
public:
// --- Plugins ---
Vector<TileSetPlugin *> get_tile_set_atlas_plugins() const;
// --- Accessors for TileSet data ---
// -- Shape and layout --
@ -440,6 +444,7 @@ public:
void set_occlusion_layer_sdf_collision(int p_layer_index, bool p_sdf_collision);
bool get_occlusion_layer_sdf_collision(int p_layer_index) const;
#ifndef PHYSICS_2D_DISABLED
// Physics
int get_physics_layers_count() const;
void add_physics_layer(int p_index = -1);
@ -453,6 +458,7 @@ public:
real_t get_physics_layer_collision_priority(int p_layer_index) const;
void set_physics_layer_physics_material(int p_layer_index, Ref<PhysicsMaterial> p_physics_material);
Ref<PhysicsMaterial> get_physics_layer_physics_material(int p_layer_index) const;
#endif // PHYSICS_2D_DISABLED
// Terrain sets
int get_terrain_sets_count() const;
@ -474,6 +480,7 @@ public:
bool is_valid_terrain_peering_bit_for_mode(TileSet::TerrainMode p_terrain_mode, TileSet::CellNeighbor p_peering_bit) const;
bool is_valid_terrain_peering_bit(int p_terrain_set, TileSet::CellNeighbor p_peering_bit) const;
#ifndef NAVIGATION_2D_DISABLED
// Navigation
int get_navigation_layers_count() const;
void add_navigation_layer(int p_index = -1);
@ -483,6 +490,7 @@ public:
uint32_t get_navigation_layer_layers(int p_layer_index) const;
void set_navigation_layer_layer_value(int p_layer_index, int p_layer_number, bool p_value);
bool get_navigation_layer_layer_value(int p_layer_index, int p_layer_number) const;
#endif // NAVIGATION_2D_DISABLED
// Custom data
int get_custom_data_layers_count() const;
@ -686,18 +694,22 @@ public:
virtual void add_occlusion_layer(int p_index) override;
virtual void move_occlusion_layer(int p_from_index, int p_to_pos) override;
virtual void remove_occlusion_layer(int p_index) override;
#ifndef PHYSICS_2D_DISABLED
virtual void add_physics_layer(int p_index) override;
virtual void move_physics_layer(int p_from_index, int p_to_pos) override;
virtual void remove_physics_layer(int p_index) override;
#endif // PHYSICS_2D_DISABLED
virtual void add_terrain_set(int p_index) override;
virtual void move_terrain_set(int p_from_index, int p_to_pos) override;
virtual void remove_terrain_set(int p_index) override;
virtual void add_terrain(int p_terrain_set, int p_index) override;
virtual void move_terrain(int p_terrain_set, int p_from_index, int p_to_pos) override;
virtual void remove_terrain(int p_terrain_set, int p_index) override;
#ifndef NAVIGATION_2D_DISABLED
virtual void add_navigation_layer(int p_index) override;
virtual void move_navigation_layer(int p_from_index, int p_to_pos) override;
virtual void remove_navigation_layer(int p_index) override;
#endif // NAVIGATION_2D_DISABLED
virtual void add_custom_data_layer(int p_index) override;
virtual void move_custom_data_layer(int p_from_index, int p_to_pos) override;
virtual void remove_custom_data_layer(int p_index) override;
@ -853,6 +865,7 @@ private:
};
Vector<OcclusionLayerTileData> occluders;
#ifndef PHYSICS_2D_DISABLED
// Physics
struct PhysicsLayerTileData {
struct PolygonShapeTileData {
@ -868,19 +881,22 @@ private:
Vector<PolygonShapeTileData> polygons;
};
Vector<PhysicsLayerTileData> physics;
// TODO add support for areas.
// TODO add support for areas.
#endif // PHYSICS_2D_DISABLED
// Terrain
int terrain_set = -1;
int terrain = -1;
int terrain_peering_bits[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
#ifndef NAVIGATION_2D_DISABLED
// Navigation
struct NavigationLayerTileData {
Ref<NavigationPolygon> navigation_polygon;
mutable HashMap<int, Ref<NavigationPolygon>> transformed_navigation_polygon;
};
Vector<NavigationLayerTileData> navigation;
#endif // NAVIGATION_2D_DISABLED
// Misc
double probability = 1.0;
@ -895,7 +911,9 @@ protected:
static void _bind_methods();
#ifndef DISABLE_DEPRECATED
#ifndef NAVIGATION_2D_DISABLED
Ref<NavigationPolygon> _get_navigation_polygon_bind_compat_84660(int p_layer_id) const;
#endif // NAVIGATION_2D_DISABLED
Ref<OccluderPolygon2D> _get_occluder_bind_compat_84660(int p_layer_id) const;
static void _bind_compatibility_methods();
@ -908,9 +926,11 @@ public:
void add_occlusion_layer(int p_index);
void move_occlusion_layer(int p_from_index, int p_to_pos);
void remove_occlusion_layer(int p_index);
#ifndef PHYSICS_2D_DISABLED
void add_physics_layer(int p_index);
void move_physics_layer(int p_from_index, int p_to_pos);
void remove_physics_layer(int p_index);
#endif // PHYSICS_2D_DISABLED
void add_terrain_set(int p_index);
void move_terrain_set(int p_from_index, int p_to_pos);
void remove_terrain_set(int p_index);
@ -960,6 +980,7 @@ public:
void set_occluder_polygon(int p_layer_id, int p_polygon_index, const Ref<OccluderPolygon2D> &p_occluder_polygon);
Ref<OccluderPolygon2D> get_occluder_polygon(int p_layer_id, int p_polygon_index, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const;
#ifndef PHYSICS_2D_DISABLED
// Physics
void set_constant_linear_velocity(int p_layer_id, const Vector2 &p_velocity);
Vector2 get_constant_linear_velocity(int p_layer_id) const;
@ -977,6 +998,7 @@ public:
float get_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index) const;
int get_collision_polygon_shapes_count(int p_layer_id, int p_polygon_index) const;
Ref<ConvexPolygonShape2D> get_collision_polygon_shape(int p_layer_id, int p_polygon_index, int shape_index, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const;
#endif // PHYSICS_2D_DISABLED
// Terrain
void set_terrain_set(int p_terrain_id);
@ -989,9 +1011,11 @@ public:
TileSet::TerrainsPattern get_terrains_pattern() const; // Not exposed.
#ifndef NAVIGATION_2D_DISABLED
// Navigation
void set_navigation_polygon(int p_layer_id, Ref<NavigationPolygon> p_navigation_polygon);
Ref<NavigationPolygon> get_navigation_polygon(int p_layer_id, bool p_flip_h = false, bool p_flip_v = false, bool p_transpose = false) const;
#endif // NAVIGATION_2D_DISABLED
// Misc
void set_probability(float p_probability);
@ -1015,5 +1039,3 @@ VARIANT_ENUM_CAST(TileSet::TileLayout);
VARIANT_ENUM_CAST(TileSet::TileOffsetAxis);
VARIANT_ENUM_CAST(TileSetAtlasSource::TileAnimationMode);
#endif // TILE_SET_H

View file

@ -35,23 +35,26 @@
#include "servers/rendering_server.h"
bool WorldBoundaryShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
Vector2 point = distance * normal;
Vector2 l[2][2] = { { point - normal.orthogonal() * 100, point + normal.orthogonal() * 100 }, { point, point + normal * 30 } };
for (int i = 0; i < 2; i++) {
Vector2 closest = Geometry2D::get_closest_point_to_segment(p_point, l[i]);
if (p_point.distance_to(closest) < p_tolerance) {
return true;
}
const Vector2 shape_center = distance * normal;
// Orthogonal part of the shape editor gizmo (the flat line).
const Vector2 ortho_segment_a = shape_center - normal.orthogonal() * 100;
const Vector2 ortho_segment_b = shape_center + normal.orthogonal() * 100;
const Vector2 ortho_closest = Geometry2D::get_closest_point_to_segment(p_point, ortho_segment_a, ortho_segment_b);
if (p_point.distance_to(ortho_closest) < p_tolerance) {
return true;
}
// Normal part of the shape editor gizmo (the arrow).
const Vector2 normal_segment_a = shape_center;
const Vector2 normal_segment_b = shape_center + normal * 30;
const Vector2 normal_closest = Geometry2D::get_closest_point_to_segment(p_point, normal_segment_a, normal_segment_b);
if (p_point.distance_to(normal_closest) < p_tolerance) {
return true;
}
return false;
}
void WorldBoundaryShape2D::_update_shape() {
Array arr;
arr.push_back(normal);
arr.push_back(distance);
Array arr = { normal, distance };
PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), arr);
emit_changed();
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef WORLD_BOUNDARY_SHAPE_2D_H
#define WORLD_BOUNDARY_SHAPE_2D_H
#pragma once
#include "scene/resources/2d/shape_2d.h"
@ -60,5 +59,3 @@ public:
WorldBoundaryShape2D();
};
#endif // WORLD_BOUNDARY_SHAPE_2D_H

View file

@ -3,5 +3,26 @@ from misc.utility.scons_hints import *
Import("env")
env.add_source_files(env.scene_sources, "*.cpp")
env.add_source_files(env.scene_sources, "fog_material.cpp")
env.add_source_files(env.scene_sources, "importer_mesh.cpp")
env.add_source_files(env.scene_sources, "mesh_library.cpp")
env.add_source_files(env.scene_sources, "primitive_meshes.cpp")
env.add_source_files(env.scene_sources, "skin.cpp")
env.add_source_files(env.scene_sources, "sky_material.cpp")
env.add_source_files(env.scene_sources, "world_3d.cpp")
env.add_source_files(env.scene_sources, "skeleton/*.cpp")
if not env["disable_physics_3d"]:
env.add_source_files(env.scene_sources, "box_shape_3d.cpp")
env.add_source_files(env.scene_sources, "capsule_shape_3d.cpp")
env.add_source_files(env.scene_sources, "circle_shape_3d.cpp")
env.add_source_files(env.scene_sources, "concave_polygon_shape_3d.cpp")
env.add_source_files(env.scene_sources, "convex_polygon_shape_3d.cpp")
env.add_source_files(env.scene_sources, "cylinder_shape_3d.cpp")
env.add_source_files(env.scene_sources, "height_map_shape_3d.cpp")
env.add_source_files(env.scene_sources, "separation_ray_shape_3d.cpp")
env.add_source_files(env.scene_sources, "shape_3d.cpp")
env.add_source_files(env.scene_sources, "sphere_shape_3d.cpp")
env.add_source_files(env.scene_sources, "world_boundary_shape_3d.cpp")
if not env["disable_navigation_3d"]:
env.add_source_files(env.scene_sources, "navigation_mesh_source_geometry_data_3d.cpp")

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef BOX_SHAPE_3D_H
#define BOX_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -56,5 +55,3 @@ public:
BoxShape3D();
};
#endif // BOX_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CAPSULE_SHAPE_3D_H
#define CAPSULE_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -57,5 +56,3 @@ public:
CapsuleShape3D();
};
#endif // CAPSULE_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CONCAVE_POLYGON_SHAPE_3D_H
#define CONCAVE_POLYGON_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -79,5 +78,3 @@ public:
ConcavePolygonShape3D();
};
#endif // CONCAVE_POLYGON_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CONVEX_POLYGON_SHAPE_3D_H
#define CONVEX_POLYGON_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -54,5 +53,3 @@ public:
ConvexPolygonShape3D();
};
#endif // CONVEX_POLYGON_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CYLINDER_SHAPE_3D_H
#define CYLINDER_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -56,5 +55,3 @@ public:
CylinderShape3D();
};
#endif // CYLINDER_SHAPE_3D_H

View file

@ -144,7 +144,7 @@ void FogMaterial::_update_shader() {
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
RS::get_singleton()->shader_set_code(shader, R"(
// NOTE: Shader automatically converted from )" VERSION_NAME " " VERSION_FULL_CONFIG R"('s FogMaterial.
// NOTE: Shader automatically converted from )" GODOT_VERSION_NAME " " GODOT_VERSION_FULL_CONFIG R"('s FogMaterial.
shader_type fog;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef FOG_MATERIAL_H
#define FOG_MATERIAL_H
#pragma once
#include "scene/resources/material.h"
@ -83,5 +82,3 @@ public:
FogMaterial();
virtual ~FogMaterial();
};
#endif // FOG_MATERIAL_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef HEIGHT_MAP_SHAPE_3D_H
#define HEIGHT_MAP_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -68,5 +67,3 @@ public:
HeightMapShape3D();
};
#endif // HEIGHT_MAP_SHAPE_3D_H

View file

@ -31,19 +31,15 @@
#include "importer_mesh.h"
#include "core/io/marshalls.h"
#include "core/math/convex_hull.h"
#include "core/math/random_pcg.h"
#include "scene/resources/surface_tool.h"
#include <cstdint>
#ifndef PHYSICS_3D_DISABLED
#include "core/math/convex_hull.h"
#endif // PHYSICS_3D_DISABLED
String ImporterMesh::validate_blend_shape_name(const String &p_name) {
String name = p_name;
const char *characters = ":";
for (const char *p = characters; *p; p++) {
name = name.replace(String::chr(*p), "_");
}
return name;
return p_name.replace_char(':', '_');
}
void ImporterMesh::add_blend_shape(const String &p_name) {
@ -91,13 +87,11 @@ void ImporterMesh::add_surface(Mesh::PrimitiveType p_primitive, const Array &p_a
s.blend_shape_data.push_back(bs);
}
List<Variant> lods;
p_lods.get_key_list(&lods);
for (const Variant &E : lods) {
ERR_CONTINUE(!E.is_num());
for (const KeyValue<Variant, Variant> &kv : p_lods) {
ERR_CONTINUE(!kv.key.is_num());
Surface::LOD lod;
lod.distance = E;
lod.indices = p_lods[E];
lod.distance = kv.key;
lod.indices = kv.value;
ERR_CONTINUE(lod.indices.is_empty());
s.lods.push_back(lod);
}
@ -787,6 +781,7 @@ Vector<Face3> ImporterMesh::get_faces() const {
return faces;
}
#ifndef PHYSICS_3D_DISABLED
Vector<Ref<Shape3D>> ImporterMesh::convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const {
ERR_FAIL_NULL_V(Mesh::convex_decomposition_function, Vector<Ref<Shape3D>>());
@ -874,7 +869,7 @@ Ref<ConvexPolygonShape3D> ImporterMesh::create_convex_shape(bool p_clean, bool p
Ref<ConcavePolygonShape3D> ImporterMesh::create_trimesh_shape() const {
Vector<Face3> faces = get_faces();
if (faces.size() == 0) {
if (faces.is_empty()) {
return Ref<ConcavePolygonShape3D>();
}
@ -892,10 +887,11 @@ Ref<ConcavePolygonShape3D> ImporterMesh::create_trimesh_shape() const {
shape->set_faces(face_points);
return shape;
}
#endif // PHYSICS_3D_DISABLED
Ref<NavigationMesh> ImporterMesh::create_navigation_mesh() {
Vector<Face3> faces = get_faces();
if (faces.size() == 0) {
if (faces.is_empty()) {
return Ref<NavigationMesh>();
}

View file

@ -28,16 +28,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef IMPORTER_MESH_H
#define IMPORTER_MESH_H
#pragma once
#include "core/io/resource.h"
#include "scene/resources/3d/concave_polygon_shape_3d.h"
#include "scene/resources/3d/convex_polygon_shape_3d.h"
#include "scene/resources/mesh.h"
#include "scene/resources/navigation_mesh.h"
#include <cstdint>
#ifndef PHYSICS_3D_DISABLED
#include "scene/resources/3d/concave_polygon_shape_3d.h"
#include "scene/resources/3d/convex_polygon_shape_3d.h"
#endif // PHYSICS_3D_DISABLED
// The following classes are used by importers instead of ArrayMesh and MeshInstance3D
// so the data is not registered (hence, quality loss), importing happens faster and
@ -120,9 +120,11 @@ public:
Ref<ImporterMesh> get_shadow_mesh() const;
Vector<Face3> get_faces() const;
#ifndef PHYSICS_3D_DISABLED
Vector<Ref<Shape3D>> convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const;
Ref<ConvexPolygonShape3D> create_convex_shape(bool p_clean = true, bool p_simplify = false) const;
Ref<ConcavePolygonShape3D> create_trimesh_shape() const;
#endif // PHYSICS_3D_DISABLED
Ref<NavigationMesh> create_navigation_mesh();
Error lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector<uint8_t> &p_src_cache, Vector<uint8_t> &r_dst_cache);
@ -133,5 +135,3 @@ public:
Ref<ArrayMesh> get_mesh(const Ref<ArrayMesh> &p_base = Ref<ArrayMesh>());
void clear();
};
#endif // IMPORTER_MESH_H

View file

@ -30,7 +30,9 @@
#include "mesh_library.h"
#ifndef PHYSICS_3D_DISABLED
#include "box_shape_3d.h"
#endif // PHYSICS_3D_DISABLED
bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
String prop_name = p_name;
@ -65,6 +67,7 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
set_item_mesh_cast_shadow(idx, RS::ShadowCastingSetting::SHADOW_CASTING_SETTING_ON);
} break;
}
#ifndef PHYSICS_3D_DISABLED
} else if (what == "shape") {
Vector<ShapeData> shapes;
ShapeData sd;
@ -73,6 +76,7 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
set_item_shapes(idx, shapes);
} else if (what == "shapes") {
_set_item_shapes(idx, p_value);
#endif // PHYSICS_3D_DISABLED
} else if (what == "preview") {
set_item_preview(idx, p_value);
} else if (what == "navigation_mesh") {
@ -111,8 +115,10 @@ bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_item_mesh_transform(idx);
} else if (what == "mesh_cast_shadow") {
r_ret = (int)get_item_mesh_cast_shadow(idx);
#ifndef PHYSICS_3D_DISABLED
} else if (what == "shapes") {
r_ret = _get_item_shapes(idx);
#endif // PHYSICS_3D_DISABLED
} else if (what == "navigation_mesh") {
r_ret = get_item_navigation_mesh(idx);
} else if (what == "navigation_mesh_transform") {
@ -181,12 +187,14 @@ void MeshLibrary::set_item_mesh_cast_shadow(int p_item, RS::ShadowCastingSetting
emit_changed();
}
#ifndef PHYSICS_3D_DISABLED
void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
item_map[p_item].shapes = p_shapes;
emit_changed();
notify_property_list_changed();
}
#endif // PHYSICS_3D_DISABLED
void MeshLibrary::set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
@ -232,10 +240,12 @@ RS::ShadowCastingSetting MeshLibrary::get_item_mesh_cast_shadow(int p_item) cons
return item_map[p_item].mesh_cast_shadow;
}
#ifndef PHYSICS_3D_DISABLED
Vector<MeshLibrary::ShapeData> MeshLibrary::get_item_shapes(int p_item) const {
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Vector<ShapeData>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
return item_map[p_item].shapes;
}
#endif // PHYSICS_3D_DISABLED
Ref<NavigationMesh> MeshLibrary::get_item_navigation_mesh(int p_item) const {
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<NavigationMesh>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
@ -302,6 +312,7 @@ int MeshLibrary::get_last_unused_item_id() const {
}
}
#ifndef PHYSICS_3D_DISABLED
void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) {
Array arr_shapes = p_shapes;
int size = p_shapes.size();
@ -351,6 +362,7 @@ Array MeshLibrary::_get_item_shapes(int p_item) const {
return ret;
}
#endif // PHYSICS_3D_DISABLED
void MeshLibrary::reset_state() {
clear();
@ -364,7 +376,9 @@ void MeshLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_item_navigation_mesh", "id", "navigation_mesh"), &MeshLibrary::set_item_navigation_mesh);
ClassDB::bind_method(D_METHOD("set_item_navigation_mesh_transform", "id", "navigation_mesh"), &MeshLibrary::set_item_navigation_mesh_transform);
ClassDB::bind_method(D_METHOD("set_item_navigation_layers", "id", "navigation_layers"), &MeshLibrary::set_item_navigation_layers);
#ifndef PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("set_item_shapes", "id", "shapes"), &MeshLibrary::_set_item_shapes);
#endif // PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("set_item_preview", "id", "texture"), &MeshLibrary::set_item_preview);
ClassDB::bind_method(D_METHOD("get_item_name", "id"), &MeshLibrary::get_item_name);
ClassDB::bind_method(D_METHOD("get_item_mesh", "id"), &MeshLibrary::get_item_mesh);
@ -373,7 +387,9 @@ void MeshLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_item_navigation_mesh", "id"), &MeshLibrary::get_item_navigation_mesh);
ClassDB::bind_method(D_METHOD("get_item_navigation_mesh_transform", "id"), &MeshLibrary::get_item_navigation_mesh_transform);
ClassDB::bind_method(D_METHOD("get_item_navigation_layers", "id"), &MeshLibrary::get_item_navigation_layers);
#ifndef PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("get_item_shapes", "id"), &MeshLibrary::_get_item_shapes);
#endif // PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("get_item_preview", "id"), &MeshLibrary::get_item_preview);
ClassDB::bind_method(D_METHOD("remove_item", "id"), &MeshLibrary::remove_item);
ClassDB::bind_method(D_METHOD("find_item_by_name", "name"), &MeshLibrary::find_item_by_name);

View file

@ -28,31 +28,37 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef MESH_LIBRARY_H
#define MESH_LIBRARY_H
#pragma once
#include "core/io/resource.h"
#include "core/templates/rb_map.h"
#include "scene/resources/mesh.h"
#include "scene/resources/navigation_mesh.h"
#include "servers/rendering_server.h"
#ifndef PHYSICS_3D_DISABLED
#include "shape_3d.h"
#endif // PHYSICS_3D_DISABLED
class MeshLibrary : public Resource {
GDCLASS(MeshLibrary, Resource);
RES_BASE_EXTENSION("meshlib");
public:
#ifndef PHYSICS_3D_DISABLED
struct ShapeData {
Ref<Shape3D> shape;
Transform3D local_transform;
};
#endif // PHYSICS_3D_DISABLED
struct Item {
String name;
Ref<Mesh> mesh;
Transform3D mesh_transform;
RS::ShadowCastingSetting mesh_cast_shadow = RS::ShadowCastingSetting::SHADOW_CASTING_SETTING_ON;
#ifndef PHYSICS_3D_DISABLED
Vector<ShapeData> shapes;
#endif // PHYSICS_3D_DISABLED
Ref<Texture2D> preview;
Ref<NavigationMesh> navigation_mesh;
Transform3D navigation_mesh_transform;
@ -61,8 +67,10 @@ public:
RBMap<int, Item> item_map;
#ifndef PHYSICS_3D_DISABLED
void _set_item_shapes(int p_item, const Array &p_shapes);
Array _get_item_shapes(int p_item) const;
#endif // PHYSICS_3D_DISABLED
protected:
bool _set(const StringName &p_name, const Variant &p_value);
@ -81,7 +89,9 @@ public:
void set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh);
void set_item_navigation_mesh_transform(int p_item, const Transform3D &p_transform);
void set_item_navigation_layers(int p_item, uint32_t p_navigation_layers);
#ifndef PHYSICS_3D_DISABLED
void set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes);
#endif // PHYSICS_3D_DISABLED
void set_item_preview(int p_item, const Ref<Texture2D> &p_preview);
String get_item_name(int p_item) const;
Ref<Mesh> get_item_mesh(int p_item) const;
@ -90,7 +100,9 @@ public:
Ref<NavigationMesh> get_item_navigation_mesh(int p_item) const;
Transform3D get_item_navigation_mesh_transform(int p_item) const;
uint32_t get_item_navigation_layers(int p_item) const;
#ifndef PHYSICS_3D_DISABLED
Vector<ShapeData> get_item_shapes(int p_item) const;
#endif // PHYSICS_3D_DISABLED
Ref<Texture2D> get_item_preview(int p_item) const;
void remove_item(int p_item);
@ -106,5 +118,3 @@ public:
MeshLibrary();
~MeshLibrary();
};
#endif // MESH_LIBRARY_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_3D_H
#define NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_3D_H
#pragma once
#include "core/os/rw_lock.h"
#include "scene/resources/mesh.h"
@ -109,5 +108,3 @@ public:
NavigationMeshSourceGeometryData3D() {}
~NavigationMeshSourceGeometryData3D() { clear(); }
};
#endif // NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_3D_H

View file

@ -103,7 +103,7 @@ void PrimitiveMesh::_update() const {
Vector<Vector2> uv = arr[RS::ARRAY_TEX_UV];
Vector<Vector2> uv2 = arr[RS::ARRAY_TEX_UV2];
if (uv.size() > 0 && uv2.size() == 0) {
if (uv.size() > 0 && uv2.is_empty()) {
Vector2 uv2_scale = get_uv2_scale();
uv2.resize(uv.size());
@ -389,7 +389,7 @@ void CapsuleMesh::_update_lightmap_size() {
Size2i _lightmap_size_hint;
float padding = get_uv2_padding();
float radial_length = radius * Math_PI * 0.5; // circumference of 90 degree bend
float radial_length = radius * Math::PI * 0.5; // circumference of 90 degree bend
float vertical_length = radial_length * 2 + (height - 2.0 * radius); // total vertical length
_lightmap_size_hint.x = MAX(1.0, 4.0 * radial_length / texel_size) + padding;
@ -413,9 +413,9 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
float twothirds = 2.0 / 3.0;
// Only used if we calculate UV2
float radial_width = 2.0 * radius * Math_PI;
float radial_width = 2.0 * radius * Math::PI;
float radial_h = radial_width / (radial_width + p_uv2_padding);
float radial_length = radius * Math_PI * 0.5; // circumference of 90 degree bend
float radial_length = radius * Math::PI * 0.5; // circumference of 90 degree bend
float vertical_length = radial_length * 2 + (height - 2.0 * radius) + p_uv2_padding; // total vertical length
float radial_v = radial_length / vertical_length; // v size of top and bottom section
float height_v = (height - 2.0 * radius) / vertical_length; // v size of height section
@ -447,8 +447,8 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
w = 1.0;
y = 0.0;
} else {
w = Math::sin(0.5 * Math_PI * v);
y = Math::cos(0.5 * Math_PI * v);
w = Math::sin(0.5 * Math::PI * v);
y = Math::cos(0.5 * Math::PI * v);
}
for (i = 0; i <= radial_segments; i++) {
@ -459,8 +459,8 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
x = 0.0;
z = 1.0;
} else {
x = -Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = -Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
Vector3 p = Vector3(x * w, y, -z * w);
@ -506,8 +506,8 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
x = 0.0;
z = 1.0;
} else {
x = -Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = -Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
Vector3 p = Vector3(x * radius, y, -z * radius);
@ -546,8 +546,8 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
w = 0.0;
y = -1.0;
} else {
w = Math::cos(0.5 * Math_PI * v);
y = -Math::sin(0.5 * Math_PI * v);
w = Math::cos(0.5 * Math::PI * v);
y = -Math::sin(0.5 * Math::PI * v);
}
for (i = 0; i <= radial_segments; i++) {
@ -558,8 +558,8 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
x = 0.0;
z = 1.0;
} else {
x = -Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = -Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
Vector3 p = Vector3(x * w, y, -z * w);
@ -1028,8 +1028,8 @@ void CylinderMesh::_update_lightmap_size() {
Size2i _lightmap_size_hint;
float padding = get_uv2_padding();
float top_circumference = top_radius * Math_PI * 2.0;
float bottom_circumference = bottom_radius * Math_PI * 2.0;
float top_circumference = top_radius * Math::PI * 2.0;
float bottom_circumference = bottom_radius * Math::PI * 2.0;
float _width = MAX(top_circumference, bottom_circumference) / texel_size + padding;
_width = MAX(_width, (((top_radius + bottom_radius) / texel_size) + padding) * 2.0); // this is extremely unlikely to be larger, will only happen if padding is larger then our diameter.
@ -1055,8 +1055,8 @@ void CylinderMesh::create_mesh_array(Array &p_arr, float top_radius, float botto
float x, y, z, u, v, radius, radius_h;
// Only used if we calculate UV2
float top_circumference = top_radius * Math_PI * 2.0;
float bottom_circumference = bottom_radius * Math_PI * 2.0;
float top_circumference = top_radius * Math::PI * 2.0;
float bottom_circumference = bottom_radius * Math::PI * 2.0;
float vertical_length = height + MAX(2.0 * top_radius, 2.0 * bottom_radius) + (2.0 * p_uv2_padding);
float height_v = height / vertical_length;
float padding_v = p_uv2_padding / vertical_length;
@ -1102,8 +1102,8 @@ void CylinderMesh::create_mesh_array(Array &p_arr, float top_radius, float botto
x = 0.0;
z = 1.0;
} else {
x = Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
Vector3 p = Vector3(x * radius, y, z * radius);
@ -1159,8 +1159,8 @@ void CylinderMesh::create_mesh_array(Array &p_arr, float top_radius, float botto
x = 0.0;
z = 1.0;
} else {
x = Math::sin(r * Math_TAU);
z = Math::cos(r * Math_TAU);
x = Math::sin(r * Math::TAU);
z = Math::cos(r * Math::TAU);
}
u = ((x + 1.0) * 0.25);
@ -1206,8 +1206,8 @@ void CylinderMesh::create_mesh_array(Array &p_arr, float top_radius, float botto
x = 0.0;
z = 1.0;
} else {
x = Math::sin(r * Math_TAU);
z = Math::cos(r * Math_TAU);
x = Math::sin(r * Math::TAU);
z = Math::cos(r * Math::TAU);
}
u = 0.5 + ((x + 1.0) * 0.25);
@ -1921,9 +1921,9 @@ void SphereMesh::_update_lightmap_size() {
Size2i _lightmap_size_hint;
float padding = get_uv2_padding();
float _width = radius * Math_TAU;
float _width = radius * Math::TAU;
_lightmap_size_hint.x = MAX(1.0, (_width / texel_size) + padding);
float _height = (is_hemisphere ? 1.0 : 0.5) * height * Math_PI; // note, with hemisphere height is our radius, while with a full sphere it is the diameter..
float _height = (is_hemisphere ? 1.0 : 0.5) * height * Math::PI; // note, with hemisphere height is our radius, while with a full sphere it is the diameter..
_lightmap_size_hint.y = MAX(1.0, (_height / texel_size) + padding);
set_lightmap_size_hint(_lightmap_size_hint);
@ -1944,11 +1944,11 @@ void SphereMesh::create_mesh_array(Array &p_arr, float radius, float height, int
float scale = height / radius * (is_hemisphere ? 1.0 : 0.5);
// Only used if we calculate UV2
float circumference = radius * Math_TAU;
float circumference = radius * Math::TAU;
float horizontal_length = circumference + p_uv2_padding;
float center_h = 0.5 * circumference / horizontal_length;
float height_v = scale * Math_PI / ((scale * Math_PI) + p_uv2_padding / radius);
float height_v = scale * Math::PI / ((scale * Math::PI) + p_uv2_padding / radius);
// set our bounding box
@ -1977,8 +1977,8 @@ void SphereMesh::create_mesh_array(Array &p_arr, float radius, float height, int
w = 0.0;
y = -1.0;
} else {
w = Math::sin(Math_PI * v);
y = Math::cos(Math_PI * v);
w = Math::sin(Math::PI * v);
y = Math::cos(Math::PI * v);
}
for (i = 0; i <= radial_segments; i++) {
@ -1989,8 +1989,8 @@ void SphereMesh::create_mesh_array(Array &p_arr, float radius, float height, int
x = 0.0;
z = 1.0;
} else {
x = Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
if (is_hemisphere && y < 0.0) {
@ -2141,9 +2141,9 @@ void TorusMesh::_update_lightmap_size() {
float radius = (max_radius - min_radius) * 0.5;
float _width = max_radius * Math_TAU;
float _width = max_radius * Math::TAU;
_lightmap_size_hint.x = MAX(1.0, (_width / texel_size) + padding);
float _height = radius * Math_TAU;
float _height = radius * Math::TAU;
_lightmap_size_hint.y = MAX(1.0, (_height / texel_size) + padding);
set_lightmap_size_hint(_lightmap_size_hint);
@ -2181,23 +2181,23 @@ void TorusMesh::_create_mesh_array(Array &p_arr) const {
bool _add_uv2 = get_add_uv2();
float _uv2_padding = get_uv2_padding() * texel_size;
float horizontal_total = max_radius * Math_TAU + _uv2_padding;
float max_h = max_radius * Math_TAU / horizontal_total;
float delta_h = (max_radius - min_radius) * Math_TAU / horizontal_total;
float horizontal_total = max_radius * Math::TAU + _uv2_padding;
float max_h = max_radius * Math::TAU / horizontal_total;
float delta_h = (max_radius - min_radius) * Math::TAU / horizontal_total;
float height_v = radius * Math_TAU / (radius * Math_TAU + _uv2_padding);
float height_v = radius * Math::TAU / (radius * Math::TAU + _uv2_padding);
for (int i = 0; i <= rings; i++) {
int prevrow = (i - 1) * (ring_segments + 1);
int thisrow = i * (ring_segments + 1);
float inci = float(i) / rings;
float angi = inci * Math_TAU;
float angi = inci * Math::TAU;
Vector2 normali = (i == rings) ? Vector2(0.0, -1.0) : Vector2(-Math::sin(angi), -Math::cos(angi));
for (int j = 0; j <= ring_segments; j++) {
float incj = float(j) / ring_segments;
float angj = incj * Math_TAU;
float angj = incj * Math::TAU;
Vector2 normalj = (j == ring_segments) ? Vector2(-1.0, 0.0) : Vector2(-Math::cos(angj), Math::sin(angj));
Vector2 normalk = normalj * radius + Vector2(min_radius + radius, 0);
@ -2486,8 +2486,8 @@ void TubeTrailMesh::_create_mesh_array(Array &p_arr) const {
float x = 0.0;
float z = 1.0;
if (i < radial_steps) {
x = Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
Vector3 p = Vector3(x * r, y, z * r);
@ -2559,8 +2559,8 @@ void TubeTrailMesh::_create_mesh_array(Array &p_arr) const {
float x = 0.0;
float z = 1.0;
if (i < radial_steps) {
x = Math::sin(r * Math_TAU);
z = Math::cos(r * Math_TAU);
x = Math::sin(r * Math::TAU);
z = Math::cos(r * Math::TAU);
}
float u = ((x + 1.0) * 0.25);
@ -2628,8 +2628,8 @@ void TubeTrailMesh::_create_mesh_array(Array &p_arr) const {
float x = 0.0;
float z = 1.0;
if (i < radial_steps) {
x = Math::sin(r * Math_TAU);
z = Math::cos(r * Math_TAU);
x = Math::sin(r * Math::TAU);
z = Math::cos(r * Math::TAU);
}
float u = 0.5 + ((x + 1.0) * 0.25);
@ -2972,7 +2972,7 @@ void TextMesh::_generate_glyph_mesh_data(const GlyphMeshKey &p_key, const Glyph
PackedInt32Array contours = d["contours"];
bool orientation = d["orientation"];
if (points.size() < 3 || contours.size() < 1) {
if (points.size() < 3 || contours.is_empty()) {
return; // No full contours, only glyph control points (or nothing), ignore.
}
@ -3105,14 +3105,13 @@ void TextMesh::_generate_glyph_mesh_data(const GlyphMeshKey &p_key, const Glyph
ERR_FAIL_MSG("Convex decomposing failed. Make sure the font doesn't contain self-intersecting lines, as these are not supported in TextMesh.");
}
List<TPPLPoly> out_tris;
for (List<TPPLPoly>::Element *I = out_poly.front(); I; I = I->next()) {
if (tpart.Triangulate_OPT(&(I->get()), &out_tris) == 0) {
for (TPPLPoly &tp : out_poly) {
if (tpart.Triangulate_OPT(&tp, &out_tris) == 0) {
ERR_FAIL_MSG("Triangulation failed. Make sure the font doesn't contain self-intersecting lines, as these are not supported in TextMesh.");
}
}
for (List<TPPLPoly>::Element *I = out_tris.front(); I; I = I->next()) {
TPPLPoly &tp = I->get();
for (const TPPLPoly &tp : out_tris) {
ERR_FAIL_COND(tp.GetNumPoints() != 3); // Triangles only.
for (int i = 0; i < 3; i++) {
@ -3249,8 +3248,8 @@ void TextMesh::_create_mesh_array(Array &p_arr) const {
Vector<Vector2> uvs;
Vector<int32_t> indices;
Vector2 min_p = Vector2(INFINITY, INFINITY);
Vector2 max_p = Vector2(-INFINITY, -INFINITY);
Vector2 min_p = Vector2(Math::INF, Math::INF);
Vector2 max_p = Vector2(-Math::INF, -Math::INF);
int32_t p_size = 0;
int32_t i_size = 0;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef PRIMITIVE_MESHES_H
#define PRIMITIVE_MESHES_H
#pragma once
#include "scene/resources/font.h"
#include "scene/resources/mesh.h"
@ -582,8 +581,8 @@ private:
Vector<Vector2> triangles;
Vector<Vector<ContourPoint>> contours;
Vector<ContourInfo> contours_info;
Vector2 min_p = Vector2(INFINITY, INFINITY);
Vector2 max_p = Vector2(-INFINITY, -INFINITY);
Vector2 min_p = Vector2(Math::INF, Math::INF);
Vector2 max_p = Vector2(-Math::INF, -Math::INF);
};
mutable HashMap<GlyphMeshKey, GlyphMeshData, GlyphMeshKeyHasher> cache;
@ -691,5 +690,3 @@ public:
};
VARIANT_ENUM_CAST(RibbonTrailMesh::Shape)
#endif // PRIMITIVE_MESHES_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SEPARATION_RAY_SHAPE_3D_H
#define SEPARATION_RAY_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -57,5 +56,3 @@ public:
SeparationRayShape3D();
};
#endif // SEPARATION_RAY_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SHAPE_3D_H
#define SHAPE_3D_H
#pragma once
#include "core/io/resource.h"
@ -94,5 +93,3 @@ public:
Shape3D();
~Shape3D();
};
#endif // SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKIN_H
#define SKIN_H
#pragma once
#include "core/io/resource.h"
@ -85,5 +84,3 @@ public:
Skin();
};
#endif // SKIN_H

View file

@ -276,7 +276,7 @@ void ProceduralSkyMaterial::_update_shader() {
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
RS::get_singleton()->shader_set_code(shader_cache[i], vformat(R"(
// NOTE: Shader automatically converted from )" VERSION_NAME " " VERSION_FULL_CONFIG R"('s ProceduralSkyMaterial.
// NOTE: Shader automatically converted from )" GODOT_VERSION_NAME " " GODOT_VERSION_FULL_CONFIG R"('s ProceduralSkyMaterial.
shader_type sky;
%s
@ -470,7 +470,7 @@ void PanoramaSkyMaterial::_update_shader() {
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
RS::get_singleton()->shader_set_code(shader_cache[i], vformat(R"(
// NOTE: Shader automatically converted from )" VERSION_NAME " " VERSION_FULL_CONFIG R"('s PanoramaSkyMaterial.
// NOTE: Shader automatically converted from )" GODOT_VERSION_NAME " " GODOT_VERSION_FULL_CONFIG R"('s PanoramaSkyMaterial.
shader_type sky;
@ -698,7 +698,7 @@ void PhysicalSkyMaterial::_update_shader() {
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
RS::get_singleton()->shader_set_code(shader_cache[i], vformat(R"(
// NOTE: Shader automatically converted from )" VERSION_NAME " " VERSION_FULL_CONFIG R"('s PhysicalSkyMaterial.
// NOTE: Shader automatically converted from )" GODOT_VERSION_NAME " " GODOT_VERSION_FULL_CONFIG R"('s PhysicalSkyMaterial.
shader_type sky;
%s

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKY_MATERIAL_H
#define SKY_MATERIAL_H
#pragma once
#include "core/templates/rid.h"
#include "scene/resources/material.h"
@ -231,5 +230,3 @@ public:
PhysicalSkyMaterial();
~PhysicalSkyMaterial();
};
#endif // SKY_MATERIAL_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SPHERE_SHAPE_3D_H
#define SPHERE_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -54,5 +53,3 @@ public:
SphereShape3D();
};
#endif // SPHERE_SHAPE_3D_H

View file

@ -45,6 +45,7 @@ void World3D::_remove_camera(Camera3D *p_camera) {
}
RID World3D::get_space() const {
#ifndef PHYSICS_3D_DISABLED
if (space.is_null()) {
space = PhysicsServer3D::get_singleton()->space_create();
PhysicsServer3D::get_singleton()->space_set_active(space, true);
@ -53,6 +54,7 @@ RID World3D::get_space() const {
PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, GLOBAL_GET("physics/3d/default_linear_damp"));
PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_GET("physics/3d/default_angular_damp"));
}
#endif // PHYSICS_3D_DISABLED
return space;
}
@ -139,9 +141,11 @@ Ref<Compositor> World3D::get_compositor() const {
return compositor;
}
#ifndef PHYSICS_3D_DISABLED
PhysicsDirectSpaceState3D *World3D::get_direct_space_state() {
return PhysicsServer3D::get_singleton()->space_get_direct_state(get_space());
}
#endif // PHYSICS_3D_DISABLED
void World3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_space"), &World3D::get_space);
@ -153,14 +157,18 @@ void World3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_fallback_environment"), &World3D::get_fallback_environment);
ClassDB::bind_method(D_METHOD("set_camera_attributes", "attributes"), &World3D::set_camera_attributes);
ClassDB::bind_method(D_METHOD("get_camera_attributes"), &World3D::get_camera_attributes);
#ifndef PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("get_direct_space_state"), &World3D::get_direct_space_state);
#endif // PHYSICS_3D_DISABLED
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fallback_environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_fallback_environment", "get_fallback_environment");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "camera_attributes", PROPERTY_HINT_RESOURCE_TYPE, "CameraAttributesPractical,CameraAttributesPhysical"), "set_camera_attributes", "get_camera_attributes");
ADD_PROPERTY(PropertyInfo(Variant::RID, "space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_space");
ADD_PROPERTY(PropertyInfo(Variant::RID, "navigation_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_navigation_map");
ADD_PROPERTY(PropertyInfo(Variant::RID, "scenario", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_scenario");
#ifndef PHYSICS_3D_DISABLED
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState3D", PROPERTY_USAGE_NONE), "", "get_direct_space_state");
#endif // PHYSICS_3D_DISABLED
}
World3D::World3D() {
@ -169,13 +177,17 @@ World3D::World3D() {
World3D::~World3D() {
ERR_FAIL_NULL(RenderingServer::get_singleton());
#ifndef PHYSICS_3D_DISABLED
ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
#endif // PHYSICS_3D_DISABLED
ERR_FAIL_NULL(NavigationServer3D::get_singleton());
RenderingServer::get_singleton()->free(scenario);
#ifndef PHYSICS_3D_DISABLED
if (space.is_valid()) {
PhysicsServer3D::get_singleton()->free(space);
}
#endif // PHYSICS_3D_DISABLED
if (navigation_map.is_valid()) {
NavigationServer3D::get_singleton()->free(navigation_map);
}

View file

@ -28,14 +28,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef WORLD_3D_H
#define WORLD_3D_H
#pragma once
#include "core/io/resource.h"
#include "scene/resources/compositor.h"
#include "scene/resources/environment.h"
#ifndef PHYSICS_3D_DISABLED
#include "servers/physics_server_3d.h"
#include "servers/rendering_server.h"
#endif // PHYSICS_3D_DISABLED
class CameraAttributes;
class Camera3D;
@ -84,10 +84,10 @@ public:
_FORCE_INLINE_ const HashSet<Camera3D *> &get_cameras() const { return cameras; }
#ifndef PHYSICS_3D_DISABLED
PhysicsDirectSpaceState3D *get_direct_space_state();
#endif // PHYSICS_3D_DISABLED
World3D();
~World3D();
};
#endif // WORLD_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef WORLD_BOUNDARY_SHAPE_3D_H
#define WORLD_BOUNDARY_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -56,5 +55,3 @@ public:
WorldBoundaryShape3D();
};
#endif // WORLD_BOUNDARY_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATED_TEXTURE_H
#define ANIMATED_TEXTURE_H
#pragma once
#include "scene/resources/texture.h"
@ -106,5 +105,3 @@ public:
AnimatedTexture();
~AnimatedTexture();
};
#endif // ANIMATED_TEXTURE_H

View file

@ -464,7 +464,9 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const {
String prop_name = p_name;
if (p_name == SNAME("_compression")) {
ERR_FAIL_COND_V(!compression.enabled, false);
if (!compression.enabled) {
return false;
}
Dictionary comp;
comp["fps"] = compression.fps;
Array bounds;
@ -2476,7 +2478,7 @@ Variant Animation::_interpolate_angle(const Variant &p_a, const Variant &p_b, re
if (vformat == ((1 << Variant::INT) | (1 << Variant::FLOAT)) || vformat == (1 << Variant::FLOAT)) {
real_t a = p_a;
real_t b = p_b;
return Math::fposmod((float)Math::lerp_angle(a, b, p_c), (float)Math_TAU);
return Math::fposmod((float)Math::lerp_angle(a, b, p_c), (float)Math::TAU);
}
return _interpolate(p_a, p_b, p_c);
}
@ -2513,7 +2515,7 @@ Variant Animation::_cubic_interpolate_angle_in_time(const Variant &p_pre_a, cons
real_t b = p_b;
real_t pa = p_pre_a;
real_t pb = p_post_b;
return Math::fposmod((float)Math::cubic_interpolate_angle_in_time(a, b, pa, pb, p_c, p_b_t, p_pre_a_t, p_post_b_t), (float)Math_TAU);
return Math::fposmod((float)Math::cubic_interpolate_angle_in_time(a, b, pa, pb, p_c, p_b_t, p_pre_a_t, p_post_b_t), (float)Math::TAU);
}
return _cubic_interpolate_in_time(p_pre_a, p_a, p_b, p_post_b, p_c, p_pre_a_t, p_b_t, p_post_b_t);
}
@ -4207,7 +4209,7 @@ bool Animation::_quaternion_track_optimize_key(const TKey<Quaternion> t0, const
if (q0.get_axis().dot(q1.get_axis()) >= 1.0 - p_allowed_angular_error * 2.0) {
double a0 = Math::acos(t0.value.dot(t1.value));
double a1 = Math::acos(t1.value.dot(t2.value));
if (a0 + a1 >= Math_PI / 2) {
if (a0 + a1 >= Math::PI / 2) {
return false; // Rotation is more than 180 deg, keep key.
}
// Calc velocities.
@ -4335,7 +4337,7 @@ void Animation::_value_track_optimize(int p_idx, real_t p_allowed_velocity_err,
ERR_FAIL_INDEX(p_idx, tracks.size());
ERR_FAIL_COND(tracks[p_idx]->type != TYPE_VALUE);
ValueTrack *vt = static_cast<ValueTrack *>(tracks[p_idx]);
if (vt->values.size() == 0) {
if (vt->values.is_empty()) {
return;
}
Variant::Type type = vt->values[0].value.get_type();
@ -4357,11 +4359,11 @@ void Animation::_value_track_optimize(int p_idx, real_t p_allowed_velocity_err,
t1.value = vt->values[i + 1].value;
t2.value = vt->values[i + 2].value;
if (is_using_angle) {
float diff1 = fmod(t1.value - t0.value, Math_TAU);
t1.value = t0.value + fmod(2.0 * diff1, Math_TAU) - diff1;
float diff2 = fmod(t2.value - t1.value, Math_TAU);
t2.value = t1.value + fmod(2.0 * diff2, Math_TAU) - diff2;
if (abs(abs(diff1) + abs(diff2)) >= Math_PI) {
float diff1 = fmod(t1.value - t0.value, Math::TAU);
t1.value = t0.value + fmod(2.0 * diff1, Math::TAU) - diff1;
float diff2 = fmod(t2.value - t1.value, Math::TAU);
t2.value = t1.value + fmod(2.0 * diff2, Math::TAU) - diff2;
if (abs(abs(diff1) + abs(diff2)) >= Math::PI) {
break; // Rotation is more than 180 deg, keep key.
}
}
@ -4421,8 +4423,8 @@ void Animation::_value_track_optimize(int p_idx, real_t p_allowed_velocity_err,
float val_0 = vt->values[0].value;
float val_1 = vt->values[1].value;
if (is_using_angle) {
float diff1 = fmod(val_1 - val_0, Math_TAU);
val_1 = val_0 + fmod(2.0 * diff1, Math_TAU) - diff1;
float diff1 = fmod(val_1 - val_0, Math::TAU);
val_1 = val_0 + fmod(2.0 * diff1, Math::TAU) - diff1;
}
single_key = abs(val_0 - val_1) < p_allowed_precision_error;
} break;
@ -4507,7 +4509,7 @@ struct AnimationCompressionDataState {
if (p_delta == 0) {
return 0;
} else if (p_delta < 0) {
p_delta = ABS(p_delta) - 1;
p_delta = Math::abs(p_delta) - 1;
if (p_delta == 0) {
return 1;
}
@ -4582,7 +4584,7 @@ struct AnimationCompressionDataState {
}
uint32_t get_temp_packet_size() const {
if (temp_packets.size() == 0) {
if (temp_packets.is_empty()) {
return 0;
} else if (temp_packets.size() == 1) {
return components == 1 ? 4 : 8; // 1 component packet is 16 bits and 16 bits unused. 3 component packets is 48 bits and 16 bits unused
@ -4624,7 +4626,7 @@ struct AnimationCompressionDataState {
}
void commit_temp_packets() {
if (temp_packets.size() == 0) {
if (temp_packets.is_empty()) {
return; // Nothing to do.
}
//#define DEBUG_PACKET_PUSH
@ -4689,7 +4691,7 @@ struct AnimationCompressionDataState {
uint16_t deltau;
if (delta < 0) {
deltau = (ABS(delta) - 1) | (1 << max_shifts[j]);
deltau = (Math::abs(delta) - 1) | (1 << max_shifts[j]);
} else {
deltau = delta;
}
@ -4754,9 +4756,9 @@ Vector3i Animation::_compress_key(uint32_t p_track, const AABB &p_bounds, int32_
}
Vector3 axis = rot.get_axis();
float angle = rot.get_angle();
angle = Math::fposmod(double(angle), double(Math_PI * 2.0));
angle = Math::fposmod(double(angle), double(Math::PI * 2.0));
Vector2 oct = axis.octahedron_encode();
Vector3 rot_norm(oct.x, oct.y, angle / (Math_PI * 2.0)); // high resolution rotation in 0-1 angle.
Vector3 rot_norm(oct.x, oct.y, angle / (Math::PI * 2.0)); // high resolution rotation in 0-1 angle.
for (int j = 0; j < 3; j++) {
values[j] = CLAMP(int32_t(rot_norm[j] * 65535.0), 0, 65535);
@ -4890,7 +4892,7 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol
track_bounds.push_back(bounds);
}
if (tracks_to_compress.size() == 0) {
if (tracks_to_compress.is_empty()) {
return; //nothing to compress
}
@ -5045,7 +5047,7 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol
uint32_t total_page_size = 0;
for (uint32_t i = 0; i < data_tracks.size(); i++) {
if (data_tracks[i].temp_packets.size() == 0 || (data_tracks[i].temp_packets[data_tracks[i].temp_packets.size() - 1].frame) < finalizer_local_frame) {
if (data_tracks[i].temp_packets.is_empty() || (data_tracks[i].temp_packets[data_tracks[i].temp_packets.size() - 1].frame) < finalizer_local_frame) {
// Add finalizer frame if it makes sense
Vector3i values = _compress_key(tracks_to_compress[i], track_bounds[i], -1, page_end_frame * frame_len);
@ -5532,7 +5534,7 @@ int Animation::_get_compressed_key_count(uint32_t p_compressed_track) const {
Quaternion Animation::_uncompress_quaternion(const Vector3i &p_value) const {
Vector3 axis = Vector3::octahedron_decode(Vector2(float(p_value.x) / 65535.0, float(p_value.y) / 65535.0));
float angle = (float(p_value.z) / 65535.0) * 2.0 * Math_PI;
float angle = (float(p_value.z) / 65535.0) * 2.0 * Math::PI;
return Quaternion(axis, angle);
}
Vector3 Animation::_uncompress_pos_scale(uint32_t p_compressed_track, const Vector3i &p_value) const {

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATION_H
#define ANIMATION_H
#pragma once
#include "core/io/resource.h"
#include "core/templates/local_vector.h"
@ -44,6 +43,7 @@ public:
typedef uint32_t TypeHash;
static inline String PARAMETERS_BASE_PATH = "parameters/";
static inline constexpr real_t DEFAULT_STEP = 1.0 / 30;
enum TrackType : uint8_t {
TYPE_VALUE, // Set a value in a property, can be interpolated.
@ -281,7 +281,7 @@ private:
_FORCE_INLINE_ void _track_get_key_indices_in_range(const Vector<T> &p_array, double from_time, double to_time, List<int> *p_indices, bool p_is_backward) const;
double length = 1.0;
real_t step = 1.0 / 30;
real_t step = DEFAULT_STEP;
LoopMode loop_mode = LOOP_NONE;
bool capture_included = false;
void _check_capture_included();
@ -335,7 +335,7 @@ private:
* data for X / Blend Shape, Y and Z must be normalized first: unorm = float(data) / 65535.0
* **Blend Shape**: (unorm * 2.0 - 1.0) * Compression::BLEND_SHAPE_RANGE
* **Pos/Scale**: unorm_vec3 * bounds[track].size + bounds[track].position
* **Rotation**: Quaternion(Vector3::octahedron_decode(unorm_vec3.xy),unorm_vec3.z * Math_PI * 2.0)
* **Rotation**: Quaternion(Vector3::octahedron_decode(unorm_vec3.xy),unorm_vec3.z * Math::PI * 2.0)
* **Frame**: page.time_offset + frame * (1.0/fps)
*/
@ -586,5 +586,3 @@ VARIANT_ENUM_CAST(Animation::FindMode);
VARIANT_ENUM_CAST(Animation::HandleMode);
VARIANT_ENUM_CAST(Animation::HandleSetMode);
#endif // TOOLS_ENABLED
#endif // ANIMATION_H

View file

@ -42,10 +42,8 @@ bool AnimationLibrary::is_valid_library_name(const String &p_name) {
String AnimationLibrary::validate_library_name(const String &p_name) {
String name = p_name;
const char *characters = "/:,[";
for (const char *p = characters; *p; p++) {
name = name.replace(String::chr(*p), "_");
}
static const char *characters = "/:,[";
name.replace_chars(characters, '_');
return name;
}
@ -134,10 +132,8 @@ void AnimationLibrary::_set_data(const Dictionary &p_data) {
K.value->disconnect_changed(callable_mp(this, &AnimationLibrary::_animation_changed));
}
animations.clear();
List<Variant> keys;
p_data.get_key_list(&keys);
for (const Variant &K : keys) {
add_animation(K, p_data[K]);
for (const KeyValue<Variant, Variant> &kv : p_data) {
add_animation(kv.key, kv.value);
}
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ANIMATION_LIBRARY_H
#define ANIMATION_LIBRARY_H
#pragma once
#include "core/variant/typed_array.h"
#include "scene/resources/animation.h"
@ -69,5 +68,3 @@ public:
AnimationLibrary();
};
#endif // ANIMATION_LIBRARY_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ATLAS_TEXTURE_H
#define ATLAS_TEXTURE_H
#pragma once
#include "scene/resources/texture.h"
@ -77,5 +76,3 @@ public:
AtlasTexture();
};
#endif // ATLAS_TEXTURE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef AUDIO_STREAM_POLYPHONIC_H
#define AUDIO_STREAM_POLYPHONIC_H
#pragma once
#include "core/templates/local_vector.h"
#include "scene/scene_string_names.h"
@ -134,5 +133,3 @@ private:
public:
AudioStreamPlaybackPolyphonic();
};
#endif // AUDIO_STREAM_POLYPHONIC_H

View file

@ -56,6 +56,7 @@ void AudioStreamPlaybackWAV::start(double p_from_pos) {
sign = 1;
active = true;
begin_resample();
}
void AudioStreamPlaybackWAV::stop() {
@ -71,7 +72,7 @@ int AudioStreamPlaybackWAV::get_loop_count() const {
}
double AudioStreamPlaybackWAV::get_playback_position() const {
return float(offset >> MIX_FRAC_BITS) / base->mix_rate;
return double(offset) / base->mix_rate;
}
void AudioStreamPlaybackWAV::seek(double p_time) {
@ -86,20 +87,17 @@ void AudioStreamPlaybackWAV::seek(double p_time) {
p_time = max - 0.001;
}
offset = uint64_t(p_time * base->mix_rate) << MIX_FRAC_BITS;
offset = int64_t(p_time * base->mix_rate);
}
template <typename Depth, bool is_stereo, bool is_ima_adpcm, bool is_qoa>
void AudioStreamPlaybackWAV::do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &p_offset, int32_t &p_increment, uint32_t p_amount, IMA_ADPCM_State *p_ima_adpcm, QOA_State *p_qoa) {
void AudioStreamPlaybackWAV::decode_samples(const Depth *p_src, AudioFrame *p_dst, int64_t &p_offset, int8_t &p_increment, uint32_t p_amount, IMA_ADPCM_State *p_ima_adpcm, QOA_State *p_qoa) {
// this function will be compiled branchless by any decent compiler
int32_t final = 0, final_r = 0, next = 0, next_r = 0;
int32_t final = 0, final_r = 0;
while (p_amount) {
p_amount--;
int64_t pos = p_offset >> MIX_FRAC_BITS;
if (is_stereo && !is_ima_adpcm && !is_qoa) {
pos <<= 1;
}
int64_t pos = p_offset << (is_stereo && !is_ima_adpcm && !is_qoa ? 1 : 0);
if (is_ima_adpcm) {
int64_t sample_pos = pos + p_ima_adpcm[0].window_ofs;
@ -175,82 +173,32 @@ void AudioStreamPlaybackWAV::do_resample(const Depth *p_src, AudioFrame *p_dst,
final_r = p_ima_adpcm[1].predictor;
}
} else {
if (is_qoa) {
if (pos != p_qoa->cache_pos) { // Prevents triple decoding on lower mix rates.
for (int i = 0; i < 2; i++) {
// Sign operations prevent triple decoding on backward loops, maxing prevents pop.
uint32_t interp_pos = MIN(pos + (i * sign) + (sign < 0), p_qoa->desc.samples - 1);
uint32_t new_data_ofs = 8 + interp_pos / QOA_FRAME_LEN * p_qoa->frame_len;
} else if (is_qoa) {
uint32_t new_data_ofs = 8 + pos / QOA_FRAME_LEN * p_qoa->frame_len;
if (p_qoa->data_ofs != new_data_ofs) {
p_qoa->data_ofs = new_data_ofs;
const uint8_t *ofs_src = (uint8_t *)p_src + p_qoa->data_ofs;
qoa_decode_frame(ofs_src, p_qoa->frame_len, &p_qoa->desc, p_qoa->dec.ptr(), &p_qoa->dec_len);
}
uint32_t dec_idx = (interp_pos % QOA_FRAME_LEN) * p_qoa->desc.channels;
if ((sign > 0 && i == 0) || (sign < 0 && i == 1)) {
final = p_qoa->dec[dec_idx];
p_qoa->cache[0] = final;
if (is_stereo) {
final_r = p_qoa->dec[dec_idx + 1];
p_qoa->cache_r[0] = final_r;
}
} else {
next = p_qoa->dec[dec_idx];
p_qoa->cache[1] = next;
if (is_stereo) {
next_r = p_qoa->dec[dec_idx + 1];
p_qoa->cache_r[1] = next_r;
}
}
}
p_qoa->cache_pos = pos;
} else {
final = p_qoa->cache[0];
if (is_stereo) {
final_r = p_qoa->cache_r[0];
}
next = p_qoa->cache[1];
if (is_stereo) {
next_r = p_qoa->cache_r[1];
}
}
} else {
final = p_src[pos];
if (is_stereo) {
final_r = p_src[pos + 1];
}
if constexpr (sizeof(Depth) == 1) { /* conditions will not exist anymore when compiled! */
final <<= 8;
if (is_stereo) {
final_r <<= 8;
}
}
if (is_stereo) {
next = p_src[pos + 2];
next_r = p_src[pos + 3];
} else {
next = p_src[pos + 1];
}
if constexpr (sizeof(Depth) == 1) {
next <<= 8;
if (is_stereo) {
next_r <<= 8;
}
}
if (p_qoa->data_ofs != new_data_ofs) {
p_qoa->data_ofs = new_data_ofs;
const uint8_t *ofs_src = (uint8_t *)p_src + p_qoa->data_ofs;
qoa_decode_frame(ofs_src, p_qoa->frame_len, &p_qoa->desc, p_qoa->dec.ptr(), &p_qoa->dec_len);
}
int32_t frac = int64_t(p_offset & MIX_FRAC_MASK);
final = final + ((next - final) * frac >> MIX_FRAC_BITS);
uint32_t dec_idx = pos % QOA_FRAME_LEN << (is_stereo ? 1 : 0);
final = p_qoa->dec[dec_idx];
if (is_stereo) {
final_r = final_r + ((next_r - final_r) * frac >> MIX_FRAC_BITS);
final_r = p_qoa->dec[dec_idx + 1];
}
} else {
final = p_src[pos];
if (is_stereo) {
final_r = p_src[pos + 1];
}
if constexpr (sizeof(Depth) == 1) { /* conditions will not exist anymore when compiled! */
final <<= 8;
if (is_stereo) {
final_r <<= 8;
}
}
}
@ -266,7 +214,7 @@ void AudioStreamPlaybackWAV::do_resample(const Depth *p_src, AudioFrame *p_dst,
}
}
int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) {
int AudioStreamPlaybackWAV::_mix_internal(AudioFrame *p_buffer, int p_frames) {
if (base->data.is_empty() || !active) {
for (int i = 0; i < p_frames; i++) {
p_buffer[i] = AudioFrame(0, 0);
@ -274,7 +222,7 @@ int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_
return 0;
}
int len = base->data_bytes;
uint32_t len = base->data_bytes;
switch (base->format) {
case AudioStreamWAV::FORMAT_8_BITS:
len /= 1;
@ -294,13 +242,10 @@ int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_
len /= 2;
}
/* some 64-bit fixed point precaches */
int64_t loop_begin_fp = ((int64_t)base->loop_begin << MIX_FRAC_BITS);
int64_t loop_end_fp = ((int64_t)base->loop_end << MIX_FRAC_BITS);
int64_t length_fp = ((int64_t)len << MIX_FRAC_BITS);
int64_t begin_limit = (base->loop_mode != AudioStreamWAV::LOOP_DISABLED) ? loop_begin_fp : 0;
int64_t end_limit = (base->loop_mode != AudioStreamWAV::LOOP_DISABLED) ? loop_end_fp : length_fp - MIX_FRAC_LEN;
int64_t loop_begin = base->loop_begin;
int64_t loop_end = base->loop_end;
int64_t begin_limit = (base->loop_mode != AudioStreamWAV::LOOP_DISABLED) ? loop_begin : 0;
int64_t end_limit = (base->loop_mode != AudioStreamWAV::LOOP_DISABLED) ? loop_end : len - 1;
bool is_stereo = base->stereo;
int32_t todo = p_frames;
@ -309,13 +254,7 @@ int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_
sign = -1;
}
float base_rate = AudioServer::get_singleton()->get_mix_rate();
float srate = base->mix_rate;
srate *= p_rate_scale;
float playback_speed_scale = AudioServer::get_singleton()->get_playback_speed_scale();
float fincrement = (srate * playback_speed_scale) / base_rate;
int32_t increment = int32_t(MAX(fincrement * MIX_FRAC_LEN, 1));
increment *= sign;
int8_t increment = sign;
//looping
@ -324,13 +263,13 @@ int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_
/* audio data */
const uint8_t *data = base->data.ptr() + AudioStreamWAV::DATA_PAD;
const uint8_t *data = base->data.ptr();
AudioFrame *dst_buff = p_buffer;
if (format == AudioStreamWAV::FORMAT_IMA_ADPCM) {
if (loop_format != AudioStreamWAV::LOOP_DISABLED) {
ima_adpcm[0].loop_pos = loop_begin_fp >> MIX_FRAC_BITS;
ima_adpcm[1].loop_pos = loop_begin_fp >> MIX_FRAC_BITS;
ima_adpcm[0].loop_pos = loop_begin;
ima_adpcm[1].loop_pos = loop_begin;
loop_format = AudioStreamWAV::LOOP_FORWARD;
}
}
@ -344,16 +283,16 @@ int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_
if (increment < 0) {
/* going backwards */
if (loop_format != AudioStreamWAV::LOOP_DISABLED && offset < loop_begin_fp) {
if (loop_format != AudioStreamWAV::LOOP_DISABLED && offset < loop_begin) {
/* loopstart reached */
if (loop_format == AudioStreamWAV::LOOP_PINGPONG) {
/* bounce ping pong */
offset = loop_begin_fp + (loop_begin_fp - offset);
offset = loop_begin + (loop_begin - offset);
increment = -increment;
sign *= -1;
} else {
/* go to loop-end */
offset = loop_end_fp - (loop_begin_fp - offset);
offset = loop_end - (loop_begin - offset);
}
} else {
/* check for sample not reaching beginning */
@ -364,12 +303,12 @@ int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_
}
} else {
/* going forward */
if (loop_format != AudioStreamWAV::LOOP_DISABLED && offset >= loop_end_fp) {
if (loop_format != AudioStreamWAV::LOOP_DISABLED && offset >= loop_end) {
/* loopend reached */
if (loop_format == AudioStreamWAV::LOOP_PINGPONG) {
/* bounce ping pong */
offset = loop_end_fp - (offset - loop_end_fp);
offset = loop_end - (offset - loop_end);
increment = -increment;
sign *= -1;
} else {
@ -379,16 +318,16 @@ int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_
for (int i = 0; i < 2; i++) {
ima_adpcm[i].step_index = ima_adpcm[i].loop_step_index;
ima_adpcm[i].predictor = ima_adpcm[i].loop_predictor;
ima_adpcm[i].last_nibble = loop_begin_fp >> MIX_FRAC_BITS;
ima_adpcm[i].last_nibble = loop_begin;
}
offset = loop_begin_fp;
offset = loop_begin;
} else {
offset = loop_begin_fp + (offset - loop_end_fp);
offset = loop_begin + (offset - loop_end);
}
}
} else {
/* no loop, check for end of sample */
if (offset >= length_fp) {
if (offset >= len) {
active = false;
break;
}
@ -415,32 +354,32 @@ int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_
switch (base->format) {
case AudioStreamWAV::FORMAT_8_BITS: {
if (is_stereo) {
do_resample<int8_t, true, false, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
decode_samples<int8_t, true, false, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
} else {
do_resample<int8_t, false, false, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
decode_samples<int8_t, false, false, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
}
} break;
case AudioStreamWAV::FORMAT_16_BITS: {
if (is_stereo) {
do_resample<int16_t, true, false, false>((int16_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
decode_samples<int16_t, true, false, false>((int16_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
} else {
do_resample<int16_t, false, false, false>((int16_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
decode_samples<int16_t, false, false, false>((int16_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
}
} break;
case AudioStreamWAV::FORMAT_IMA_ADPCM: {
if (is_stereo) {
do_resample<int8_t, true, true, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
decode_samples<int8_t, true, true, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
} else {
do_resample<int8_t, false, true, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
decode_samples<int8_t, false, true, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
}
} break;
case AudioStreamWAV::FORMAT_QOA: {
if (is_stereo) {
do_resample<uint8_t, true, false, true>((uint8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
decode_samples<uint8_t, true, false, true>((uint8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
} else {
do_resample<uint8_t, false, false, true>((uint8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
decode_samples<uint8_t, false, false, true>((uint8_t *)data, dst_buff, offset, increment, target, ima_adpcm, &qoa);
}
} break;
}
@ -460,6 +399,10 @@ int AudioStreamPlaybackWAV::mix(AudioFrame *p_buffer, float p_rate_scale, int p_
return p_frames;
}
float AudioStreamPlaybackWAV::get_stream_sampling_rate() {
return base->mix_rate;
}
void AudioStreamPlaybackWAV::tag_used_streams() {
base->tag_used(get_playback_position());
}
@ -552,7 +495,7 @@ double AudioStreamWAV::get_length() const {
break;
case AudioStreamWAV::FORMAT_QOA:
qoa_desc desc = {};
qoa_decode_header(data.ptr() + DATA_PAD, data_bytes, &desc);
qoa_decode_header(data.ptr(), data_bytes, &desc);
len = desc.samples * desc.channels;
break;
}
@ -571,28 +514,14 @@ bool AudioStreamWAV::is_monophonic() const {
void AudioStreamWAV::set_data(const Vector<uint8_t> &p_data) {
AudioServer::get_singleton()->lock();
int src_data_len = p_data.size();
data.clear();
int alloc_len = src_data_len + DATA_PAD * 2;
data.resize(alloc_len);
memset(data.ptr(), 0, alloc_len);
memcpy(data.ptr() + DATA_PAD, p_data.ptr(), src_data_len);
data_bytes = src_data_len;
data = p_data;
data_bytes = p_data.size();
AudioServer::get_singleton()->unlock();
}
Vector<uint8_t> AudioStreamWAV::get_data() const {
Vector<uint8_t> pv;
if (data_bytes) {
pv.resize(data_bytes);
memcpy(pv.ptrw(), data.ptr() + DATA_PAD, data_bytes);
}
return pv;
return data;
}
Error AudioStreamWAV::save_to_wav(const String &p_path) {
@ -681,7 +610,7 @@ Ref<AudioStreamPlayback> AudioStreamWAV::instantiate_playback() {
sample->base = Ref<AudioStreamWAV>(this);
if (format == AudioStreamWAV::FORMAT_QOA) {
uint32_t ffp = qoa_decode_header(data.ptr() + DATA_PAD, data_bytes, &sample->qoa.desc);
uint32_t ffp = qoa_decode_header(data.ptr(), data_bytes, &sample->qoa.desc);
ERR_FAIL_COND_V(ffp != 8, Ref<AudioStreamPlaybackWAV>());
sample->qoa.frame_len = qoa_max_frame_size(&sample->qoa.desc);
int samples_len = (sample->qoa.desc.samples > QOA_FRAME_LEN ? QOA_FRAME_LEN : sample->qoa.desc.samples);

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef AUDIO_STREAM_WAV_H
#define AUDIO_STREAM_WAV_H
#pragma once
#include "servers/audio/audio_stream.h"
@ -37,13 +36,8 @@
class AudioStreamWAV;
class AudioStreamPlaybackWAV : public AudioStreamPlayback {
GDCLASS(AudioStreamPlaybackWAV, AudioStreamPlayback);
enum {
MIX_FRAC_BITS = 13,
MIX_FRAC_LEN = (1 << MIX_FRAC_BITS),
MIX_FRAC_MASK = MIX_FRAC_LEN - 1,
};
class AudioStreamPlaybackWAV : public AudioStreamPlaybackResampled {
GDCLASS(AudioStreamPlaybackWAV, AudioStreamPlaybackResampled);
struct IMA_ADPCM_State {
int16_t step_index = 0;
@ -62,23 +56,24 @@ class AudioStreamPlaybackWAV : public AudioStreamPlayback {
uint32_t frame_len = 0;
LocalVector<int16_t> dec;
uint32_t dec_len = 0;
int64_t cache_pos = -1;
int16_t cache[2] = { 0, 0 };
int16_t cache_r[2] = { 0, 0 };
} qoa;
int64_t offset = 0;
int sign = 1;
int8_t sign = 1;
bool active = false;
friend class AudioStreamWAV;
Ref<AudioStreamWAV> base;
template <typename Depth, bool is_stereo, bool is_ima_adpcm, bool is_qoa>
void do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &p_offset, int32_t &p_increment, uint32_t p_amount, IMA_ADPCM_State *p_ima_adpcm, QOA_State *p_qoa);
void decode_samples(const Depth *p_src, AudioFrame *p_dst, int64_t &p_offset, int8_t &p_increment, uint32_t p_amount, IMA_ADPCM_State *p_ima_adpcm, QOA_State *p_qoa);
bool _is_sample = false;
Ref<AudioSamplePlayback> sample_playback;
protected:
virtual int _mix_internal(AudioFrame *p_buffer, int p_frames) override;
virtual float get_stream_sampling_rate() override;
public:
virtual void start(double p_from_pos = 0.0) override;
virtual void stop() override;
@ -89,8 +84,6 @@ public:
virtual double get_playback_position() const override;
virtual void seek(double p_time) override;
virtual int mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) override;
virtual void tag_used_streams() override;
virtual void set_is_sample(bool p_is_sample) override;
@ -125,10 +118,6 @@ public:
private:
friend class AudioStreamPlaybackWAV;
enum {
DATA_PAD = 16 //padding for interpolation
};
Format format = FORMAT_8_BITS;
LoopMode loop_mode = LOOP_DISABLED;
bool stereo = false;
@ -305,5 +294,3 @@ public:
VARIANT_ENUM_CAST(AudioStreamWAV::Format)
VARIANT_ENUM_CAST(AudioStreamWAV::LoopMode)
#endif // AUDIO_STREAM_WAV_H

View file

@ -523,7 +523,6 @@ static void fill_bits(const BitMap *p_src, Ref<BitMap> &p_map, const Point2i &p_
Vector<Vector<Vector2>> BitMap::clip_opaque_to_polygons(const Rect2i &p_rect, float p_epsilon) const {
Rect2i r = Rect2i(0, 0, width, height).intersection(p_rect);
Point2i from;
Ref<BitMap> fill;
fill.instantiate();
fill->create(get_size());

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef BIT_MAP_H
#define BIT_MAP_H
#pragma once
#include "core/io/image.h"
#include "core/io/resource.h"
@ -80,5 +79,3 @@ public:
BitMap();
};
#endif // BIT_MAP_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef BONE_MAP_H
#define BONE_MAP_H
#pragma once
#include "skeleton_profile.h"
@ -64,5 +63,3 @@ public:
BoneMap();
~BoneMap();
};
#endif // BONE_MAP_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CAMERA_ATTRIBUTES_H
#define CAMERA_ATTRIBUTES_H
#pragma once
#include "core/io/resource.h"
#include "core/templates/rid.h"
@ -179,5 +178,3 @@ public:
CameraAttributesPhysical();
~CameraAttributesPhysical();
};
#endif // CAMERA_ATTRIBUTES_H

View file

@ -45,6 +45,7 @@ void CameraTexture::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "camera_feed_id"), "set_camera_feed_id", "get_camera_feed_id");
ADD_PROPERTY(PropertyInfo(Variant::INT, "which_feed"), "set_which_feed", "get_which_feed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "camera_is_active"), "set_camera_active", "get_camera_active");
ADD_PROPERTY_DEFAULT("camera_is_active", false);
}
void CameraTexture::_on_format_changed() {

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CAMERA_TEXTURE_H
#define CAMERA_TEXTURE_H
#pragma once
#include "scene/resources/texture.h"
@ -65,5 +64,3 @@ public:
CameraTexture();
~CameraTexture();
};
#endif // CAMERA_TEXTURE_H

View file

@ -78,7 +78,7 @@ void CanvasItemMaterial::_update_shader() {
//must create a shader!
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
String code = "// NOTE: Shader automatically converted from " VERSION_NAME " " VERSION_FULL_CONFIG "'s CanvasItemMaterial.\n\n";
String code = "// NOTE: Shader automatically converted from " GODOT_VERSION_NAME " " GODOT_VERSION_FULL_CONFIG "'s CanvasItemMaterial.\n\n";
code += "shader_type canvas_item;\nrender_mode ";
switch (blend_mode) {

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CANVAS_ITEM_MATERIAL_H
#define CANVAS_ITEM_MATERIAL_H
#pragma once
#include "scene/resources/material.h"
@ -149,5 +148,3 @@ public:
VARIANT_ENUM_CAST(CanvasItemMaterial::BlendMode)
VARIANT_ENUM_CAST(CanvasItemMaterial::LightMode)
#endif // CANVAS_ITEM_MATERIAL_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef COLOR_PALETTE_H
#define COLOR_PALETTE_H
#pragma once
#include "core/io/resource.h"
@ -46,5 +45,3 @@ public:
void set_colors(const PackedColorArray &p_colors);
PackedColorArray get_colors() const;
};
#endif // COLOR_PALETTE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef COMPOSITOR_H
#define COMPOSITOR_H
#pragma once
#include "core/io/resource.h"
#include "core/object/gdvirtual.gen.inc"
@ -123,5 +122,3 @@ public:
void set_compositor_effects(const TypedArray<CompositorEffect> &p_compositor_effects);
TypedArray<CompositorEffect> get_compositor_effects() const;
};
#endif // COMPOSITOR_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef COMPRESSED_TEXTURE_H
#define COMPRESSED_TEXTURE_H
#pragma once
#include "core/io/resource_loader.h"
#include "scene/resources/texture.h"
@ -270,5 +269,3 @@ public:
virtual bool handles_type(const String &p_type) const override;
virtual String get_resource_type(const String &p_path) const override;
};
#endif // COMPRESSED_TEXTURE_H

View file

@ -56,7 +56,7 @@ void Curve::set_point_count(int p_count) {
notify_property_list_changed();
}
int Curve::_add_point(Vector2 p_position, real_t p_left_tangent, real_t p_right_tangent, TangentMode p_left_mode, TangentMode p_right_mode) {
int Curve::_add_point(Vector2 p_position, real_t p_left_tangent, real_t p_right_tangent, TangentMode p_left_mode, TangentMode p_right_mode, bool p_mark_dirty) {
// Add a point and preserve order.
// Points must remain within the given value and domain ranges.
@ -65,7 +65,7 @@ int Curve::_add_point(Vector2 p_position, real_t p_left_tangent, real_t p_right_
int ret = -1;
if (_points.size() == 0) {
if (_points.is_empty()) {
_points.push_back(Point(p_position, p_left_tangent, p_right_tangent, p_left_mode, p_right_mode));
ret = 0;
@ -99,7 +99,9 @@ int Curve::_add_point(Vector2 p_position, real_t p_left_tangent, real_t p_right_
update_auto_tangents(ret);
mark_dirty();
if (p_mark_dirty) {
mark_dirty();
}
return ret;
}
@ -221,10 +223,12 @@ Curve::TangentMode Curve::get_point_right_mode(int p_index) const {
return _points[p_index].right_mode;
}
void Curve::_remove_point(int p_index) {
void Curve::_remove_point(int p_index, bool p_mark_dirty) {
ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_index, _points.size());
_points.remove_at(p_index);
mark_dirty();
if (p_mark_dirty) {
mark_dirty();
}
}
void Curve::remove_point(int p_index) {
@ -252,16 +256,13 @@ void Curve::set_point_value(int p_index, real_t p_position) {
int Curve::set_point_offset(int p_index, real_t p_offset) {
ERR_FAIL_UNSIGNED_INDEX_V((uint32_t)p_index, _points.size(), -1);
Point p = _points[p_index];
_remove_point(p_index);
int i = _add_point(Vector2(p_offset, p.position.y));
_points[i].left_tangent = p.left_tangent;
_points[i].right_tangent = p.right_tangent;
_points[i].left_mode = p.left_mode;
_points[i].right_mode = p.right_mode;
_remove_point(p_index, false);
int i = _add_point(Vector2(p_offset, p.position.y), p.left_tangent, p.right_tangent, p.left_mode, p.right_mode, false);
if (p_index != i) {
update_auto_tangents(p_index);
}
update_auto_tangents(i);
mark_dirty();
return i;
}
@ -376,7 +377,7 @@ void Curve::set_max_domain(real_t p_max) {
}
real_t Curve::sample(real_t p_offset) const {
if (_points.size() == 0) {
if (_points.is_empty()) {
return 0;
}
if (_points.size() == 1) {
@ -538,8 +539,8 @@ real_t Curve::sample_baked(real_t p_offset) const {
}
// Special cases if the cache is too small.
if (_baked_cache.size() == 0) {
if (_points.size() == 0) {
if (_baked_cache.is_empty()) {
if (_points.is_empty()) {
return 0;
}
return _points[0].position.y;
@ -568,7 +569,7 @@ real_t Curve::sample_baked(real_t p_offset) const {
}
void Curve::ensure_default_setup(real_t p_min, real_t p_max) {
if (_points.size() == 0 && _min_value == 0 && _max_value == 1) {
if (_points.is_empty() && _min_value == 0 && _max_value == 1) {
add_point(Vector2(0, 1));
add_point(Vector2(1, 1));
set_min_value(p_min);
@ -880,12 +881,22 @@ void Curve2D::_bake_segment2d_even_length(RBMap<real_t, Vector2> &r_bake, real_t
Vector2 Curve2D::_calculate_tangent(const Vector2 &p_begin, const Vector2 &p_control_1, const Vector2 &p_control_2, const Vector2 &p_end, const real_t p_t) {
// Handle corner cases.
if (Math::is_zero_approx(p_t - 0.0f) && p_control_1.is_equal_approx(p_begin)) {
return (p_end - p_begin).normalized();
}
if (Math::is_zero_approx(p_t - 1.0f) && p_control_2.is_equal_approx(p_end)) {
return (p_end - p_begin).normalized();
if (Math::is_zero_approx(p_t - 0.0f)) {
if (p_control_1.is_equal_approx(p_begin)) {
if (p_control_1.is_equal_approx(p_control_2)) {
return (p_end - p_begin).normalized();
} else {
return (p_control_2 - p_begin).normalized();
}
}
} else if (Math::is_zero_approx(p_t - 1.0f)) {
if (p_control_2.is_equal_approx(p_end)) {
if (p_control_2.is_equal_approx(p_control_1)) {
return (p_end - p_begin).normalized();
} else {
return (p_end - p_control_1).normalized();
}
}
}
return p_begin.bezier_derivative(p_control_1, p_control_2, p_end, p_t).normalized();
@ -899,7 +910,7 @@ void Curve2D::_bake() const {
baked_max_ofs = 0;
baked_cache_dirty = false;
if (points.size() == 0) {
if (points.is_empty()) {
baked_point_cache.clear();
baked_dist_cache.clear();
baked_forward_vector_cache.clear();
@ -1248,7 +1259,7 @@ void Curve2D::_set_data(const Dictionary &p_data) {
PackedVector2Array Curve2D::tessellate(int p_max_stages, real_t p_tolerance) const {
PackedVector2Array tess;
if (points.size() == 0) {
if (points.is_empty()) {
return tess;
}
@ -1298,7 +1309,7 @@ PackedVector2Array Curve2D::tessellate_even_length(int p_max_stages, real_t p_le
PackedVector2Array tess;
Vector<RBMap<real_t, Vector2>> midpoints = _tessellate_even_length(p_max_stages, p_length);
if (midpoints.size() == 0) {
if (midpoints.is_empty()) {
return tess;
}
@ -1619,12 +1630,22 @@ void Curve3D::_bake_segment3d_even_length(RBMap<real_t, Vector3> &r_bake, real_t
Vector3 Curve3D::_calculate_tangent(const Vector3 &p_begin, const Vector3 &p_control_1, const Vector3 &p_control_2, const Vector3 &p_end, const real_t p_t) {
// Handle corner cases.
if (Math::is_zero_approx(p_t - 0.0f) && p_control_1.is_equal_approx(p_begin)) {
return (p_end - p_begin).normalized();
}
if (Math::is_zero_approx(p_t - 1.0f) && p_control_2.is_equal_approx(p_end)) {
return (p_end - p_begin).normalized();
if (Math::is_zero_approx(p_t - 0.0f)) {
if (p_control_1.is_equal_approx(p_begin)) {
if (p_control_1.is_equal_approx(p_control_2)) {
return (p_end - p_begin).normalized();
} else {
return (p_control_2 - p_begin).normalized();
}
}
} else if (Math::is_zero_approx(p_t - 1.0f)) {
if (p_control_2.is_equal_approx(p_end)) {
if (p_control_2.is_equal_approx(p_control_1)) {
return (p_end - p_begin).normalized();
} else {
return (p_end - p_control_1).normalized();
}
}
}
return p_begin.bezier_derivative(p_control_1, p_control_2, p_end, p_t).normalized();
@ -1638,7 +1659,7 @@ void Curve3D::_bake() const {
baked_max_ofs = 0;
baked_cache_dirty = false;
if (points.size() == 0) {
if (points.is_empty()) {
#ifdef TOOLS_ENABLED
points_in_cache.clear();
#endif
@ -2272,7 +2293,7 @@ void Curve3D::_set_data(const Dictionary &p_data) {
PackedVector3Array Curve3D::tessellate(int p_max_stages, real_t p_tolerance) const {
PackedVector3Array tess;
if (points.size() == 0) {
if (points.is_empty()) {
return tess;
}
Vector<RBMap<real_t, Vector3>> midpoints;
@ -2335,7 +2356,7 @@ PackedVector3Array Curve3D::tessellate_even_length(int p_max_stages, real_t p_le
PackedVector3Array tess;
Vector<RBMap<real_t, Vector3>> midpoints = _tessellate_even_length(p_max_stages, p_length);
if (midpoints.size() == 0) {
if (midpoints.is_empty()) {
return tess;
}

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CURVE_H
#define CURVE_H
#pragma once
#include "core/io/resource.h"
@ -77,15 +76,15 @@ public:
void set_point_count(int p_count);
int add_point(Vector2 p_position,
real_t left_tangent = 0,
real_t right_tangent = 0,
TangentMode left_mode = TANGENT_FREE,
TangentMode right_mode = TANGENT_FREE);
real_t p_left_tangent = 0,
real_t p_right_tangent = 0,
TangentMode p_left_mode = TANGENT_FREE,
TangentMode p_right_mode = TANGENT_FREE);
int add_point_no_update(Vector2 p_position,
real_t left_tangent = 0,
real_t right_tangent = 0,
TangentMode left_mode = TANGENT_FREE,
TangentMode right_mode = TANGENT_FREE);
real_t p_left_tangent = 0,
real_t p_right_tangent = 0,
TangentMode p_left_mode = TANGENT_FREE,
TangentMode p_right_mode = TANGENT_FREE);
void remove_point(int p_index);
void clear_points();
@ -127,10 +126,10 @@ public:
TangentMode get_point_left_mode(int p_index) const;
TangentMode get_point_right_mode(int p_index) const;
void update_auto_tangents(int i);
void update_auto_tangents(int p_index);
Array get_data() const;
void set_data(Array input);
void set_data(Array p_input);
void bake();
void _bake() const;
@ -150,11 +149,12 @@ protected:
private:
void mark_dirty();
int _add_point(Vector2 p_position,
real_t left_tangent = 0,
real_t right_tangent = 0,
TangentMode left_mode = TANGENT_FREE,
TangentMode right_mode = TANGENT_FREE);
void _remove_point(int p_index);
real_t p_left_tangent = 0,
real_t p_right_tangent = 0,
TangentMode p_left_mode = TANGENT_FREE,
TangentMode p_right_mode = TANGENT_FREE,
bool p_mark_dirty = true);
void _remove_point(int p_index, bool p_mark_dirty = true);
LocalVector<Point> _points;
mutable bool _baked_cache_dirty = false;
@ -363,5 +363,3 @@ public:
Curve3D();
};
#endif // CURVE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CURVE_TEXTURE_H
#define CURVE_TEXTURE_H
#pragma once
#include "scene/resources/texture.h"
@ -118,5 +117,3 @@ public:
CurveXYZTexture();
~CurveXYZTexture();
};
#endif // CURVE_TEXTURE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef ENVIRONMENT_H
#define ENVIRONMENT_H
#pragma once
#include "core/io/resource.h"
#include "scene/resources/sky.h"
@ -454,5 +453,3 @@ VARIANT_ENUM_CAST(Environment::ToneMapper)
VARIANT_ENUM_CAST(Environment::SDFGIYScale)
VARIANT_ENUM_CAST(Environment::GlowBlendMode)
VARIANT_ENUM_CAST(Environment::FogMode)
#endif // ENVIRONMENT_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef EXTERNAL_TEXTURE_H
#define EXTERNAL_TEXTURE_H
#pragma once
#include "scene/resources/texture.h"
@ -65,5 +64,3 @@ public:
ExternalTexture();
~ExternalTexture();
};
#endif // EXTERNAL_TEXTURE_H

View file

@ -298,7 +298,7 @@ void Font::set_cache_capacity(int p_single_line, int p_multi_line) {
Size2 Font::get_string_size(const String &p_text, HorizontalAlignment p_alignment, float p_width, int p_font_size, BitField<TextServer::JustificationFlag> p_jst_flags, TextServer::Direction p_direction, TextServer::Orientation p_orientation) const {
bool fill = (p_alignment == HORIZONTAL_ALIGNMENT_FILL);
ShapedTextKey key = ShapedTextKey(p_text, p_font_size, fill ? p_width : 0.0, fill ? p_jst_flags : TextServer::JUSTIFICATION_NONE, TextServer::BREAK_NONE, p_direction, p_orientation);
ShapedTextKey key = ShapedTextKey(p_text, p_font_size, fill ? p_width : 0.0, fill ? p_jst_flags : BitField(TextServer::JUSTIFICATION_NONE), TextServer::BREAK_NONE, p_direction, p_orientation);
Ref<TextLine> buffer;
if (cache.has(key)) {
@ -347,7 +347,7 @@ Size2 Font::get_multiline_string_size(const String &p_text, HorizontalAlignment
void Font::draw_string(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment, float p_width, int p_font_size, const Color &p_modulate, BitField<TextServer::JustificationFlag> p_jst_flags, TextServer::Direction p_direction, TextServer::Orientation p_orientation) const {
bool fill = (p_alignment == HORIZONTAL_ALIGNMENT_FILL);
ShapedTextKey key = ShapedTextKey(p_text, p_font_size, fill ? p_width : 0.0, fill ? p_jst_flags : TextServer::JUSTIFICATION_NONE, TextServer::BREAK_NONE, p_direction, p_orientation);
ShapedTextKey key = ShapedTextKey(p_text, p_font_size, fill ? p_width : 0.0, fill ? p_jst_flags : BitField(TextServer::JUSTIFICATION_NONE), TextServer::BREAK_NONE, p_direction, p_orientation);
Ref<TextLine> buffer;
if (cache.has(key)) {
@ -410,7 +410,7 @@ void Font::draw_multiline_string(RID p_canvas_item, const Point2 &p_pos, const S
void Font::draw_string_outline(RID p_canvas_item, const Point2 &p_pos, const String &p_text, HorizontalAlignment p_alignment, float p_width, int p_font_size, int p_size, const Color &p_modulate, BitField<TextServer::JustificationFlag> p_jst_flags, TextServer::Direction p_direction, TextServer::Orientation p_orientation) const {
bool fill = (p_alignment == HORIZONTAL_ALIGNMENT_FILL);
ShapedTextKey key = ShapedTextKey(p_text, p_font_size, fill ? p_width : 0.0, fill ? p_jst_flags : TextServer::JUSTIFICATION_NONE, TextServer::BREAK_NONE, p_direction, p_orientation);
ShapedTextKey key = ShapedTextKey(p_text, p_font_size, fill ? p_width : 0.0, fill ? p_jst_flags : BitField(TextServer::JUSTIFICATION_NONE), TextServer::BREAK_NONE, p_direction, p_orientation);
Ref<TextLine> buffer;
if (cache.has(key)) {
@ -602,6 +602,7 @@ _FORCE_INLINE_ void FontFile::_ensure_rid(int p_cache_index, int p_make_linked_f
TS->font_set_fixed_size(cache[p_cache_index], fixed_size);
TS->font_set_fixed_size_scale_mode(cache[p_cache_index], fixed_size_scale_mode);
TS->font_set_force_autohinter(cache[p_cache_index], force_autohinter);
TS->font_set_modulate_color_glyphs(cache[p_cache_index], modulate_color_glyphs);
TS->font_set_allow_system_fallback(cache[p_cache_index], allow_system_fallback);
TS->font_set_hinting(cache[p_cache_index], hinting);
TS->font_set_subpixel_positioning(cache[p_cache_index], subpixel_positioning);
@ -929,6 +930,9 @@ void FontFile::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_force_autohinter", "force_autohinter"), &FontFile::set_force_autohinter);
ClassDB::bind_method(D_METHOD("is_force_autohinter"), &FontFile::is_force_autohinter);
ClassDB::bind_method(D_METHOD("set_modulate_color_glyphs", "modulate"), &FontFile::set_modulate_color_glyphs);
ClassDB::bind_method(D_METHOD("is_modulate_color_glyphs"), &FontFile::is_modulate_color_glyphs);
ClassDB::bind_method(D_METHOD("set_hinting", "hinting"), &FontFile::set_hinting);
ClassDB::bind_method(D_METHOD("get_hinting"), &FontFile::get_hinting);
@ -1054,6 +1058,7 @@ void FontFile::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_msdf_size", "get_msdf_size");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_system_fallback", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_allow_system_fallback", "is_allow_system_fallback");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "force_autohinter", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_force_autohinter", "is_force_autohinter");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "modulate_color_glyphs", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_modulate_color_glyphs", "is_modulate_color_glyphs");
ADD_PROPERTY(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal", PROPERTY_USAGE_STORAGE), "set_hinting", "get_hinting");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_oversampling", "get_oversampling");
ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_fixed_size", "get_fixed_size");
@ -1413,6 +1418,7 @@ void FontFile::reset_state() {
disable_embedded_bitmaps = true;
msdf = false;
force_autohinter = false;
modulate_color_glyphs = false;
allow_system_fallback = true;
hinting = TextServer::HINTING_LIGHT;
subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED;
@ -1453,6 +1459,7 @@ Error FontFile::_load_bitmap_font(const String &p_path, List<String> *r_image_fi
disable_embedded_bitmaps = true;
msdf = false;
force_autohinter = false;
modulate_color_glyphs = false;
allow_system_fallback = true;
hinting = TextServer::HINTING_NONE;
oversampling = 1.0f;
@ -1488,7 +1495,7 @@ Error FontFile::_load_bitmap_font(const String &p_path, List<String> *r_image_fi
switch (block_type) {
case 1: /* info */ {
ERR_FAIL_COND_V_MSG(block_size < 15, ERR_CANT_CREATE, "Invalid BMFont info block size.");
base_size = ABS(static_cast<int16_t>(f->get_16()));
base_size = Math::abs(static_cast<int16_t>(f->get_16()));
if (base_size == 0) {
base_size = 16;
}
@ -1782,7 +1789,7 @@ Error FontFile::_load_bitmap_font(const String &p_path, List<String> *r_image_fi
if (type == "info") {
if (keys.has("size")) {
base_size = ABS(keys["size"].to_int());
base_size = Math::abs(keys["size"].to_int());
if (base_size == 0) {
base_size = 16;
}
@ -2271,6 +2278,21 @@ bool FontFile::is_force_autohinter() const {
return force_autohinter;
}
void FontFile::set_modulate_color_glyphs(bool p_modulate) {
if (modulate_color_glyphs != p_modulate) {
modulate_color_glyphs = p_modulate;
for (int i = 0; i < cache.size(); i++) {
_ensure_rid(i);
TS->font_set_modulate_color_glyphs(cache[i], modulate_color_glyphs);
}
emit_changed();
}
}
bool FontFile::is_modulate_color_glyphs() const {
return modulate_color_glyphs;
}
void FontFile::set_hinting(TextServer::Hinting p_hinting) {
if (hinting != p_hinting) {
hinting = p_hinting;
@ -3100,6 +3122,9 @@ void SystemFont::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_force_autohinter", "force_autohinter"), &SystemFont::set_force_autohinter);
ClassDB::bind_method(D_METHOD("is_force_autohinter"), &SystemFont::is_force_autohinter);
ClassDB::bind_method(D_METHOD("set_modulate_color_glyphs", "modulate"), &SystemFont::set_modulate_color_glyphs);
ClassDB::bind_method(D_METHOD("is_modulate_color_glyphs"), &SystemFont::is_modulate_color_glyphs);
ClassDB::bind_method(D_METHOD("set_hinting", "hinting"), &SystemFont::set_hinting);
ClassDB::bind_method(D_METHOD("get_hinting"), &SystemFont::get_hinting);
@ -3138,6 +3163,7 @@ void SystemFont::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_embedded_bitmaps"), "set_disable_embedded_bitmaps", "get_disable_embedded_bitmaps");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_system_fallback"), "set_allow_system_fallback", "is_allow_system_fallback");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "force_autohinter"), "set_force_autohinter", "is_force_autohinter");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "modulate_color_glyphs"), "set_modulate_color_glyphs", "is_modulate_color_glyphs");
ADD_PROPERTY(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), "set_hinting", "get_hinting");
ADD_PROPERTY(PropertyInfo(Variant::INT, "subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel"), "set_subpixel_positioning", "get_subpixel_positioning");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_rounding_remainders"), "set_keep_rounding_remainders", "get_keep_rounding_remainders");
@ -3243,6 +3269,7 @@ void SystemFont::_update_base_font() {
file->set_generate_mipmaps(mipmaps);
file->set_disable_embedded_bitmaps(disable_embedded_bitmaps);
file->set_force_autohinter(force_autohinter);
file->set_modulate_color_glyphs(modulate_color_glyphs);
file->set_allow_system_fallback(allow_system_fallback);
file->set_hinting(hinting);
file->set_subpixel_positioning(subpixel_positioning);
@ -3287,6 +3314,7 @@ void SystemFont::reset_state() {
mipmaps = false;
disable_embedded_bitmaps = true;
force_autohinter = false;
modulate_color_glyphs = false;
allow_system_fallback = true;
hinting = TextServer::HINTING_LIGHT;
subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED;
@ -3416,6 +3444,20 @@ bool SystemFont::is_force_autohinter() const {
return force_autohinter;
}
void SystemFont::set_modulate_color_glyphs(bool p_modulate) {
if (modulate_color_glyphs != p_modulate) {
modulate_color_glyphs = p_modulate;
if (base_font.is_valid()) {
base_font->set_modulate_color_glyphs(modulate_color_glyphs);
}
emit_changed();
}
}
bool SystemFont::is_modulate_color_glyphs() const {
return modulate_color_glyphs;
}
void SystemFont::set_hinting(TextServer::Hinting p_hinting) {
if (hinting != p_hinting) {
hinting = p_hinting;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef FONT_H
#define FONT_H
#pragma once
#include "core/io/resource.h"
#include "core/templates/lru.h"
@ -193,6 +192,7 @@ class FontFile : public Font {
int fixed_size = 0;
TextServer::FixedSizeScaleMode fixed_size_scale_mode = TextServer::FIXED_SIZE_SCALE_DISABLE;
bool force_autohinter = false;
bool modulate_color_glyphs = false;
bool allow_system_fallback = true;
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
@ -274,6 +274,9 @@ public:
virtual void set_force_autohinter(bool p_force_autohinter);
virtual bool is_force_autohinter() const;
virtual void set_modulate_color_glyphs(bool p_modulate);
virtual bool is_modulate_color_glyphs() const;
virtual void set_hinting(TextServer::Hinting p_hinting);
virtual TextServer::Hinting get_hinting() const;
@ -480,6 +483,7 @@ class SystemFont : public Font {
bool mipmaps = false;
bool disable_embedded_bitmaps = true;
bool force_autohinter = false;
bool modulate_color_glyphs = false;
bool allow_system_fallback = true;
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
@ -516,6 +520,9 @@ public:
virtual void set_force_autohinter(bool p_force_autohinter);
virtual bool is_force_autohinter() const;
virtual void set_modulate_color_glyphs(bool p_modulate);
virtual bool is_modulate_color_glyphs() const;
virtual void set_hinting(TextServer::Hinting p_hinting);
virtual TextServer::Hinting get_hinting() const;
@ -559,5 +566,3 @@ public:
SystemFont();
~SystemFont();
};
#endif // FONT_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GRADIENT_H
#define GRADIENT_H
#pragma once
#include "core/io/resource.h"
@ -240,5 +239,3 @@ public:
VARIANT_ENUM_CAST(Gradient::InterpolationMode);
VARIANT_ENUM_CAST(Gradient::ColorSpace);
#endif // GRADIENT_H

View file

@ -292,10 +292,7 @@ float GradientTexture2D::_get_gradient_offset_at(int x, int y) const {
pos.y = static_cast<float>(y) / (height - 1);
}
if (fill == Fill::FILL_LINEAR) {
Vector2 segment[2];
segment[0] = fill_from;
segment[1] = fill_to;
Vector2 closest = Geometry2D::get_closest_point_to_segment_uncapped(pos, &segment[0]);
const Vector2 closest = Geometry2D::get_closest_point_to_segment_uncapped(pos, fill_from, fill_to);
ofs = (closest - fill_from).length() / (fill_to - fill_from).length();
if ((closest - fill_from).dot(fill_to - fill_from) < 0) {
ofs *= -1;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GRADIENT_TEXTURE_H
#define GRADIENT_TEXTURE_H
#pragma once
#include "scene/resources/texture.h"
@ -142,5 +141,3 @@ public:
VARIANT_ENUM_CAST(GradientTexture2D::Fill);
VARIANT_ENUM_CAST(GradientTexture2D::Repeat);
#endif // GRADIENT_TEXTURE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef IMAGE_TEXTURE_H
#define IMAGE_TEXTURE_H
#pragma once
#include "scene/resources/texture.h"
@ -202,5 +201,3 @@ public:
virtual Ref<Resource> create_placeholder() const;
};
#endif // IMAGE_TEXTURE_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef IMMEDIATE_MESH_H
#define IMMEDIATE_MESH_H
#pragma once
#include "core/templates/local_vector.h"
#include "scene/resources/mesh.h"
@ -114,5 +113,3 @@ public:
ImmediateMesh();
~ImmediateMesh();
};
#endif // IMMEDIATE_MESH_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef LABEL_SETTINGS_H
#define LABEL_SETTINGS_H
#pragma once
#include "core/io/resource.h"
#include "font.h"
@ -89,5 +88,3 @@ public:
void set_shadow_offset(const Vector2 &p_offset);
Vector2 get_shadow_offset() const;
};
#endif // LABEL_SETTINGS_H

View file

@ -257,10 +257,10 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
bool is_none_group_undefined = true;
bool is_none_group = true;
for (List<PropertyInfo>::Element *E = list.front(); E; E = E->next()) {
if (E->get().usage == PROPERTY_USAGE_GROUP) {
if (!E->get().name.is_empty()) {
Vector<String> vgroup = E->get().name.split("::");
for (const PropertyInfo &pi : list) {
if (pi.usage == PROPERTY_USAGE_GROUP) {
if (!pi.name.is_empty()) {
Vector<String> vgroup = pi.name.split("::");
last_group = vgroup[0];
if (vgroup.size() > 1) {
last_subgroup = vgroup[1];
@ -322,23 +322,23 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
vgroups.push_back(Pair<String, LocalVector<String>>("<None>", { "<None>" }));
}
const bool is_uniform_cached = param_cache.has(E->get().name);
const bool is_uniform_cached = param_cache.has(pi.name);
bool is_uniform_type_compatible = true;
if (is_uniform_cached) {
// Check if the uniform Variant type changed, for example vec3 to vec4.
const Variant &cached = param_cache.get(E->get().name);
const Variant &cached = param_cache.get(pi.name);
if (cached.is_array()) {
// Allow some array conversions for backwards compatibility.
is_uniform_type_compatible = Variant::can_convert(E->get().type, cached.get_type());
is_uniform_type_compatible = Variant::can_convert(pi.type, cached.get_type());
} else {
is_uniform_type_compatible = E->get().type == cached.get_type();
is_uniform_type_compatible = pi.type == cached.get_type();
}
#ifndef DISABLE_DEPRECATED
// PackedFloat32Array -> PackedVector4Array conversion.
if (!is_uniform_type_compatible && E->get().type == Variant::PACKED_VECTOR4_ARRAY && cached.get_type() == Variant::PACKED_FLOAT32_ARRAY) {
if (!is_uniform_type_compatible && pi.type == Variant::PACKED_VECTOR4_ARRAY && cached.get_type() == Variant::PACKED_FLOAT32_ARRAY) {
PackedVector4Array varray;
PackedFloat32Array array = (PackedFloat32Array)cached;
@ -346,28 +346,28 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
varray.push_back(Vector4(array[i], array[i + 1], array[i + 2], array[i + 3]));
}
param_cache.insert(E->get().name, varray);
param_cache.insert(pi.name, varray);
is_uniform_type_compatible = true;
}
#endif
if (is_uniform_type_compatible && E->get().type == Variant::OBJECT && cached.get_type() == Variant::OBJECT) {
if (is_uniform_type_compatible && pi.type == Variant::OBJECT && cached.get_type() == Variant::OBJECT) {
// Check if the Object class (hint string) changed, for example Texture2D sampler to Texture3D.
// Allow inheritance, Texture2D type sampler should also accept CompressedTexture2D.
Object *cached_obj = cached;
if (!cached_obj->is_class(E->get().hint_string)) {
if (!cached_obj->is_class(pi.hint_string)) {
is_uniform_type_compatible = false;
}
}
}
PropertyInfo info = E->get();
PropertyInfo info = pi;
info.name = "shader_parameter/" + info.name;
if (!is_uniform_cached || !is_uniform_type_compatible) {
// Property has never been edited or its type changed, retrieve with default value.
Variant default_value = RenderingServer::get_singleton()->shader_get_parameter_default(shader->get_rid(), E->get().name);
param_cache.insert(E->get().name, default_value);
remap_cache.insert(info.name, E->get().name);
Variant default_value = RenderingServer::get_singleton()->shader_get_parameter_default(shader->get_rid(), pi.name);
param_cache.insert(pi.name, default_value);
remap_cache.insert(info.name, pi.name);
}
groups[last_group][last_subgroup].push_back(info);
}
@ -376,8 +376,8 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
String group = group_pair.first;
for (const String &subgroup : group_pair.second) {
List<PropertyInfo> &prop_infos = groups[group][subgroup];
for (List<PropertyInfo>::Element *item = prop_infos.front(); item; item = item->next()) {
p_list->push_back(item->get());
for (const PropertyInfo &item : prop_infos) {
p_list->push_back(item);
}
}
}
@ -750,7 +750,7 @@ void BaseMaterial3D::_update_shader() {
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
String code = vformat(
"// NOTE: Shader automatically converted from " VERSION_NAME " " VERSION_FULL_CONFIG "'s %s.\n\n",
"// NOTE: Shader automatically converted from " GODOT_VERSION_NAME " " GODOT_VERSION_FULL_CONFIG "'s %s.\n\n",
orm ? "ORMMaterial3D" : "StandardMaterial3D");
// Define shader type and render mode based on property values.

Some files were not shown because too many files have changed in this diff Show more