diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/camera_2d.cpp | 47 | ||||
-rw-r--r-- | scene/2d/camera_2d.h | 12 | ||||
-rw-r--r-- | scene/resources/dynamic_font.cpp | 16 | ||||
-rw-r--r-- | scene/resources/dynamic_font.h | 1 |
4 files changed, 52 insertions, 24 deletions
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index aeee301e6e..11846654c5 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -61,6 +61,20 @@ void Camera2D::_update_scroll() { }; } +void Camera2D::_update_process_mode() { + + if (Engine::get_singleton()->is_editor_hint()) { + set_process_internal(false); + set_physics_process_internal(false); + } else if (process_mode == CAMERA2D_PROCESS_IDLE) { + set_process_internal(true); + set_physics_process_internal(false); + } else { + set_process_internal(false); + set_physics_process_internal(true); + } +} + void Camera2D::set_zoom(const Vector2 &p_zoom) { zoom = p_zoom; @@ -143,7 +157,7 @@ Transform2D Camera2D::get_camera_transform() { if (smoothing_enabled && !Engine::get_singleton()->is_editor_hint()) { - float c = smoothing * get_process_delta_time(); + float c = smoothing * (process_mode == CAMERA2D_PROCESS_PHYSICS ? get_physics_process_delta_time() : get_process_delta_time()); smoothed_camera_pos = ((camera_pos - smoothed_camera_pos) * c) + smoothed_camera_pos; ret_camera_pos = smoothed_camera_pos; //camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing; @@ -217,14 +231,15 @@ void Camera2D::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_INTERNAL_PROCESS: { + case NOTIFICATION_INTERNAL_PROCESS: + case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { _update_scroll(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { - if (!is_processing_internal()) + if (!is_processing_internal() && !is_physics_processing_internal()) _update_scroll(); } break; @@ -245,10 +260,7 @@ void Camera2D::_notification(int p_what) { add_to_group(group_name); add_to_group(canvas_group_name); - if (Engine::get_singleton()->is_editor_hint()) { - set_process_internal(false); - } - + _update_process_mode(); _update_scroll(); first = true; @@ -379,6 +391,20 @@ bool Camera2D::is_rotating() const { return rotating; } +void Camera2D::set_process_mode(Camera2DProcessMode p_mode) { + + if (process_mode == p_mode) + return; + + process_mode = p_mode; + _update_process_mode(); +} + +Camera2D::Camera2DProcessMode Camera2D::get_process_mode() const { + + return process_mode; +} + void Camera2D::_make_current(Object *p_which) { if (p_which == this) { @@ -657,6 +683,9 @@ void Camera2D::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_scroll"), &Camera2D::_update_scroll); + ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Camera2D::set_process_mode); + ClassDB::bind_method(D_METHOD("get_process_mode"), &Camera2D::get_process_mode); + ClassDB::bind_method(D_METHOD("_set_current", "current"), &Camera2D::_set_current); ClassDB::bind_method(D_METHOD("is_current"), &Camera2D::is_current); @@ -717,6 +746,7 @@ void Camera2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "_set_current", "is_current"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "zoom"), "set_zoom", "get_zoom"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport", 0), "set_custom_viewport", "get_custom_viewport"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode"); ADD_GROUP("Limit", "limit_"); ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_left"), "set_limit", "get_limit", MARGIN_LEFT); @@ -750,6 +780,8 @@ void Camera2D::_bind_methods() { BIND_ENUM_CONSTANT(ANCHOR_MODE_FIXED_TOP_LEFT); BIND_ENUM_CONSTANT(ANCHOR_MODE_DRAG_CENTER); + BIND_ENUM_CONSTANT(CAMERA2D_PROCESS_PHYSICS); + BIND_ENUM_CONSTANT(CAMERA2D_PROCESS_IDLE); } Camera2D::Camera2D() { @@ -772,6 +804,7 @@ Camera2D::Camera2D() { limit_smoothing_enabled = false; custom_viewport = NULL; custom_viewport_id = 0; + process_mode = CAMERA2D_PROCESS_IDLE; smoothing = 5.0; zoom = Vector2(1, 1); diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index fc572c6181..7f16ecff41 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -44,6 +44,11 @@ public: ANCHOR_MODE_DRAG_CENTER }; + enum Camera2DProcessMode { + CAMERA2D_PROCESS_PHYSICS, + CAMERA2D_PROCESS_IDLE + }; + protected: Point2 camera_pos; Point2 smoothed_camera_pos; @@ -73,6 +78,7 @@ protected: float v_ofs; Point2 camera_screen_center; + void _update_process_mode(); void _update_scroll(); void _make_current(Object *p_which); @@ -84,6 +90,8 @@ protected: bool limit_drawing_enabled; bool margin_drawing_enabled; + Camera2DProcessMode process_mode; + protected: virtual Transform2D get_camera_transform(); void _notification(int p_what); @@ -126,6 +134,9 @@ public: void set_follow_smoothing(float p_speed); float get_follow_smoothing() const; + void set_process_mode(Camera2DProcessMode p_mode); + Camera2DProcessMode get_process_mode() const; + void make_current(); void clear_current(); bool is_current() const; @@ -156,5 +167,6 @@ public: }; VARIANT_ENUM_CAST(Camera2D::AnchorMode); +VARIANT_ENUM_CAST(Camera2D::Camera2DProcessMode); #endif // CAMERA_2D_H diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index fce697a0ea..5660f0a1b9 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -281,18 +281,6 @@ const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFon return Pair<const Character *, DynamicFontAtSize *>(chr, const_cast<DynamicFontAtSize *>(this)); } -float DynamicFontAtSize::_get_kerning_advance(const DynamicFontAtSize *font, CharType p_char, CharType p_next) const { - float advance = 0.0; - - if (p_next) { - FT_Vector delta; - FT_Get_Kerning(font->face, p_char, p_next, FT_KERNING_DEFAULT, &delta); - advance = (delta.x / 64.0) / oversampling; - } - - return advance; -} - Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const { if (!valid) @@ -301,7 +289,6 @@ Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const V Pair<const Character *, DynamicFontAtSize *> char_pair_with_font = _find_char_with_font(p_char, p_fallbacks); const Character *ch = char_pair_with_font.first; - DynamicFontAtSize *font = char_pair_with_font.second; ERR_FAIL_COND_V(!ch, Size2()); Size2 ret(0, get_height()); @@ -309,7 +296,6 @@ Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const V if (ch->found) { ret.x = ch->advance; } - ret.x += _get_kerning_advance(font, p_char, p_next); return ret; } @@ -358,8 +344,6 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT advance = ch->advance; } - advance += _get_kerning_advance(font, p_char, p_next); - return advance; } diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index df54203080..39e81ca43d 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -164,7 +164,6 @@ class DynamicFontAtSize : public Reference { const Pair<const Character *, DynamicFontAtSize *> _find_char_with_font(CharType p_char, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const; Character _make_outline_char(CharType p_char); - float _get_kerning_advance(const DynamicFontAtSize *font, CharType p_char, CharType p_next) const; TexturePosition _find_texture_pos_for_glyph(int p_color_size, Image::Format p_image_format, int p_width, int p_height); Character _bitmap_to_character(FT_Bitmap bitmap, int yofs, int xofs, float advance); |