summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/editor_node.cpp10
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.cpp72
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.h13
-rw-r--r--modules/stb_vorbis/resource_importer_ogg_vorbis.cpp9
-rw-r--r--scene/2d/camera_2d.cpp6
-rw-r--r--scene/2d/parallax_background.cpp10
-rw-r--r--scene/2d/parallax_background.h3
-rw-r--r--scene/2d/parallax_layer.cpp20
-rw-r--r--scene/2d/parallax_layer.h4
9 files changed, 58 insertions, 89 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 6559048172..817e6affbd 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -401,7 +401,15 @@ void EditorNode::_fs_changed() {
// ensures export_project does not loop infinitely, because notifications may
// come during the export
export_defer.preset = "";
- platform->export_project(preset, export_defer.debug, export_defer.path, /*p_flags*/ 0);
+ if (!preset->is_runnable() && (export_defer.path.ends_with(".pck") || export_defer.path.ends_with(".zip"))) {
+ if (export_defer.path.ends_with(".zip")) {
+ platform->save_zip(preset, export_defer.path);
+ } else if (export_defer.path.ends_with(".pck")) {
+ platform->save_pack(preset, export_defer.path);
+ }
+ } else {
+ platform->export_project(preset, export_defer.debug, export_defer.path, /*p_flags*/ 0);
+ }
}
}
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
index 951fc002b7..5c252bda86 100644
--- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
@@ -36,54 +36,36 @@
#include "thirdparty/misc/stb_vorbis.c"
#pragma GCC diagnostic pop
-#ifndef CLAMP
-#define CLAMP(m_a, m_min, m_max) (((m_a) < (m_min)) ? (m_min) : (((m_a) > (m_max)) ? m_max : m_a))
-#endif
-
void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) {
ERR_FAIL_COND(!active);
int todo = p_frames;
- int start_buffer = 0;
+ while (todo && active) {
- while (todo > 0 && active) {
- float *buffer = (float *)p_buffer;
- if (start_buffer > 0) {
- buffer = (buffer + start_buffer * 2);
- }
- int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, buffer, todo * 2);
+ int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream, 2, (float *)p_buffer, todo * 2);
if (vorbis_stream->channels == 1 && mixed > 0) {
//mix mono to stereo
- for (int i = start_buffer; i < mixed; i++) {
+ for (int i = 0; i < mixed; i++) {
p_buffer[i].r = p_buffer[i].l;
}
}
todo -= mixed;
frames_mixed += mixed;
- if (todo > 0) {
+ if (todo) {
//end of file!
if (vorbis_stream->loop) {
- //loop to the loop_beginning
- seek(vorbis_stream->loop_begin);
+ //loop
+ seek(vorbis_stream->loop_offset);
loops++;
- // we still have buffer to fill, start from this element in the next iteration.
- start_buffer = p_frames - todo;
} else {
- for (int i = p_frames - todo; i < p_frames; i++) {
+ for (int i = mixed; i < p_frames; i++) {
p_buffer[i] = AudioFrame(0, 0);
}
active = false;
- todo = 0;
}
- } else if (vorbis_stream->loop && frames_mixed >= vorbis_stream->loop_end_frames) {
- // We reached loop_end. Loop to loop_begin plus whatever extra length we already mixed
- uint32_t frames_to_advance = uint32_t(frames_mixed - vorbis_stream->loop_end_frames);
- float start_loop = vorbis_stream->loop_begin + (float(frames_to_advance) / vorbis_stream->sample_rate);
- seek(start_loop);
- loops++;
}
}
}
@@ -217,9 +199,6 @@ void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) {
//print_line("succeeded "+itos(ogg_alloc.alloc_buffer_length_in_bytes)+" setup "+itos(info.setup_memory_required)+" setup temp "+itos(info.setup_temp_memory_required)+" temp "+itos(info.temp_memory_required)+" maxframe"+itos(info.max_frame_size));
length = stb_vorbis_stream_length_in_seconds(ogg_stream);
- if (loop_end == 0) {
- set_loop_end(length);
- }
stb_vorbis_close(ogg_stream);
data = AudioServer::get_singleton()->audio_data_alloc(src_data_len, src_datar.ptr());
@@ -254,24 +233,12 @@ bool AudioStreamOGGVorbis::has_loop() const {
return loop;
}
-void AudioStreamOGGVorbis::set_loop_begin(float p_seconds) {
- p_seconds = CLAMP(p_seconds, 0, length);
- loop_begin = p_seconds;
- loop_begin_frames = uint32_t(sample_rate * p_seconds);
-}
-
-float AudioStreamOGGVorbis::get_loop_begin() const {
- return loop_begin;
-}
-
-void AudioStreamOGGVorbis::set_loop_end(float p_seconds) {
- p_seconds = CLAMP(p_seconds, 0, length);
- loop_end = p_seconds;
- loop_end_frames = uint32_t(sample_rate * p_seconds);
+void AudioStreamOGGVorbis::set_loop_offset(float p_seconds) {
+ loop_offset = p_seconds;
}
-float AudioStreamOGGVorbis::get_loop_end() const {
- return loop_end;
+float AudioStreamOGGVorbis::get_loop_offset() const {
+ return loop_offset;
}
void AudioStreamOGGVorbis::_bind_methods() {
@@ -282,16 +249,12 @@ void AudioStreamOGGVorbis::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_loop", "enable"), &AudioStreamOGGVorbis::set_loop);
ClassDB::bind_method(D_METHOD("has_loop"), &AudioStreamOGGVorbis::has_loop);
- ClassDB::bind_method(D_METHOD("set_loop_begin", "seconds"), &AudioStreamOGGVorbis::set_loop_begin);
- ClassDB::bind_method(D_METHOD("get_loop_begin"), &AudioStreamOGGVorbis::get_loop_begin);
-
- ClassDB::bind_method(D_METHOD("set_loop_end", "seconds"), &AudioStreamOGGVorbis::set_loop_end);
- ClassDB::bind_method(D_METHOD("get_loop_end"), &AudioStreamOGGVorbis::get_loop_end);
+ ClassDB::bind_method(D_METHOD("set_loop_offset", "seconds"), &AudioStreamOGGVorbis::set_loop_offset);
+ ClassDB::bind_method(D_METHOD("get_loop_offset"), &AudioStreamOGGVorbis::get_loop_offset);
ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_data", "get_data");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop", "has_loop");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "loop_begin", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop_begin", "get_loop_begin");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "loop_end", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop_end", "get_loop_end");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "loop_offset", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_loop_offset", "get_loop_offset");
}
AudioStreamOGGVorbis::AudioStreamOGGVorbis() {
@@ -300,10 +263,7 @@ AudioStreamOGGVorbis::AudioStreamOGGVorbis() {
length = 0;
sample_rate = 1;
channels = 1;
- loop_begin = 0;
- loop_end = 0;
- loop_begin_frames = 0;
- loop_end_frames = 0;
+ loop_offset = 0;
decode_mem_size = 0;
- loop = true;
+ loop = false;
}
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h
index 9297d2246b..f4d381897b 100644
--- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h
+++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h
@@ -92,11 +92,7 @@ class AudioStreamOGGVorbis : public AudioStream {
int channels;
float length;
bool loop;
- float loop_begin;
- float loop_end;
-
- uint32_t loop_begin_frames;
- uint32_t loop_end_frames;
+ float loop_offset;
protected:
static void _bind_methods();
@@ -105,11 +101,8 @@ public:
void set_loop(bool p_enable);
bool has_loop() const;
- void set_loop_begin(float p_seconds);
- float get_loop_begin() const;
-
- void set_loop_end(float p_seconds);
- float get_loop_end() const;
+ void set_loop_offset(float p_seconds);
+ float get_loop_offset() const;
virtual Ref<AudioStreamPlayback> instance_playback();
virtual String get_stream_name() const;
diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp
index b7949e381c..4d28dc027b 100644
--- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp
+++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp
@@ -72,15 +72,13 @@ String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const {
void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *r_options, int p_preset) const {
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), true));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "loop_begin"), 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "loop_end"), 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "loop_offset"), 0));
}
Error ResourceImporterOGGVorbis::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) {
bool loop = p_options["loop"];
- float loop_begin = p_options["loop_begin"];
- float loop_end = p_options["loop_end"];
+ float loop_offset = p_options["loop_offset"];
FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ);
if (!f) {
@@ -102,8 +100,7 @@ Error ResourceImporterOGGVorbis::import(const String &p_source_file, const Strin
ogg_stream->set_data(data);
ogg_stream->set_loop(loop);
- ogg_stream->set_loop_begin(loop_begin);
- if (loop_end > 0) ogg_stream->set_loop_end(loop_end);
+ ogg_stream->set_loop_offset(loop_offset);
return ResourceSaver::save(p_save_path + ".oggstr", ogg_stream);
}
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index d65a3bfe80..3164344d15 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -52,7 +52,11 @@ void Camera2D::_update_scroll() {
if (viewport) {
viewport->set_canvas_transform(xform);
}
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_camera_moved", xform);
+
+ Size2 screen_size = viewport->get_visible_rect().size;
+ Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5) : Point2());
+
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_camera_moved", xform, screen_offset);
};
}
diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp
index a13ce6278e..b9012e37b2 100644
--- a/scene/2d/parallax_background.cpp
+++ b/scene/2d/parallax_background.cpp
@@ -47,10 +47,12 @@ void ParallaxBackground::_notification(int p_what) {
}
}
-void ParallaxBackground::_camera_moved(const Transform2D &p_transform) {
+void ParallaxBackground::_camera_moved(const Transform2D &p_transform, const Point2 &p_screen_offset) {
+
+ screen_offset = p_screen_offset;
set_scroll_scale(p_transform.get_scale().dot(Vector2(0.5, 0.5)));
- set_scroll_offset(p_transform.get_origin() / p_transform.get_scale());
+ set_scroll_offset(p_transform.get_origin());
}
void ParallaxBackground::set_scroll_scale(float p_scale) {
@@ -106,9 +108,9 @@ void ParallaxBackground::_update_scroll() {
continue;
if (ignore_camera_zoom)
- l->set_base_offset_and_scale(ofs, 1.0);
+ l->set_base_offset_and_scale(ofs, 1.0, screen_offset);
else
- l->set_base_offset_and_scale(ofs, scale);
+ l->set_base_offset_and_scale(ofs, scale, screen_offset);
}
}
diff --git a/scene/2d/parallax_background.h b/scene/2d/parallax_background.h
index 0dad1daeab..e37ec0db99 100644
--- a/scene/2d/parallax_background.h
+++ b/scene/2d/parallax_background.h
@@ -42,6 +42,7 @@ class ParallaxBackground : public CanvasLayer {
float scale;
Point2 base_offset;
Point2 base_scale;
+ Point2 screen_offset;
String group_name;
Point2 limit_begin;
Point2 limit_end;
@@ -51,7 +52,7 @@ class ParallaxBackground : public CanvasLayer {
void _update_scroll();
protected:
- void _camera_moved(const Transform2D &p_transform);
+ void _camera_moved(const Transform2D &p_transform, const Point2 &p_screen_offset);
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp
index 8fe651cb5f..4a69841975 100644
--- a/scene/2d/parallax_layer.cpp
+++ b/scene/2d/parallax_layer.cpp
@@ -40,7 +40,7 @@ void ParallaxLayer::set_motion_scale(const Size2 &p_scale) {
if (pb && is_inside_tree()) {
Vector2 ofs = pb->get_final_offset();
float scale = pb->get_scroll_scale();
- set_base_offset_and_scale(ofs, scale);
+ set_base_offset_and_scale(ofs, scale, screen_offset);
}
}
@@ -57,7 +57,7 @@ void ParallaxLayer::set_motion_offset(const Size2 &p_offset) {
if (pb && is_inside_tree()) {
Vector2 ofs = pb->get_final_offset();
float scale = pb->get_scroll_scale();
- set_base_offset_and_scale(ofs, scale);
+ set_base_offset_and_scale(ofs, scale, screen_offset);
}
}
@@ -106,26 +106,28 @@ void ParallaxLayer::_notification(int p_what) {
}
}
-void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_scale) {
+void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_scale, const Point2 &p_screen_offset) {
+ screen_offset = p_screen_offset;
if (!is_inside_tree())
return;
if (Engine::get_singleton()->is_editor_hint())
return;
- Point2 new_ofs = ((orig_offset + p_offset) * motion_scale) * p_scale + motion_offset;
+
+ Point2 new_ofs = (screen_offset + (p_offset - screen_offset) * motion_scale) + motion_offset * p_scale + orig_offset * p_scale;
+
+ Vector2 mirror = Vector2(1, 1);
if (mirroring.x) {
- double den = mirroring.x * p_scale;
- new_ofs.x -= den * ceil(new_ofs.x / den);
+ mirror.x = -1;
}
if (mirroring.y) {
- double den = mirroring.y * p_scale;
- new_ofs.y -= den * ceil(new_ofs.y / den);
+ mirror.y = -1;
}
set_position(new_ofs);
- set_scale(Vector2(1, 1) * p_scale);
+ set_scale(mirror * p_scale * orig_scale);
}
String ParallaxLayer::get_configuration_warning() const {
diff --git a/scene/2d/parallax_layer.h b/scene/2d/parallax_layer.h
index 95ca27c41a..6feb1fad67 100644
--- a/scene/2d/parallax_layer.h
+++ b/scene/2d/parallax_layer.h
@@ -43,6 +43,8 @@ class ParallaxLayer : public Node2D {
Vector2 mirroring;
void _update_mirroring();
+ Point2 screen_offset;
+
protected:
void _notification(int p_what);
static void _bind_methods();
@@ -57,7 +59,7 @@ public:
void set_mirroring(const Size2 &p_mirroring);
Size2 get_mirroring() const;
- void set_base_offset_and_scale(const Point2 &p_offset, float p_scale);
+ void set_base_offset_and_scale(const Point2 &p_offset, float p_scale, const Point2 &p_screen_offset);
virtual String get_configuration_warning() const;
ParallaxLayer();