summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/physics_body.cpp11
-rw-r--r--scene/gui/color_picker.cpp4
-rw-r--r--scene/gui/label.cpp18
-rw-r--r--scene/main/viewport.cpp52
-rw-r--r--scene/main/viewport.h2
-rw-r--r--scene/resources/packed_scene.cpp34
-rw-r--r--scene/resources/style_box.cpp6
-rw-r--r--scene/resources/texture.cpp2
-rw-r--r--scene/resources/world.cpp10
9 files changed, 94 insertions, 45 deletions
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index 44dc3d0c26..c2860c25d8 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -1151,17 +1151,8 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve
}
}
- Vector3 current_floor_velocity = floor_velocity;
- if (on_floor && on_floor_body.is_valid()) {
- //this approach makes sure there is less delay between the actual body velocity and the one we saved
- PhysicsDirectBodyState *bs = PhysicsServer::get_singleton()->body_get_direct_state(on_floor_body);
- if (bs) {
- current_floor_velocity = bs->get_linear_velocity();
- }
- }
-
// Hack in order to work with calling from _process as well as from _physics_process; calling from thread is risky
- Vector3 motion = (current_floor_velocity + body_velocity) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time());
+ Vector3 motion = (floor_velocity + body_velocity) * (Engine::get_singleton()->is_in_physics_frame() ? get_physics_process_delta_time() : get_process_delta_time());
on_floor = false;
on_floor_body = RID();
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index bab8d9167b..01f4070883 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -573,9 +573,7 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
}
if (index < 0 || index >= presets.size())
return;
- preset->set_tooltip("Color: #" + presets[index].to_html(presets[index].a < 1) + "\n"
- "LMB: Set color\n"
- "RMB: Remove preset");
+ preset->set_tooltip(vformat(RTR("Color: #%s\nLMB: Set color\nRMB: Remove preset"), presets[index].to_html(presets[index].a < 1)));
}
}
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 11172ac7a9..fa795361a8 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -313,8 +313,8 @@ Size2 Label::get_minimum_size() const {
int Label::get_longest_line_width() const {
Ref<Font> font = get_font("font");
- int max_line_width = 0;
- int line_width = 0;
+ real_t max_line_width = 0;
+ real_t line_width = 0;
for (int i = 0; i < xl_text.size(); i++) {
@@ -332,8 +332,7 @@ int Label::get_longest_line_width() const {
}
} else {
- // ceiling to ensure autowrapping does not cut text
- int char_width = Math::ceil(font->get_char_size(current, xl_text[i + 1]).width);
+ real_t char_width = font->get_char_size(current, xl_text[i + 1]).width;
line_width += char_width;
}
}
@@ -341,7 +340,8 @@ int Label::get_longest_line_width() const {
if (line_width > max_line_width)
max_line_width = line_width;
- return max_line_width;
+ // ceiling to ensure autowrapping does not cut text
+ return Math::ceil(max_line_width);
}
int Label::get_line_count() const {
@@ -388,7 +388,7 @@ void Label::regenerate_word_cache() {
Ref<Font> font = get_font("font");
- int current_word_size = 0;
+ real_t current_word_size = 0;
int word_pos = 0;
int line_width = 0;
int space_count = 0;
@@ -413,7 +413,7 @@ void Label::regenerate_word_cache() {
bool separatable = (current >= 0x2E08 && current <= 0xFAFF) || (current >= 0xFE30 && current <= 0xFE4F);
//current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57);
bool insert_newline = false;
- int char_width = 0;
+ real_t char_width = 0;
if (current < 33) {
@@ -455,9 +455,9 @@ void Label::regenerate_word_cache() {
word_pos = i;
}
// ceiling to ensure autowrapping does not cut text
- char_width = Math::ceil(font->get_char_size(current, xl_text[i + 1]).width);
+ char_width = font->get_char_size(current, xl_text[i + 1]).width;
current_word_size += char_width;
- line_width += char_width;
+ line_width += Math::ceil(char_width);
total_char_cache++;
// allow autowrap to cut words when they exceed line width
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 9e9a25883e..a56903636f 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -30,6 +30,7 @@
#include "viewport.h"
+#include "core/core_string_names.h"
#include "core/os/input.h"
#include "core/os/os.h"
#include "core/project_settings.h"
@@ -251,6 +252,27 @@ void Viewport::_collision_object_input_event(CollisionObject *p_object, Camera *
physics_last_id = id;
}
+void Viewport::_own_world_changed() {
+ ERR_FAIL_COND(world.is_null());
+ ERR_FAIL_COND(own_world.is_null());
+
+ if (is_inside_tree()) {
+ _propagate_exit_world(this);
+ }
+
+ own_world = world->duplicate();
+
+ if (is_inside_tree()) {
+ _propagate_enter_world(this);
+ }
+
+ if (is_inside_tree()) {
+ VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario());
+ }
+
+ _update_listener();
+}
+
void Viewport::_notification(int p_what) {
switch (p_what) {
@@ -1105,8 +1127,21 @@ void Viewport::set_world(const Ref<World> &p_world) {
if (is_inside_tree())
_propagate_exit_world(this);
+ if (own_world.is_valid() && world.is_valid()) {
+ world->disconnect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
+ }
+
world = p_world;
+ if (own_world.is_valid()) {
+ if (world.is_valid()) {
+ own_world = world->duplicate();
+ world->connect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
+ } else {
+ own_world = Ref<World>(memnew(World));
+ }
+ }
+
if (is_inside_tree())
_propagate_enter_world(this);
@@ -2826,10 +2861,19 @@ void Viewport::set_use_own_world(bool p_world) {
if (is_inside_tree())
_propagate_exit_world(this);
- if (!p_world)
+ if (!p_world) {
own_world = Ref<World>();
- else
- own_world = Ref<World>(memnew(World));
+ if (world.is_valid()) {
+ world->disconnect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
+ }
+ } else {
+ if (world.is_valid()) {
+ own_world = world->duplicate();
+ world->connect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
+ } else {
+ own_world = Ref<World>(memnew(World));
+ }
+ }
if (is_inside_tree())
_propagate_enter_world(this);
@@ -3178,6 +3222,8 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("_subwindow_visibility_changed"), &Viewport::_subwindow_visibility_changed);
+ ClassDB::bind_method(D_METHOD("_own_world_changed"), &Viewport::_own_world_changed);
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "arvr"), "set_use_arvr", "use_arvr");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 396bbc91cd..79b606cda3 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -406,6 +406,8 @@ private:
void _update_canvas_items(Node *p_node);
+ void _own_world_changed();
+
protected:
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 5a2cd9a1c2..978d81d5c2 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -39,7 +39,7 @@
#include "scene/gui/control.h"
#include "scene/main/instance_placeholder.h"
-#define PACK_VERSION 2
+#define PACKED_SCENE_VERSION 2
bool SceneState::can_instance() const {
@@ -1095,7 +1095,15 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
if (p_dictionary.has("version"))
version = p_dictionary["version"];
- ERR_FAIL_COND_MSG(version > PACK_VERSION, "Save format version too new.");
+ ERR_FAIL_COND_MSG(version > PACKED_SCENE_VERSION, "Save format version too new.");
+
+ const int node_count = p_dictionary["node_count"];
+ const PoolVector<int> snodes = p_dictionary["nodes"];
+ ERR_FAIL_COND(snodes.size() != node_count);
+
+ const int conn_count = p_dictionary["conn_count"];
+ const PoolVector<int> sconns = p_dictionary["conns"];
+ ERR_FAIL_COND(sconns.size() != conn_count);
PoolVector<String> snames = p_dictionary["names"];
if (snames.size()) {
@@ -1121,13 +1129,11 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
variants.clear();
}
- nodes.resize(p_dictionary["node_count"]);
- int nc = nodes.size();
- if (nc) {
- PoolVector<int> snodes = p_dictionary["nodes"];
+ nodes.resize(node_count);
+ if (node_count) {
PoolVector<int>::Read r = snodes.read();
int idx = 0;
- for (int i = 0; i < nc; i++) {
+ for (int i = 0; i < node_count; i++) {
NodeData &nd = nodes.write[i];
nd.parent = r[idx++];
nd.owner = r[idx++];
@@ -1151,15 +1157,11 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
}
}
- connections.resize(p_dictionary["conn_count"]);
- int cc = connections.size();
-
- if (cc) {
-
- PoolVector<int> sconns = p_dictionary["conns"];
+ connections.resize(conn_count);
+ if (conn_count) {
PoolVector<int>::Read r = sconns.read();
int idx = 0;
- for (int i = 0; i < cc; i++) {
+ for (int i = 0; i < conn_count; i++) {
ConnectionData &cd = connections.write[i];
cd.from = r[idx++];
cd.to = r[idx++];
@@ -1283,9 +1285,7 @@ Dictionary SceneState::get_bundled_scene() const {
d["base_scene"] = base_scene_idx;
}
- d["version"] = PACK_VERSION;
-
- //d["path"]=path;
+ d["version"] = PACKED_SCENE_VERSION;
return d;
}
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index c59fa8cab8..9408d1aa71 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -719,6 +719,7 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
bool rounded_corners = (corner_radius[0] > 0) || (corner_radius[1] > 0) || (corner_radius[2] > 0) || (corner_radius[3] > 0);
bool aa_on = rounded_corners && anti_aliased;
+ float aa_size_grow = 0.5 * ((float)aa_size + 1.0);
bool blend_on = blend_border && draw_border;
@@ -744,7 +745,6 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
Rect2 border_style_rect = style_rect;
if (aa_on) {
- float aa_size_grow = 0.5 * ((aa_size + 1) / 2);
for (int i = 0; i < 4; i++) {
if (border_width[i] > 0) {
border_style_rect = border_style_rect.grow_margin((Margin)i, -aa_size_grow);
@@ -789,7 +789,6 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
}
if (aa_on) {
- float aa_size_grow = 0.5 * ((aa_size + 1) / 2);
int aa_border_width[4];
int aa_fill_width[4];
if (draw_border) {
@@ -804,6 +803,7 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
}
} else {
for (int i = 0; i < 4; i++) {
+ aa_border_width[i] = 0;
aa_fill_width[i] = aa_size_grow;
}
}
@@ -844,7 +844,7 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
}
//COMPUTE UV COORDINATES
- Rect2 uv_rect = style_rect.grow(aa_on ? aa_size : 0);
+ Rect2 uv_rect = style_rect.grow(aa_on ? aa_size_grow : 0);
uvs.resize(verts.size());
for (int i = 0; i < verts.size(); i++) {
uvs.write[i].x = (verts[i].x - uv_rect.position.x) / uv_rect.size.width;
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index dc2b708ae7..4d23f0eb41 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -2271,6 +2271,7 @@ void TextureLayered::create(uint32_t p_width, uint32_t p_height, uint32_t p_dept
void TextureLayered::set_layer_data(const Ref<Image> &p_image, int p_layer) {
ERR_FAIL_COND(!texture.is_valid());
+ ERR_FAIL_COND(!p_image.is_valid());
VS::get_singleton()->texture_set_data(texture, p_image, p_layer);
}
@@ -2282,6 +2283,7 @@ Ref<Image> TextureLayered::get_layer_data(int p_layer) const {
void TextureLayered::set_data_partial(const Ref<Image> &p_image, int p_x_ofs, int p_y_ofs, int p_z, int p_mipmap) {
ERR_FAIL_COND(!texture.is_valid());
+ ERR_FAIL_COND(!p_image.is_valid());
VS::get_singleton()->texture_set_data_partial(texture, p_image, 0, 0, p_image->get_width(), p_image->get_height(), p_x_ofs, p_y_ofs, p_mipmap, p_z);
}
diff --git a/scene/resources/world.cpp b/scene/resources/world.cpp
index b498acd707..1099852098 100644
--- a/scene/resources/world.cpp
+++ b/scene/resources/world.cpp
@@ -268,12 +268,17 @@ RID World::get_scenario() const {
}
void World::set_environment(const Ref<Environment> &p_environment) {
+ if (environment == p_environment) {
+ return;
+ }
environment = p_environment;
if (environment.is_valid())
VS::get_singleton()->scenario_set_environment(scenario, environment->get_rid());
else
VS::get_singleton()->scenario_set_environment(scenario, RID());
+
+ emit_changed();
}
Ref<Environment> World::get_environment() const {
@@ -282,12 +287,17 @@ Ref<Environment> World::get_environment() const {
}
void World::set_fallback_environment(const Ref<Environment> &p_environment) {
+ if (fallback_environment == p_environment) {
+ return;
+ }
fallback_environment = p_environment;
if (fallback_environment.is_valid())
VS::get_singleton()->scenario_set_fallback_environment(scenario, p_environment->get_rid());
else
VS::get_singleton()->scenario_set_fallback_environment(scenario, RID());
+
+ emit_changed();
}
Ref<Environment> World::get_fallback_environment() const {