summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/canvas_item.cpp23
-rw-r--r--scene/2d/canvas_item.h2
-rw-r--r--scene/2d/collision_object_2d.cpp6
-rw-r--r--scene/2d/collision_object_2d.h2
-rw-r--r--scene/2d/node_2d.cpp2
-rw-r--r--scene/2d/tile_map.cpp8
-rw-r--r--scene/3d/mesh_instance.cpp81
-rw-r--r--scene/3d/mesh_instance.h2
-rw-r--r--scene/3d/spatial.cpp13
-rw-r--r--scene/gui/graph_edit.cpp20
-rw-r--r--scene/gui/graph_edit.h2
-rw-r--r--scene/gui/split_container.cpp22
-rwxr-xr-xscene/main/node.cpp98
-rw-r--r--scene/main/node.h19
-rw-r--r--scene/main/scene_tree.cpp18
-rw-r--r--scene/main/scene_tree.h1
-rw-r--r--scene/resources/material.cpp4
-rw-r--r--scene/resources/primitive_meshes.cpp60
-rw-r--r--scene/resources/primitive_meshes.h3
-rw-r--r--scene/resources/tile_set.cpp49
-rw-r--r--scene/resources/tile_set.h8
21 files changed, 269 insertions, 174 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index 4a80aba355..68a3166aa7 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -609,6 +609,27 @@ void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color
VisualServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width, p_antialiased);
}
+void CanvasItem::draw_polyline(const Vector<Point2> &p_points, const Color &p_color, float p_width, bool p_antialiased) {
+
+ if (!drawing) {
+ ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
+ ERR_FAIL();
+ }
+
+ Vector<Color> colors;
+ colors.push_back(p_color);
+ VisualServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, colors, p_width, p_antialiased);
+}
+
+void CanvasItem::draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width, bool p_antialiased) {
+
+ if (!drawing) {
+ ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
+ ERR_FAIL();
+ }
+
+ VisualServer::get_singleton()->canvas_item_add_polyline(canvas_item, p_points, p_colors, p_width, p_antialiased);
+}
void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled) {
if (!drawing) {
@@ -955,6 +976,8 @@ void CanvasItem::_bind_methods() {
//ClassDB::bind_method(D_METHOD("get_transform"),&CanvasItem::get_transform);
ClassDB::bind_method(D_METHOD("draw_line", "from", "to", "color", "width", "antialiased"), &CanvasItem::draw_line, DEFVAL(1.0), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("draw_polyline", "points", "color", "width", "antialiased"), &CanvasItem::draw_polyline, DEFVAL(1.0), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("draw_polyline_colors", "points", "colors", "width", "antialiased"), &CanvasItem::draw_polyline_colors, DEFVAL(1.0), DEFVAL(false));
ClassDB::bind_method(D_METHOD("draw_rect", "rect", "color", "filled"), &CanvasItem::draw_rect, DEFVAL(true));
ClassDB::bind_method(D_METHOD("draw_circle", "pos", "radius", "color"), &CanvasItem::draw_circle);
ClassDB::bind_method(D_METHOD("draw_texture", "texture:Texture", "pos", "modulate", "normal_map:Texture"), &CanvasItem::draw_texture, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(Variant()));
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 06130e3252..27842727ac 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -242,6 +242,8 @@ public:
/* DRAWING API */
void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width = 1.0, bool p_antialiased = false);
+ void draw_polyline(const Vector<Point2> &p_points, const Color &p_color, float p_width = 1.0, bool p_antialiased = false);
+ void draw_polyline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, float p_width = 1.0, bool p_antialiased = false);
void draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled = true);
void draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color);
void draw_texture(const Ref<Texture> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1), const Ref<Texture> &p_normal_map = Ref<Texture>());
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index c5c274e225..0821b00dd9 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -204,10 +204,10 @@ int CollisionObject2D::shape_owner_get_shape_count(uint32_t p_owner) const {
return shapes[p_owner].shapes.size();
}
-Ref<Shape> CollisionObject2D::shape_owner_get_shape(uint32_t p_owner, int p_shape) const {
+Ref<Shape2D> CollisionObject2D::shape_owner_get_shape(uint32_t p_owner, int p_shape) const {
- ERR_FAIL_COND_V(!shapes.has(p_owner), Ref<Shape>());
- ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), Ref<Shape>());
+ ERR_FAIL_COND_V(!shapes.has(p_owner), Ref<Shape2D>());
+ ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), Ref<Shape2D>());
return shapes[p_owner].shapes[p_shape].shape;
}
diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h
index deffe8a002..3580d3d942 100644
--- a/scene/2d/collision_object_2d.h
+++ b/scene/2d/collision_object_2d.h
@@ -94,7 +94,7 @@ public:
void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2D> &p_shape);
int shape_owner_get_shape_count(uint32_t p_owner) const;
- Ref<Shape> shape_owner_get_shape(uint32_t p_owner, int p_shape) const;
+ Ref<Shape2D> shape_owner_get_shape(uint32_t p_owner, int p_shape) const;
int shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const;
void shape_owner_remove_shape(uint32_t p_owner, int p_shape);
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index 6fe1dd73fe..bd6ab99801 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -319,7 +319,7 @@ void Node2D::set_global_scale(const Size2 &p_scale) {
CanvasItem *pi = get_parent_item();
if (pi) {
const Size2 parent_global_scale = pi->get_global_transform().get_scale();
- set_scale(p_scale - parent_global_scale);
+ set_scale(p_scale / parent_global_scale);
} else {
set_scale(p_scale);
}
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 57e25ec609..9d70b75027 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -461,16 +461,18 @@ void TileMap::_update_dirty_quadrants() {
Transform2D xform;
xform.set_origin(offset.floor());
- _fix_cell_transform(xform, c, shapes[i].shape_offset + center_ofs, s);
+ _fix_cell_transform(xform, c, center_ofs, s);
+
+ xform *= shapes[i].shape_transform;
if (debug_canvas_item.is_valid()) {
vs->canvas_item_add_set_transform(debug_canvas_item, xform);
shape->draw(debug_canvas_item, debug_collision_color);
}
ps->body_add_shape(q.body, shape->get_rid(), xform);
- shape_idx++;
- ps->body_set_shape_as_one_way_collision(q.body, shape_idx, shapes[i].one_way_collision);
ps->body_set_shape_metadata(q.body, shape_idx, Vector2(E->key().x, E->key().y));
+ ps->body_set_shape_as_one_way_collision(q.body, shape_idx, shapes[i].one_way_collision);
+ shape_idx++;
}
}
diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance.cpp
index e755b1480b..14886f4b7a 100644
--- a/scene/3d/mesh_instance.cpp
+++ b/scene/3d/mesh_instance.cpp
@@ -32,6 +32,7 @@
#include "body_shape.h"
#include "core_string_names.h"
#include "physics_body.h"
+#include "scene/resources/material.h"
#include "scene/scene_string_names.h"
#include "skeleton.h"
bool MeshInstance::_set(const StringName &p_name, const Variant &p_value) {
@@ -274,6 +275,80 @@ void MeshInstance::_mesh_changed() {
materials.resize(mesh->get_surface_count());
}
+void MeshInstance::create_debug_tagents() {
+
+ Vector<Vector3> lines;
+ Vector<Color> colors;
+
+ Ref<Mesh> mesh = get_mesh();
+ if (!mesh.is_valid())
+ return;
+
+ for (int i = 0; i < mesh->get_surface_count(); i++) {
+ Array arrays = mesh->surface_get_arrays(i);
+ Vector<Vector3> verts = arrays[Mesh::ARRAY_VERTEX];
+ Vector<Vector3> norms = arrays[Mesh::ARRAY_NORMAL];
+ if (norms.size() == 0)
+ continue;
+ Vector<float> tangents = arrays[Mesh::ARRAY_TANGENT];
+ if (tangents.size() == 0)
+ continue;
+
+ for (int j = 0; j < verts.size(); j++) {
+ Vector3 v = verts[j];
+ Vector3 n = norms[j];
+ Vector3 t = Vector3(tangents[j * 4 + 0], tangents[j * 4 + 1], tangents[j * 4 + 2]);
+ Vector3 b = (n.cross(t)).normalized() * tangents[j * 4 + 3];
+
+ lines.push_back(v); //normal
+ colors.push_back(Color(0, 0, 1)); //color
+ lines.push_back(v + n * 0.04); //normal
+ colors.push_back(Color(0, 0, 1)); //color
+
+ lines.push_back(v); //tangent
+ colors.push_back(Color(1, 0, 0)); //color
+ lines.push_back(v + t * 0.04); //tangent
+ colors.push_back(Color(1, 0, 0)); //color
+
+ lines.push_back(v); //binormal
+ colors.push_back(Color(0, 1, 0)); //color
+ lines.push_back(v + b * 0.04); //binormal
+ colors.push_back(Color(0, 1, 0)); //color
+ }
+ }
+
+ if (lines.size()) {
+
+ Ref<SpatialMaterial> sm;
+ sm.instance();
+
+ sm->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
+ sm->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
+ sm->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
+
+ Ref<ArrayMesh> am;
+ am.instance();
+ Array a;
+ a.resize(Mesh::ARRAY_MAX);
+ a[Mesh::ARRAY_VERTEX] = lines;
+ a[Mesh::ARRAY_COLOR] = colors;
+
+ am->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, a);
+ am->surface_set_material(0, sm);
+
+ MeshInstance *mi = memnew(MeshInstance);
+ mi->set_mesh(am);
+ mi->set_name("DebugTangents");
+ add_child(mi);
+ if (get_parent()) {
+ if (get_parent() == get_tree()->get_edited_scene_root())
+ mi->set_owner(get_parent());
+ else
+ mi->set_owner(get_parent()->get_owner());
+ }
+ }
+}
+
void MeshInstance::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_mesh", "mesh:Mesh"), &MeshInstance::set_mesh);
@@ -281,12 +356,18 @@ void MeshInstance::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path:NodePath"), &MeshInstance::set_skeleton_path);
ClassDB::bind_method(D_METHOD("get_skeleton_path:NodePath"), &MeshInstance::get_skeleton_path);
+ ClassDB::bind_method(D_METHOD("set_surface_material", "surface", "material:Material"), &MeshInstance::set_surface_material);
+ ClassDB::bind_method(D_METHOD("get_surface_material:Material", "surface"), &MeshInstance::get_surface_material);
+
ClassDB::bind_method(D_METHOD("create_trimesh_collision"), &MeshInstance::create_trimesh_collision);
ClassDB::set_method_flags("MeshInstance", "create_trimesh_collision", METHOD_FLAGS_DEFAULT);
ClassDB::bind_method(D_METHOD("create_convex_collision"), &MeshInstance::create_convex_collision);
ClassDB::set_method_flags("MeshInstance", "create_convex_collision", METHOD_FLAGS_DEFAULT);
ClassDB::bind_method(D_METHOD("_mesh_changed"), &MeshInstance::_mesh_changed);
+ ClassDB::bind_method(D_METHOD("create_debug_tagents"), &MeshInstance::create_debug_tagents);
+ ClassDB::set_method_flags("MeshInstance", "create_debug_tagents", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
+
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton"), "set_skeleton_path", "get_skeleton_path");
}
diff --git a/scene/3d/mesh_instance.h b/scene/3d/mesh_instance.h
index c11c52b76d..be328084af 100644
--- a/scene/3d/mesh_instance.h
+++ b/scene/3d/mesh_instance.h
@@ -83,6 +83,8 @@ public:
Node *create_convex_collision_node();
void create_convex_collision();
+ void create_debug_tagents();
+
virtual Rect3 get_aabb() const;
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp
index 3debbf02c3..20c2cc1eb5 100644
--- a/scene/3d/spatial.cpp
+++ b/scene/3d/spatial.cpp
@@ -541,10 +541,7 @@ void Spatial::show() {
if (!is_inside_tree())
return;
- if (!data.parent || is_visible_in_tree()) {
-
- _propagate_visibility_changed();
- }
+ _propagate_visibility_changed();
}
void Spatial::hide() {
@@ -552,14 +549,14 @@ void Spatial::hide() {
if (!data.visible)
return;
- bool was_visible = is_visible_in_tree();
data.visible = false;
- if (!data.parent || was_visible) {
+ if (!is_inside_tree())
+ return;
- _propagate_visibility_changed();
- }
+ _propagate_visibility_changed();
}
+
bool Spatial::is_visible_in_tree() const {
const Spatial *s = this;
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 8d085d5399..9d45b6e70a 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -568,7 +568,7 @@ static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, Vector2 start, Vector2 co
return start * omt3 + control_1 * omt2 * t * 3.0 + control_2 * omt * t2 * 3.0 + end * t3;
}
-void GraphEdit::_bake_segment2d(CanvasItem *p_where, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const {
+void GraphEdit::_bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const {
float mp = p_begin + (p_end - p_begin) * 0.5;
Vector2 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b);
@@ -581,11 +581,12 @@ void GraphEdit::_bake_segment2d(CanvasItem *p_where, float p_begin, float p_end,
if (p_depth >= p_min_depth && (dp < p_tol || p_depth >= p_max_depth)) {
- p_where->draw_line(beg, end, p_color.linear_interpolate(p_to_color, mp), 2, true);
+ points.push_back((beg + end) * 0.5);
+ colors.push_back(p_color.linear_interpolate(p_to_color, mp));
lines++;
} else {
- _bake_segment2d(p_where, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
- _bake_segment2d(p_where, mp, p_end, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
+ _bake_segment2d(points, colors, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
+ _bake_segment2d(points, colors, mp, p_end, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
}
}
@@ -609,7 +610,16 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const
Vector2 c2 = Vector2(-cp_offset * zoom, 0);
int lines = 0;
- _bake_segment2d(p_where, 0, 1, p_from, c1, p_to, c2, 0, 3, 9, 8, p_color, p_to_color, lines);
+
+ Vector<Point2> points;
+ Vector<Color> colors;
+ points.push_back(p_from);
+ colors.push_back(p_color);
+ _bake_segment2d(points, colors, 0, 1, p_from, c1, p_to, c2, 0, 3, 9, 8, p_color, p_to_color, lines);
+ points.push_back(p_to);
+ colors.push_back(p_to_color);
+
+ p_where->draw_polyline_colors(points, colors, 2, true);
#else
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index 22d053d312..e908829d5f 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -110,7 +110,7 @@ private:
bool awaiting_scroll_offset_update;
List<Connection> connections;
- void _bake_segment2d(CanvasItem *p_where, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const;
+ void _bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const;
void _draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color);
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index 31236fa277..e3dad08809 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -131,7 +131,12 @@ void SplitContainer::_resort() {
if (ratiomode) {
- middle_sep = ms_first[axis] + available / 2;
+ int first_ratio = first->get_stretch_ratio();
+ int second_ratio = second->get_stretch_ratio();
+
+ float ratio = float(first_ratio) / (first_ratio + second_ratio);
+
+ middle_sep = ms_first[axis] + available * ratio;
} else if (expand_first_mode) {
@@ -144,12 +149,17 @@ void SplitContainer::_resort() {
} else if (ratiomode) {
- if (expand_ofs < -(available / 2))
- expand_ofs = -(available / 2);
- else if (expand_ofs > (available / 2))
- expand_ofs = (available / 2);
+ int first_ratio = first->get_stretch_ratio();
+ int second_ratio = second->get_stretch_ratio();
+
+ float ratio = float(first_ratio) / (first_ratio + second_ratio);
+
+ if (expand_ofs < -(available * ratio))
+ expand_ofs = -(available * ratio);
+ else if (expand_ofs > (available * (1.0 - ratio)))
+ expand_ofs = (available * (1.0 - ratio));
- middle_sep = ms_first[axis] + available / 2 + expand_ofs;
+ middle_sep = ms_first[axis] + available * ratio + expand_ofs;
} else if (expand_first_mode) {
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 0c65c44392..61e563143c 100755
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -37,7 +37,6 @@
#include "viewport.h"
VARIANT_ENUM_CAST(Node::PauseMode);
-VARIANT_ENUM_CAST(Node::NetworkMode);
VARIANT_ENUM_CAST(Node::RPCMode);
void Node::_notification(int p_notification) {
@@ -77,16 +76,6 @@ void Node::_notification(int p_notification) {
data.pause_owner = this;
}
- if (data.network_mode == NETWORK_MODE_INHERIT) {
-
- if (data.parent)
- data.network_owner = data.parent->data.network_owner;
- else
- data.network_owner = NULL;
- } else {
- data.network_owner = this;
- }
-
if (data.input)
add_to_group("_vp_input" + itos(get_viewport()->get_instance_ID()));
if (data.unhandled_input)
@@ -108,7 +97,6 @@ void Node::_notification(int p_notification) {
remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_ID()));
data.pause_owner = NULL;
- data.network_owner = NULL;
if (data.path_cache) {
memdelete(data.path_cache);
data.path_cache = NULL;
@@ -472,69 +460,28 @@ void Node::_propagate_pause_owner(Node *p_owner) {
}
}
-void Node::set_network_mode(NetworkMode p_mode) {
+void Node::set_network_master(int p_peer_id, bool p_recursive) {
- if (data.network_mode == p_mode)
- return;
+ data.network_master = p_peer_id;
- bool prev_inherits = data.network_mode == NETWORK_MODE_INHERIT;
- data.network_mode = p_mode;
- if (!is_inside_tree())
- return; //pointless
- if ((data.network_mode == NETWORK_MODE_INHERIT) == prev_inherits)
- return; ///nothing changed
-
- Node *owner = NULL;
-
- if (data.network_mode == NETWORK_MODE_INHERIT) {
+ if (p_recursive) {
+ for (int i = 0; i < data.children.size(); i++) {
- if (data.parent)
- owner = data.parent->data.network_owner;
- } else {
- owner = this;
+ data.children[i]->set_network_master(p_peer_id, true);
+ }
}
-
- _propagate_network_owner(owner);
}
-Node::NetworkMode Node::get_network_mode() const {
+int Node::get_network_master() const {
- return data.network_mode;
+ return data.network_master;
}
bool Node::is_network_master() const {
ERR_FAIL_COND_V(!is_inside_tree(), false);
- switch (data.network_mode) {
- case NETWORK_MODE_INHERIT: {
-
- if (data.network_owner)
- return data.network_owner->is_network_master();
- else
- return get_tree()->is_network_server();
- } break;
- case NETWORK_MODE_MASTER: {
-
- return true;
- } break;
- case NETWORK_MODE_SLAVE: {
- return false;
- } break;
- }
-
- return false;
-}
-
-void Node::_propagate_network_owner(Node *p_owner) {
-
- if (data.network_mode != NETWORK_MODE_INHERIT)
- return;
- data.network_owner = p_owner;
- for (int i = 0; i < data.children.size(); i++) {
-
- data.children[i]->_propagate_network_owner(p_owner);
- }
+ return get_tree()->get_network_unique_id() == data.network_master;
}
/***** RPC CONFIG ********/
@@ -962,7 +909,7 @@ void Node::rset_unreliable_id(int p_peer_id, const StringName &p_property, const
//////////// end of rpc
-bool Node::can_call_rpc(const StringName &p_method) const {
+bool Node::can_call_rpc(const StringName &p_method, int p_from) const {
const Map<StringName, RPCMode>::Element *E = data.rpc_methods.find(p_method);
if (E) {
@@ -982,7 +929,7 @@ bool Node::can_call_rpc(const StringName &p_method) const {
return is_network_master();
} break;
case RPC_MODE_SLAVE: {
- return !is_network_master();
+ return !is_network_master() && p_from == get_network_master();
} break;
}
}
@@ -1006,16 +953,16 @@ bool Node::can_call_rpc(const StringName &p_method) const {
return is_network_master();
} break;
case ScriptInstance::RPC_MODE_SLAVE: {
- return !is_network_master();
+ return !is_network_master() && p_from == get_network_master();
} break;
}
}
- ERR_PRINTS("RPC on unauthorized method attempted: " + String(p_method) + " on base: " + String(Variant(this)));
+ ERR_PRINTS("RPC from " + itos(p_from) + " on unauthorized method attempted: " + String(p_method) + " on base: " + String(Variant(this)));
return false;
}
-bool Node::can_call_rset(const StringName &p_property) const {
+bool Node::can_call_rset(const StringName &p_property, int p_from) const {
const Map<StringName, RPCMode>::Element *E = data.rpc_properties.find(p_property);
if (E) {
@@ -1035,7 +982,7 @@ bool Node::can_call_rset(const StringName &p_property) const {
return is_network_master();
} break;
case RPC_MODE_SLAVE: {
- return !is_network_master();
+ return !is_network_master() && p_from == get_network_master();
} break;
}
}
@@ -1059,12 +1006,12 @@ bool Node::can_call_rset(const StringName &p_property) const {
return is_network_master();
} break;
case ScriptInstance::RPC_MODE_SLAVE: {
- return !is_network_master();
+ return !is_network_master() && p_from == get_network_master();
} break;
}
}
- ERR_PRINTS("RSET on unauthorized property attempted: " + String(p_property) + " on base: " + String(Variant(this)));
+ ERR_PRINTS("RSET from " + itos(p_from) + " on unauthorized property attempted: " + String(p_property) + " on base: " + String(Variant(this)));
return false;
}
@@ -2845,8 +2792,8 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("request_ready"), &Node::request_ready);
- ClassDB::bind_method(D_METHOD("set_network_mode", "mode"), &Node::set_network_mode);
- ClassDB::bind_method(D_METHOD("get_network_mode"), &Node::get_network_mode);
+ ClassDB::bind_method(D_METHOD("set_network_master", "id", "recursive"), &Node::set_network_master, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("get_network_master"), &Node::get_network_master);
ClassDB::bind_method(D_METHOD("is_network_master"), &Node::is_network_master);
@@ -2902,10 +2849,6 @@ void Node::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_INTERNAL_PROCESS);
BIND_CONSTANT(NOTIFICATION_INTERNAL_FIXED_PROCESS);
- BIND_CONSTANT(NETWORK_MODE_INHERIT);
- BIND_CONSTANT(NETWORK_MODE_MASTER);
- BIND_CONSTANT(NETWORK_MODE_SLAVE);
-
BIND_CONSTANT(RPC_MODE_DISABLED);
BIND_CONSTANT(RPC_MODE_REMOTE);
BIND_CONSTANT(RPC_MODE_SYNC);
@@ -2977,8 +2920,7 @@ Node::Node() {
data.unhandled_key_input = false;
data.pause_mode = PAUSE_MODE_INHERIT;
data.pause_owner = NULL;
- data.network_mode = NETWORK_MODE_INHERIT;
- data.network_owner = NULL;
+ data.network_master = 1; //server by default
data.path_cache = NULL;
data.parent_owned = false;
data.in_constructor = true;
diff --git a/scene/main/node.h b/scene/main/node.h
index ffd2b7ce5f..7baa65c022 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -61,13 +61,6 @@ public:
DUPLICATE_USE_INSTANCING = 8
};
- enum NetworkMode {
-
- NETWORK_MODE_INHERIT,
- NETWORK_MODE_MASTER,
- NETWORK_MODE_SLAVE
- };
-
enum RPCMode {
RPC_MODE_DISABLED, //no rpc for this method, calls to this will be blocked (default)
@@ -122,8 +115,7 @@ private:
PauseMode pause_mode;
Node *pause_owner;
- NetworkMode network_mode;
- Node *network_owner;
+ int network_master;
Map<StringName, RPCMode> rpc_methods;
Map<StringName, RPCMode> rpc_properties;
@@ -173,7 +165,6 @@ private:
void _propagate_validate_owner();
void _print_stray_nodes();
void _propagate_pause_owner(Node *p_owner);
- void _propagate_network_owner(Node *p_owner);
Array _get_node_and_resource(const NodePath &p_path);
void _duplicate_signals(const Node *p_original, Node *p_copy) const;
@@ -393,8 +384,8 @@ public:
bool is_displayed_folded() const;
/* NETWORK */
- void set_network_mode(NetworkMode p_mode);
- NetworkMode get_network_mode() const;
+ void set_network_master(int p_peer_id, bool p_recursive = true);
+ int get_network_master() const;
bool is_network_master() const;
void rpc_config(const StringName &p_method, RPCMode p_mode); // config a local method for RPC
@@ -414,8 +405,8 @@ public:
void rsetp(int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value);
- bool can_call_rpc(const StringName &p_method) const;
- bool can_call_rset(const StringName &p_property) const;
+ bool can_call_rpc(const StringName &p_method, int p_from) const;
+ bool can_call_rset(const StringName &p_property, int p_from) const;
Node();
~Node();
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 479abccda6..1e5735de97 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -1763,6 +1763,16 @@ int SceneTree::get_network_unique_id() const {
return network_peer->get_unique_id();
}
+Vector<int> SceneTree::get_network_connected_peers() const {
+ ERR_FAIL_COND_V(!network_peer.is_valid(), Vector<int>());
+
+ Vector<int> ret;
+ for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
+ ret.push_back(E->get());
+ }
+
+ return ret;
+}
void SceneTree::set_refuse_new_network_connections(bool p_refuse) {
ERR_FAIL_COND(!network_peer.is_valid());
network_peer->set_refuse_new_connections(p_refuse);
@@ -1973,6 +1983,7 @@ void SceneTree::_network_process_packet(int p_from, const uint8_t *p_packet, int
Node *node = NULL;
if (target & 0x80000000) {
+ //use full path (not cached yet)
int ofs = target & 0x7FFFFFFF;
ERR_FAIL_COND(ofs >= p_packet_len);
@@ -1988,7 +1999,7 @@ void SceneTree::_network_process_packet(int p_from, const uint8_t *p_packet, int
ERR_FAIL_COND(node == NULL);
}
} else {
-
+ //use cached path
int id = target;
Map<int, PathGetCache>::Element *E = path_get_cache.find(p_from);
@@ -2023,7 +2034,7 @@ void SceneTree::_network_process_packet(int p_from, const uint8_t *p_packet, int
if (packet_type == NETWORK_COMMAND_REMOTE_CALL) {
- if (!node->can_call_rpc(name))
+ if (!node->can_call_rpc(name, p_from))
return;
int ofs = len_end + 1;
@@ -2060,7 +2071,7 @@ void SceneTree::_network_process_packet(int p_from, const uint8_t *p_packet, int
} else {
- if (!node->can_call_rset(name))
+ if (!node->can_call_rset(name, p_from))
return;
int ofs = len_end + 1;
@@ -2236,6 +2247,7 @@ void SceneTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_network_peer", "peer:NetworkedMultiplayerPeer"), &SceneTree::set_network_peer);
ClassDB::bind_method(D_METHOD("is_network_server"), &SceneTree::is_network_server);
ClassDB::bind_method(D_METHOD("has_network_peer"), &SceneTree::has_network_peer);
+ ClassDB::bind_method(D_METHOD("get_network_connected_peers"), &SceneTree::get_network_connected_peers);
ClassDB::bind_method(D_METHOD("get_network_unique_id"), &SceneTree::get_network_unique_id);
ClassDB::bind_method(D_METHOD("set_refuse_new_network_connections", "refuse"), &SceneTree::set_refuse_new_network_connections);
ClassDB::bind_method(D_METHOD("is_refusing_new_network_connections"), &SceneTree::is_refusing_new_network_connections);
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index 2ea79bf945..76a4becdbc 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -451,6 +451,7 @@ public:
bool is_network_server() const;
bool has_network_peer() const;
int get_network_unique_id() const;
+ Vector<int> get_network_connected_peers() const;
void set_refuse_new_network_connections(bool p_refuse);
bool is_refusing_new_network_connections() const;
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 3934467855..6209f99d9d 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -452,7 +452,7 @@ void SpatialMaterial::_update_shader() {
if (features[FEATURE_DEPTH_MAPPING]) {
code += "\t{\n";
- code += "\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT,BINORMAL,NORMAL));\n";
+ code += "\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT,-BINORMAL,NORMAL));\n"; //binormal is negative due to mikktpsace
if (deep_parallax) {
code += "\t\tfloat num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n";
@@ -1265,7 +1265,7 @@ void SpatialMaterial::_bind_methods() {
ADD_GROUP("Anisotropy", "anisotropy_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "anisotropy_enabled"), "set_feature", "get_feature", FEATURE_ANISOTROPY);
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "anisotropy", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_anisotropy", "get_anisotropy");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "anisotropy", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_anisotropy", "get_anisotropy");
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anisotropy_flowmap", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_FLOWMAP);
ADD_GROUP("Ambient Occlusion", "ao_");
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp
index 8d058377db..81cfd0e5f0 100644
--- a/scene/resources/primitive_meshes.cpp
+++ b/scene/resources/primitive_meshes.cpp
@@ -53,7 +53,15 @@ void PrimitiveMesh::_update() {
emit_changed();
}
-void PrimitiveMesh::_queue_update() {
+void PrimitiveMesh::_queue_update(bool p_first_mesh) {
+
+ if (first_mesh && p_first_mesh) {
+ first_mesh = false;
+ cache_is_dirty = true;
+ _update();
+ return;
+ }
+
if (!cache_is_dirty) {
cache_is_dirty = true;
call_deferred("_update");
@@ -145,6 +153,7 @@ PrimitiveMesh::PrimitiveMesh() {
// make sure we do an update after we've finished constructing our object
cache_is_dirty = false;
+ first_mesh = true;
_queue_update();
}
@@ -162,7 +171,9 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) {
float onethird = 1.0 / 3.0;
float twothirds = 2.0 / 3.0;
- set_aabb(Rect3(Vector3(-radius, (mid_height * -0.5) - radius, -radius), Vector3(radius * 2.0, mid_height + (2.0 * radius), radius * 2.0)));
+ // note, this has been aligned with our collision shape but I've left the descriptions as top/middle/bottom
+
+ set_aabb(Rect3(Vector3(-radius, -radius, (mid_height * -0.5) - radius), Vector3(radius * 2.0, radius * 2.0, mid_height + (2.0 * radius))));
PoolVector<Vector3> points;
PoolVector<Vector3> normals;
@@ -186,19 +197,19 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) {
v /= (rings + 1);
w = sin(0.5 * Math_PI * v);
- y = radius * cos(0.5 * Math_PI * v);
+ z = radius * cos(0.5 * Math_PI * v);
for (i = 0; i <= radial_segments; i++) {
u = i;
u /= radial_segments;
x = sin(u * (Math_PI * 2.0));
- z = cos(u * (Math_PI * 2.0));
+ y = -cos(u * (Math_PI * 2.0));
- Vector3 p = Vector3(x * radius * w, y, z * radius * w);
- points.push_back(p + Vector3(0.0, 0.5 * mid_height, 0.0));
+ Vector3 p = Vector3(x * radius * w, y * radius * w, z);
+ points.push_back(p + Vector3(0.0, 0.0, 0.5 * mid_height));
normals.push_back(p.normalized());
- ADD_TANGENT(-z, 0.0, x, -1.0)
+ ADD_TANGENT(y, -x, 0.0, -1.0)
uvs.push_back(Vector2(u, v * onethird));
point++;
@@ -224,20 +235,20 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) {
v = j;
v /= (rings + 1);
- y = mid_height * v;
- y = (mid_height * 0.5) - y;
+ z = mid_height * v;
+ z = (mid_height * 0.5) - z;
for (i = 0; i <= radial_segments; i++) {
u = i;
u /= radial_segments;
x = sin(u * (Math_PI * 2.0));
- z = cos(u * (Math_PI * 2.0));
+ y = -cos(u * (Math_PI * 2.0));
- Vector3 p = Vector3(x * radius, y, z * radius);
+ Vector3 p = Vector3(x * radius, y * radius, z);
points.push_back(p);
- normals.push_back(Vector3(x, 0.0, z));
- ADD_TANGENT(-z, 0.0, x, -1.0)
+ normals.push_back(Vector3(x, y, 0.0));
+ ADD_TANGENT(y, -x, 0.0, -1.0)
uvs.push_back(Vector2(u, onethird + (v * onethird)));
point++;
@@ -266,19 +277,19 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) {
v /= (rings + 1);
v += 1.0;
w = sin(0.5 * Math_PI * v);
- y = radius * cos(0.5 * Math_PI * v);
+ z = radius * cos(0.5 * Math_PI * v);
for (i = 0; i <= radial_segments; i++) {
float u = i;
u /= radial_segments;
x = sin(u * (Math_PI * 2.0));
- z = cos(u * (Math_PI * 2.0));
+ y = -cos(u * (Math_PI * 2.0));
- Vector3 p = Vector3(x * radius * w, y, z * radius * w);
- points.push_back(p + Vector3(0.0, -0.5 * mid_height, 0.0));
+ Vector3 p = Vector3(x * radius * w, y * radius * w, z);
+ points.push_back(p + Vector3(0.0, 0.0, -0.5 * mid_height));
normals.push_back(p.normalized());
- ADD_TANGENT(-z, 0.0, x, -1.0)
+ ADD_TANGENT(y, -x, 0.0, -1.0)
uvs.push_back(Vector2(u, twothirds + ((v - 1.0) * onethird)));
point++;
@@ -350,7 +361,7 @@ int CapsuleMesh::get_radial_segments() const {
void CapsuleMesh::set_rings(const int p_rings) {
rings = p_rings > 1 ? p_rings : 1;
- _queue_update();
+ _queue_update(true); //last property set, force update mesh
}
int CapsuleMesh::get_rings() const {
@@ -608,7 +619,7 @@ int CubeMesh::get_subdivide_height() const {
void CubeMesh::set_subdivide_depth(const int p_subdivide) {
subdivide_d = p_subdivide > 0 ? p_subdivide : 0;
- _queue_update();
+ _queue_update(true); //last property set, force update mesh
}
int CubeMesh::get_subdivide_depth() const {
@@ -825,7 +836,7 @@ int CylinderMesh::get_radial_segments() const {
void CylinderMesh::set_rings(const int p_rings) {
rings = p_rings > 0 ? p_rings : 0;
- _queue_update();
+ _queue_update(true); //last property set, force update mesh
}
int CylinderMesh::get_rings() const {
@@ -942,7 +953,7 @@ int PlaneMesh::get_subdivide_width() const {
void PlaneMesh::set_subdivide_depth(const int p_subdivide) {
subdivide_d = p_subdivide > 0 ? p_subdivide : 0;
- _queue_update();
+ _queue_update(true); //last property set, force update mesh
}
int PlaneMesh::get_subdivide_depth() const {
@@ -1232,7 +1243,7 @@ int PrismMesh::get_subdivide_height() const {
void PrismMesh::set_subdivide_depth(const int p_divisions) {
subdivide_d = p_divisions > 0 ? p_divisions : 0;
- _queue_update();
+ _queue_update(true); //last property set, force update mesh
}
int PrismMesh::get_subdivide_depth() const {
@@ -1301,6 +1312,7 @@ void QuadMesh::_bind_methods() {
QuadMesh::QuadMesh() {
primitive_type = PRIMITIVE_TRIANGLE_FAN;
+ _queue_update(true);
}
/**
@@ -1437,7 +1449,7 @@ int SphereMesh::get_rings() const {
void SphereMesh::set_is_hemisphere(const bool p_is_hemisphere) {
is_hemisphere = p_is_hemisphere;
- _queue_update();
+ _queue_update(true); //last property set, force update mesh
}
bool SphereMesh::get_is_hemisphere() const {
diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h
index 91d1af2ee1..5e1387e864 100644
--- a/scene/resources/primitive_meshes.h
+++ b/scene/resources/primitive_meshes.h
@@ -51,6 +51,7 @@ private:
Ref<Material> material;
+ bool first_mesh;
bool cache_is_dirty;
void _update();
@@ -60,7 +61,7 @@ protected:
static void _bind_methods();
virtual void _create_mesh_array(Array &p_arr) = 0;
- void _queue_update();
+ void _queue_update(bool p_first_mesh = false); //pretty bad hack to have the mesh built firt time parameters are set without delay
void set_aabb(Rect3 p_aabb);
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index b9d2c503e1..dc8f6a0a69 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -57,8 +57,12 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
tile_set_region(id, p_value);
else if (what == "shape")
tile_set_shape(id, 0, p_value);
- else if (what == "shape_offset")
- tile_set_shape_offset(id, 0, p_value);
+ else if (what == "shape_offset") {
+ Transform2D xform = tile_get_shape_transform(id, 0);
+ xform.set_origin(p_value);
+ tile_set_shape_transform(id, 0, xform);
+ } else if (what == "shape_transform")
+ tile_set_shape_transform(id, 0, p_value);
else if (what == "shape_one_way")
tile_set_shape_one_way(id, 0, p_value);
else if (what == "shapes")
@@ -106,7 +110,9 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
else if (what == "shape")
r_ret = tile_get_shape(id, 0);
else if (what == "shape_offset")
- r_ret = tile_get_shape_offset(id, 0);
+ r_ret = tile_get_shape_transform(id, 0).get_origin();
+ else if (what == "shape_transform")
+ r_ret = tile_get_shape_transform(id, 0);
else if (what == "shape_one_way")
r_ret = tile_get_shape_one_way(id, 0);
else if (what == "shapes")
@@ -143,6 +149,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "navigation_offset"));
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "navigation", PROPERTY_HINT_RESOURCE_TYPE, "NavigationPolygon"));
p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "shape_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
+ p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "shape_transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
p_list->push_back(PropertyInfo(Variant::OBJECT, pre + "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D", PROPERTY_USAGE_EDITOR));
p_list->push_back(PropertyInfo(Variant::BOOL, pre + "shape_one_way", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "shapes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
@@ -252,13 +259,13 @@ void TileSet::tile_clear_shapes(int p_id) {
tile_map[p_id].shapes_data.clear();
}
-void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Vector2 &p_offset, bool p_one_way) {
+void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way) {
ERR_FAIL_COND(!tile_map.has(p_id));
ShapeData new_data = ShapeData();
new_data.shape = p_shape;
- new_data.shape_offset = p_offset;
+ new_data.shape_transform = p_transform;
new_data.one_way_collision = p_one_way;
tile_map[p_id].shapes_data.push_back(new_data);
@@ -288,22 +295,22 @@ Ref<Shape2D> TileSet::tile_get_shape(int p_id, int p_shape_id) const {
return Ref<Shape2D>();
}
-void TileSet::tile_set_shape_offset(int p_id, int p_shape_id, const Vector2 &p_offset) {
+void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform2D &p_offset) {
ERR_FAIL_COND(!tile_map.has(p_id));
if (tile_map[p_id].shapes_data.size() <= p_shape_id)
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
- tile_map[p_id].shapes_data[p_shape_id].shape_offset = p_offset;
+ tile_map[p_id].shapes_data[p_shape_id].shape_transform = p_offset;
emit_changed();
}
-Vector2 TileSet::tile_get_shape_offset(int p_id, int p_shape_id) const {
+Transform2D TileSet::tile_get_shape_transform(int p_id, int p_shape_id) const {
- ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2());
+ ERR_FAIL_COND_V(!tile_map.has(p_id), Transform2D());
if (tile_map[p_id].shapes_data.size() > p_shape_id)
- return tile_map[p_id].shapes_data[p_shape_id].shape_offset;
+ return tile_map[p_id].shapes_data[p_shape_id].shape_transform;
- return Vector2();
+ return Transform2D();
}
void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_way) {
@@ -388,7 +395,7 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {
ERR_FAIL_COND(!tile_map.has(p_id));
Vector<ShapeData> shapes_data;
- Vector2 default_offset = tile_get_shape_offset(p_id, 0);
+ Transform2D default_transform = tile_get_shape_transform(p_id, 0);
bool default_one_way = tile_get_shape_one_way(p_id, 0);
for (int i = 0; i < p_shapes.size(); i++) {
ShapeData s = ShapeData();
@@ -398,7 +405,7 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {
if (shape.is_null()) continue;
s.shape = shape;
- s.shape_offset = default_offset;
+ s.shape_transform = default_transform;
s.one_way_collision = default_one_way;
} else if (p_shapes[i].get_type() == Variant::DICTIONARY) {
Dictionary d = p_shapes[i];
@@ -408,10 +415,12 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {
else
continue;
- if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2)
- s.shape_offset = d["shape_offset"];
+ if (d.has("shape_transform") && d["shape_transform"].get_type() == Variant::TRANSFORM2D)
+ s.shape_transform = d["shape_transform"];
+ else if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2)
+ s.shape_transform = Transform2D(0, (Vector2)d["shape_offset"]);
else
- s.shape_offset = default_offset;
+ s.shape_transform = default_transform;
if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL)
s.one_way_collision = d["one_way"];
@@ -438,7 +447,7 @@ Array TileSet::_tile_get_shapes(int p_id) const {
for (int i = 0; i < data.size(); i++) {
Dictionary shape_data;
shape_data["shape"] = data[i].shape;
- shape_data["shape_offset"] = data[i].shape_offset;
+ shape_data["shape_transform"] = data[i].shape_transform;
shape_data["one_way"] = data[i].one_way_collision;
arr.push_back(shape_data);
}
@@ -520,11 +529,11 @@ void TileSet::_bind_methods() {
ClassDB::bind_method(D_METHOD("tile_get_region", "id"), &TileSet::tile_get_region);
ClassDB::bind_method(D_METHOD("tile_set_shape", "id", "shape_id", "shape:Shape2D"), &TileSet::tile_set_shape);
ClassDB::bind_method(D_METHOD("tile_get_shape:Shape2D", "id", "shape_id"), &TileSet::tile_get_shape);
- ClassDB::bind_method(D_METHOD("tile_set_shape_offset", "id", "shape_id", "shape_offset"), &TileSet::tile_set_shape_offset);
- ClassDB::bind_method(D_METHOD("tile_get_shape_offset", "id", "shape_id"), &TileSet::tile_get_shape_offset);
+ ClassDB::bind_method(D_METHOD("tile_set_shape_transform", "id", "shape_id", "shape_transform"), &TileSet::tile_set_shape_transform);
+ ClassDB::bind_method(D_METHOD("tile_get_shape_transform", "id", "shape_id"), &TileSet::tile_get_shape_transform);
ClassDB::bind_method(D_METHOD("tile_set_shape_one_way", "id", "shape_id", "one_way"), &TileSet::tile_set_shape_one_way);
ClassDB::bind_method(D_METHOD("tile_get_shape_one_way", "id", "shape_id"), &TileSet::tile_get_shape_one_way);
- ClassDB::bind_method(D_METHOD("tile_add_shape", "id", "shape:Shape2D", "shape_offset", "one_way"), &TileSet::tile_add_shape, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("tile_add_shape", "id", "shape:Shape2D", "shape_transform", "one_way"), &TileSet::tile_add_shape, DEFVAL(false));
ClassDB::bind_method(D_METHOD("tile_get_shape_count", "id"), &TileSet::tile_get_shape_count);
ClassDB::bind_method(D_METHOD("tile_set_shapes", "id", "shapes"), &TileSet::_tile_set_shapes);
ClassDB::bind_method(D_METHOD("tile_get_shapes", "id"), &TileSet::_tile_get_shapes);
diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h
index c07d82c75a..99c506390c 100644
--- a/scene/resources/tile_set.h
+++ b/scene/resources/tile_set.h
@@ -43,7 +43,7 @@ class TileSet : public Resource {
public:
struct ShapeData {
Ref<Shape2D> shape;
- Vector2 shape_offset;
+ Transform2D shape_transform;
bool one_way_collision;
ShapeData() {
@@ -105,14 +105,14 @@ public:
void tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_shape);
Ref<Shape2D> tile_get_shape(int p_id, int p_shape_id) const;
- void tile_set_shape_offset(int p_id, int p_shape_id, const Vector2 &p_offset);
- Vector2 tile_get_shape_offset(int p_id, int p_shape_id) const;
+ void tile_set_shape_transform(int p_id, int p_shape_id, const Transform2D &p_transform);
+ Transform2D tile_get_shape_transform(int p_id, int p_shape_id) const;
void tile_set_shape_one_way(int p_id, int p_shape_id, bool p_one_way);
bool tile_get_shape_one_way(int p_id, int p_shape_id) const;
void tile_clear_shapes(int p_id);
- void tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Vector2 &p_offset, bool p_one_way = false);
+ void tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way = false);
int tile_get_shape_count(int p_id) const;
void tile_set_shapes(int p_id, const Vector<ShapeData> &p_shapes);