diff options
894 files changed, 25030 insertions, 30515 deletions
diff --git a/.gitignore b/.gitignore index abbda17ee2..f7eac1122d 100644 --- a/.gitignore +++ b/.gitignore @@ -144,7 +144,9 @@ ipch/ *.sdf *.cachefile *.VC.db +*.VC.opendb *.VC.VC.opendb +enc_temp_folder/ # Visual Studio profiler *.psess diff --git a/.travis.yml b/.travis.yml index 12b49f4c07..ca110a3073 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ os: - osx env: - #- GODOT_TARGET=iphone + - GODOT_TARGET=iphone - GODOT_TARGET=osx - GODOT_TARGET=x11 #- GODOT_TARGET=android diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 294acd5bae..93ded6c954 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,19 +1,17 @@ -vvv Remove me vvv - -*NOTE:* If you using the current master branch / 3.0-alpha version, do note that -breakage is *expected*. Projects from Godot 2.x are expected not to work. Please -wait for the upcoming stabilisation period to report bugs regarding recent changes. - -^^^ Remove me ^^^ - +<!-- +README: Incompatibilities and broken features in the current master branch / 3.0-alpha +are known and expected due to important refactoring work, so no need to report them for now. Thanks! +--> **Operating system or device - Godot version:** -**Issue description** (what happened, and what was expected): +**Issue description:** +<!-- What happened, and what was expected. --> **Steps to reproduce:** -**Link to minimal example project** (optional but very welcome): +**Link to minimal example project:** +<!-- Optional but very welcome. You can drag and drop a zip archive to upload it. -->: diff --git a/SConstruct b/SConstruct index 2ecfea92e3..4c79304ef2 100644 --- a/SConstruct +++ b/SConstruct @@ -358,7 +358,7 @@ if selected_platform in platform_list: SConscript("core/SCsub") SConscript("servers/SCsub") SConscript("scene/SCsub") - SConscript("tools/SCsub") + SConscript("tools/editor/SCsub") SConscript("drivers/SCsub") SConscript("modules/SCsub") @@ -374,7 +374,7 @@ if selected_platform in platform_list: AddToVSProject(env.modules_sources) AddToVSProject(env.scene_sources) AddToVSProject(env.servers_sources) - AddToVSProject(env.tool_sources) + AddToVSProject(env.editor_sources) # this env flag won't work, it needs to be set in env_base=Environment(MSVC_VERSION='9.0') # Even then, SCons still seems to ignore it and builds with the latest MSVC... diff --git a/core/array.cpp b/core/array.cpp index b9c8f543da..16598a044d 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "array.h" + #include "vector.h" #include "hashfuncs.h" #include "variant.h" diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 657f527a51..636a3f07c1 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -106,17 +106,12 @@ bool _ResourceLoader::has(const String &p_path) { return ResourceCache::has(local_path); }; -Ref<ResourceImportMetadata> _ResourceLoader::load_import_metadata(const String& p_path) { - - return ResourceLoader::load_import_metadata(p_path); -} void _ResourceLoader::_bind_methods() { ClassDB::bind_method(_MD("load_interactive:ResourceInteractiveLoader","path","type_hint"),&_ResourceLoader::load_interactive,DEFVAL("")); ClassDB::bind_method(_MD("load:Resource","path","type_hint", "p_no_cache"),&_ResourceLoader::load,DEFVAL(""), DEFVAL(false)); - ClassDB::bind_method(_MD("load_import_metadata:ResourceImportMetadata","path"),&_ResourceLoader::load_import_metadata); ClassDB::bind_method(_MD("get_recognized_extensions_for_type","type"),&_ResourceLoader::get_recognized_extensions_for_type); ClassDB::bind_method(_MD("set_abort_on_missing_resources","abort"),&_ResourceLoader::set_abort_on_missing_resources); ClassDB::bind_method(_MD("get_dependencies","path"),&_ResourceLoader::get_dependencies); @@ -592,28 +587,20 @@ uint64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const { static const unsigned int SECONDS_PER_MINUTE = 60; static const unsigned int MINUTES_PER_HOUR = 60; static const unsigned int HOURS_PER_DAY = 24; - static const unsigned int SECONDS_PER_HOUR = MINUTES_PER_HOUR * - SECONDS_PER_MINUTE; + static const unsigned int SECONDS_PER_HOUR = MINUTES_PER_HOUR * SECONDS_PER_MINUTE; static const unsigned int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY; // Get all time values from the dictionary, set to zero if it doesn't exist. // Risk incorrect calculation over throwing errors - unsigned int second = ((datetime.has(SECOND_KEY))? - static_cast<unsigned int>(datetime[SECOND_KEY]): 0); - unsigned int minute = ((datetime.has(MINUTE_KEY))? - static_cast<unsigned int>(datetime[MINUTE_KEY]): 0); - unsigned int hour = ((datetime.has(HOUR_KEY))? - static_cast<unsigned int>(datetime[HOUR_KEY]): 0); - unsigned int day = ((datetime.has(DAY_KEY))? - static_cast<unsigned int>(datetime[DAY_KEY]): 0); - unsigned int month = ((datetime.has(MONTH_KEY))? - static_cast<unsigned int>(datetime[MONTH_KEY]) -1: 0); - unsigned int year = ((datetime.has(YEAR_KEY))? - static_cast<unsigned int>(datetime[YEAR_KEY]):0); + unsigned int second = ((datetime.has(SECOND_KEY)) ? static_cast<unsigned int>(datetime[SECOND_KEY]): 0); + unsigned int minute = ((datetime.has(MINUTE_KEY)) ? static_cast<unsigned int>(datetime[MINUTE_KEY]): 0); + unsigned int hour = ((datetime.has(HOUR_KEY)) ? static_cast<unsigned int>(datetime[HOUR_KEY]): 0); + unsigned int day = ((datetime.has(DAY_KEY)) ? static_cast<unsigned int>(datetime[DAY_KEY]): 0); + unsigned int month = ((datetime.has(MONTH_KEY)) ? static_cast<unsigned int>(datetime[MONTH_KEY]) -1: 0); + unsigned int year = ((datetime.has(YEAR_KEY)) ? static_cast<unsigned int>(datetime[YEAR_KEY]):0); /// How many days come before each month (0-12) - static const unsigned short int DAYS_PAST_THIS_YEAR_TABLE[2][13] = - { + static const unsigned short int DAYS_PAST_THIS_YEAR_TABLE[2][13] = { /* Normal years. */ { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, /* Leap years. */ @@ -633,19 +620,16 @@ uint64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const { ERR_FAIL_COND_V( month+1 > 12, 0); // Do this check after month is tested as valid - ERR_EXPLAIN("Invalid day value of: " + itos(day) + " which is larger " - "than "+ itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month])); + ERR_EXPLAIN("Invalid day value of: " + itos(day) + " which is larger than "+ itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month])); ERR_FAIL_COND_V( day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month], 0); // Calculate all the seconds from months past in this year - uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR = - DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month] * SECONDS_PER_DAY; + uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR = DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month] * SECONDS_PER_DAY; uint64_t SECONDS_FROM_YEARS_PAST = 0; for(unsigned int iyear = EPOCH_YR; iyear < year; iyear++) { - SECONDS_FROM_YEARS_PAST += YEARSIZE(iyear) * - SECONDS_PER_DAY; + SECONDS_FROM_YEARS_PAST += YEARSIZE(iyear) * SECONDS_PER_DAY; } uint64_t epoch = @@ -676,8 +660,7 @@ Dictionary _OS::get_datetime_from_unix_time( uint64_t unix_time_val) const { // Just fail if unix time is negative (when interpreted as an int). // This means the user passed in a negative value by accident - ERR_EXPLAIN("unix_time_val was really huge!"+ itos(unix_time_val) + - " You probably passed in a negative value!"); + ERR_EXPLAIN("unix_time_val was really huge!"+ itos(unix_time_val) + " You probably passed in a negative value!"); ERR_FAIL_COND_V( (int64_t)unix_time_val < 0, Dictionary()); OS::Date date; @@ -1744,6 +1727,11 @@ Variant _File::get_var() const { return v; } +uint64_t _File::get_modified_time(const String &p_file) const { + + return FileAccess::get_modified_time(p_file); +} + void _File::_bind_methods() { @@ -1792,6 +1780,7 @@ void _File::_bind_methods() { ClassDB::bind_method(_MD("get_pascal_string"),&_File::get_pascal_string); ClassDB::bind_method(_MD("file_exists","path"),&_File::file_exists); + ClassDB::bind_method(_MD("get_modified_time", "file"),&_File::get_modified_time); BIND_CONSTANT( READ ); BIND_CONSTANT( WRITE ); @@ -1831,16 +1820,28 @@ Error _Directory::open(const String& p_path) { return OK; } -Error _Directory::list_dir_begin() { +Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) { ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED); + + _list_skip_navigational = p_skip_navigational; + _list_skip_hidden = p_skip_hidden; + return d->list_dir_begin(); } String _Directory::get_next(){ ERR_FAIL_COND_V(!d,""); - return d->get_next(); + + String next = d->get_next(); + while (next != "" + && ((_list_skip_navigational && (next == "." || next == "..")) + || (_list_skip_hidden && d->current_is_hidden()))) { + + next = d->get_next(); + } + return next; } bool _Directory::current_is_dir() const{ @@ -1970,7 +1971,7 @@ void _Directory::_bind_methods() { ClassDB::bind_method(_MD("open:Error","path"),&_Directory::open); - ClassDB::bind_method(_MD("list_dir_begin"),&_Directory::list_dir_begin); + ClassDB::bind_method(_MD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(_MD("get_next"),&_Directory::get_next); ClassDB::bind_method(_MD("current_is_dir"),&_Directory::current_is_dir); ClassDB::bind_method(_MD("list_dir_end"),&_Directory::list_dir_end); @@ -2511,7 +2512,7 @@ void _ClassDB::_bind_methods() { ClassDB::bind_method(_MD("class_exists","class"),&_ClassDB::class_exists); ClassDB::bind_method(_MD("is_parent_class","class","inherits"),&_ClassDB::is_parent_class); ClassDB::bind_method(_MD("can_instance","class"),&_ClassDB::can_instance); - ClassDB::bind_method(_MD("instance","class"),&_ClassDB::instance); + ClassDB::bind_method(_MD("instance:Variant","class"),&_ClassDB::instance); ClassDB::bind_method(_MD("class_has_signal","class","signal"),&_ClassDB::has_signal); ClassDB::bind_method(_MD("class_get_signal","class","signal"),&_ClassDB::get_signal); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index f10714720f..00cbb254d6 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -54,7 +54,6 @@ public: void set_abort_on_missing_resources(bool p_abort); PoolStringArray get_dependencies(const String& p_path); bool has(const String& p_path); - Ref<ResourceImportMetadata> load_import_metadata(const String& p_path); _ResourceLoader(); }; @@ -440,6 +439,8 @@ public: bool file_exists(const String& p_name) const; ///< return true if a file exists + uint64_t get_modified_time(const String& p_file) const; + _File(); virtual ~_File(); @@ -456,7 +457,7 @@ public: Error open(const String& p_path); - Error list_dir_begin(); ///< This starts dir listing + Error list_dir_begin(bool p_skip_internal = false, bool p_skip_hidden = false); ///< This starts dir listing String get_next(); bool current_is_dir() const; @@ -485,6 +486,9 @@ public: _Directory(); virtual ~_Directory(); +private: + bool _list_skip_navigational; + bool _list_skip_hidden; }; class _Marshalls : public Reference { diff --git a/core/object_type_db.cpp b/core/class_db.cpp index 24b9c26e71..2a3a12b127 100644 --- a/core/object_type_db.cpp +++ b/core/class_db.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* object_type_db.cpp */ +/* class_db.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -26,12 +26,14 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "object_type_db.h" +#include "class_db.h" + #include "os/mutex.h" #ifdef NO_THREADS #define OBJTYPE_RLOCK +#define OBJTYPE_WLOCK #else @@ -775,11 +777,15 @@ void ClassDB::add_property(StringName p_class,const PropertyInfo& p_pinfo, const +#ifndef NO_THREADS lock->read_lock(); +#endif ClassInfo *type=classes.getptr(p_class); +#ifndef NO_THREADS lock->read_unlock(); +#endif ERR_FAIL_COND(!type); diff --git a/core/object_type_db.h b/core/class_db.h index f745e3d5fd..a09a42423b 100644 --- a/core/object_type_db.h +++ b/core/class_db.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* object_type_db.h */ +/* class_db.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -26,12 +26,13 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef OBJECT_TYPE_DB_H -#define OBJECT_TYPE_DB_H +#ifndef CLASS_DB_H +#define CLASS_DB_H #include "object.h" #include "method_bind.h" #include "print_string.h" + /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -537,4 +538,4 @@ public: -#endif +#endif // CLASS_DB_H diff --git a/core/color.cpp b/core/color.cpp index 89accbb6d2..80a98da252 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "color.h" + #include "math_funcs.h" #include "print_string.h" #include "map.h" diff --git a/core/color_names.inc b/core/color_names.inc index 7b674bb289..b05684acc6 100644 --- a/core/color_names.inc +++ b/core/color_names.inc @@ -1,4 +1,6 @@ // Names from https://en.wikipedia.org/wiki/List_of_colors (through https://raw.githubusercontent.com/SuperUserNameMan/color_to_name/616a7cddafefda91478b7bc26167de97fb5badb1/godot_version.gd), slightly edited and normalized +#include "map.h" + static Map<String, Color> _named_colors; static void _populate_named_colors() { if(!_named_colors.empty()) return; diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index 9b1c052eb9..6d50ed8d9a 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "command_queue_mt.h" + #include "os/os.h" void CommandQueueMT::lock() { diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index 779bbe1b58..3975df7658 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -179,7 +179,7 @@ class CommandQueueMT { R* ret; SyncSemaphore *sync; - virtual void call() { *ret = (instance->*method)(); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { *ret = (instance->*method)(); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class R> @@ -204,7 +204,7 @@ class CommandQueueMT { R* ret; SyncSemaphore *sync; - virtual void call() { *ret = (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { *ret = (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class R> @@ -218,7 +218,7 @@ class CommandQueueMT { R* ret; SyncSemaphore *sync; - virtual void call() { *ret = (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { *ret = (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class P4,class R> @@ -233,7 +233,7 @@ class CommandQueueMT { R* ret; SyncSemaphore *sync; - virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class R> @@ -249,7 +249,7 @@ class CommandQueueMT { R* ret; SyncSemaphore *sync; - virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class R> @@ -266,7 +266,7 @@ class CommandQueueMT { R* ret; SyncSemaphore *sync; - virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class R> @@ -284,7 +284,7 @@ class CommandQueueMT { R* ret; SyncSemaphore *sync; - virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class P8,class R> @@ -303,7 +303,7 @@ class CommandQueueMT { R* ret; SyncSemaphore *sync; - virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; } }; /** commands that don't return but sync */ @@ -318,7 +318,7 @@ class CommandQueueMT { SyncSemaphore *sync; - virtual void call() { (instance->*method)(); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { (instance->*method)(); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1> @@ -330,7 +330,7 @@ class CommandQueueMT { SyncSemaphore *sync; - virtual void call() { (instance->*method)(p1); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { (instance->*method)(p1); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2> @@ -343,7 +343,7 @@ class CommandQueueMT { SyncSemaphore *sync; - virtual void call() { (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3> @@ -357,7 +357,7 @@ class CommandQueueMT { SyncSemaphore *sync; - virtual void call() { (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class P4> @@ -372,7 +372,7 @@ class CommandQueueMT { SyncSemaphore *sync; - virtual void call() { (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5> @@ -388,7 +388,7 @@ class CommandQueueMT { SyncSemaphore *sync; - virtual void call() { (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6> @@ -405,7 +405,7 @@ class CommandQueueMT { SyncSemaphore *sync; - virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7> @@ -423,7 +423,7 @@ class CommandQueueMT { SyncSemaphore *sync; - virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class P8> @@ -442,7 +442,7 @@ class CommandQueueMT { SyncSemaphore *sync; - virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; ; } + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7,p8); sync->sem->post(); sync->in_use=false; } }; /***** BASE *******/ diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp index 1e3a51fede..d39db5044b 100644 --- a/core/compressed_translation.cpp +++ b/core/compressed_translation.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "compressed_translation.h" + #include "pair.h" #include <string.h> diff --git a/core/dictionary.cpp b/core/dictionary.cpp index 3b4d3b65d0..1176b9be3b 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "dictionary.h" + #include "safe_refcount.h" #include "variant.h" diff --git a/core/dvector.h b/core/dvector.h index cac9e8ef85..53a29738f7 100644 --- a/core/dvector.h +++ b/core/dvector.h @@ -89,7 +89,7 @@ class PoolVector { if (!alloc) return; - ERR_FAIL_COND(alloc->lock>0); +// ERR_FAIL_COND(alloc->lock>0); should not be illegal to lock this for copy on write, as it's a copy on write after all if (alloc->refcount.get()==1) return; //nothing to do diff --git a/core/engine.cpp b/core/engine.cpp index eb6d8a3478..b017e77275 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "engine.h" + #include "version.h" void Engine::set_iterations_per_second(int p_ips) { diff --git a/core/error_list.h b/core/error_list.h index c3cd9b399d..f4063a9285 100644 --- a/core/error_list.h +++ b/core/error_list.h @@ -58,7 +58,7 @@ enum Error { ERR_FILE_EOF, ERR_CANT_OPEN, ///< Can't open a resource/socket/file ERR_CANT_CREATE, // (20) - ERROR_QUERY_FAILED, + ERR_QUERY_FAILED, ERR_ALREADY_IN_USE, ERR_LOCKED, ///< resource is locked ERR_TIMEOUT, diff --git a/core/error_macros.cpp b/core/error_macros.cpp index 53a361fa3a..e963f6122b 100644 --- a/core/error_macros.cpp +++ b/core/error_macros.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "error_macros.h" + #include "os/os.h" diff --git a/core/global_constants.cpp b/core/global_constants.cpp index 936facdd23..be811ccbd2 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "global_constants.h" + #include "variant.h" #include "os/keyboard.h" #include "object.h" @@ -433,7 +434,7 @@ static _GlobalConstant _global_constants[]={ BIND_GLOBAL_CONSTANT( ERR_CANT_OPEN ), ///< Can't open a resource/socket/file BIND_GLOBAL_CONSTANT( ERR_CANT_CREATE ), BIND_GLOBAL_CONSTANT( ERR_PARSE_ERROR ), - BIND_GLOBAL_CONSTANT( ERROR_QUERY_FAILED ), + BIND_GLOBAL_CONSTANT( ERR_QUERY_FAILED ), BIND_GLOBAL_CONSTANT( ERR_ALREADY_IN_USE ), BIND_GLOBAL_CONSTANT( ERR_LOCKED ), ///< resource is locked BIND_GLOBAL_CONSTANT( ERR_TIMEOUT ), diff --git a/core/globals.cpp b/core/globals.cpp index a4c24a6cc8..ed0b6f6d8b 100644 --- a/core/globals.cpp +++ b/core/globals.cpp @@ -27,9 +27,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "globals.h" + #include "os/dir_access.h" #include "os/file_access.h" - #include "os/keyboard.h" #include "io/marshalls.h" #include "bind/core_bind.h" @@ -37,6 +37,9 @@ #include "io/file_access_pack.h" #include "io/file_access_network.h" #include "variant_parser.h" + +#define FORMAT_VERSION 3 + GlobalConfig *GlobalConfig::singleton=NULL; GlobalConfig *GlobalConfig::get_singleton() { @@ -122,6 +125,7 @@ bool GlobalConfig::_set(const StringName& p_name, const Variant& p_value) { _THREAD_SAFE_METHOD_ + if (p_value.get_type()==Variant::NIL) props.erase(p_name); else { @@ -166,8 +170,10 @@ bool GlobalConfig::_get(const StringName& p_name,Variant &r_ret) const { _THREAD_SAFE_METHOD_ - if (!props.has(p_name)) + if (!props.has(p_name)) { + print_line("WARNING: not found: "+String(p_name)); return false; + } r_ret=props[p_name].variant; return true; @@ -250,7 +256,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { bool ok = _load_resource_pack(p_main_pack); ERR_FAIL_COND_V(!ok,ERR_CANT_OPEN); - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { _load_settings("res://override.cfg"); @@ -272,7 +278,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { memdelete(d); } - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { _load_settings("res://override.cfg"); @@ -288,7 +294,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { if (FileAccessNetworkClient::get_singleton()) { - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { _load_settings("res://override.cfg"); @@ -308,9 +314,9 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { if (!_load_resource_pack("res://data.pck")) _load_resource_pack("res://data.zip"); // make sure this is load from the resource path - print_line("exists engine cfg? "+itos(FileAccess::exists("/engine.cfg"))); - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { - print_line("loaded engine.cfg"); + print_line("exists engine cfg? "+itos(FileAccess::exists("/godot.cfg"))); + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { + print_line("loaded godot.cfg"); _load_settings("res://override.cfg"); } @@ -338,7 +344,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { //tries to open pack, but only first time if (first_time && (_load_resource_pack(current_dir+"/"+exec_name+".pck") || _load_resource_pack(current_dir+"/"+exec_name+".zip") )) { - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { _load_settings("res://override.cfg"); found=true; @@ -347,7 +353,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { } break; } else if (first_time && (_load_resource_pack(current_dir+"/data.pck") || _load_resource_pack(current_dir+"/data.zip") )) { - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { _load_settings("res://override.cfg"); found=true; @@ -355,7 +361,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { } break; - } else if (_load_settings(current_dir+"/engine.cfg")==OK || _load_settings_binary(current_dir+"/engine.cfb")==OK) { + } else if (_load_settings(current_dir+"/godot.cfg")==OK || _load_settings_binary(current_dir+"/godot.cfb")==OK) { _load_settings(current_dir+"/override.cfg"); candidate=current_dir; @@ -413,7 +419,7 @@ Error GlobalConfig::_load_settings_binary(const String p_path) { if (hdr[0]!='E'|| hdr[1]!='C' || hdr[2]!='F' || hdr[3]!='G') { memdelete(f); - ERR_EXPLAIN("Corrupted header in binary engine.cfb (not ECFG)"); + ERR_EXPLAIN("Corrupted header in binary godot.cfb (not ECFG)"); ERR_FAIL_V(ERR_FILE_CORRUPT;) } @@ -488,6 +494,14 @@ Error GlobalConfig::_load_settings(const String p_path) { } if (assign!=String()) { + if (section==String() && assign=="config_version") { + int config_version = value; + if (config_version > FORMAT_VERSION) { + memdelete(f); + ERR_FAIL_COND_V(config_version > FORMAT_VERSION,ERR_FILE_CANT_OPEN); + } + + } set(section+"/"+assign,value); } else if (next_tag.name!=String()) { section=next_tag.name; @@ -523,7 +537,7 @@ void GlobalConfig::clear(const String& p_name) { Error GlobalConfig::save() { - return save_custom(get_resource_path()+"/engine.cfg"); + return save_custom(get_resource_path()+"/godot.cfg"); } Error GlobalConfig::_save_settings_binary(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom) { @@ -533,7 +547,7 @@ Error GlobalConfig::_save_settings_binary(const String& p_file,const Map<String, FileAccess *file = FileAccess::open(p_file,FileAccess::WRITE,&err); if (err!=OK) { - ERR_EXPLAIN("Coudln't save engine.cfb at "+p_file); + ERR_EXPLAIN("Coudln't save godot.cfb at "+p_file); ERR_FAIL_COND_V(err,err) } @@ -601,10 +615,13 @@ Error GlobalConfig::_save_settings_text(const String& p_file,const Map<String,Li FileAccess *file = FileAccess::open(p_file,FileAccess::WRITE,&err); if (err) { - ERR_EXPLAIN("Coudln't save engine.cfg - "+p_file); + ERR_EXPLAIN("Coudln't save godot.cfg - "+p_file); ERR_FAIL_COND_V(err,err) } + file->store_string("config_version="+itos(FORMAT_VERSION)+"\n"); + + for(Map<String,List<String> >::Element *E=props.front();E;E=E->next()) { if (E!=props.front()) @@ -731,7 +748,7 @@ Error GlobalConfig::save_custom(const String& p_path,const CustomMap& p_custom,c Error err = file->open(dst_file,FileAccess::WRITE); if (err) { memdelete(file); - ERR_EXPLAIN("Coudln't save engine.cfg"); + ERR_EXPLAIN("Coudln't save godot.cfg"); ERR_FAIL_COND_V(err,err) } @@ -922,6 +939,7 @@ GlobalConfig::GlobalConfig() { GLOBAL_DEF("application/main_scene",""); custom_prop_info["application/main_scene"]=PropertyInfo(Variant::STRING,"application/main_scene",PROPERTY_HINT_FILE,"tscn,scn,xscn,xml,res"); GLOBAL_DEF("application/disable_stdout",false); + GLOBAL_DEF("application/disable_stderr",false); GLOBAL_DEF("application/use_shared_user_dir",true); diff --git a/core/image.cpp b/core/image.cpp index d769e6a0b3..037ff82452 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -27,11 +27,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "image.h" + #include "hash_map.h" #include "core/io/image_loader.h" #include "core/os/copymem.h" #include "hq2x.h" #include "print_string.h" + #include <stdio.h> @@ -243,7 +245,7 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width } int Image::get_mipmap_offset(int p_mipmap) const { - ERR_FAIL_INDEX_V(p_mipmap,(mipmaps+1),-1); + ERR_FAIL_INDEX_V(p_mipmap,get_mipmap_count()+1,-1); int ofs,w,h; _get_mipmap_offset_and_size(p_mipmap,ofs,w,h); @@ -762,7 +764,7 @@ void Image::flip_y() { bool gm=mipmaps; if (gm) - clear_mipmaps();; + clear_mipmaps(); @@ -789,7 +791,7 @@ void Image::flip_y() { if (gm) - generate_mipmaps();; + generate_mipmaps(); } @@ -802,7 +804,7 @@ void Image::flip_x() { bool gm=mipmaps; if (gm) - clear_mipmaps();; + clear_mipmaps(); { @@ -827,7 +829,7 @@ void Image::flip_x() { } if (gm) - generate_mipmaps();; + generate_mipmaps(); } @@ -1009,7 +1011,7 @@ void Image::shrink_x2() { } } -Error Image::generate_mipmaps(bool p_keep_existing) { +Error Image::generate_mipmaps() { if (!_can_modify(format)) { ERR_EXPLAIN("Cannot generate mipmaps in indexed, compressed or custom image formats."); @@ -1017,15 +1019,14 @@ Error Image::generate_mipmaps(bool p_keep_existing) { } - int mmcount = get_mipmap_count(); + ERR_FAIL_COND_V(width==0 || height==0,ERR_UNCONFIGURED); + + int mmcount; - int from_mm=1; - if (p_keep_existing) { - from_mm=mmcount+1; - } int size = _get_dst_image_size(width,height,format,mmcount); data.resize(size); + print_line("to gen mipmaps w "+itos(width)+" h "+itos(height) +" format "+get_format_name(format)+" mipmaps " +itos(mmcount)+" new size is: "+itos(size)); PoolVector<uint8_t>::Write wp=data.write(); @@ -1041,18 +1042,16 @@ Error Image::generate_mipmaps(bool p_keep_existing) { int ofs,w,h; _get_mipmap_offset_and_size(i,ofs, w,h); - if (i>=from_mm) { - switch(format) { + switch(format) { - case FORMAT_L8: - case FORMAT_R8: _generate_po2_mipmap<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; - case FORMAT_LA8: - case FORMAT_RG8: _generate_po2_mipmap<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; - case FORMAT_RGB8: _generate_po2_mipmap<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; - case FORMAT_RGBA8: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; - default: {} - } + case FORMAT_L8: + case FORMAT_R8: _generate_po2_mipmap<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; + case FORMAT_LA8: + case FORMAT_RG8: _generate_po2_mipmap<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; + case FORMAT_RGB8: _generate_po2_mipmap<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; + case FORMAT_RGBA8: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; + default: {} } prev_ofs=ofs; @@ -1075,18 +1074,15 @@ Error Image::generate_mipmaps(bool p_keep_existing) { int ofs,w,h; _get_mipmap_offset_and_size(i,ofs, w,h); - if (i>=from_mm) { - - switch(format) { + switch(format) { - case FORMAT_L8: - case FORMAT_R8: _scale_bilinear<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; - case FORMAT_LA8: - case FORMAT_RG8: _scale_bilinear<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; - case FORMAT_RGB8:_scale_bilinear<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; - case FORMAT_RGBA8: _scale_bilinear<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; - default: {} - } + case FORMAT_L8: + case FORMAT_R8: _scale_bilinear<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; + case FORMAT_LA8: + case FORMAT_RG8: _scale_bilinear<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; + case FORMAT_RGB8:_scale_bilinear<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; + case FORMAT_RGBA8: _scale_bilinear<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; + default: {} } prev_ofs=ofs; @@ -1094,8 +1090,11 @@ Error Image::generate_mipmaps(bool p_keep_existing) { prev_h=h; } + + } + mipmaps=true; return OK; } @@ -1152,7 +1151,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma ERR_FAIL_INDEX(p_height-1,MAX_HEIGHT); int mm; - int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps); + int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps?-1:0); if (size!=p_data.size()) { ERR_EXPLAIN("Expected data size of "+itos(size)+" in Image::create()"); @@ -2153,7 +2152,7 @@ void Image::fix_alpha_edges() { return; //not needed PoolVector<uint8_t> dcopy = data; - PoolVector<uint8_t>::Read rp = data.read(); + PoolVector<uint8_t>::Read rp = dcopy.read(); const uint8_t *srcptr=rp.ptr(); PoolVector<uint8_t>::Write wp = data.write(); diff --git a/core/image.h b/core/image.h index 620160147b..1a257f28a0 100644 --- a/core/image.h +++ b/core/image.h @@ -196,7 +196,7 @@ public: /** * Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1) */ - Error generate_mipmaps(bool p_keep_existing=false); + Error generate_mipmaps(); void clear_mipmaps(); diff --git a/core/input_map.cpp b/core/input_map.cpp index bcae630c76..dcce13ba1b 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "input_map.h" + #include "globals.h" #include "os/keyboard.h" @@ -106,7 +107,7 @@ List<StringName> InputMap::get_actions() const { return actions; } -List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore=false) const { +List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_action_test) const { for (List<InputEvent>::Element *E=p_list.front();E;E=E->next()) { @@ -122,7 +123,13 @@ List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list,const case InputEvent::KEY: { - same=(e.key.scancode==p_event.key.scancode && (p_mod_ignore || e.key.mod == p_event.key.mod)); + if(p_action_test) { + uint32_t code = e.key.get_scancode_with_modifiers(); + uint32_t event_code = p_event.key.get_scancode_with_modifiers(); + same=(e.key.scancode==p_event.key.scancode && (!p_event.key.pressed || ((code & event_code) == code))); + } else { + same=(e.key.scancode==p_event.key.scancode && e.key.mod == p_event.key.mod); + } } break; case InputEvent::JOYPAD_BUTTON: { @@ -198,7 +205,7 @@ Array InputMap::_get_action_list(const StringName& p_action) { if (al) { for(const List<InputEvent>::Element *E=al->front();E;E=E->next()) { - ret.push_back(E->get());; + ret.push_back(E->get()); } } @@ -229,7 +236,7 @@ bool InputMap::event_is_action(const InputEvent& p_event, const StringName& p_ac return p_event.action.action==E->get().id; } - return _find_event(E->get().inputs,p_event,!p_event.is_pressed())!=NULL; + return _find_event(E->get().inputs,p_event,true)!=NULL; } const Map<StringName, InputMap::Action>& InputMap::get_action_map() const { @@ -238,7 +245,7 @@ const Map<StringName, InputMap::Action>& InputMap::get_action_map() const { void InputMap::load_from_globals() { - input_map.clear();; + input_map.clear(); List<PropertyInfo> pinfo; GlobalConfig::get_singleton()->get_property_list(&pinfo); @@ -253,7 +260,7 @@ void InputMap::load_from_globals() { add_action(name); - Array va = GlobalConfig::get_singleton()->get(pi.name);; + Array va = GlobalConfig::get_singleton()->get(pi.name); for(int i=0;i<va.size();i++) { diff --git a/core/input_map.h b/core/input_map.h index 306845fc89..6ccd24f29c 100644 --- a/core/input_map.h +++ b/core/input_map.h @@ -46,7 +46,7 @@ private: mutable Map<StringName, Action> input_map; mutable Map<int,StringName> input_id_map; - List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_mod_ignore) const; + List<InputEvent>::Element *_find_event(List<InputEvent> &p_list,const InputEvent& p_event, bool p_action_test=false) const; Array _get_action_list(const StringName& p_action); Array _get_actions(); diff --git a/core/io/aes256.cpp b/core/io/aes256.cpp index cfdac0214d..dc271928b4 100644 --- a/core/io/aes256.cpp +++ b/core/io/aes256.cpp @@ -44,8 +44,7 @@ static uint8_t rj_sbox_inv(uint8_t); #ifdef BACK_TO_TABLES -static const uint8_t sbox[256] = -{ +static const uint8_t sbox[256] = { 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, @@ -79,8 +78,7 @@ static const uint8_t sbox[256] = 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; -static const uint8_t sboxinv[256] = -{ +static const uint8_t sboxinv[256] = { 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, diff --git a/core/io/base64.c b/core/io/base64.c index 0c799e9f07..0929ae5db5 100644 --- a/core/io/base64.c +++ b/core/io/base64.c @@ -1,3 +1,11 @@ +/* + * File: base64.c + * Description: Simple BASE64 conversion methods + * Author: Ari Edelkind + * License: Public Domain + * Website: http://episec.com/people/edelkind/c.html + */ + #include <string.h> char b64string[] = diff --git a/core/io/base64.h b/core/io/base64.h index b70b387983..456ef1811b 100644 --- a/core/io/base64.h +++ b/core/io/base64.h @@ -1,3 +1,11 @@ +/* + * File: base64.h + * Description: Simple BASE64 conversion methods + * Author: Ari Edelkind + * License: Public Domain + * Website: http://episec.com/people/edelkind/c.html + */ + #ifndef BASE64_H #define BASE64_H diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 0d3b494106..6fda7d52f3 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -59,7 +59,7 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,M return -1; strm.avail_in=p_src_size; - int aout = deflateBound(&strm,p_src_size);; + int aout = deflateBound(&strm,p_src_size); /*if (aout>p_src_size) { deflateEnd(&strm); return -1; diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index a9de740806..b944906e78 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -119,7 +119,10 @@ void ConfigFile::get_section_keys(const String& p_section,List<String> *r_keys) } +void ConfigFile::erase_section(const String& p_section) { + values.erase(p_section); +} Error ConfigFile::save(const String& p_path){ @@ -215,6 +218,8 @@ void ConfigFile::_bind_methods(){ ClassDB::bind_method(_MD("get_sections"),&ConfigFile::_get_sections); ClassDB::bind_method(_MD("get_section_keys","section"),&ConfigFile::_get_section_keys); + ClassDB::bind_method(_MD("erase_section","section"),&ConfigFile::erase_section); + ClassDB::bind_method(_MD("load:Error","path"),&ConfigFile::load); ClassDB::bind_method(_MD("save:Error","path"),&ConfigFile::save); diff --git a/core/io/config_file.h b/core/io/config_file.h index 397342f90f..c9c4a9fbc0 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -54,6 +54,8 @@ public: void get_sections(List<String> *r_sections) const; void get_section_keys(const String& p_section,List<String> *r_keys) const; + void erase_section(const String& p_section); + Error save(const String& p_path); Error load(const String& p_path); diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 63c8abbbad..fd06d27c1f 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -566,11 +566,13 @@ PoolByteArray HTTPClient::read_response_body_chunk() { int to_read = MIN(body_left,read_chunk_size); PoolByteArray ret; ret.resize(to_read); - PoolByteArray::Write w = ret.write(); int _offset = 0; while (to_read > 0) { int rec=0; - err = _get_http_data(w.ptr()+_offset,to_read,rec); + { + PoolByteArray::Write w = ret.write(); + err = _get_http_data(w.ptr()+_offset,to_read,rec); + } if (rec>0) { body_left-=rec; to_read-=rec; diff --git a/core/io/json.cpp b/core/io/json.cpp index c0aa530a12..5ade25aab4 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -100,7 +100,7 @@ String JSON::print(const Variant& p_var) { Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token& r_token,int &line,String &r_err_str) { - while (true) { + while (p_len > 0) { switch(p_str[idx]) { case '\n': { @@ -374,7 +374,7 @@ Error JSON::_parse_array(Array &array,const CharType *p_str,int &index, int p_le } - return OK; + return ERR_PARSE_ERROR; } @@ -446,7 +446,7 @@ Error JSON::_parse_object(Dictionary &object,const CharType *p_str,int &index, i } } - return OK; + return ERR_PARSE_ERROR; } diff --git a/core/io/networked_multiplayer_peer.cpp b/core/io/networked_multiplayer_peer.cpp index 6133401a8c..2981307af6 100644 --- a/core/io/networked_multiplayer_peer.cpp +++ b/core/io/networked_multiplayer_peer.cpp @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* networked_multiplayer_peer.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #include "networked_multiplayer_peer.h" diff --git a/core/io/networked_multiplayer_peer.h b/core/io/networked_multiplayer_peer.h index a59d9367d1..5d859a2f25 100644 --- a/core/io/networked_multiplayer_peer.h +++ b/core/io/networked_multiplayer_peer.h @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* networked_multiplayer_peer.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #ifndef NETWORKED_MULTIPLAYER_PEER_H #define NETWORKED_MULTIPLAYER_PEER_H diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index a9f357a7c8..fb5875e4cc 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* pkc_packer.cpp */ +/* pck_packer.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 4af3503434..c75e476764 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -80,7 +80,8 @@ enum { OBJECT_EXTERNAL_RESOURCE=1, OBJECT_INTERNAL_RESOURCE=2, OBJECT_EXTERNAL_RESOURCE_INDEX=3, - FORMAT_VERSION=1, + //version 2: added 64 bits support for float and int + FORMAT_VERSION=2, FORMAT_VERSION_CAN_RENAME_DEPS=1 @@ -758,30 +759,7 @@ Error ResourceInteractiveLoaderBinary::poll(){ resource_cache.push_back(res); if (main) { - if (importmd_ofs) { - f->seek(importmd_ofs); - Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); - imd->set_editor(get_unicode_string()); - int sc = f->get_32(); - for(int i=0;i<sc;i++) { - - String src = get_unicode_string(); - String md5 = get_unicode_string(); - imd->add_source(src,md5); - } - int pc = f->get_32(); - - for(int i=0;i<pc;i++) { - - String name = get_unicode_string(); - Variant val; - parse_variant(val); - imd->set_option(name,val); - } - res->set_import_metadata(imd); - - } f->close(); resource=res; error=ERR_FILE_EOF; @@ -848,9 +826,6 @@ void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f,List<Stri for(int i=0;i<external_resources.size();i++) { String dep=external_resources[i].path; - if (dep.ends_with("*")) { - dep=ResourceLoader::guess_full_filename(dep,external_resources[i].type); - } if (p_add_types && external_resources[i].type!=String()) { dep+="::"+external_resources[i].type; @@ -1103,53 +1078,6 @@ bool ResourceFormatLoaderBinary::handles_type(const String& p_type) const{ return true; //handles all } -Error ResourceFormatLoaderBinary::load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const { - - - FileAccess *f = FileAccess::open(p_path,FileAccess::READ); - if (!f) { - return ERR_FILE_CANT_OPEN; - } - - Ref<ResourceInteractiveLoaderBinary> ria = memnew( ResourceInteractiveLoaderBinary ); - ria->local_path=GlobalConfig::get_singleton()->localize_path(p_path); - ria->res_path=ria->local_path; - //ria->set_local_path( Globals::get_singleton()->localize_path(p_path) ); - ria->recognize(f); - if(ria->error!=OK) - return ERR_FILE_UNRECOGNIZED; - f=ria->f; - uint64_t imp_ofs = f->get_64(); - - if (imp_ofs==0) - return ERR_UNAVAILABLE; - - f->seek(imp_ofs); - Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata ); - imd->set_editor(ria->get_unicode_string()); - int sc = f->get_32(); - for(int i=0;i<sc;i++) { - - String src = ria->get_unicode_string(); - String md5 = ria->get_unicode_string(); - imd->add_source(src,md5); - } - int pc = f->get_32(); - - for(int i=0;i<pc;i++) { - - String name = ria->get_unicode_string(); - Variant val; - ria->parse_variant(val); - imd->set_option(name,val); - } - - r_var=imd; - - return OK; - -} - void ResourceFormatLoaderBinary::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types) { @@ -2178,30 +2106,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_ } f->seek_end(); - print_line("SAVING: "+p_path); - if (p_resource->get_import_metadata().is_valid()) { - uint64_t md_pos = f->get_pos(); - Ref<ResourceImportMetadata> imd=p_resource->get_import_metadata(); - save_unicode_string(imd->get_editor()); - f->store_32(imd->get_source_count()); - for(int i=0;i<imd->get_source_count();i++) { - save_unicode_string(imd->get_source_path(i)); - save_unicode_string(imd->get_source_md5(i)); - print_line("SAVE PATH: "+imd->get_source_path(i)); - print_line("SAVE MD5: "+imd->get_source_md5(i)); - } - List<String> options; - imd->get_options(&options); - f->store_32(options.size()); - for(List<String>::Element *E=options.front();E;E=E->next()) { - save_unicode_string(E->get()); - write_variant(imd->get_option(E->get())); - } - - f->seek(md_at); - f->store_64(md_pos); - f->seek_end(); - } f->store_buffer((const uint8_t*)"RSRC",4); //magic at end diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 611029e792..1dac51cc5c 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -109,7 +109,6 @@ public: virtual bool handles_type(const String& p_type) const; virtual String get_resource_type(const String &p_path) const; virtual void get_dependencies(const String& p_path, List<String> *p_dependencies, bool p_add_types=false); - virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const; virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map); diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp new file mode 100644 index 0000000000..556dff3125 --- /dev/null +++ b/core/io/resource_import.cpp @@ -0,0 +1,257 @@ +#include "resource_import.h" +#include "variant_parser.h" +#include "os/os.h" + +Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndType &r_path_and_type) const { + + Error err; + FileAccess *f= FileAccess::open(p_path+".import",FileAccess::READ,&err); + + if (!f) + return err; + + VariantParser::StreamFile stream; + stream.f=f; + + String assign; + Variant value; + VariantParser::Tag next_tag; + + int lines=0; + String error_text; + while(true) { + + assign=Variant(); + next_tag.fields.clear(); + next_tag.name=String(); + + err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL,true); + if (err==ERR_FILE_EOF) { + memdelete(f); + return OK; + } + else if (err!=OK) { + ERR_PRINTS("ResourceFormatImporter::load - "+p_path+".import:"+itos(lines)+" error: "+error_text); + memdelete(f); + return err; + } + + if (assign!=String()) { + if (assign.begins_with("path.") && r_path_and_type.path==String()) { + String feature = assign.get_slicec('.',1); + if (OS::get_singleton()->check_feature_support(feature)) { + r_path_and_type.path=value; + } + + } else if (assign=="path") { + r_path_and_type.path=value; + } else if (assign=="type") { + r_path_and_type.type=value; + } + + } else if (next_tag.name!="remap") { + break; + } + } + + memdelete(f); + + if (r_path_and_type.path==String() || r_path_and_type.type==String()) { + return ERR_FILE_CORRUPT; + } + return OK; + +} + + +RES ResourceFormatImporter::load(const String &p_path,const String& p_original_path,Error *r_error) { + + PathAndType pat; + Error err = _get_path_and_type(p_path,pat); + + if (err!=OK) { + + if (r_error) + *r_error=err; + + return RES(); + } + + + RES res = ResourceLoader::load(pat.path,pat.type,false,r_error); + +#ifdef TOOLS_ENABLED + res->set_import_last_modified_time( res->get_last_modified_time() ); //pass this, if used + res->set_import_path(pat.path); +#endif + + return res; + +} + +void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const{ + + Set<String> found; + + for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) { + List<String> local_exts; + E->get()->get_recognized_extensions(&local_exts); + for (List<String>::Element *F=local_exts.front();F;F=F->next()) { + if (!found.has(F->get())) { + p_extensions->push_back(F->get()); + found.insert(F->get()); + } + } + } +} + +void ResourceFormatImporter::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const{ + + if (p_type=="") { + return get_recognized_extensions(p_extensions); + } + + Set<String> found; + + for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) { + String res_type = E->get()->get_resource_type(); + if (res_type==String()) + continue; + + if (!ClassDB::is_parent_class(res_type,p_type)) + continue; + + List<String> local_exts; + E->get()->get_recognized_extensions(&local_exts); + for (List<String>::Element *F=local_exts.front();F;F=F->next()) { + if (!found.has(F->get())) { + p_extensions->push_back(F->get()); + found.insert(F->get()); + } + } + } +} + +bool ResourceFormatImporter::recognize_path(const String& p_path,const String& p_for_type) const{ + + return FileAccess::exists(p_path+".import"); + +} + +bool ResourceFormatImporter::can_be_imported(const String& p_path) const { + + return ResourceFormatLoader::recognize_path(p_path); +} + + +bool ResourceFormatImporter::handles_type(const String& p_type) const { + + for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) { + + String res_type = E->get()->get_resource_type(); + if (res_type==String()) + continue; + if (ClassDB::is_parent_class(res_type,p_type)) + return true; + + } + + return true; +} + + +String ResourceFormatImporter::get_internal_resource_path(const String& p_path) const { + + PathAndType pat; + Error err = _get_path_and_type(p_path,pat); + + if (err!=OK) { + + return String(); + } + + return pat.path; +} + +String ResourceFormatImporter::get_resource_type(const String &p_path) const { + + PathAndType pat; + Error err = _get_path_and_type(p_path,pat); + + if (err!=OK) { + + return ""; + } + + return pat.type; +} + +void ResourceFormatImporter::get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types){ + + PathAndType pat; + Error err = _get_path_and_type(p_path,pat); + + if (err!=OK) { + + return; + } + + return ResourceLoader::get_dependencies(pat.path,p_dependencies,p_add_types); +} + +Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_name(const String& p_name) { + + for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) { + if (E->get()->get_importer_name()==p_name) { + return E->get(); + } + } + + return Ref<ResourceImporter>(); +} + + +void ResourceFormatImporter::get_importers_for_extension(const String& p_extension,List<Ref<ResourceImporter> > *r_importers) { + + for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) { + List<String> local_exts; + E->get()->get_recognized_extensions(&local_exts); + for (List<String>::Element *F=local_exts.front();F;F=F->next()) { + if (p_extension.to_lower()==F->get()) { + r_importers->push_back(E->get()); + } + } + } +} + +Ref<ResourceImporter> ResourceFormatImporter::get_importer_by_extension(const String& p_extension) { + + + Ref<ResourceImporter> importer; + float priority=0; + + for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) { + + List<String> local_exts; + E->get()->get_recognized_extensions(&local_exts); + for (List<String>::Element *F=local_exts.front();F;F=F->next()) { + if (p_extension.to_lower()==F->get() && E->get()->get_priority() > priority) { + importer=E->get(); + priority=E->get()->get_priority(); + } + } + } + + return importer; +} + +String ResourceFormatImporter::get_import_base_path(const String& p_for_file) const { + + return "res://.import/"+p_for_file.get_file()+"-"+p_for_file.md5_text(); +} + +ResourceFormatImporter *ResourceFormatImporter::singleton=NULL; + +ResourceFormatImporter::ResourceFormatImporter() { + singleton=this; +} diff --git a/core/io/resource_import.h b/core/io/resource_import.h new file mode 100644 index 0000000000..387b3902fe --- /dev/null +++ b/core/io/resource_import.h @@ -0,0 +1,77 @@ +#ifndef RESOURCE_IMPORT_H +#define RESOURCE_IMPORT_H + + +#include "io/resource_loader.h" +class ResourceImporter; + +class ResourceFormatImporter : public ResourceFormatLoader { + + struct PathAndType { + String path; + String type; + }; + + + Error _get_path_and_type(const String& p_path,PathAndType & r_path_and_type) const; + + static ResourceFormatImporter *singleton; + + Set< Ref<ResourceImporter> > importers; +public: + + static ResourceFormatImporter *get_singleton() { return singleton; } + virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const; + virtual bool recognize_path(const String& p_path,const String& p_for_type=String()) const; + virtual bool handles_type(const String& p_type) const; + virtual String get_resource_type(const String &p_path) const; + virtual void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false); + + virtual bool can_be_imported(const String& p_path) const; + + String get_internal_resource_path(const String& p_path) const; + + void add_importer(const Ref<ResourceImporter>& p_importer) { importers.insert(p_importer); } + Ref<ResourceImporter> get_importer_by_name(const String& p_name); + Ref<ResourceImporter> get_importer_by_extension(const String& p_extension); + void get_importers_for_extension(const String& p_extension,List<Ref<ResourceImporter> > *r_importers); + + String get_import_base_path(const String& p_for_file) const; + ResourceFormatImporter(); +}; + + +class ResourceImporter : public Reference { + + GDCLASS(ResourceImporter,Reference) +public: + virtual String get_importer_name() const=0; + virtual String get_visible_name() const=0; + virtual void get_recognized_extensions(List<String> *p_extensions) const=0; + virtual String get_save_extension() const=0; + virtual String get_resource_type() const=0; + virtual float get_priority() const { return 1.0; } + + struct ImportOption { + PropertyInfo option; + Variant default_value; + + ImportOption(const PropertyInfo& p_info,const Variant& p_default) { option=p_info; default_value=p_default; } + ImportOption() {} + }; + + + virtual int get_preset_count() const { return 0; } + virtual String get_preset_name(int p_idx) const { return String(); } + + virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const=0; + virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const=0; + + + virtual Error 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=NULL)=0; + +}; + +#endif // RESOURCE_IMPORT_H diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 354efaa83f..fbf6a2cea2 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -47,21 +47,29 @@ Error ResourceInteractiveLoader::wait() { return err; } +bool ResourceFormatLoader::recognize_path(const String& p_path,const String& p_for_type) const { -bool ResourceFormatLoader::recognize(const String& p_extension) const { + String extension = p_path.get_extension(); List<String> extensions; - get_recognized_extensions(&extensions); + if (p_for_type==String()) { + get_recognized_extensions(&extensions); + } else { + get_recognized_extensions_for_type(p_for_type,&extensions); + } + for (List<String>::Element *E=extensions.front();E;E=E->next()) { - if (E->get().nocasecmp_to(p_extension.get_extension())==0) + if (E->get().nocasecmp_to(extension)==0) return true; } return false; + } + void ResourceFormatLoader::get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const { if (p_type=="" || handles_type(p_type)) @@ -166,7 +174,7 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p else local_path = GlobalConfig::get_singleton()->localize_path(p_path); - local_path=find_complete_path(local_path,p_type_hint); + ERR_FAIL_COND_V(local_path=="",RES()); if (!p_no_cache && ResourceCache::has(local_path)) { @@ -177,22 +185,16 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p return RES( ResourceCache::get(local_path ) ); } - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - if (OS::get_singleton()->is_stdout_verbose()) - print_line("load resource: "+remapped_path); - - String extension=remapped_path.get_extension(); + print_line("load resource: "+local_path); bool found=false; for (int i=0;i<loader_count;i++) { - if (!loader[i]->recognize(extension)) - continue; - if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) + if (!loader[i]->recognize_path(local_path,p_type_hint)) continue; found=true; - RES res = loader[i]->load(remapped_path,local_path,r_error); + RES res = loader[i]->load(local_path,local_path,r_error); if (res.is_null()) continue; if (!p_no_cache) @@ -201,7 +203,7 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p res->set_edited(false); if (timestamp_on_load) { - uint64_t mt = FileAccess::get_modified_time(remapped_path); + uint64_t mt = FileAccess::get_modified_time(local_path); //printf("mt %s: %lli\n",remapped_path.utf8().get_data(),mt); res->set_last_modified_time(mt); } @@ -220,82 +222,6 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p } -Ref<ResourceImportMetadata> ResourceLoader::load_import_metadata(const String &p_path) { - - - - String local_path; - if (p_path.is_rel_path()) - local_path="res://"+p_path; - else - local_path = GlobalConfig::get_singleton()->localize_path(p_path); - - String extension=p_path.get_extension(); - Ref<ResourceImportMetadata> ret; - - for (int i=0;i<loader_count;i++) { - - if (!loader[i]->recognize(extension)) - continue; - - Error err = loader[i]->load_import_metadata(local_path,ret); - if (err==OK) - break; - } - - - return ret; - -} - - - -String ResourceLoader::find_complete_path(const String& p_path,const String& p_type) { - //this is an old vestige when the engine saved files without extension. - //remains here for compatibility with old projects and only because it - //can be sometimes nice to open files using .* from a script and have it guess - //the right extension. - - String local_path = p_path; - if (local_path.ends_with("*")) { - - //find the extension for resource that ends with * - local_path = local_path.substr(0,local_path.length()-1); - List<String> extensions; - get_recognized_extensions_for_type(p_type,&extensions); - List<String> candidates; - - for(List<String>::Element *E=extensions.front();E;E=E->next()) { - - String path = local_path+E->get(); - - if (PathRemap::get_singleton()->has_remap(path) || FileAccess::exists(path)) { - candidates.push_back(path); - } - - } - - - if (candidates.size()==0) { - return ""; - } else if (candidates.size()==1 || p_type=="") { - return candidates.front()->get(); - } else { - - for(List<String>::Element *E=candidates.front();E;E=E->next()) { - - String rt = get_resource_type(E->get()); - if (ClassDB::is_parent_class(rt,p_type)) { - return E->get(); - } - } - - return ""; - } - } - - return local_path; -} Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_path,const String& p_type_hint,bool p_no_cache,Error *r_error) { @@ -309,7 +235,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ else local_path = GlobalConfig::get_singleton()->localize_path(p_path); - local_path=find_complete_path(local_path,p_type_hint); + ERR_FAIL_COND_V(local_path=="",Ref<ResourceInteractiveLoader>()); @@ -329,19 +255,14 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ if (OS::get_singleton()->is_stdout_verbose()) print_line("load resource: "); - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - - String extension=remapped_path.get_extension(); bool found=false; for (int i=0;i<loader_count;i++) { - if (!loader[i]->recognize(extension)) - continue; - if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) + if (!loader[i]->recognize_path(local_path,p_type_hint)) continue; found=true; - Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(remapped_path,r_error); + Ref<ResourceInteractiveLoader> ril = loader[i]->load_interactive(local_path,r_error); if (ril.is_null()) continue; if (!p_no_cache) @@ -383,20 +304,16 @@ void ResourceLoader::get_dependencies(const String& p_path, List<String> *p_depe else local_path = GlobalConfig::get_singleton()->localize_path(p_path); - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - - String extension=remapped_path.get_extension(); - for (int i=0;i<loader_count;i++) { - if (!loader[i]->recognize(extension)) + if (!loader[i]->recognize_path(local_path)) continue; /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; */ - loader[i]->get_dependencies(remapped_path,p_dependencies,p_add_types); + loader[i]->get_dependencies(local_path,p_dependencies,p_add_types); } } @@ -410,20 +327,17 @@ Error ResourceLoader::rename_dependencies(const String &p_path,const Map<String, else local_path = GlobalConfig::get_singleton()->localize_path(p_path); - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - - String extension=remapped_path.get_extension(); for (int i=0;i<loader_count;i++) { - if (!loader[i]->recognize(extension)) + if (!loader[i]->recognize_path(local_path)) continue; /* if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) continue; */ - return loader[i]->rename_dependencies(p_path,p_map); + return loader[i]->rename_dependencies(local_path,p_map); } @@ -432,17 +346,6 @@ Error ResourceLoader::rename_dependencies(const String &p_path,const Map<String, } -String ResourceLoader::guess_full_filename(const String &p_path,const String& p_type) { - - String local_path; - if (p_path.is_rel_path()) - local_path="res://"+p_path; - else - local_path = GlobalConfig::get_singleton()->localize_path(p_path); - - return find_complete_path(local_path,p_type); - -} String ResourceLoader::get_resource_type(const String &p_path) { @@ -452,8 +355,6 @@ String ResourceLoader::get_resource_type(const String &p_path) { else local_path = GlobalConfig::get_singleton()->localize_path(p_path); - String remapped_path = PathRemap::get_singleton()->get_remap(local_path); - String extension=remapped_path.get_extension(); for (int i=0;i<loader_count;i++) { diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 7979bd02a7..f464415e12 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -61,11 +61,10 @@ public: virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL); virtual void get_recognized_extensions(List<String> *p_extensions) const=0; virtual void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions) const; - bool recognize(const String& p_extension) const; + virtual bool recognize_path(const String& p_path,const String& p_for_type=String()) const; virtual bool handles_type(const String& p_type) const=0; virtual String get_resource_type(const String &p_path) const=0; virtual void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false); - virtual Error load_import_metadata(const String &p_path, Ref<ResourceImportMetadata>& r_var) const { return ERR_UNAVAILABLE; } virtual Error rename_dependencies(const String &p_path,const Map<String,String>& p_map) { return OK; } virtual ~ResourceFormatLoader() {} @@ -92,14 +91,12 @@ class ResourceLoader { static DependencyErrorNotify dep_err_notify; static bool abort_on_missing_resource; - static String find_complete_path(const String& p_path,const String& p_type); public: static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL); static RES load(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL); - static Ref<ResourceImportMetadata> load_import_metadata(const String &p_path); static void get_recognized_extensions_for_type(const String& p_type,List<String> *p_extensions); static void add_resource_format_loader(ResourceFormatLoader *p_format_loader,bool p_at_front=false); @@ -107,8 +104,6 @@ public: static void get_dependencies(const String& p_path,List<String> *p_dependencies,bool p_add_types=false); static Error rename_dependencies(const String &p_path,const Map<String,String>& p_map); - static String guess_full_filename(const String &p_path,const String& p_type); - static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load=p_timestamp; } static void notify_load_error(const String& p_err) { if (err_notify) err_notify(err_notify_ud,p_err); } @@ -122,4 +117,6 @@ public: static bool get_abort_on_missing_resources() { return abort_on_missing_resource; } }; + + #endif diff --git a/core/map.h b/core/map.h index 9448389169..d1a4c209ad 100644 --- a/core/map.h +++ b/core/map.h @@ -428,7 +428,7 @@ private: Element *aux=node->parent->left; if (aux->color==RED) { _set_color(aux,BLACK); - _set_color(node->parent,RED);; + _set_color(node->parent,RED); _rotate_right(node->parent); aux=node->parent->left; } diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 0d6997183f..a1f471ebe3 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* a_star.cpp */ +/* a_star.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -39,7 +39,7 @@ int AStar::get_available_point_id() const { return points.back()->key()+1; } -void AStar::add_point(int p_id, const Vector3 &p_pos, float p_weight_scale) { +void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) { ERR_FAIL_COND(p_id<0); if (!points.has(p_id)) { Point *pt = memnew( Point ); @@ -62,7 +62,7 @@ Vector3 AStar::get_point_pos(int p_id) const{ return points[p_id]->pos; } -float AStar::get_point_weight_scale(int p_id) const{ +real_t AStar::get_point_weight_scale(int p_id) const{ ERR_FAIL_COND_V(!points.has(p_id),0); @@ -145,11 +145,11 @@ void AStar::clear(){ int AStar::get_closest_point(const Vector3& p_point) const{ int closest_id=-1; - float closest_dist=1e20; + real_t closest_dist=1e20; for (const Map<int,Point*>::Element *E=points.front();E;E=E->next()) { - float d = p_point.distance_squared_to(E->get()->pos); + real_t d = p_point.distance_squared_to(E->get()->pos); if (closest_id<0 || d<closest_dist) { closest_dist=d; closest_id=E->key(); @@ -162,7 +162,7 @@ int AStar::get_closest_point(const Vector3& p_point) const{ } Vector3 AStar::get_closest_pos_in_segment(const Vector3& p_point) const { - float closest_dist = 1e20; + real_t closest_dist = 1e20; bool found=false; Vector3 closest_point; @@ -175,7 +175,7 @@ Vector3 AStar::get_closest_pos_in_segment(const Vector3& p_point) const { }; Vector3 p = Geometry::get_closest_point_to_segment(p_point,segment); - float d = p_point.distance_squared_to(p); + real_t d = p_point.distance_squared_to(p); if (!found || d<closest_dist) { closest_point=p; @@ -220,14 +220,14 @@ bool AStar::_solve(Point* begin_point, Point* end_point) { //check open list SelfList<Point> *least_cost_point=NULL; - float least_cost=1e30; + real_t least_cost=1e30; //this could be faster (cache previous results) for (SelfList<Point> *E=open_list.first();E;E=E->next()) { Point *p=E->self(); - float cost=p->distance; + real_t cost=p->distance; cost+=p->pos.distance_to(end_point->pos); cost*=p->weight_scale; @@ -249,7 +249,7 @@ bool AStar::_solve(Point* begin_point, Point* end_point) { Point* e=p->neighbours[i]; - float distance = p->pos.distance_to(e->pos) + p->distance; + real_t distance = p->pos.distance_to(e->pos) + p->distance; distance*=e->weight_scale; diff --git a/core/math/a_star.h b/core/math/a_star.h index 35e6ead226..c4c955ed2d 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -48,14 +48,14 @@ class AStar: public Reference { int id; Vector3 pos; - float weight_scale; + real_t weight_scale; uint64_t last_pass; Vector<Point*> neighbours; //used for pathfinding Point *prev_point; - float distance; + real_t distance; Point() : list(this) {} }; @@ -98,9 +98,9 @@ public: int get_available_point_id() const; - void add_point(int p_id,const Vector3& p_pos,float p_weight_scale=1); + void add_point(int p_id,const Vector3& p_pos,real_t p_weight_scale=1); Vector3 get_point_pos(int p_id) const; - float get_point_weight_scale(int p_id) const; + real_t get_point_weight_scale(int p_id) const; void remove_point(int p_id); void connect_points(int p_id,int p_with_id); diff --git a/core/math/audio_frame.cpp b/core/math/audio_frame.cpp new file mode 100644 index 0000000000..566ba23992 --- /dev/null +++ b/core/math/audio_frame.cpp @@ -0,0 +1,2 @@ +#include "audio_frame.h" + diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h new file mode 100644 index 0000000000..acd74903bb --- /dev/null +++ b/core/math/audio_frame.h @@ -0,0 +1,61 @@ +#ifndef AUDIOFRAME_H +#define AUDIOFRAME_H + +#include "typedefs.h" + + +static inline float undenormalise(volatile float f) +{ + union { + uint32_t i; + float f; + } v; + + v.f = f; + + // original: return (v.i & 0x7f800000) == 0 ? 0.0f : f; + // version from Tim Blechmann: + return (v.i & 0x7f800000) < 0x08000000 ? 0.0f : f; +} + + +struct AudioFrame { + + //left and right samples + float l,r; + + _ALWAYS_INLINE_ const float& operator[](int idx) const { return idx==0?l:r; } + _ALWAYS_INLINE_ float& operator[](int idx) { return idx==0?l:r; } + + _ALWAYS_INLINE_ AudioFrame operator+(const AudioFrame& p_frame) const { return AudioFrame(l+p_frame.l,r+p_frame.r); } + _ALWAYS_INLINE_ AudioFrame operator-(const AudioFrame& p_frame) const { return AudioFrame(l-p_frame.l,r-p_frame.r); } + _ALWAYS_INLINE_ AudioFrame operator*(const AudioFrame& p_frame) const { return AudioFrame(l*p_frame.l,r*p_frame.r); } + _ALWAYS_INLINE_ AudioFrame operator/(const AudioFrame& p_frame) const { return AudioFrame(l/p_frame.l,r/p_frame.r); } + + _ALWAYS_INLINE_ AudioFrame operator+(float p_sample) const { return AudioFrame(l+p_sample,r+p_sample); } + _ALWAYS_INLINE_ AudioFrame operator-(float p_sample) const { return AudioFrame(l-p_sample,r-p_sample); } + _ALWAYS_INLINE_ AudioFrame operator*(float p_sample) const { return AudioFrame(l*p_sample,r*p_sample); } + _ALWAYS_INLINE_ AudioFrame operator/(float p_sample) const { return AudioFrame(l/p_sample,r/p_sample); } + + _ALWAYS_INLINE_ void operator+=(const AudioFrame& p_frame) { l+=p_frame.l; r+=p_frame.r; } + _ALWAYS_INLINE_ void operator-=(const AudioFrame& p_frame) { l-=p_frame.l; r-=p_frame.r; } + _ALWAYS_INLINE_ void operator*=(const AudioFrame& p_frame) { l*=p_frame.l; r*=p_frame.r; } + _ALWAYS_INLINE_ void operator/=(const AudioFrame& p_frame) { l/=p_frame.l; r/=p_frame.r; } + + _ALWAYS_INLINE_ void operator+=(float p_sample) { l+=p_sample; r+=p_sample; } + _ALWAYS_INLINE_ void operator-=(float p_sample) { l-=p_sample; r-=p_sample; } + _ALWAYS_INLINE_ void operator*=(float p_sample) { l*=p_sample; r*=p_sample; } + _ALWAYS_INLINE_ void operator/=(float p_sample) { l/=p_sample; r/=p_sample; } + + _ALWAYS_INLINE_ void undenormalise() { + l = ::undenormalise(l); + r = ::undenormalise(r); + } + + _ALWAYS_INLINE_ AudioFrame(float p_l, float p_r) {l=p_l; r=p_r;} + _ALWAYS_INLINE_ AudioFrame(const AudioFrame& p_frame) {l=p_frame.l; r=p_frame.r;} + + _ALWAYS_INLINE_ AudioFrame() {} +}; + +#endif diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp index e2526f5134..1ca6385032 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -87,8 +87,8 @@ int BSP_Tree::_get_points_inside(int p_node,const Vector3* p_points,int *p_indic max+=p_center; min+=p_center; - float dist_min = p.distance_to(min); - float dist_max = p.distance_to(max); + real_t dist_min = p.distance_to(min); + real_t dist_max = p.distance_to(max); if ((dist_min * dist_max) < CMP_EPSILON ) { //intersection, test point by point @@ -290,13 +290,13 @@ bool BSP_Tree::point_is_inside(const Vector3& p_point) const { } -static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,float p_tolerance) { +static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,real_t p_tolerance) { int ic = p_indices.size(); const int*indices=p_indices.ptr(); int best_plane = -1; - float best_plane_cost = 1e20; + real_t best_plane_cost = 1e20; // Loop to find the polygon that best divides the set. @@ -317,7 +317,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i for(int k=0;k<3;k++) { - float d = p.distance_to(g.vertex[j]); + real_t d = p.distance_to(g.vertex[j]); if (Math::abs(d)>p_tolerance) { @@ -340,13 +340,13 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i - //double split_cost = num_spanning / (double) face_count; - double relation = Math::abs(num_over-num_under) / (double) ic; + //real_t split_cost = num_spanning / (real_t) face_count; + real_t relation = Math::abs(num_over-num_under) / (real_t) ic; // being honest, i never found a way to add split cost to the mix in a meaninguful way // in this engine, also, will likely be ignored anyway - double plane_cost = /*split_cost +*/ relation; + real_t plane_cost = /*split_cost +*/ relation; //printf("plane %i, %i over, %i under, %i spanning, cost is %g\n",i,num_over,num_under,num_spanning,plane_cost); if (plane_cost<best_plane_cost) { @@ -362,7 +362,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i } -static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Vector<Plane> &p_planes, Vector<BSP_Tree::Node> &p_nodes,float p_tolerance) { +static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Vector<Plane> &p_planes, Vector<BSP_Tree::Node> &p_nodes,real_t p_tolerance) { ERR_FAIL_COND_V( p_nodes.size() == BSP_Tree::MAX_NODES, -1 ); @@ -400,7 +400,7 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve for(int j=0;j<3;j++) { - float d = divisor_plane.distance_to(f.vertex[j]); + real_t d = divisor_plane.distance_to(f.vertex[j]); if (Math::abs(d)>p_tolerance) { if (d > 0) @@ -473,7 +473,7 @@ BSP_Tree::operator Variant() const { Dictionary d; d["error_radius"]=error_radius; - Vector<float> plane_values; + Vector<real_t> plane_values; plane_values.resize(planes.size()*4); for(int i=0;i<planes.size();i++) { @@ -522,13 +522,13 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) { if (d["planes"].get_type()==Variant::POOL_REAL_ARRAY) { - PoolVector<float> src_planes=d["planes"]; + PoolVector<real_t> src_planes=d["planes"]; int plane_count=src_planes.size(); ERR_FAIL_COND(plane_count%4); planes.resize(plane_count/4); if (plane_count) { - PoolVector<float>::Read r = src_planes.read(); + PoolVector<real_t>::Read r = src_planes.read(); for(int i=0;i<plane_count/4;i++) { planes[i].normal.x=r[i*4+0]; @@ -562,7 +562,7 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) { } -BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius) { +BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,real_t p_error_radius) { // compute aabb @@ -615,7 +615,7 @@ BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius) { error_radius=p_error_radius; } -BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,float p_error_radius) { +BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,real_t p_error_radius) { nodes=p_nodes; planes=p_planes; diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h index e01df96555..c0071438db 100644 --- a/core/math/bsp_tree.h +++ b/core/math/bsp_tree.h @@ -30,7 +30,7 @@ #define BSP_TREE_H #include "plane.h" -#include "aabb.h" +#include "rect3.h" #include "face3.h" #include "vector.h" #include "dvector.h" @@ -66,7 +66,7 @@ private: Vector<Node> nodes; Vector<Plane> planes; Rect3 aabb; - float error_radius; + real_t error_radius; int _get_points_inside(int p_node,const Vector3* p_points,int *p_indices, const Vector3& p_center,const Vector3& p_half_extents,int p_indices_count) const; @@ -91,8 +91,8 @@ public: BSP_Tree(); BSP_Tree(const Variant& p_variant); - BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius=0); - BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,float p_error_radius=0); + BSP_Tree(const PoolVector<Face3>& p_faces,real_t p_error_radius=0); + BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,real_t p_error_radius=0); ~BSP_Tree(); }; @@ -110,7 +110,7 @@ bool BSP_Tree::_test_convex(const Node* p_nodes, const Plane* p_planes,int p_cur const Plane& p=p_planes[n.plane]; - float min,max; + real_t min,max; p_convex.project_range(p.normal,min,max); bool go_under = min < p.d; diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index c44ff4682a..3b47a75c65 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -65,15 +65,15 @@ Plane CameraMatrix::xform4(const Plane& p_vec4) const { return ret; } -void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p_z_near, float p_z_far,bool p_flip_fov) { +void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far,bool p_flip_fov) { if (p_flip_fov) { p_fovy_degrees=get_fovy(p_fovy_degrees,1.0/p_aspect); } - float sine, cotangent, deltaZ; - float radians = p_fovy_degrees / 2.0 * Math_PI / 180.0; + real_t sine, cotangent, deltaZ; + real_t radians = p_fovy_degrees / 2.0 * Math_PI / 180.0; deltaZ = p_z_far - p_z_near; sine = Math::sin(radians); @@ -94,7 +94,7 @@ void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p } -void CameraMatrix::set_orthogonal(float p_left, float p_right, float p_bottom, float p_top, float p_znear, float p_zfar) { +void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) { set_identity(); @@ -109,7 +109,7 @@ void CameraMatrix::set_orthogonal(float p_left, float p_right, float p_bottom, f } -void CameraMatrix::set_orthogonal(float p_size, float p_aspect, float p_znear, float p_zfar,bool p_flip_fov) { +void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar,bool p_flip_fov) { if (!p_flip_fov) { p_size*=p_aspect; @@ -120,7 +120,7 @@ void CameraMatrix::set_orthogonal(float p_size, float p_aspect, float p_znear, f -void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, float p_top, float p_near, float p_far) { +void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) { #if 0 ///@TODO, give a check to this. I'm not sure if it's working. set_identity(); @@ -134,19 +134,31 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa matrix[3][2]=-1; matrix[3][3]=0; #else - float *te = &matrix[0][0]; - float x = 2 * p_near / ( p_right - p_left ); - float y = 2 * p_near / ( p_top - p_bottom ); - - float a = ( p_right + p_left ) / ( p_right - p_left ); - float b = ( p_top + p_bottom ) / ( p_top - p_bottom ); - float c = - ( p_far + p_near ) / ( p_far - p_near ); - float d = - 2 * p_far * p_near / ( p_far - p_near ); - - te[0] = x; te[4] = 0; te[8] = a; te[12] = 0; - te[1] = 0; te[5] = y; te[9] = b; te[13] = 0; - te[2] = 0; te[6] = 0; te[10] = c; te[14] = d; - te[3] = 0; te[7] = 0; te[11] = - 1; te[15] = 0; + real_t *te = &matrix[0][0]; + real_t x = 2 * p_near / ( p_right - p_left ); + real_t y = 2 * p_near / ( p_top - p_bottom ); + + real_t a = ( p_right + p_left ) / ( p_right - p_left ); + real_t b = ( p_top + p_bottom ) / ( p_top - p_bottom ); + real_t c = - ( p_far + p_near ) / ( p_far - p_near ); + real_t d = - 2 * p_far * p_near / ( p_far - p_near ); + + te[0] = x; + te[1] = 0; + te[2] = 0; + te[3] = 0; + te[4] = 0; + te[5] = y; + te[6] = 0; + te[7] = 0; + te[8] = a; + te[9] = b; + te[10] = c; + te[11] = -1; + te[12] = 0; + te[13] = 0; + te[14] = d; + te[15] = 0; #endif @@ -154,9 +166,9 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa -float CameraMatrix::get_z_far() const { +real_t CameraMatrix::get_z_far() const { - const float * matrix = (const float*)this->matrix; + const real_t * matrix = (const real_t*)this->matrix; Plane new_plane=Plane(matrix[ 3] - matrix[ 2], matrix[ 7] - matrix[ 6], matrix[11] - matrix[10], @@ -167,9 +179,9 @@ float CameraMatrix::get_z_far() const { return new_plane.d; } -float CameraMatrix::get_z_near() const { +real_t CameraMatrix::get_z_near() const { - const float * matrix = (const float*)this->matrix; + const real_t * matrix = (const real_t*)this->matrix; Plane new_plane=Plane(matrix[ 3] + matrix[ 2], matrix[ 7] + matrix[ 6], matrix[11] + matrix[10], @@ -179,25 +191,28 @@ float CameraMatrix::get_z_near() const { return new_plane.d; } -void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const { +void CameraMatrix::get_viewport_size(real_t& r_width, real_t& r_height) const { - const float * matrix = (const float*)this->matrix; + const real_t * matrix = (const real_t*)this->matrix; ///////--- Near Plane ---/////// Plane near_plane=Plane(matrix[ 3] + matrix[ 2], matrix[ 7] + matrix[ 6], matrix[11] + matrix[10], - -matrix[15] - matrix[14]).normalized(); + -matrix[15] - matrix[14]); + near_plane.normalize(); ///////--- Right Plane ---/////// Plane right_plane=Plane(matrix[ 3] - matrix[ 0], matrix[ 7] - matrix[ 4], matrix[11] - matrix[ 8], - - matrix[15] + matrix[12]).normalized(); + - matrix[15] + matrix[12]); + right_plane.normalize(); Plane top_plane=Plane(matrix[ 3] - matrix[ 1], matrix[ 7] - matrix[ 5], matrix[11] - matrix[ 9], - -matrix[15] + matrix[13]).normalized(); + -matrix[15] + matrix[13]); + top_plane.normalize(); Vector3 res; near_plane.intersect_3(right_plane,top_plane,&res); @@ -208,32 +223,35 @@ void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const { bool CameraMatrix::get_endpoints(const Transform& p_transform, Vector3 *p_8points) const { - const float * matrix = (const float*)this->matrix; + const real_t * matrix = (const real_t*)this->matrix; ///////--- Near Plane ---/////// Plane near_plane=Plane(matrix[ 3] + matrix[ 2], matrix[ 7] + matrix[ 6], matrix[11] + matrix[10], - -matrix[15] - matrix[14]).normalized(); + -matrix[15] - matrix[14]); + near_plane.normalize(); ///////--- Far Plane ---/////// Plane far_plane=Plane(matrix[ 2] - matrix[ 3], matrix[ 6] - matrix[ 7], matrix[10] - matrix[11], - matrix[15] - matrix[14]).normalized(); - + matrix[15] - matrix[14]); + far_plane.normalize(); ///////--- Right Plane ---/////// Plane right_plane=Plane(matrix[ 0] - matrix[ 3], matrix[ 4] - matrix[ 7], matrix[8] - matrix[ 11], - - matrix[15] + matrix[12]).normalized(); + - matrix[15] + matrix[12]); + right_plane.normalize(); ///////--- Top Plane ---/////// Plane top_plane=Plane(matrix[ 1] - matrix[ 3], matrix[ 5] - matrix[ 7], matrix[9] - matrix[ 11], - -matrix[15] + matrix[13]).normalized(); + -matrix[15] + matrix[13]); + top_plane.normalize(); Vector3 near_endpoint; Vector3 far_endpoint; @@ -266,7 +284,7 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform) Vector<Plane> planes; - const float * matrix = (const float*)this->matrix; + const real_t * matrix = (const real_t*)this->matrix; Plane new_plane; @@ -359,9 +377,9 @@ void CameraMatrix::invert() { int i,j,k; int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */ - float pvt_val; /* Value of current pivot element */ - float hold; /* Temporary storage */ - float determinat; /* Determinant */ + real_t pvt_val; /* Value of current pivot element */ + real_t hold; /* Temporary storage */ + real_t determinat; /* Determinant */ determinat = 1.0; for (k=0; k<4; k++) { @@ -474,7 +492,7 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix& p_matrix) const { void CameraMatrix::set_light_bias() { - float *m=&matrix[0][0]; + real_t *m=&matrix[0][0]; m[0]=0.5, m[1]=0.0, @@ -497,7 +515,7 @@ void CameraMatrix::set_light_bias() { void CameraMatrix::set_light_atlas_rect(const Rect2& p_rect) { - float *m=&matrix[0][0]; + real_t *m=&matrix[0][0]; m[0]=p_rect.size.width, m[1]=0.0, @@ -527,9 +545,9 @@ CameraMatrix::operator String() const { return str; } -float CameraMatrix::get_aspect() const { +real_t CameraMatrix::get_aspect() const { - float w,h; + real_t w,h; get_viewport_size(w,h); return w/h; } @@ -543,13 +561,14 @@ int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const { } -float CameraMatrix::get_fov() const { - const float * matrix = (const float*)this->matrix; +real_t CameraMatrix::get_fov() const { + const real_t * matrix = (const real_t*)this->matrix; Plane right_plane=Plane(matrix[ 3] - matrix[ 0], matrix[ 7] - matrix[ 4], matrix[11] - matrix[ 8], - - matrix[15] + matrix[12]).normalized(); + - matrix[15] + matrix[12]); + right_plane.normalize(); return Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x)))*2.0; } @@ -594,7 +613,7 @@ void CameraMatrix::scale_translate_to_fit(const Rect3& p_aabb) { CameraMatrix::operator Transform() const { Transform tr; - const float *m=&matrix[0][0]; + const real_t *m=&matrix[0][0]; tr.basis.elements[0][0]=m[0]; tr.basis.elements[1][0]=m[1]; @@ -618,7 +637,7 @@ CameraMatrix::operator Transform() const { CameraMatrix::CameraMatrix(const Transform& p_transform) { const Transform &tr = p_transform; - float *m=&matrix[0][0]; + real_t *m=&matrix[0][0]; m[0]=tr.basis.elements[0][0]; m[1]=tr.basis.elements[1][0]; diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h index 952f1e8fb2..c96f8259b5 100644 --- a/core/math/camera_matrix.h +++ b/core/math/camera_matrix.h @@ -48,32 +48,32 @@ struct CameraMatrix { PLANE_BOTTOM }; - float matrix[4][4]; + real_t matrix[4][4]; void set_identity(); void set_zero(); void set_light_bias(); void set_light_atlas_rect(const Rect2& p_rect); - void set_perspective(float p_fovy_degrees, float p_aspect, float p_z_near, float p_z_far,bool p_flip_fov=false); - void set_orthogonal(float p_left, float p_right, float p_bottom, float p_top, float p_znear, float p_zfar); - void set_orthogonal(float p_size, float p_aspect, float p_znear, float p_zfar,bool p_flip_fov=false); - void set_frustum(float p_left, float p_right, float p_bottom, float p_top, float p_near, float p_far); + void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far,bool p_flip_fov=false); + void set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar); + void set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar,bool p_flip_fov=false); + void set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far); - static float get_fovy(float p_fovx,float p_aspect) { + static real_t get_fovy(real_t p_fovx,real_t p_aspect) { return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5))*2.0); } - float get_z_far() const; - float get_z_near() const; - float get_aspect() const; - float get_fov() const; + real_t get_z_far() const; + real_t get_z_near() const; + real_t get_aspect() const; + real_t get_fov() const; Vector<Plane> get_projection_planes(const Transform& p_transform) const; bool get_endpoints(const Transform& p_transform,Vector3 *p_8points) const; - void get_viewport_size(float& r_width, float& r_height) const; + void get_viewport_size(real_t& r_width, real_t& r_height) const; void invert(); CameraMatrix inverse() const; @@ -102,7 +102,7 @@ Vector3 CameraMatrix::xform(const Vector3& p_vec3) const { ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0]; ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1]; ret.z = matrix[0][2] * p_vec3.x + matrix[1][2] * p_vec3.y + matrix[2][2] * p_vec3.z + matrix[3][2]; - float w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3]; + real_t w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3]; return ret/w; } diff --git a/core/math/face3.cpp b/core/math/face3.cpp index faf124593e..60fab6748a 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -168,8 +168,8 @@ Face3::Side Face3::get_side_of(const Face3& p_face,ClockDirection p_clock_dir) c Vector3 Face3::get_random_point_inside() const { - float a=Math::random(0,1); - float b=Math::random(0,1); + real_t a=Math::random(0,1); + real_t b=Math::random(0,1); if (a>b) { SWAP(a,b); } @@ -215,9 +215,9 @@ bool Face3::intersects_aabb(const Rect3& p_aabb) const { #define TEST_AXIS(m_ax)\ {\ - float aabb_min=p_aabb.pos.m_ax;\ - float aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\ - float tri_min,tri_max;\ + real_t aabb_min=p_aabb.pos.m_ax;\ + real_t aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\ + real_t tri_min,tri_max;\ for (int i=0;i<3;i++) {\ if (i==0 || vertex[i].m_ax > tri_max)\ tri_max=vertex[i].m_ax;\ @@ -255,7 +255,7 @@ bool Face3::intersects_aabb(const Rect3& p_aabb) const { continue; // coplanar axis.normalize(); - float minA,maxA,minB,maxB; + real_t minA,maxA,minB,maxB; p_aabb.project_range_in_plane(Plane(axis,0),minA,maxA); project_range(axis,Transform(),minB,maxB); @@ -272,12 +272,12 @@ Face3::operator String() const { return String()+vertex[0]+", "+vertex[1]+", "+vertex[2]; } -void Face3::project_range(const Vector3& p_normal,const Transform& p_transform,float& r_min, float& r_max) const { +void Face3::project_range(const Vector3& p_normal,const Transform& p_transform,real_t& r_min, real_t& r_max) const { for (int i=0;i<3;i++) { Vector3 v=p_transform.xform(vertex[i]); - float d=p_normal.dot(v); + real_t d=p_normal.dot(v); if (i==0 || d > r_max) r_max=d; @@ -316,11 +316,11 @@ void Face3::get_support(const Vector3& p_normal,const Transform& p_transform,Vec /** FIND SUPPORT VERTEX **/ int vert_support_idx=-1; - float support_max; + real_t support_max; for (int i=0;i<3;i++) { - float d=n.dot(vertex[i]); + real_t d=n.dot(vertex[i]); if (i==0 || d > support_max) { support_max=d; @@ -336,7 +336,7 @@ void Face3::get_support(const Vector3& p_normal,const Transform& p_transform,Vec continue; // check if edge is valid as a support - float dot=(vertex[i]-vertex[(i+1)%3]).normalized().dot(n); + real_t dot=(vertex[i]-vertex[(i+1)%3]).normalized().dot(n); dot=ABS(dot); if (dot < _EDGE_IS_VALID_SUPPORT_TRESHOLD) { @@ -362,15 +362,15 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const { Vector3 edge1 = vertex[2] - vertex[0]; Vector3 v0 = vertex[0] - p_point; - float a = edge0.dot( edge0 ); - float b = edge0.dot( edge1 ); - float c = edge1.dot( edge1 ); - float d = edge0.dot( v0 ); - float e = edge1.dot( v0 ); + real_t a = edge0.dot( edge0 ); + real_t b = edge0.dot( edge1 ); + real_t c = edge1.dot( edge1 ); + real_t d = edge0.dot( v0 ); + real_t e = edge1.dot( v0 ); - float det = a*c - b*b; - float s = b*e - c*d; - float t = b*d - a*e; + real_t det = a*c - b*b; + real_t s = b*e - c*d; + real_t t = b*d - a*e; if ( s + t < det ) { @@ -402,7 +402,7 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const { } else { - float invDet = 1.f / det; + real_t invDet = 1.f / det; s *= invDet; t *= invDet; } @@ -411,12 +411,12 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const { { if ( s < 0.f ) { - float tmp0 = b+d; - float tmp1 = c+e; + real_t tmp0 = b+d; + real_t tmp1 = c+e; if ( tmp1 > tmp0 ) { - float numer = tmp1 - tmp0; - float denom = a-2*b+c; + real_t numer = tmp1 - tmp0; + real_t denom = a-2*b+c; s = CLAMP( numer/denom, 0.f, 1.f ); t = 1-s; } @@ -430,8 +430,8 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const { { if ( a+d > b+e ) { - float numer = c+e-b-d; - float denom = a-2*b+c; + real_t numer = c+e-b-d; + real_t denom = a-2*b+c; s = CLAMP( numer/denom, 0.f, 1.f ); t = 1-s; } @@ -443,8 +443,8 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const { } else { - float numer = c+e-b-d; - float denom = a-2*b+c; + real_t numer = c+e-b-d; + real_t denom = a-2*b+c; s = CLAMP( numer/denom, 0.f, 1.f ); t = 1.f - s; } diff --git a/core/math/face3.h b/core/math/face3.h index f08eb227b1..a0da588ea5 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -31,7 +31,7 @@ #include "vector3.h" #include "plane.h" -#include "aabb.h" +#include "rect3.h" #include "transform.h" class Face3 { @@ -76,7 +76,7 @@ public: ClockDirection get_clock_dir() const; ///< todo, test if this is returning the proper clockwisity void get_support(const Vector3& p_normal,const Transform& p_transform,Vector3 *p_vertices,int* p_count,int p_max) const; - void project_range(const Vector3& p_normal,const Transform& p_transform,float& r_min, float& r_max) const; + void project_range(const Vector3& p_normal,const Transform& p_transform,real_t& r_min, real_t& r_max) const; Rect3 get_aabb() const { @@ -109,9 +109,9 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const { (perp.z>0) ? -half_extents.z : half_extents.z ); - float d = perp.dot(vertex[0]); - float dist_a = perp.dot(ofs+sup)-d; - float dist_b = perp.dot(ofs-sup)-d; + real_t d = perp.dot(vertex[0]); + real_t dist_a = perp.dot(ofs+sup)-d; + real_t dist_b = perp.dot(ofs-sup)-d; if (dist_a*dist_b > 0) return false; //does not intersect the plane @@ -119,9 +119,9 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const { #define TEST_AXIS(m_ax)\ {\ - float aabb_min=p_aabb.pos.m_ax;\ - float aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\ - float tri_min,tri_max;\ + real_t aabb_min=p_aabb.pos.m_ax;\ + real_t aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\ + real_t tri_min,tri_max;\ for (int i=0;i<3;i++) {\ if (i==0 || vertex[i].m_ax > tri_max)\ tri_max=vertex[i].m_ax;\ @@ -236,16 +236,16 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const { (axis.z>0) ? -half_extents.z : half_extents.z ); - float maxB = axis.dot(ofs+sup2); - float minB = axis.dot(ofs-sup2); + real_t maxB = axis.dot(ofs+sup2); + real_t minB = axis.dot(ofs-sup2); if (minB>maxB) { SWAP(maxB,minB); } - float minT=1e20,maxT=-1e20; + real_t minT=1e20,maxT=-1e20; for (int k=0;k<3;k++) { - float d=axis.dot(vertex[k]); + real_t d=axis.dot(vertex[k]); if (d > maxT) maxT=d; diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index bf3364a052..6570dfe672 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -580,7 +580,7 @@ static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int l } -PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,float *p_error ) { +PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,real_t *p_error ) { #define _MIN_SIZE 1.0 #define _MAX_LENGTH 20 @@ -755,7 +755,7 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector<Plane> &p_planes #define SUBPLANE_SIZE 1024.0 - float subplane_size = 1024.0; // should compute this from the actual plane + real_t subplane_size = 1024.0; // should compute this from the actual plane for (int i=0;i<p_planes.size();i++) { Plane p =p_planes[i]; @@ -910,7 +910,7 @@ PoolVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) { return planes; } -PoolVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) { +PoolVector<Plane> Geometry::build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis) { PoolVector<Plane> planes; @@ -933,7 +933,7 @@ PoolVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height } -PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) { +PoolVector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) { PoolVector<Plane> planes; @@ -957,7 +957,7 @@ PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p for (int j=1;j<=p_lats;j++) { //todo this is stupid, fix - Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized(); + Vector3 angle = normal.linear_interpolate(axis,j/(real_t)p_lats).normalized(); Vector3 pos = angle*p_radius; planes.push_back( Plane( pos, angle ) ); planes.push_back( Plane( pos * axis_neg, angle * axis_neg) ); @@ -969,7 +969,7 @@ PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p } -PoolVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) { +PoolVector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis) { PoolVector<Plane> planes; @@ -991,7 +991,7 @@ PoolVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height, for (int j=1;j<=p_lats;j++) { - Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized(); + Vector3 angle = normal.linear_interpolate(axis,j/(real_t)p_lats).normalized(); Vector3 pos = axis*p_height*0.5 + angle*p_radius; planes.push_back( Plane( pos, angle ) ); planes.push_back( Plane( pos * axis_neg, angle * axis_neg) ); @@ -1108,13 +1108,13 @@ void Geometry::make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_resul //find the result with the best aspect ratio int best=-1; - float best_aspect=1e20; + real_t best_aspect=1e20; for(int i=0;i<results.size();i++) { - float h = nearest_power_of_2(results[i].max_h); - float w = nearest_power_of_2(results[i].max_w); - float aspect = h>w ? h/w : w/h; + real_t h = nearest_power_of_2(results[i].max_h); + real_t w = nearest_power_of_2(results[i].max_w); + real_t aspect = h>w ? h/w : w/h; if (aspect < best_aspect) { best=i; best_aspect=aspect; diff --git a/core/math/geometry.h b/core/math/geometry.h index d5b3a3068c..13cbbdce6f 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -48,15 +48,15 @@ public: - static float get_closest_points_between_segments( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2, Vector2& c1, Vector2& c2) { + static real_t get_closest_points_between_segments( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2, Vector2& c1, Vector2& c2) { Vector2 d1 = q1 - p1; // Direction vector of segment S1 Vector2 d2 = q2 - p2; // Direction vector of segment S2 Vector2 r = p1 - p2; - float a = d1.dot(d1); // Squared length of segment S1, always nonnegative - float e = d2.dot(d2); // Squared length of segment S2, always nonnegative - float f = d2.dot(r); - float s,t; + real_t a = d1.dot(d1); // Squared length of segment S1, always nonnegative + real_t e = d2.dot(d2); // Squared length of segment S2, always nonnegative + real_t f = d2.dot(r); + real_t s,t; // Check if either or both segments degenerate into points if (a <= CMP_EPSILON && e <= CMP_EPSILON) { // Both segments degenerate into points @@ -66,25 +66,25 @@ public: } if (a <= CMP_EPSILON) { // First segment degenerates into a point - s = 0.0f; + s = 0.0; t = f / e; // s = 0 => t = (b*s + f) / e = f / e - t = CLAMP(t, 0.0f, 1.0f); + t = CLAMP(t, 0.0, 1.0); } else { - float c = d1.dot(r); + real_t c = d1.dot(r); if (e <= CMP_EPSILON) { // Second segment degenerates into a point - t = 0.0f; - s = CLAMP(-c / a, 0.0f, 1.0f); // t = 0 => s = (b*t - c) / a = -c / a + t = 0.0; + s = CLAMP(-c / a, 0.0, 1.0); // t = 0 => s = (b*t - c) / a = -c / a } else { // The general nondegenerate case starts here - float b = d1.dot(d2); - float denom = a*e-b*b; // Always nonnegative + real_t b = d1.dot(d2); + real_t denom = a*e-b*b; // Always nonnegative // If segments not parallel, compute closest point on L1 to L2 and // clamp to segment S1. Else pick arbitrary s (here 0) - if (denom != 0.0f) { - s = CLAMP((b*f - c*e) / denom, 0.0f, 1.0f); + if (denom != 0.0) { + s = CLAMP((b*f - c*e) / denom, 0.0, 1.0); } else - s = 0.0f; + s = 0.0; // Compute point on L2 closest to S1(s) using // t = Dot((P1 + D1*s) - P2,D2) / Dot(D2,D2) = (b*s + f) / e t = (b*s + f) / e; @@ -92,12 +92,12 @@ public: //If t in [0,1] done. Else clamp t, recompute s for the new value // of t using s = Dot((P2 + D2*t) - P1,D1) / Dot(D1,D1)= (t*b - c) / a // and clamp s to [0, 1] - if (t < 0.0f) { - t = 0.0f; - s = CLAMP(-c / a, 0.0f, 1.0f); - } else if (t > 1.0f) { - t = 1.0f; - s = CLAMP((b - c) / a, 0.0f, 1.0f); + if (t < 0.0) { + t = 0.0; + s = CLAMP(-c / a, 0.0, 1.0); + } else if (t > 1.0) { + t = 1.0; + s = CLAMP((b - c) / a, 0.0, 1.0); } } } @@ -113,8 +113,8 @@ public: #define d_of(m,n,o,p) ( (m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z) ) //caluclate the parpametric position on the 2 curves, mua and mub - float mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) ); - float mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1); + real_t mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) ); + real_t mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1); //clip the value between [0..1] constraining the solution to lie on the original curves if (mua < 0) mua = 0; @@ -125,7 +125,7 @@ public: c2 = q1.linear_interpolate(q2,mub); } - static float get_closest_distance_between_segments( const Vector3& p_from_a,const Vector3& p_to_a, const Vector3& p_from_b,const Vector3& p_to_b) { + static real_t get_closest_distance_between_segments( const Vector3& p_from_a,const Vector3& p_to_a, const Vector3& p_from_b,const Vector3& p_to_b) { Vector3 u = p_to_a - p_from_a; Vector3 v = p_to_b - p_from_b; Vector3 w = p_from_a - p_to_a; @@ -273,22 +273,22 @@ public: Vector3 sphere_pos=p_sphere_pos-p_from; Vector3 rel=(p_to-p_from); - float rel_l=rel.length(); + real_t rel_l=rel.length(); if (rel_l<CMP_EPSILON) return false; // both points are the same Vector3 normal=rel/rel_l; - float sphere_d=normal.dot(sphere_pos); + real_t sphere_d=normal.dot(sphere_pos); //Vector3 ray_closest=normal*sphere_d; - float ray_distance=sphere_pos.distance_to(normal*sphere_d); + real_t ray_distance=sphere_pos.distance_to(normal*sphere_d); if (ray_distance>=p_sphere_radius) return false; - float inters_d2=p_sphere_radius*p_sphere_radius - ray_distance*ray_distance; - float inters_d=sphere_d; + real_t inters_d2=p_sphere_radius*p_sphere_radius - ray_distance*ray_distance; + real_t inters_d=sphere_d; if (inters_d2>=CMP_EPSILON) inters_d-=Math::sqrt(inters_d2); @@ -297,7 +297,7 @@ public: if (inters_d<0 || inters_d>rel_l) return false; - Vector3 result=p_from+normal*inters_d;; + Vector3 result=p_from+normal*inters_d; if (r_res) *r_res=result; @@ -307,17 +307,17 @@ public: return true; } - static inline bool segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius,Vector3* r_res=0,Vector3 *r_norm=0) { + static inline bool segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, real_t p_height,real_t p_radius,Vector3* r_res=0,Vector3 *r_norm=0) { Vector3 rel=(p_to-p_from); - float rel_l=rel.length(); + real_t rel_l=rel.length(); if (rel_l<CMP_EPSILON) return false; // both points are the same // first check if they are parallel Vector3 normal=(rel/rel_l); Vector3 crs = normal.cross(Vector3(0,0,1)); - float crs_l=crs.length(); + real_t crs_l=crs.length(); Vector3 z_dir; @@ -328,13 +328,13 @@ public: z_dir=crs/crs_l; } - float dist=z_dir.dot(p_from); + real_t dist=z_dir.dot(p_from); if (dist>=p_radius) return false; // too far away // convert to 2D - float w2=p_radius*p_radius-dist*dist; + real_t w2=p_radius*p_radius-dist*dist; if (w2<CMP_EPSILON) return false; //avoid numerical error Size2 size(Math::sqrt(w2),p_height*0.5); @@ -344,7 +344,7 @@ public: Vector2 from2D(x_dir.dot(p_from),p_from.z); Vector2 to2D(x_dir.dot(p_to),p_to.z); - float min=0,max=1; + real_t min=0,max=1; int axis=-1; @@ -464,12 +464,12 @@ public: Vector3 p=p_point-p_segment[0]; Vector3 n=p_segment[1]-p_segment[0]; - float l =n.length(); + real_t l =n.length(); if (l<1e-10) return p_segment[0]; // both points are the same, just give any n/=l; - float d=n.dot(p); + real_t d=n.dot(p); if (d<=0.0) return p_segment[0]; // before first point @@ -483,12 +483,12 @@ public: Vector3 p=p_point-p_segment[0]; Vector3 n=p_segment[1]-p_segment[0]; - float l =n.length(); + real_t l =n.length(); if (l<1e-10) return p_segment[0]; // both points are the same, just give any n/=l; - float d=n.dot(p); + real_t d=n.dot(p); return p_segment[0]+n*d; // inside } @@ -497,12 +497,12 @@ public: Vector2 p=p_point-p_segment[0]; Vector2 n=p_segment[1]-p_segment[0]; - float l =n.length(); + real_t l =n.length(); if (l<1e-10) return p_segment[0]; // both points are the same, just give any n/=l; - float d=n.dot(p); + real_t d=n.dot(p); if (d<=0.0) return p_segment[0]; // before first point @@ -529,12 +529,12 @@ public: Vector2 p=p_point-p_segment[0]; Vector2 n=p_segment[1]-p_segment[0]; - float l =n.length(); + real_t l =n.length(); if (l<1e-10) return p_segment[0]; // both points are the same, just give any n/=l; - float d=n.dot(p); + real_t d=n.dot(p); return p_segment[0]+n*d; // inside } @@ -555,7 +555,7 @@ public: if ((C.y<0 && D.y<0) || (C.y>=0 && D.y>=0)) return false; - float ABpos=D.x+(C.x-D.x)*D.y/(D.y-C.y); + real_t ABpos=D.x+(C.x-D.x)*D.y/(D.y-C.y); // Fail if segment C-D crosses line A-B outside of segment A-B. if (ABpos<0 || ABpos>1.0) @@ -595,7 +595,7 @@ public: static inline bool triangle_sphere_intersection_test(const Vector3 *p_triangle,const Vector3& p_normal,const Vector3& p_sphere_pos, real_t p_sphere_radius,Vector3& r_triangle_contact,Vector3& r_sphere_contact) { - float d=p_normal.dot(p_sphere_pos)-p_normal.dot(p_triangle[0]); + real_t d=p_normal.dot(p_sphere_pos)-p_normal.dot(p_triangle[0]); if (d > p_sphere_radius || d < -p_sphere_radius) // not touching the plane of the face, return return false; @@ -629,7 +629,7 @@ public: Vector3 axis =n1.cross(n2).cross(n1); axis.normalize(); // ugh - float ad=axis.dot(n2); + real_t ad=axis.dot(n2); if (ABS(ad)>p_sphere_radius) { // no chance with this edge, too far away @@ -639,7 +639,7 @@ public: // check point within edge capsule cylinder /** 4th TEST INSIDE EDGE POINTS **/ - float sphere_at = n1.dot(n2); + real_t sphere_at = n1.dot(n2); if (sphere_at>=0 && sphere_at<n1.dot(n1)) { @@ -650,7 +650,7 @@ public: return true; } - float r2=p_sphere_radius*p_sphere_radius; + real_t r2=p_sphere_radius*p_sphere_radius; if (n2.length_squared()<r2) { @@ -726,8 +726,8 @@ public: int outside_count = 0; for (int a = 0; a < polygon.size(); a++) { - //float p_plane.d = (*this) * polygon[a]; - float dist = p_plane.distance_to(polygon[a]); + //real_t p_plane.d = (*this) * polygon[a]; + real_t dist = p_plane.distance_to(polygon[a]); if (dist <-CMP_POINT_IN_PLANE_EPSILON) { location_cache[a] = LOC_INSIDE; inside_count++; @@ -761,8 +761,8 @@ public: const Vector3& v2 = polygon[index]; Vector3 segment= v1 - v2; - double den=p_plane.normal.dot( segment ); - double dist=p_plane.distance_to( v1 ) / den; + real_t den=p_plane.normal.dot( segment ); + real_t dist=p_plane.distance_to( v1 ) / den; dist=-dist; clipped.push_back( v1 + segment * dist ); } @@ -771,8 +771,8 @@ public: if ((loc == LOC_INSIDE) && (location_cache[previous] == LOC_OUTSIDE)) { const Vector3& v2 = polygon[previous]; Vector3 segment= v1 - v2; - double den=p_plane.normal.dot( segment ); - double dist=p_plane.distance_to( v1 ) / den; + real_t den=p_plane.normal.dot( segment ); + real_t dist=p_plane.distance_to( v1 ) / den; dist=-dist; clipped.push_back( v1 + segment * dist ); } @@ -808,7 +808,7 @@ public: static PoolVector< PoolVector< Face3 > > separate_objects( PoolVector< Face3 > p_array ); - static PoolVector< Face3 > wrap_geometry( PoolVector< Face3 > p_array, float *p_error=NULL ); ///< create a "wrap" that encloses the given geometry + static PoolVector< Face3 > wrap_geometry( PoolVector< Face3 > p_array, real_t *p_error=NULL ); ///< create a "wrap" that encloses the given geometry struct MeshData { @@ -884,9 +884,9 @@ public: } - static double vec2_cross(const Point2 &O, const Point2 &A, const Point2 &B) + static real_t vec2_cross(const Point2 &O, const Point2 &A, const Point2 &B) { - return (double)(A.x - O.x) * (B.y - O.y) - (double)(A.y - O.y) * (B.x - O.x); + return (real_t)(A.x - O.x) * (B.y - O.y) - (real_t)(A.y - O.y) * (B.x - O.x); } // Returns a list of points on the convex hull in counter-clockwise order. @@ -918,10 +918,10 @@ public: } static MeshData build_convex_mesh(const PoolVector<Plane> &p_planes); - static PoolVector<Plane> build_sphere_planes(float p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z); + static PoolVector<Plane> build_sphere_planes(real_t p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z); static PoolVector<Plane> build_box_planes(const Vector3& p_extents); - static PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z); - static PoolVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z); + static PoolVector<Plane> build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z); + static PoolVector<Plane> build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z); static void make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_result, Size2i& r_size); diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index c6860ba2e8..76eeece688 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -239,10 +239,10 @@ Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, co real_t t3 = t2 * t; Vector2 out; - out = 0.5f * ( ( p1 * 2.0f) + + out = 0.5 * ( ( p1 * 2.0) + ( -p0 + p2 ) * t + - ( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 + - ( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 ); + ( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 + + ( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 ); return out; /* diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 8353aa0ebe..c730b4fa30 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -27,12 +27,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "math_funcs.h" - #include "core/os/os.h" -#include "float.h" -uint32_t Math::default_seed=1; - +pcg32_random_t Math::default_pcg = {1, PCG_DEFAULT_INC_64}; #define PHI 0x9e3779b9 @@ -40,59 +37,30 @@ uint32_t Math::default_seed=1; static uint32_t Q[4096]; #endif -uint32_t Math::rand_from_seed(uint32_t *seed) { - // Xorshift31 PRNG - if ( *seed == 0 ) *seed = Math::RANDOM_MAX; - (*seed) ^= (*seed) << 13; - (*seed) ^= (*seed) >> 17; - (*seed) ^= (*seed) << 5; - return (*seed) & Math::RANDOM_MAX; +// TODO: we should eventually expose pcg.inc too +uint32_t Math::rand_from_seed(uint64_t *seed) { + pcg32_random_t pcg = {*seed, PCG_DEFAULT_INC_64}; + uint32_t r = pcg32_random_r(&pcg); + *seed = pcg.state; + return r; } -void Math::seed(uint32_t x) { - default_seed=x; +void Math::seed(uint64_t x) { + default_pcg.state=x; } void Math::randomize() { OS::Time time = OS::get_singleton()->get_time(); - seed(OS::get_singleton()->get_ticks_usec()*(time.hour+1)*(time.min+1)*(time.sec+1)*rand()); /* *OS::get_singleton()->get_time().sec); // windows doesn't have get_time(), returns always 0 */ + seed(OS::get_singleton()->get_ticks_usec()*(time.hour+1)*(time.min+1)*(time.sec+1)*rand()); // TODO: can be simplified. } uint32_t Math::rand() { - - return rand_from_seed(&default_seed); -} - -double Math::randf() { - - return (double)rand() / (double)Math::RANDOM_MAX; -} - - -double Math::round(double p_val) { - - if (p_val>=0) { - return ::floor(p_val+0.5); - } else { - p_val=-p_val; - return -::floor(p_val+0.5); - } -} - -double Math::dectime(double p_value,double p_amount, double p_step) { - - float sgn = p_value < 0 ? -1.0 : 1.0; - float val = absf(p_value); - val-=p_amount*p_step; - if (val<0.0) - val=0.0; - return val*sgn; + return pcg32_random_r(&default_pcg); } int Math::step_decimals(double p_step) { - static const int maxn=9; static const double sd[maxn]={ 0.9999, // somehow compensate for floating point error @@ -106,7 +74,7 @@ int Math::step_decimals(double p_step) { 0.000000009999 }; - double as=absf(p_step); + double as=Math::abs(p_step); for(int i=0;i<maxn;i++) { if (as>=sd[i]) { return i; @@ -116,8 +84,16 @@ int Math::step_decimals(double p_step) { return maxn; } -double Math::ease(double p_x, double p_c) { +double Math::dectime(double p_value,double p_amount, double p_step) { + double sgn = p_value < 0 ? -1.0 : 1.0; + double val = Math::abs(p_value); + val-=p_amount*p_step; + if (val<0.0) + val=0.0; + return val*sgn; +} +double Math::ease(double p_x, double p_c) { if (p_x<0) p_x=0; else if (p_x>1.0) @@ -138,20 +114,16 @@ double Math::ease(double p_x, double p_c) { } } else return 0; // no ease (raw) - } double Math::stepify(double p_value,double p_step) { - if (p_step!=0) { - - p_value=floor( p_value / p_step + 0.5 ) * p_step; + p_value=Math::floor( p_value / p_step + 0.5 ) * p_step; } return p_value; } - uint32_t Math::larger_prime(uint32_t p_val) { static const uint32_t primes[] = { @@ -200,22 +172,15 @@ uint32_t Math::larger_prime(uint32_t p_val) { } double Math::random(double from, double to) { - unsigned int r = Math::rand(); double ret = (double)r/(double)RANDOM_MAX; return (ret)*(to-from) + from; } -double Math::pow(double x, double y) { - - return ::pow(x,y); +float Math::random(float from, float to) { + unsigned int r = Math::rand(); + float ret = (float)r/(float)RANDOM_MAX; + return (ret)*(to-from) + from; } -double Math::log(double x) { - - return ::log(x); -} -double Math::exp(double x) { - return ::exp(x); -} diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 8ce59224ff..511af91835 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -31,18 +31,19 @@ #include "typedefs.h" #include "math_defs.h" +#include "pcg.h" -#ifndef NO_MATH_H #include <math.h> -#endif - +#include <float.h> + #define Math_PI 3.14159265358979323846 #define Math_SQRT12 0.7071067811865475244008443621048490 +#define Math_LN2 0.693147180559945309417 class Math { + static pcg32_random_t default_pcg; - static uint32_t default_seed; public: Math() {} // useless to instance @@ -51,149 +52,122 @@ public: }; - static _ALWAYS_INLINE_ double sin(double p_x) { - - return ::sin(p_x); - - } - - static _ALWAYS_INLINE_ double cos(double p_x) { - - return ::cos(p_x); - - } - - static _ALWAYS_INLINE_ double tan(double p_x) { - - return ::tan(p_x); - - } - static _ALWAYS_INLINE_ double sinh(double p_x) { - - return ::sinh(p_x); - } - - static _ALWAYS_INLINE_ double cosh(double p_x) { - - return ::cosh(p_x); - } - - static _ALWAYS_INLINE_ double tanh(double p_x) { - - return ::tanh(p_x); - } + static _ALWAYS_INLINE_ double sin(double p_x) { return ::sin(p_x); } + static _ALWAYS_INLINE_ float sin(float p_x) { return ::sinf(p_x); } + static _ALWAYS_INLINE_ double cos(double p_x) { return ::cos(p_x); } + static _ALWAYS_INLINE_ float cos(float p_x) { return ::cosf(p_x); } - static _ALWAYS_INLINE_ double asin(double p_x) { + static _ALWAYS_INLINE_ double tan(double p_x) { return ::tan(p_x); } + static _ALWAYS_INLINE_ float tan(float p_x) { return ::tanf(p_x); } - return ::asin(p_x); + static _ALWAYS_INLINE_ double sinh(double p_x) { return ::sinh(p_x); } + static _ALWAYS_INLINE_ float sinh(float p_x) { return ::sinhf(p_x); } - } + static _ALWAYS_INLINE_ double cosh(double p_x) { return ::cosh(p_x); } + static _ALWAYS_INLINE_ float cosh(float p_x) { return ::coshf(p_x); } - static _ALWAYS_INLINE_ double acos(double p_x) { + static _ALWAYS_INLINE_ double tanh(double p_x) { return ::tanh(p_x); } + static _ALWAYS_INLINE_ float tanh(float p_x) { return ::tanhf(p_x); } - return ::acos(p_x); - } + static _ALWAYS_INLINE_ double asin(double p_x) { return ::asin(p_x); } + static _ALWAYS_INLINE_ float asin(float p_x) { return ::asinf(p_x); } - static _ALWAYS_INLINE_ double atan(double p_x) { + static _ALWAYS_INLINE_ double acos(double p_x) { return ::acos(p_x); } + static _ALWAYS_INLINE_ float acos(float p_x) { return ::acosf(p_x); } - return ::atan(p_x); - } + static _ALWAYS_INLINE_ double atan(double p_x) { return ::atan(p_x); } + static _ALWAYS_INLINE_ float atan(float p_x) { return ::atanf(p_x); } - static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) { + static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) { return ::atan2(p_y,p_x); } + static _ALWAYS_INLINE_ float atan2(float p_y, float p_x) { return ::atan2f(p_y,p_x); } - return ::atan2(p_y,p_x); + static _ALWAYS_INLINE_ double sqrt(double p_x) { return ::sqrt(p_x); } + static _ALWAYS_INLINE_ float sqrt(float p_x) { return ::sqrtf(p_x); } - } + static _ALWAYS_INLINE_ double fmod(double p_x,double p_y) { return ::fmod(p_x,p_y); } + static _ALWAYS_INLINE_ float fmod(float p_x,float p_y) { return ::fmodf(p_x,p_y); } - static _ALWAYS_INLINE_ double deg2rad(double p_y) { + static _ALWAYS_INLINE_ double floor(double p_x) { return ::floor(p_x); } + static _ALWAYS_INLINE_ float floor(float p_x) { return ::floorf(p_x); } - return p_y*Math_PI/180.0; - } + static _ALWAYS_INLINE_ double ceil(double p_x) { return ::ceil(p_x); } + static _ALWAYS_INLINE_ float ceil(float p_x) { return ::ceilf(p_x); } - static _ALWAYS_INLINE_ double rad2deg(double p_y) { + static _ALWAYS_INLINE_ double pow(double p_x, double p_y) { return ::pow(p_x,p_y); } + static _ALWAYS_INLINE_ float pow(float p_x, float p_y) { return ::powf(p_x,p_y); } - return p_y*180.0/Math_PI; - } + static _ALWAYS_INLINE_ double log(double p_x) { return ::log(p_x); } + static _ALWAYS_INLINE_ float log(float p_x) { return ::logf(p_x); } + static _ALWAYS_INLINE_ double exp(double p_x) { return ::exp(p_x); } + static _ALWAYS_INLINE_ float exp(float p_x) { return ::expf(p_x); } - static _ALWAYS_INLINE_ double sqrt(double p_x) { + static _ALWAYS_INLINE_ bool is_nan(double p_val) { return (p_val!=p_val); } + static _ALWAYS_INLINE_ bool is_nan(float p_val) { return (p_val!=p_val); } - return ::sqrt(p_x); + static _ALWAYS_INLINE_ bool is_inf(double p_val) { + #ifdef _MSC_VER + return !_finite(p_val); + #else + return isinf(p_val); + #endif } - - static _ALWAYS_INLINE_ double fmod(double p_x,double p_y) { - - return ::fmod(p_x,p_y); + + static _ALWAYS_INLINE_ bool is_inf(float p_val) { + #ifdef _MSC_VER + return !_finite(p_val); + #else + return isinf(p_val); + #endif } + + static _ALWAYS_INLINE_ double abs(double g) { return absd(g); } + static _ALWAYS_INLINE_ float abs(float g) { return absf(g); } + static _ALWAYS_INLINE_ int abs(int g) { return g > 0 ? g : -g; } - static _ALWAYS_INLINE_ double fposmod(double p_x,double p_y) { - - if (p_x>=0) { - - return fmod(p_x,p_y); + static _ALWAYS_INLINE_ double fposmod(double p_x,double p_y) { return (p_x>=0) ? Math::fmod(p_x,p_y) : p_y-Math::fmod(-p_x,p_y); } + static _ALWAYS_INLINE_ float fposmod(float p_x,float p_y) { return (p_x>=0) ? Math::fmod(p_x,p_y) : p_y-Math::fmod(-p_x,p_y); } - } else { + static _ALWAYS_INLINE_ double deg2rad(double p_y) { return p_y*Math_PI/180.0; } + static _ALWAYS_INLINE_ float deg2rad(float p_y) { return p_y*Math_PI/180.0; } - return p_y-fmod(-p_x,p_y); - } - - } - static _ALWAYS_INLINE_ double floor(double p_x) { + static _ALWAYS_INLINE_ double rad2deg(double p_y) { return p_y*180.0/Math_PI; } + static _ALWAYS_INLINE_ float rad2deg(float p_y) { return p_y*180.0/Math_PI; } - return ::floor(p_x); - } - - static _ALWAYS_INLINE_ double ceil(double p_x) { + static _ALWAYS_INLINE_ double lerp(double a, double b, double c) { return a+(b-a)*c; } + static _ALWAYS_INLINE_ float lerp(float a, float b, float c) { return a+(b-a)*c; } - return ::ceil(p_x); - } + static _ALWAYS_INLINE_ double linear2db(double p_linear) { return Math::log( p_linear ) * 8.6858896380650365530225783783321; } + static _ALWAYS_INLINE_ float linear2db(float p_linear) { return Math::log( p_linear ) * 8.6858896380650365530225783783321; } + static _ALWAYS_INLINE_ double db2linear(double p_db) { return Math::exp( p_db * 0.11512925464970228420089957273422 ); } + static _ALWAYS_INLINE_ float db2linear(float p_db) { return Math::exp( p_db * 0.11512925464970228420089957273422 ); } - static uint32_t rand_from_seed(uint32_t *seed); + static _ALWAYS_INLINE_ double round(double p_val) { return (p_val>=0) ? Math::floor(p_val+0.5) : -Math::floor(-p_val+0.5); } + static _ALWAYS_INLINE_ float round(float p_val) { return (p_val>=0) ? Math::floor(p_val+0.5) : -Math::floor(-p_val+0.5); } + // double only, as these functions are mainly used by the editor and not performance-critical, static double ease(double p_x, double p_c); static int step_decimals(double p_step); static double stepify(double p_value,double p_step); - static void seed(uint32_t x=0); - static void randomize(); - static uint32_t larger_prime(uint32_t p_val); static double dectime(double p_value,double p_amount, double p_step); + static uint32_t larger_prime(uint32_t p_val); - static inline double linear2db(double p_linear) { - - return Math::log( p_linear ) * 8.6858896380650365530225783783321; - } - - static inline double db2linear(double p_db) { - - return Math::exp( p_db * 0.11512925464970228420089957273422 ); - } - - static _ALWAYS_INLINE_ bool is_nan(double p_val) { - - return (p_val!=p_val); - } - - static _ALWAYS_INLINE_ bool is_inf(double p_val) { - - #ifdef _MSC_VER - return !_finite(p_val); - #else - return isinf(p_val); - #endif - - } - + static void seed(uint64_t x=0); + static void randomize(); + static uint32_t rand_from_seed(uint64_t *seed); static uint32_t rand(); - static double randf(); - - static double round(double p_val); + static _ALWAYS_INLINE_ double randf() { return (double)rand() / (double)Math::RANDOM_MAX; } + static _ALWAYS_INLINE_ float randd() { return (float)rand() / (float)Math::RANDOM_MAX; } static double random(double from, double to); + static float random(float from, float to); + static real_t random(int from, int to) { return (real_t)random((real_t)from, (real_t)to); } - static _FORCE_INLINE_ bool isequal_approx(real_t a, real_t b) { + + static _ALWAYS_INLINE_ bool isequal_approx(real_t a, real_t b) { // TODO: Comparing floats for approximate-equality is non-trivial. // Using epsilon should cover the typical cases in Godot (where a == b is used to compare two reals), such as matrix and vector comparison operators. // A proper implementation in terms of ULPs should eventually replace the contents of this function. @@ -203,18 +177,7 @@ public: } - static _FORCE_INLINE_ real_t abs(real_t g) { - -#ifdef REAL_T_IS_DOUBLE - - return absd(g); -#else - - return absf(g); -#endif - } - - static _FORCE_INLINE_ float absf(float g) { + static _ALWAYS_INLINE_ float absf(float g) { union { float f; @@ -226,7 +189,7 @@ public: return u.f; } - static _FORCE_INLINE_ double absd(double g) { + static _ALWAYS_INLINE_ double absd(double g) { union { double d; @@ -238,12 +201,12 @@ public: } //this function should be as fast as possible and rounding mode should not matter - static _FORCE_INLINE_ int fast_ftoi(float a) { + static _ALWAYS_INLINE_ int fast_ftoi(float a) { static int b; #if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // windows 8 phone? - b = (int)((a>0.0f) ? (a + 0.5f):(a -0.5f)); + b = (int)((a>0.0) ? (a + 0.5):(a -0.5)); #elif defined(_MSC_VER) && _MSC_VER < 1800 __asm fld a @@ -266,23 +229,16 @@ public: #if defined(__GNUC__) - static _FORCE_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE + static _ALWAYS_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE + static _ALWAYS_INLINE_ int64_t dtoll(float p_float) { return (int64_t)p_float; } ///@TODO OPTIMIZE and rename #else - static _FORCE_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE + static _ALWAYS_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE + static _ALWAYS_INLINE_ int64_t dtoll(float p_float) { return (int64_t)p_float; } ///@TODO OPTIMIZE and rename #endif - static _FORCE_INLINE_ float lerp(float a, float b, float c) { - - return a+(b-a)*c; - } - - static double pow(double x, double y); - static double log(double x); - static double exp(double x); - - static _FORCE_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h) + static _ALWAYS_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h) { uint16_t h_exp, h_sig; uint32_t f_sgn, f_exp, f_sig; @@ -314,7 +270,7 @@ public: } } - static _FORCE_INLINE_ float halfptr_to_float(const uint16_t *h) { + static _ALWAYS_INLINE_ float halfptr_to_float(const uint16_t *h) { union { uint32_t u32; @@ -325,7 +281,7 @@ public: return u.f32; } - static _FORCE_INLINE_ uint16_t make_half_float(float f) { + static _ALWAYS_INLINE_ uint16_t make_half_float(float f) { union { float fv; diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp index e9c3442582..1fabfbbd4c 100644 --- a/core/math/matrix3.cpp +++ b/core/math/matrix3.cpp @@ -504,9 +504,9 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const { ERR_FAIL_COND(is_rotation() == false); - double angle,x,y,z; // variables for result - double epsilon = 0.01; // margin to allow for rounding errors - double epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees + real_t angle,x,y,z; // variables for result + real_t epsilon = 0.01; // margin to allow for rounding errors + real_t epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees if ( (Math::abs(elements[1][0]-elements[0][1])< epsilon) && (Math::abs(elements[2][0]-elements[0][2])< epsilon) @@ -525,12 +525,12 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const { } // otherwise this singularity is angle = 180 angle = Math_PI; - double xx = (elements[0][0]+1)/2; - double yy = (elements[1][1]+1)/2; - double zz = (elements[2][2]+1)/2; - double xy = (elements[1][0]+elements[0][1])/4; - double xz = (elements[2][0]+elements[0][2])/4; - double yz = (elements[2][1]+elements[1][2])/4; + real_t xx = (elements[0][0]+1)/2; + real_t yy = (elements[1][1]+1)/2; + real_t zz = (elements[2][2]+1)/2; + real_t xy = (elements[1][0]+elements[0][1])/4; + real_t xz = (elements[2][0]+elements[0][2])/4; + real_t yz = (elements[2][1]+elements[1][2])/4; if ((xx > yy) && (xx > zz)) { // elements[0][0] is the largest diagonal term if (xx< epsilon) { x = 0; @@ -567,7 +567,7 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const { return; } // as we have reached here there are no singularities so we can handle normally - double s = Math::sqrt((elements[1][2] - elements[2][1])*(elements[1][2] - elements[2][1]) + real_t s = Math::sqrt((elements[1][2] - elements[2][1])*(elements[1][2] - elements[2][1]) +(elements[2][0] - elements[0][2])*(elements[2][0] - elements[0][2]) +(elements[0][1] - elements[1][0])*(elements[0][1] - elements[1][0])); // s=|axis||sin(angle)|, used to normalise diff --git a/core/math/octree.h b/core/math/octree.h index 483ba1d510..e566df6a4f 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -30,7 +30,7 @@ #define OCTREE_H #include "vector3.h" -#include "aabb.h" +#include "rect3.h" #include "list.h" #include "variant.h" #include "map.h" @@ -435,7 +435,7 @@ int Octree<T,use_pairs,AL>::get_subindex(OctreeElementID p_id) const { template<class T,bool use_pairs,class AL> void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant) { - float element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues + real_t element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues if (p_octant->aabb.size.x/OCTREE_DIVISOR < element_size) { //if (p_octant->aabb.size.x*0.5 < element_size) { diff --git a/core/math/pcg.cpp b/core/math/pcg.cpp new file mode 100644 index 0000000000..eac3b36d36 --- /dev/null +++ b/core/math/pcg.cpp @@ -0,0 +1,15 @@ +// *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org +// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website) + +#include "pcg.h" + +uint32_t pcg32_random_r(pcg32_random_t* rng) +{ + uint64_t oldstate = rng->state; + // Advance internal state + rng->state = oldstate * 6364136223846793005ULL + (rng->inc|1); + // Calculate output function (XSH RR), uses old state for max ILP + uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u; + uint32_t rot = oldstate >> 59u; + return (xorshifted >> rot) | (xorshifted << ((-rot) & 31)); +} diff --git a/core/math/pcg.h b/core/math/pcg.h new file mode 100644 index 0000000000..81f4c9770e --- /dev/null +++ b/core/math/pcg.h @@ -0,0 +1,14 @@ +// *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org +// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website) + +#ifndef RANDOM_H +#define RANDOM_H + +#include "typedefs.h" + +#define PCG_DEFAULT_INC_64 1442695040888963407ULL + +typedef struct { uint64_t state; uint64_t inc; } pcg32_random_t; +uint32_t pcg32_random_r(pcg32_random_t* rng); + +#endif // RANDOM_H diff --git a/core/math/plane.h b/core/math/plane.h index f746ea2067..8235c59135 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -99,7 +99,7 @@ real_t Plane::distance_to(const Vector3 &p_point) const { bool Plane::has_point(const Vector3 &p_point,real_t _epsilon) const { - float dist=normal.dot(p_point) - d; + real_t dist=normal.dot(p_point) - d; dist=ABS(dist); return ( dist <= _epsilon); diff --git a/core/math/quat.cpp b/core/math/quat.cpp index 055e2b7c35..4085f9b84a 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -124,8 +124,8 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const { // Standard case (slerp) real_t sine = Math::sqrt(1 - cosine*cosine); real_t angle = Math::atan2(sine, cosine); - real_t inv_sine = 1.0f / sine; - real_t coeff_0 = Math::sin((1.0f - t) * angle) * inv_sine; + real_t inv_sine = 1.0 / sine; + real_t coeff_0 = Math::sin((1.0 - t) * angle) * inv_sine; real_t coeff_1 = Math::sin(t * angle) * inv_sine; Quat ret= src * coeff_0 + dst * coeff_1; @@ -137,7 +137,7 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const { // 2. "rkP" and "q" are almost invedste of each other (cosine ~= -1), there // are an infinite number of possibilities interpolation. but we haven't // have method to fix this case, so just use linear interpolation here. - Quat ret = src * (1.0f - t) + dst *t; + Quat ret = src * (1.0 - t) + dst *t; // taking the complement requires renormalisation ret.normalize(); return ret; @@ -194,14 +194,14 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const { const Quat &from = *this; - float dot = from.dot(q); + real_t dot = from.dot(q); - if (Math::absf(dot) > 0.9999f) return from; + if (Math::absf(dot) > 0.9999) return from; - float theta = Math::acos(dot), - sinT = 1.0f / Math::sin(theta), + real_t theta = Math::acos(dot), + sinT = 1.0 / Math::sin(theta), newFactor = Math::sin(t * theta) * sinT, - invFactor = Math::sin((1.0f - t) * theta) * sinT; + invFactor = Math::sin((1.0 - t) * theta) * sinT; return Quat(invFactor * from.x + newFactor * q.x, invFactor * from.y + newFactor * q.y, @@ -259,7 +259,7 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const { Quat Quat::cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const real_t& t) const { //the only way to do slerp :| - float t2 = (1.0-t)*t*2; + real_t t2 = (1.0-t)*t*2; Quat sp = this->slerp(q,t); Quat sq = prep.slerpni(postq,t); return sp.slerpni(sq,t2); diff --git a/core/math/quat.h b/core/math/quat.h index 43c2cab9e6..d3a50343a3 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -119,8 +119,8 @@ public: w=0; } else { - real_t s = Math::sqrt((1.0f + d) * 2.0f); - real_t rs = 1.0f / s; + real_t s = Math::sqrt((1.0 + d) * 2.0); + real_t rs = 1.0 / s; x=c.x*rs; y=c.y*rs; diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index 756e48d0b4..32fc0e01e8 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -86,7 +86,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me if (!valid_points[i]) continue; - float d = p_points[i][longest_axis]; + real_t d = p_points[i][longest_axis]; if (i==0 || d < min) { simplex[0]=i; @@ -105,7 +105,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me { - float maxd; + real_t maxd; Vector3 rel12 = p_points[simplex[0]] - p_points[simplex[1]]; for(int i=0;i<p_points.size();i++) { @@ -127,7 +127,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me //fourth vertex is the one most further away from the plane { - float maxd; + real_t maxd; Plane p(p_points[simplex[0]],p_points[simplex[1]],p_points[simplex[2]]); for(int i=0;i<p_points.size();i++) { diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h index 04d25fef18..7bd23d31f2 100644 --- a/core/math/quick_hull.h +++ b/core/math/quick_hull.h @@ -29,7 +29,7 @@ #ifndef QUICK_HULL_H #define QUICK_HULL_H -#include "aabb.h" +#include "rect3.h" #include "set.h" #include "list.h" #include "geometry.h" diff --git a/core/math/aabb.cpp b/core/math/rect3.cpp index 3518eea7ac..d3f95b89e8 100644 --- a/core/math/aabb.cpp +++ b/core/math/rect3.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* aabb.cpp */ +/* rect3.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -26,11 +26,11 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "aabb.h" +#include "rect3.h" #include "print_string.h" -float Rect3::get_area() const { +real_t Rect3::get_area() const { return size.x*size.y*size.z; @@ -114,8 +114,8 @@ bool Rect3::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* Vector3 c1, c2; Vector3 end = pos+size; - float near=-1e20; - float far=1e20; + real_t near=-1e20; + real_t far=1e20; int axis=0; for (int i=0;i<3;i++){ @@ -159,7 +159,7 @@ bool Rect3::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector real_t min=0,max=1; int axis=0; - float sign=0; + real_t sign=0; for(int i=0;i<3;i++) { real_t seg_from=p_from[i]; @@ -167,7 +167,7 @@ bool Rect3::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector real_t box_begin=pos[i]; real_t box_end=box_begin+size[i]; real_t cmin,cmax; - float csign; + real_t csign; if (seg_from < seg_to) { diff --git a/core/math/aabb.h b/core/math/rect3.h index 2816d1f012..902592b02c 100644 --- a/core/math/aabb.h +++ b/core/math/rect3.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* aabb.h */ +/* rect3.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -33,6 +33,8 @@ #include "vector3.h" #include "plane.h" +#include "math_defs.h" + /** * AABB / AABB (Axis Aligned Bounding Box) * This is implemented by a point (pos) and the box size @@ -45,7 +47,7 @@ public: Vector3 pos; Vector3 size; - float get_area() const; /// get area + real_t get_area() const; /// get area _FORCE_INLINE_ bool has_no_area() const { return (size.x<=CMP_EPSILON || size.y<=CMP_EPSILON || size.z<=CMP_EPSILON); @@ -74,7 +76,7 @@ public: Rect3 intersection(const Rect3& p_aabb) const; ///get box where two intersect, empty if no intersection occurs bool intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const; bool intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const; - _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, float t0, float t1) const; + _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, real_t t0, real_t t1) const; _FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const; bool intersects_plane(const Plane &p_plane) const; @@ -98,7 +100,7 @@ public: _FORCE_INLINE_ Vector3 get_endpoint(int p_point) const; Rect3 expand(const Vector3& p_vector) const; - _FORCE_INLINE_ void project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max) const; + _FORCE_INLINE_ void project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const; _FORCE_INLINE_ void expand_to(const Vector3& p_vector); /** expand to contain a point if necesary */ operator String() const; @@ -293,13 +295,13 @@ inline void Rect3::expand_to(const Vector3& p_vector) { size=end-begin; } -void Rect3::project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max) const { +void Rect3::project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const { Vector3 half_extents( size.x * 0.5, size.y * 0.5, size.z * 0.5 ); Vector3 center( pos.x + half_extents.x, pos.y + half_extents.y, pos.z + half_extents.z ); - float length = p_plane.normal.abs().dot(half_extents); - float distance = p_plane.distance_to( center ); + real_t length = p_plane.normal.abs().dot(half_extents); + real_t distance = p_plane.distance_to( center ); r_min = distance - length; r_max = distance + length; } @@ -334,14 +336,14 @@ inline real_t Rect3::get_shortest_axis_size() const { return max_size; } -bool Rect3::smits_intersect_ray(const Vector3 &from,const Vector3& dir, float t0, float t1) const { +bool Rect3::smits_intersect_ray(const Vector3 &from,const Vector3& dir, real_t t0, real_t t1) const { - float divx=1.0/dir.x; - float divy=1.0/dir.y; - float divz=1.0/dir.z; + real_t divx=1.0/dir.x; + real_t divy=1.0/dir.y; + real_t divz=1.0/dir.z; Vector3 upbound=pos+size; - float tmin, tmax, tymin, tymax, tzmin, tzmax; + real_t tmin, tmax, tymin, tymax, tzmin, tzmax; if (dir.x >= 0) { tmin = (pos.x - from.x) * divx; tmax = (upbound.x - from.x) * divx; diff --git a/core/math/transform.h b/core/math/transform.h index d65e87cc6a..45d7b2a12c 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -31,7 +31,7 @@ #include "matrix3.h" #include "plane.h" -#include "aabb.h" +#include "rect3.h" /** @author Juan Linietsky <reduzio@gmail.com> */ diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 74c4656771..247cb90a48 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -236,21 +236,22 @@ Vector3 TriangleMesh::get_area_normal(const Rect3& p_aabb) const { stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node; } } - - } continue; + continue; + } case VISIT_LEFT_BIT: { stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node; stack[level+1]=b.left|TEST_AABB_BIT; level++; - - } continue; + continue; + } case VISIT_RIGHT_BIT: { stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; stack[level+1]=b.right|TEST_AABB_BIT; level++; - } continue; + continue; + } case VISIT_DONE_BIT: { if (level==0) { @@ -258,8 +259,8 @@ Vector3 TriangleMesh::get_area_normal(const Rect3& p_aabb) const { break; } else level--; - - } continue; + continue; + } } @@ -339,7 +340,7 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end if (f3.intersects_segment(p_begin,p_end,&res)) { - float nd = n.dot(res); + real_t nd = n.dot(res); if (nd<d) { d=nd; @@ -357,21 +358,22 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node; } } - - } continue; + continue; + } case VISIT_LEFT_BIT: { stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node; stack[level+1]=b.left|TEST_AABB_BIT; level++; - - } continue; + continue; + } case VISIT_RIGHT_BIT: { stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; stack[level+1]=b.right|TEST_AABB_BIT; level++; - } continue; + continue; + } case VISIT_DONE_BIT: { if (level==0) { @@ -379,8 +381,8 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end break; } else level--; - - } continue; + continue; + } } @@ -460,7 +462,7 @@ bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vec if (f3.intersects_ray(p_begin,p_dir,&res)) { - float nd = n.dot(res); + real_t nd = n.dot(res); if (nd<d) { d=nd; @@ -478,21 +480,22 @@ bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vec stack[level]=(VISIT_LEFT_BIT<<VISITED_BIT_SHIFT)|node; } } - - } continue; + continue; + } case VISIT_LEFT_BIT: { stack[level]=(VISIT_RIGHT_BIT<<VISITED_BIT_SHIFT)|node; stack[level+1]=b.left|TEST_AABB_BIT; level++; - - } continue; + continue; + } case VISIT_RIGHT_BIT: { stack[level]=(VISIT_DONE_BIT<<VISITED_BIT_SHIFT)|node; stack[level+1]=b.right|TEST_AABB_BIT; level++; - } continue; + continue; + } case VISIT_DONE_BIT: { if (level==0) { @@ -500,8 +503,8 @@ bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vec break; } else level--; - - } continue; + continue; + } } diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp index 82b49be7f3..128b6ca331 100644 --- a/core/math/triangulate.cpp +++ b/core/math/triangulate.cpp @@ -28,19 +28,19 @@ /*************************************************************************/ #include "triangulate.h" -float Triangulate::get_area(const Vector<Vector2> &contour) +real_t Triangulate::get_area(const Vector<Vector2> &contour) { int n = contour.size(); const Vector2 *c=&contour[0]; - float A=0.0f; + real_t A=0.0; for(int p=n-1,q=0; q<n; p=q++) { A+= c[p].cross(c[q]); } - return A*0.5f; + return A*0.5; } /* @@ -48,14 +48,14 @@ float Triangulate::get_area(const Vector<Vector2> &contour) defined by A, B, C. */ -bool Triangulate::is_inside_triangle(float Ax, float Ay, - float Bx, float By, - float Cx, float Cy, - float Px, float Py) +bool Triangulate::is_inside_triangle(real_t Ax, real_t Ay, + real_t Bx, real_t By, + real_t Cx, real_t Cy, + real_t Px, real_t Py) { - float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy; - float cCROSSap, bCROSScp, aCROSSbp; + real_t ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy; + real_t cCROSSap, bCROSScp, aCROSSbp; ax = Cx - Bx; ay = Cy - By; bx = Ax - Cx; by = Ay - Cy; @@ -68,13 +68,13 @@ bool Triangulate::is_inside_triangle(float Ax, float Ay, cCROSSap = cx*apy - cy*apx; bCROSScp = bx*cpy - by*cpx; - return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f)); + return ((aCROSSbp >= 0.0) && (bCROSScp >= 0.0) && (cCROSSap >= 0.0)); }; bool Triangulate::snip(const Vector<Vector2> &p_contour,int u,int v,int w,int n,const Vector<int>& V) { int p; - float Ax, Ay, Bx, By, Cx, Cy, Px, Py; + real_t Ax, Ay, Bx, By, Cx, Cy, Px, Py; const Vector2 *contour=&p_contour[0]; Ax = contour[V[u]].x; @@ -112,7 +112,7 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result /* we want a counter-clockwise polygon in V */ - if ( 0.0f < get_area(contour) ) + if ( 0.0 < get_area(contour) ) for (int v=0; v<n; v++) V[v] = v; else for(int v=0; v<n; v++) V[v] = (n-1)-v; diff --git a/core/math/triangulate.h b/core/math/triangulate.h index d22677a8b8..ce77334519 100644 --- a/core/math/triangulate.h +++ b/core/math/triangulate.h @@ -45,14 +45,14 @@ public: static bool triangulate(const Vector< Vector2 > &contour, Vector<int> &result); // compute area of a contour/polygon - static float get_area(const Vector< Vector2 > &contour); + static real_t get_area(const Vector< Vector2 > &contour); // decide if point Px/Py is inside triangle defined by // (Ax,Ay) (Bx,By) (Cx,Cy) - static bool is_inside_triangle(float Ax, float Ay, - float Bx, float By, - float Cx, float Cy, - float Px, float Py); + static bool is_inside_triangle(real_t Ax, real_t Ay, + real_t Bx, real_t By, + real_t Cx, real_t Cy, + real_t Px, real_t Py); private: diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index 3eb978333d..2ab5fa0465 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -30,12 +30,12 @@ #include "matrix3.h" -void Vector3::rotate(const Vector3& p_axis,float p_phi) { +void Vector3::rotate(const Vector3& p_axis,real_t p_phi) { *this=Basis(p_axis,p_phi).xform(*this); } -Vector3 Vector3::rotated(const Vector3& p_axis,float p_phi) const { +Vector3 Vector3::rotated(const Vector3& p_axis,real_t p_phi) const { Vector3 r = *this; r.rotate(p_axis,p_phi); @@ -63,13 +63,13 @@ int Vector3::max_axis() const { } -void Vector3::snap(float p_val) { +void Vector3::snap(real_t p_val) { x=Math::stepify(x,p_val); y=Math::stepify(y,p_val); z=Math::stepify(z,p_val); } -Vector3 Vector3::snapped(float p_val) const { +Vector3 Vector3::snapped(real_t p_val) const { Vector3 v=*this; v.snap(p_val); @@ -77,7 +77,7 @@ Vector3 Vector3::snapped(float p_val) const { } -Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const { +Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const { Vector3 p0=p_pre_a; Vector3 p1=*this; @@ -87,9 +87,9 @@ Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, c { //normalize - float ab = p0.distance_to(p1); - float bc = p1.distance_to(p2); - float cd = p2.distance_to(p3); + real_t ab = p0.distance_to(p1); + real_t bc = p1.distance_to(p2); + real_t cd = p2.distance_to(p3); if (ab>0) p0 = p1+(p0-p1)*(bc/ab); @@ -98,41 +98,41 @@ Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, c } - float t = p_t; - float t2 = t * t; - float t3 = t2 * t; + real_t t = p_t; + real_t t2 = t * t; + real_t t3 = t2 * t; Vector3 out; - out = 0.5f * ( ( p1 * 2.0f) + + out = 0.5 * ( ( p1 * 2.0) + ( -p0 + p2 ) * t + - ( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 + - ( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 ); + ( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 + + ( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 ); return out; } -Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const { +Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const { Vector3 p0=p_pre_a; Vector3 p1=*this; Vector3 p2=p_b; Vector3 p3=p_post_b; - float t = p_t; - float t2 = t * t; - float t3 = t2 * t; + real_t t = p_t; + real_t t2 = t * t; + real_t t3 = t2 * t; Vector3 out; - out = 0.5f * ( ( p1 * 2.0f) + + out = 0.5 * ( ( p1 * 2.0) + ( -p0 + p2 ) * t + - ( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 + - ( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 ); + ( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 + + ( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 ); return out; } #if 0 -Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const { +Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const { Vector3 p0=p_pre_a; Vector3 p1=*this; @@ -141,9 +141,9 @@ Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, co if (true) { - float ab = p0.distance_to(p1); - float bc = p1.distance_to(p2); - float cd = p2.distance_to(p3); + real_t ab = p0.distance_to(p1); + real_t bc = p1.distance_to(p2); + real_t cd = p2.distance_to(p3); //if (ab>bc) { if (ab>0) @@ -156,23 +156,23 @@ Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, co //} } - float t = p_t; - float t2 = t * t; - float t3 = t2 * t; + real_t t = p_t; + real_t t2 = t * t; + real_t t3 = t2 * t; Vector3 out; - out.x = 0.5f * ( ( 2.0f * p1.x ) + + out.x = 0.5 * ( ( 2.0 * p1.x ) + ( -p0.x + p2.x ) * t + - ( 2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x ) * t2 + - ( -p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x ) * t3 ); - out.y = 0.5f * ( ( 2.0f * p1.y ) + + ( 2.0 * p0.x - 5.0 * p1.x + 4 * p2.x - p3.x ) * t2 + + ( -p0.x + 3.0 * p1.x - 3.0 * p2.x + p3.x ) * t3 ); + out.y = 0.5 * ( ( 2.0 * p1.y ) + ( -p0.y + p2.y ) * t + - ( 2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y ) * t2 + - ( -p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y ) * t3 ); - out.z = 0.5f * ( ( 2.0f * p1.z ) + + ( 2.0 * p0.y - 5.0 * p1.y + 4 * p2.y - p3.y ) * t2 + + ( -p0.y + 3.0 * p1.y - 3.0 * p2.y + p3.y ) * t3 ); + out.z = 0.5 * ( ( 2.0 * p1.z ) + ( -p0.z + p2.z ) * t + - ( 2.0f * p0.z - 5.0f * p1.z + 4 * p2.z - p3.z ) * t2 + - ( -p0.z + 3.0f * p1.z - 3.0f * p2.z + p3.z ) * t3 ); + ( 2.0 * p0.z - 5.0 * p1.z + 4 * p2.z - p3.z ) * t2 + + ( -p0.z + 3.0 * p1.z - 3.0 * p2.z + p3.z ) * t3 ); return out; } # endif diff --git a/core/math/vector3.h b/core/math/vector3.h index 9ae9b69dfa..a289f9bf4c 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -79,17 +79,17 @@ struct Vector3 { _FORCE_INLINE_ void zero(); - void snap(float p_val); - Vector3 snapped(float p_val) const; + void snap(real_t p_val); + Vector3 snapped(real_t p_val) const; - void rotate(const Vector3& p_axis,float p_phi); - Vector3 rotated(const Vector3& p_axis,float p_phi) const; + void rotate(const Vector3& p_axis,real_t p_phi); + Vector3 rotated(const Vector3& p_axis,real_t p_phi) const; /* Static Methods between 2 vector3s */ - _FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,float p_t) const; - Vector3 cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const; - Vector3 cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const; + _FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,real_t p_t) const; + Vector3 cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const; + Vector3 cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const; _FORCE_INLINE_ Vector3 cross(const Vector3& p_b) const; _FORCE_INLINE_ real_t dot(const Vector3& p_b) const; @@ -195,7 +195,7 @@ Vector3 Vector3::ceil() const { return Vector3( Math::ceil(x), Math::ceil(y), Math::ceil(z) ); } -Vector3 Vector3::linear_interpolate(const Vector3& p_b,float p_t) const { +Vector3 Vector3::linear_interpolate(const Vector3& p_b,real_t p_t) const { return Vector3( x+(p_t * (p_b.x-x)), diff --git a/core/message_queue.cpp b/core/message_queue.cpp index fe46e1671c..668d321e05 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -27,8 +27,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "message_queue.h" + #include "globals.h" #include "script_language.h" + MessageQueue *MessageQueue::singleton=NULL; MessageQueue *MessageQueue::get_singleton() { diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h index 36b42c84f3..a35e44b66c 100644 --- a/core/method_ptrcall.h +++ b/core/method_ptrcall.h @@ -74,7 +74,7 @@ MAKE_PTRARG(Vector3); MAKE_PTRARG(Transform2D); MAKE_PTRARG(Plane); MAKE_PTRARG(Quat); -MAKE_PTRARG(AABB); +MAKE_PTRARG(Rect3); MAKE_PTRARG(Basis); MAKE_PTRARG(Transform); MAKE_PTRARG(Color); @@ -84,13 +84,13 @@ MAKE_PTRARG(RID); MAKE_PTRARG(InputEvent); MAKE_PTRARG(Dictionary); MAKE_PTRARG(Array); -MAKE_PTRARG(ByteArray); -MAKE_PTRARG(IntArray); -MAKE_PTRARG(RealArray); -MAKE_PTRARG(StringArray); -MAKE_PTRARG(Vector2Array); -MAKE_PTRARG(Vector3Array); -MAKE_PTRARG(ColorArray); +MAKE_PTRARG(PoolByteArray); +MAKE_PTRARG(PoolIntArray); +MAKE_PTRARG(PoolRealArray); +MAKE_PTRARG(PoolStringArray); +MAKE_PTRARG(PoolVector2Array); +MAKE_PTRARG(PoolVector3Array); +MAKE_PTRARG(PoolColorArray); MAKE_PTRARG(Variant); diff --git a/core/object.cpp b/core/object.cpp index 8af088122e..26308dc64f 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -27,8 +27,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "object.h" + #include "print_string.h" -#include "object_type_db.h" +#include "class_db.h" #include "script_language.h" #include "message_queue.h" #include "core_string_names.h" diff --git a/core/object.h b/core/object.h index 6ce579ea99..3032452ccf 100644 --- a/core/object.h +++ b/core/object.h @@ -103,6 +103,7 @@ enum PropertyUsageFlags { PROPERTY_USAGE_SCRIPT_VARIABLE=8192, PROPERTY_USAGE_STORE_IF_NULL=16384, PROPERTY_USAGE_ANIMATE_AS_TRIGGER=32768, + PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED=65536, PROPERTY_USAGE_DEFAULT=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK, PROPERTY_USAGE_DEFAULT_INTL=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK|PROPERTY_USAGE_INTERNATIONALIZED, @@ -721,6 +722,6 @@ public: }; //needed by macros -#include "object_type_db.h" +#include "class_db.h" #endif diff --git a/core/os/input.cpp b/core/os/input.cpp index acfd5ba540..4e7b037453 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -38,7 +38,7 @@ Input *Input::get_singleton() { } void Input::set_mouse_mode(MouseMode p_mode) { - ERR_FAIL_INDEX(p_mode,3); + ERR_FAIL_INDEX(p_mode,4); OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode); } @@ -70,6 +70,7 @@ void Input::_bind_methods() { ClassDB::bind_method(_MD("get_joy_axis_index_from_string", "axis"), &Input::get_joy_axis_index_from_string); ClassDB::bind_method(_MD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0)); ClassDB::bind_method(_MD("stop_joy_vibration", "device"), &Input::stop_joy_vibration); + ClassDB::bind_method(_MD("get_gravity"),&Input::get_gravity); ClassDB::bind_method(_MD("get_accelerometer"),&Input::get_accelerometer); ClassDB::bind_method(_MD("get_magnetometer"),&Input::get_magnetometer); ClassDB::bind_method(_MD("get_gyroscope"),&Input::get_gyroscope); @@ -86,6 +87,7 @@ void Input::_bind_methods() { BIND_CONSTANT( MOUSE_MODE_VISIBLE ); BIND_CONSTANT( MOUSE_MODE_HIDDEN ); BIND_CONSTANT( MOUSE_MODE_CAPTURED ); + BIND_CONSTANT( MOUSE_MODE_CONFINED ); ADD_SIGNAL( MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "connected")) ); } diff --git a/core/os/input.h b/core/os/input.h index a1b60ba0c8..2cea154a50 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -47,7 +47,8 @@ public: enum MouseMode { MOUSE_MODE_VISIBLE, MOUSE_MODE_HIDDEN, - MOUSE_MODE_CAPTURED + MOUSE_MODE_CAPTURED, + MOUSE_MODE_CONFINED }; void set_mouse_mode(MouseMode p_mode); @@ -82,6 +83,7 @@ public: virtual void warp_mouse_pos(const Vector2& p_to)=0; + virtual Vector3 get_gravity() const=0; virtual Vector3 get_accelerometer() const=0; virtual Vector3 get_magnetometer() const=0; virtual Vector3 get_gyroscope() const=0; diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 3cc595208f..4ef99558ad 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -39,6 +39,8 @@ bool InputEvent::operator==(const InputEvent &p_event) const { } switch(type) { + /** Current clang-format style doesn't play well with the aligned return values of that switch. */ + /* clang-format off */ case NONE: return true; case KEY: @@ -80,6 +82,7 @@ bool InputEvent::operator==(const InputEvent &p_event) const { case ACTION: return action.action == p_event.action.action && action.pressed == p_event.action.pressed; + /* clang-format on */ default: ERR_PRINT("No logic to compare InputEvents of this type, this shouldn't happen."); } diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index 309348ea31..40fa86d09f 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -36,6 +36,7 @@ struct _KeyCodeText { static const _KeyCodeText _keycodes[]={ + /* clang-format off */ {KEY_ESCAPE ,"Escape"}, {KEY_TAB ,"Tab"}, {KEY_BACKTAB ,"BackTab"}, @@ -281,7 +282,8 @@ static const _KeyCodeText _keycodes[]={ {KEY_DIVISION ,"Division"}, {KEY_YDIAERESIS ,"Ydiaeresis"}, - {0 ,0} + {0 ,0} + /* clang-format on */ }; bool keycode_has_unicode(uint32_t p_keycode) { @@ -299,7 +301,8 @@ bool keycode_has_unicode(uint32_t p_keycode) { case KEY_MEDIAPREVIOUS: case KEY_MEDIANEXT: case KEY_MEDIARECORD: case KEY_HOMEPAGE: case KEY_FAVORITES: case KEY_SEARCH: case KEY_STANDBY: case KEY_OPENURL: case KEY_LAUNCHMAIL: case KEY_LAUNCHMEDIA: case KEY_LAUNCH0: case KEY_LAUNCH1: case KEY_LAUNCH2: case KEY_LAUNCH3: case KEY_LAUNCH4: case KEY_LAUNCH5: case KEY_LAUNCH6: case KEY_LAUNCH7: case KEY_LAUNCH8: case KEY_LAUNCH9: case KEY_LAUNCHA: case KEY_LAUNCHB: case KEY_LAUNCHC: case KEY_LAUNCHD: - case KEY_LAUNCHE: case KEY_LAUNCHF: return false; + case KEY_LAUNCHE: case KEY_LAUNCHF: + return false; } return true; diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp index f5f7f757c3..acdcb492d9 100644 --- a/core/os/mutex.cpp +++ b/core/os/mutex.cpp @@ -47,7 +47,7 @@ Mutex::~Mutex() { } -Mutex *_global_mutex=NULL;; +Mutex *_global_mutex=NULL; void _global_lock() { diff --git a/core/os/os.h b/core/os/os.h index ea03481a92..e179b82dae 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -131,7 +131,8 @@ public: enum MouseMode { MOUSE_MODE_VISIBLE, MOUSE_MODE_HIDDEN, - MOUSE_MODE_CAPTURED + MOUSE_MODE_CAPTURED, + MOUSE_MODE_CONFINED }; virtual void set_mouse_mode(MouseMode p_mode); @@ -402,6 +403,8 @@ public: virtual void set_use_vsync(bool p_enable); virtual bool is_vsync_enabled() const; + virtual bool check_feature_support(const String& p_feature)=0; + bool is_hidpi_allowed() const { return _allow_hidpi; } OS(); virtual ~OS(); diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp index 5f3b877822..d3bb03ab5e 100644 --- a/core/packed_data_container.cpp +++ b/core/packed_data_container.cpp @@ -27,11 +27,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "packed_data_container.h" + #include "io/marshalls.h" #include "core_string_names.h" - Variant PackedDataContainer::getvar(const Variant& p_key, bool *r_valid) const { bool err=false; diff --git a/core/pair.h b/core/pair.h index d75cbed642..174ffb3883 100644 --- a/core/pair.h +++ b/core/pair.h @@ -39,4 +39,13 @@ struct Pair { Pair( F p_first, S p_second) { first=p_first; second=p_second; } }; +template<class F,class S> +struct PairSort { + + bool operator()(const Pair<F,S>& A, const Pair<F,S>& B) const { + return A.first < B.first; + } +}; + + #endif // PAIR_H diff --git a/core/path_db.cpp b/core/path_db.cpp index 25f62ed951..679372898c 100644 --- a/core/path_db.cpp +++ b/core/path_db.cpp @@ -27,8 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "path_db.h" -#include "print_string.h" +#include "print_string.h" uint32_t NodePath::hash() const { @@ -334,7 +334,7 @@ NodePath::NodePath(const String& p_path) { StringName property; Vector<StringName> subpath; - int absolute=(path[0]=='/')?1:0;; + int absolute=(path[0]=='/')?1:0; bool last_is_slash=true; int slices=0; int subpath_pos=path.find(":"); diff --git a/core/path_remap.cpp b/core/path_remap.cpp index 42383e212d..bbaba71bba 100644 --- a/core/path_remap.cpp +++ b/core/path_remap.cpp @@ -27,177 +27,4 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "path_remap.h" -#include "globals.h" -#include "os/os.h" -#include "translation.h" -PathRemap* PathRemap::singleton=NULL; -PathRemap* PathRemap::get_singleton() { - - return singleton; -} - -void PathRemap::add_remap(const String& p_from, const String& p_to,const String& p_locale) { - - if (!remap.has(p_from)) { - remap[p_from]=RemapData(); - } - - if (p_locale==String()) - remap[p_from].always=p_to; - else - remap[p_from].locale[p_locale]=p_to; -} - - -String PathRemap::get_remap(const String& p_from) const { - - const RemapData *ptr=remap.getptr(p_from); - if (!ptr) { - if (OS::get_singleton()->is_stdout_verbose()) - print_line("remap failed: "+p_from); - return p_from; - } else { - - const RemapData *ptr2=NULL; - - String locale = TranslationServer::get_singleton()->get_locale(); - - if (ptr->locale.has(locale)) { - if (OS::get_singleton()->is_stdout_verbose()) - print_line("remap found: "+p_from+" -> "+ptr->locale[locale]); - - ptr2=remap.getptr(ptr->locale[locale]); - - if (ptr2 && ptr2->always!=String()) //may have atlas or export remap too - return ptr2->always; - else - return ptr->locale[locale]; - } - - int p = locale.find("_"); - if (p!=-1) { - locale=locale.substr(0,p); - if (ptr->locale.has(locale)) { - if (OS::get_singleton()->is_stdout_verbose()) - print_line("remap found: "+p_from+" -> "+ptr->locale[locale]); - - ptr2=remap.getptr(ptr->locale[locale]); - - if (ptr2 && ptr2->always!=String()) //may have atlas or export remap too - return ptr2->always; - else - return ptr->locale[locale]; - - } - } - - if (ptr->always!=String()) { - if (OS::get_singleton()->is_stdout_verbose()) { - print_line("remap found: "+p_from+" -> "+ptr->always); - } - return ptr->always; - } - - if (OS::get_singleton()->is_stdout_verbose()) - print_line("remap failed: "+p_from); - - return p_from; - } -} -bool PathRemap::has_remap(const String& p_from) const{ - - return remap.has(p_from); -} - -void PathRemap::erase_remap(const String& p_from){ - - ERR_FAIL_COND(!remap.has(p_from)); - remap.erase(p_from); -} - -void PathRemap::clear_remaps() { - - remap.clear(); -} - -void PathRemap::load_remaps() { - - // default remaps first - PoolVector<String> remaps = GlobalConfig::get_singleton()->get("remap/all"); - - { - int rlen = remaps.size(); - - ERR_FAIL_COND( rlen%2 ); - PoolVector<String>::Read r = remaps.read(); - for(int i=0;i<rlen/2;i++) { - - String from = r[i*2+0]; - String to = r[i*2+1]; - add_remap(from,to); - } - } - - - // platform remaps second, so override - remaps = GlobalConfig::get_singleton()->get("remap/"+OS::get_singleton()->get_name()); - //remaps = Globals::get_singleton()->get("remap/PSP"); - { - int rlen = remaps.size(); - - ERR_FAIL_COND( rlen%2 ); - PoolVector<String>::Read r = remaps.read(); - for(int i=0;i<rlen/2;i++) { - - String from = r[i*2+0]; - String to = r[i*2+1]; - //print_line("add remap: "+from+" -> "+to); - add_remap(from,to); - } - } - - - //locale based remaps - - if (GlobalConfig::get_singleton()->has("locale/translation_remaps")) { - - Dictionary remaps = GlobalConfig::get_singleton()->get("locale/translation_remaps"); - List<Variant> rk; - remaps.get_key_list(&rk); - for(List<Variant>::Element *E=rk.front();E;E=E->next()) { - - String source = E->get(); - PoolStringArray sa = remaps[E->get()]; - int sas = sa.size(); - PoolStringArray::Read r = sa.read(); - - for(int i=0;i<sas;i++) { - - String s = r[i]; - int qp = s.find_last(":"); - if (qp!=-1) { - String path = s.substr(0,qp); - String locale = s.substr(qp+1,s.length()); - add_remap(source,path,locale); - } - } - } - - } - -} - -void PathRemap::_bind_methods() { - - ClassDB::bind_method(_MD("add_remap","from","to","locale"),&PathRemap::add_remap,DEFVAL(String())); - ClassDB::bind_method(_MD("has_remap","path"),&PathRemap::has_remap); - ClassDB::bind_method(_MD("get_remap","path"),&PathRemap::get_remap); - ClassDB::bind_method(_MD("erase_remap","path"),&PathRemap::erase_remap); - ClassDB::bind_method(_MD("clear_remaps"),&PathRemap::clear_remaps); -} - -PathRemap::PathRemap() { - - singleton=this; -} diff --git a/core/path_remap.h b/core/path_remap.h index a106030f95..966bb10ea5 100644 --- a/core/path_remap.h +++ b/core/path_remap.h @@ -29,39 +29,4 @@ #ifndef PATH_REMAP_H #define PATH_REMAP_H -#include "hash_map.h" -#include "ustring.h" -#include "object.h" - - -class PathRemap : public Object { - - GDCLASS(PathRemap,Object); - - static PathRemap* singleton; - struct RemapData { - String always; - Map<String,String> locale; - }; - - HashMap<String,RemapData> remap; -protected: - - static void _bind_methods(); -public: - - void add_remap(const String& p_from, const String& p_to,const String& p_locale=String()); - bool has_remap(const String& p_from) const; - //_FORCE_INLINE_ String get_remap(const String& p_from) const { const String *ptr=remap.getptr(p_from); if (!ptr) return p_from; else return *ptr; } - String get_remap(const String& p_from) const; - void erase_remap(const String& p_from); - void clear_remaps(); - - void load_remaps(); - - static PathRemap* get_singleton(); - - PathRemap(); -}; - #endif // PATH_REMAP_H diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp index e425218060..b1417dd107 100644 --- a/core/pool_allocator.cpp +++ b/core/pool_allocator.cpp @@ -27,12 +27,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "pool_allocator.h" + #include "error_macros.h" #include "core/os/os.h" #include "os/memory.h" #include "os/copymem.h" #include "print_string.h" + #include <assert.h> + #define COMPACT_CHUNK( m_entry , m_to_pos ) \ do { \ void *_dst=&((unsigned char*)pool)[m_to_pos]; \ diff --git a/core/print_string.cpp b/core/print_string.cpp index 3faed62bb4..36316af619 100644 --- a/core/print_string.cpp +++ b/core/print_string.cpp @@ -27,7 +27,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "print_string.h" + #include "os/os.h" + #include <stdio.h> static PrintHandlerList *print_handler_list=NULL; diff --git a/core/profile_clock.cpp b/core/profile_clock.cpp deleted file mode 100644 index 0806275463..0000000000 --- a/core/profile_clock.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "profile_clock.h" - - diff --git a/core/profile_clock.h b/core/profile_clock.h deleted file mode 100644 index e254580249..0000000000 --- a/core/profile_clock.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef PROFILE_CLOCK_H -#define PROFILE_CLOCK_H - - - - -#endif // PROFILE_CLOCK_H diff --git a/core/ref_ptr.cpp b/core/ref_ptr.cpp index e781bae496..29ffe974d2 100644 --- a/core/ref_ptr.cpp +++ b/core/ref_ptr.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "ref_ptr.h" + #include "reference.h" #include "resource.h" diff --git a/core/reference.cpp b/core/reference.cpp index 69e053cc1a..d21caf0839 100644 --- a/core/reference.cpp +++ b/core/reference.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "reference.h" + #include "script_language.h" diff --git a/core/reference.h b/core/reference.h index ce196801bb..e130b4c2b4 100644 --- a/core/reference.h +++ b/core/reference.h @@ -32,7 +32,7 @@ #include "object.h" #include "safe_refcount.h" #include "ref_ptr.h" -#include "object_type_db.h" +#include "class_db.h" /** @author Juan Linietsky <reduzio@gmail.com> diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 85fa5d27c0..ab94b56cdc 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -36,7 +36,7 @@ #include "math/a_star.h" #include "math/triangle_mesh.h" #include "globals.h" -#include "object_type_db.h" +#include "class_db.h" #include "geometry.h" #include "bind/core_bind.h" #include "core_string_names.h" @@ -45,6 +45,7 @@ #include "compressed_translation.h" #include "io/translation_loader_po.h" #include "io/resource_format_binary.h" +#include "io/resource_import.h" #include "io/stream_peer_ssl.h" #include "os/input.h" #include "core/io/xml_parser.h" @@ -57,7 +58,7 @@ static ResourceFormatSaverBinary *resource_saver_binary=NULL; static ResourceFormatLoaderBinary *resource_loader_binary=NULL; - +static ResourceFormatImporter *resource_format_importer=NULL; static _ResourceLoader *_resource_loader=NULL; static _ResourceSaver *_resource_saver=NULL; @@ -105,12 +106,14 @@ void register_core_types() { resource_loader_binary = memnew( ResourceFormatLoaderBinary ); ResourceLoader::add_resource_format_loader(resource_loader_binary); + resource_format_importer = memnew( ResourceFormatImporter ); + ResourceLoader::add_resource_format_loader(resource_format_importer); + ClassDB::register_class<Object>(); ClassDB::register_class<Reference>(); ClassDB::register_class<WeakRef>(); - ClassDB::register_class<ResourceImportMetadata>(); ClassDB::register_class<Resource>(); ClassDB::register_class<FuncRef>(); ClassDB::register_virtual_class<StreamPeer>(); @@ -179,13 +182,11 @@ void register_core_singletons() { GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Geometry",_Geometry::get_singleton()) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ResourceLoader",_ResourceLoader::get_singleton()) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ResourceSaver",_ResourceSaver::get_singleton()) ); - GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("PathRemap",PathRemap::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("OS",_OS::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Engine",_Engine::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("ClassDB",_classdb ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Marshalls",_Marshalls::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("TranslationServer",TranslationServer::get_singleton() ) ); - GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("TS",TranslationServer::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Input",Input::get_singleton() ) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("InputMap",InputMap::get_singleton() ) ); @@ -209,6 +210,8 @@ void unregister_core_types() { memdelete(resource_saver_binary); if (resource_loader_binary) memdelete(resource_loader_binary); + if (resource_format_importer) + memdelete(resource_format_importer); memdelete( resource_format_po ); diff --git a/core/resource.cpp b/core/resource.cpp index 3369e4a5a2..9b5bac5f32 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -27,124 +27,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "resource.h" + #include "core_string_names.h" -#include <stdio.h> #include "os/file_access.h" #include "io/resource_loader.h" #include "script_language.h" -void ResourceImportMetadata::set_editor(const String& p_editor) { - - editor=p_editor; -} - -String ResourceImportMetadata::get_editor() const{ - - return editor; -} - -void ResourceImportMetadata::add_source(const String& p_path,const String& p_md5) { - - Source s; - s.md5=p_md5; - s.path=p_path; - sources.push_back(s); -} - -String ResourceImportMetadata::get_source_path(int p_idx) const{ - ERR_FAIL_INDEX_V(p_idx,sources.size(),String()); - return sources[p_idx].path; -} -String ResourceImportMetadata::get_source_md5(int p_idx) const{ - ERR_FAIL_INDEX_V(p_idx,sources.size(),String()); - return sources[p_idx].md5; -} - -void ResourceImportMetadata::set_source_md5(int p_idx,const String& p_md5) { - - ERR_FAIL_INDEX(p_idx,sources.size()); - sources[p_idx].md5=p_md5; - -} - -void ResourceImportMetadata::remove_source(int p_idx){ - - ERR_FAIL_INDEX(p_idx,sources.size()); - sources.remove(p_idx); - -} - -int ResourceImportMetadata::get_source_count() const { - - return sources.size(); -} -void ResourceImportMetadata::set_option(const String& p_key, const Variant& p_value) { - - if (p_value.get_type()==Variant::NIL) { - options.erase(p_key); - return; - } - - ERR_FAIL_COND(p_value.get_type() == Variant::OBJECT); - ERR_FAIL_COND(p_value.get_type() == Variant::_RID); - - options[p_key]=p_value; - -} - -bool ResourceImportMetadata::has_option(const String& p_key) const { - - return options.has(p_key); -} - -Variant ResourceImportMetadata::get_option(const String& p_key) const { - - ERR_FAIL_COND_V(!options.has(p_key),Variant()); - - return options[p_key]; -} - -void ResourceImportMetadata::get_options(List<String> *r_options) const { - - for(Map<String,Variant>::Element *E=options.front();E;E=E->next()) { - - r_options->push_back(E->key()); - } - -} - -PoolStringArray ResourceImportMetadata::_get_options() const { - - PoolStringArray option_names; - option_names.resize(options.size()); - int i=0; - for(Map<String,Variant>::Element *E=options.front();E;E=E->next()) { - - option_names.set(i++,E->key()); - } - - return option_names; -} - -void ResourceImportMetadata::_bind_methods() { - - ClassDB::bind_method(_MD("set_editor","name"),&ResourceImportMetadata::set_editor); - ClassDB::bind_method(_MD("get_editor"),&ResourceImportMetadata::get_editor); - ClassDB::bind_method(_MD("add_source","path","md5"),&ResourceImportMetadata::add_source, ""); - ClassDB::bind_method(_MD("get_source_path","idx"),&ResourceImportMetadata::get_source_path); - ClassDB::bind_method(_MD("get_source_md5","idx"),&ResourceImportMetadata::get_source_md5); - ClassDB::bind_method(_MD("set_source_md5","idx", "md5"),&ResourceImportMetadata::set_source_md5); - ClassDB::bind_method(_MD("remove_source","idx"),&ResourceImportMetadata::remove_source); - ClassDB::bind_method(_MD("get_source_count"),&ResourceImportMetadata::get_source_count); - ClassDB::bind_method(_MD("set_option","key","value"),&ResourceImportMetadata::set_option); - ClassDB::bind_method(_MD("get_option","key"),&ResourceImportMetadata::get_option); - ClassDB::bind_method(_MD("get_options"),&ResourceImportMetadata::_get_options); -} - -ResourceImportMetadata::ResourceImportMetadata() { - - -} +#include <stdio.h> void Resource::emit_changed() { @@ -198,7 +87,7 @@ void Resource::set_path(const String& p_path, bool p_take_over) { if (path_cache!="") { ResourceCache::lock->write_lock(); - ResourceCache::resources[path_cache]=this;; + ResourceCache::resources[path_cache]=this; ResourceCache::lock->write_unlock(); } @@ -379,21 +268,6 @@ void Resource::notify_change_to_owners() { } } -void Resource::set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata) { -#ifdef TOOLS_ENABLED - import_metadata=p_metadata; -#endif -} - -Ref<ResourceImportMetadata> Resource::get_import_metadata() const { - -#ifdef TOOLS_ENABLED - return import_metadata; -#else - return Ref<ResourceImportMetadata>(); -#endif - -} #ifdef TOOLS_ENABLED @@ -459,8 +333,6 @@ void Resource::_bind_methods() { ClassDB::bind_method(_MD("set_name","name"),&Resource::set_name); ClassDB::bind_method(_MD("get_name"),&Resource::get_name); ClassDB::bind_method(_MD("get_rid"),&Resource::get_rid); - ClassDB::bind_method(_MD("set_import_metadata","metadata"),&Resource::set_import_metadata); - ClassDB::bind_method(_MD("get_import_metadata"),&Resource::get_import_metadata); ClassDB::bind_method(_MD("set_local_to_scene","enable"),&Resource::set_local_to_scene); ClassDB::bind_method(_MD("is_local_to_scene"),&Resource::is_local_to_scene); ClassDB::bind_method(_MD("get_local_scene:Node"),&Resource::get_local_scene); @@ -481,9 +353,11 @@ Resource::Resource() { #ifdef TOOLS_ENABLED last_modified_time=0; + import_last_modified_time=0; #endif subindex=0; + local_to_scene=false; local_scene=NULL; } @@ -532,9 +406,9 @@ void ResourceCache::reload_externals() { bool ResourceCache::has(const String& p_path) { - lock->read_lock();; + lock->read_lock(); bool b = resources.has(p_path); - lock->read_unlock();; + lock->read_unlock(); return b; diff --git a/core/resource.h b/core/resource.h index 284c59e1a8..b29077a3b8 100644 --- a/core/resource.h +++ b/core/resource.h @@ -33,7 +33,7 @@ #include "safe_refcount.h" #include "ref_ptr.h" #include "reference.h" -#include "object_type_db.h" +#include "class_db.h" /** @author Juan Linietsky <reduzio@gmail.com> @@ -46,47 +46,6 @@ virtual String get_base_extension() const { return m_ext; }\ private: -class ResourceImportMetadata : public Reference { - - GDCLASS( ResourceImportMetadata, Reference ); - - struct Source { - String path; - String md5; - }; - - Vector<Source> sources; - String editor; - - Map<String,Variant> options; - - PoolStringArray _get_options() const; - -protected: - - static void _bind_methods(); -public: - - void set_editor(const String& p_editor); - String get_editor() const; - - void add_source(const String& p_path,const String& p_md5=""); - String get_source_path(int p_idx) const; - String get_source_md5(int p_idx) const; - void set_source_md5(int p_idx,const String& p_md5); - void remove_source(int p_idx); - int get_source_count() const; - - void set_option(const String& p_key, const Variant& p_value); - Variant get_option(const String& p_key) const; - bool has_option(const String& p_key) const; - - void get_options(List<String> *r_options) const; - - - ResourceImportMetadata(); -}; - class Resource : public Reference { @@ -106,8 +65,9 @@ friend class ResourceCache; virtual bool _use_builtin_script() const { return true; } #ifdef TOOLS_ENABLED - Ref<ResourceImportMetadata> import_metadata; uint64_t last_modified_time; + uint64_t import_last_modified_time; + String import_path; #endif bool local_to_scene; @@ -147,10 +107,6 @@ public: Ref<Resource> duplicate(bool p_subresources=false); Ref<Resource> duplicate_for_local_scene(Node *p_scene,Map<Ref<Resource>,Ref<Resource> >& remap_cache); - - void set_import_metadata(const Ref<ResourceImportMetadata>& p_metadata); - Ref<ResourceImportMetadata> get_import_metadata() const; - void set_local_to_scene(bool p_enable); bool is_local_to_scene() const; virtual void setup_local_to_scene(); @@ -164,6 +120,12 @@ public: virtual void set_last_modified_time(uint64_t p_time) { last_modified_time=p_time; } uint64_t get_last_modified_time() const { return last_modified_time; } + virtual void set_import_last_modified_time(uint64_t p_time) { import_last_modified_time=p_time; } + uint64_t get_import_last_modified_time() const { return import_last_modified_time; } + + void set_import_path(const String& p_path) { import_path=p_path; } + String get_import_path() const { return import_path; } + #endif virtual RID get_rid() const; // some resources may offer conversion to RID diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp index ede37bbe8a..50617f2062 100644 --- a/core/safe_refcount.cpp +++ b/core/safe_refcount.cpp @@ -44,6 +44,14 @@ uint32_t atomic_conditional_increment( register uint32_t * pw ) { return *pw; } +uint32_t atomic_increment( register uint32_t * pw ) { + + (*pw)++; + + return *pw; + +} + uint32_t atomic_decrement( register uint32_t * pw ) { (*pw)--; diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp index a8d77668f5..22aceac4c5 100644 --- a/core/script_debugger_local.cpp +++ b/core/script_debugger_local.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "script_debugger_local.h" + #include "os/os.h" void ScriptDebuggerLocal::debug(ScriptLanguage *p_script,bool p_can_continue) { @@ -286,7 +287,7 @@ void ScriptDebuggerLocal::profiling_end() { for(int i=0;i<ofs;i++) { print_line(itos(i)+":"+pinfo[i].signature); - float tt=USEC_TO_SEC(pinfo[i].total_time);; + float tt=USEC_TO_SEC(pinfo[i].total_time); float st=USEC_TO_SEC(pinfo[i].self_time); print_line("\ttotal_ms: "+rtos(tt)+"\tself_ms: "+rtos(st)+"total%: "+itos(tt*100/total_time)+"\tself%: "+itos(st*100/total_time)+"\tcalls: "+itos(pinfo[i].call_count)); } diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index bb0109467e..62d14c4e5a 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -27,10 +27,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "script_debugger_remote.h" + #include "os/os.h" #include "io/ip.h" #include "globals.h" #include "os/input.h" + void ScriptDebuggerRemote::_send_video_memory() { List<ResourceUsage> usage; diff --git a/core/set.h b/core/set.h index 13c2b3a4f6..a921fc661f 100644 --- a/core/set.h +++ b/core/set.h @@ -416,7 +416,7 @@ private: Element *aux=node->parent->left; if (aux->color==RED) { _set_color(aux,BLACK); - _set_color(node->parent,RED);; + _set_color(node->parent,RED); _rotate_right(node->parent); aux=node->parent->left; } diff --git a/core/string_db.cpp b/core/string_db.cpp index be35a44ed1..004b07b9e5 100644 --- a/core/string_db.cpp +++ b/core/string_db.cpp @@ -27,8 +27,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "string_db.h" + #include "print_string.h" #include "os/os.h" + StaticCString StaticCString::create(const char *p_ptr) { StaticCString scs; scs.ptr=p_ptr; return scs; } diff --git a/core/translation.cpp b/core/translation.cpp index 5215e5f6d1..2fee0e6550 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "translation.h" + #include "globals.h" #include "io/resource_loader.h" #include "os/os.h" @@ -669,6 +670,7 @@ static const char* locale_names[]={ "Sanskrit (India)", "Santali (India)", "Sardinian (Italy)", +"Scots (Scotland)", "Sindhi (India)", "Northern Sami (Norway)", "Samogitian (Lithuania)", @@ -750,6 +752,20 @@ static const char* locale_names[]={ 0 }; +bool TranslationServer::is_locale_valid(const String& p_locale) { + + const char **ptr=locale_list; + + while (*ptr) { + + if (*ptr==p_locale) + return true; + ptr++; + } + + return false; + +} Vector<String> TranslationServer::get_all_locales() { diff --git a/core/translation.h b/core/translation.h index 85ab4a229d..feed352549 100644 --- a/core/translation.h +++ b/core/translation.h @@ -102,6 +102,7 @@ public: static Vector<String> get_all_locales(); static Vector<String> get_all_locale_names(); + static bool is_locale_valid(const String& p_locale); void set_tool_translation(const Ref<Translation>& p_translation); StringName tool_translate(const StringName& p_message) const; diff --git a/core/typedefs.h b/core/typedefs.h index 176c77570d..c630887924 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -40,41 +40,39 @@ #define _STR(m_x) #m_x #define _MKSTR(m_x) _STR(m_x) #endif -// have to include version.h for this to work, include it in the .cpp not the .h + +/** + * Version macros - it is necessary to include "version.h" for those to work. + * Include it in the .cpp file, not the header. + */ #ifdef VERSION_PATCH -#define VERSION_MKSTRING _MKSTR(VERSION_MAJOR)"." _MKSTR(VERSION_MINOR)"." _MKSTR(VERSION_PATCH)"." _MKSTR(VERSION_STATUS)"." _MKSTR(VERSION_REVISION) +#define VERSION_MKSTRING "" _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR) "." _MKSTR(VERSION_PATCH) "." _MKSTR(VERSION_STATUS) "." _MKSTR(VERSION_REVISION) #else -#define VERSION_MKSTRING _MKSTR(VERSION_MAJOR)"." _MKSTR(VERSION_MINOR)"." _MKSTR(VERSION_STATUS)"." _MKSTR(VERSION_REVISION) +#define VERSION_MKSTRING "" _MKSTR(VERSION_MAJOR) "." _MKSTR(VERSION_MINOR) "." _MKSTR(VERSION_STATUS) "." _MKSTR(VERSION_REVISION) #endif // VERSION_PATCH -#define VERSION_FULL_NAME _MKSTR(VERSION_NAME)" v" VERSION_MKSTRING +#define VERSION_FULL_NAME "" _MKSTR(VERSION_NAME) " v" VERSION_MKSTRING #ifndef _ALWAYS_INLINE_ #if defined(__GNUC__) && (__GNUC__ >= 4 ) -# define _ALWAYS_INLINE_ __attribute__((always_inline)) inline +#define _ALWAYS_INLINE_ __attribute__((always_inline)) inline #elif defined(__llvm__) -# define _ALWAYS_INLINE_ __attribute__((always_inline)) inline +#define _ALWAYS_INLINE_ __attribute__((always_inline)) inline #elif defined(_MSC_VER) -# define _ALWAYS_INLINE_ __forceinline +#define _ALWAYS_INLINE_ __forceinline #else -# define _ALWAYS_INLINE_ inline +#define _ALWAYS_INLINE_ inline #endif #endif #ifndef _FORCE_INLINE_ - #ifdef DEBUG_ENABLED - #define _FORCE_INLINE_ inline - #else - #define _FORCE_INLINE_ _ALWAYS_INLINE_ - #endif - #endif @@ -97,16 +95,16 @@ T *_nullptr() { T*t=NULL; return t; } */ #ifdef _WIN32 -# undef min // override standard definition -# undef max // override standard definition -# undef ERROR // override (really stupid) wingdi.h standard definition -# undef DELETE // override (another really stupid) winnt.h standard definition -# undef MessageBox // override winuser.h standard definition -# undef MIN // override standard definition -# undef MAX // override standard definition -# undef CLAMP // override standard definition -# undef Error -# undef OK +#undef min // override standard definition +#undef max // override standard definition +#undef ERROR // override (really stupid) wingdi.h standard definition +#undef DELETE // override (another really stupid) winnt.h standard definition +#undef MessageBox // override winuser.h standard definition +#undef MIN // override standard definition +#undef MAX // override standard definition +#undef CLAMP // override standard definition +#undef Error +#undef OK #endif #include "error_macros.h" @@ -150,30 +148,30 @@ inline void __swap_tmpl(T &x, T &y ) { #endif //swap -#define HEX2CHR( m_hex ) ( (m_hex>='0' && m_hex<='9')?(m_hex-'0'):\ - ((m_hex>='A' && m_hex<='F')?(10+m_hex-'A'):\ - ((m_hex>='a' && m_hex<='f')?(10+m_hex-'a'):0))) +/* clang-format off */ +#define HEX2CHR(m_hex) \ + ((m_hex >= '0' && m_hex <= '9') ? (m_hex - '0') : \ + ((m_hex >= 'A' && m_hex <= 'F') ? (10 + m_hex - 'A') : \ + ((m_hex >= 'a' && m_hex <= 'f') ? (10 + m_hex - 'a') : 0))) +/* clang-format on */ // Macro to check whether we are compiled by clang // and we have a specific builtin #if defined(__llvm__) && defined(__has_builtin) - #define _llvm_has_builtin(x) __has_builtin(x) +#define _llvm_has_builtin(x) __has_builtin(x) #else - #define _llvm_has_builtin(x) 0 +#define _llvm_has_builtin(x) 0 #endif #if (defined(__GNUC__) && (__GNUC__ >= 5)) || _llvm_has_builtin(__builtin_mul_overflow) -# define _mul_overflow __builtin_mul_overflow +#define _mul_overflow __builtin_mul_overflow #endif #if (defined(__GNUC__) && (__GNUC__ >= 5)) || _llvm_has_builtin(__builtin_add_overflow) -# define _add_overflow __builtin_add_overflow +#define _add_overflow __builtin_add_overflow #endif - - - /** Function to find the nearest (bigger) power of 2 to an integer */ static _FORCE_INLINE_ unsigned int nearest_power_of_2(unsigned int x) { @@ -276,14 +274,11 @@ struct _GlobalLock { }; #define GLOBAL_LOCK_FUNCTION _GlobalLock _global_lock_; -#ifdef NO_SAFE_CAST +#ifdef NO_SAFE_CAST #define SAFE_CAST static_cast - #else - #define SAFE_CAST dynamic_cast - #endif #define MT_SAFE @@ -291,7 +286,4 @@ struct _GlobalLock { #define __STRX(m_index) #m_index #define __STR(m_index) __STRX(m_index) - - #endif /* typedefs.h */ - diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index acb262d400..1a0ccc4a7e 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "undo_redo.h" + #include "os/os.h" void UndoRedo::_discard_redo() { diff --git a/core/ustring.cpp b/core/ustring.cpp index 66608379be..a0d26ea0af 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -26,8 +26,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include <wchar.h> #include "ustring.h" + #include "os/memory.h" #include "print_string.h" #include "math_funcs.h" @@ -36,10 +36,8 @@ #include "ucaps.h" #include "color.h" #include "variant.h" -#define MAX_DIGITS 6 -#define UPPERCASE(m_c) (((m_c)>='a' && (m_c)<='z')?((m_c)-('a'-'A')):(m_c)) -#define LOWERCASE(m_c) (((m_c)>='A' && (m_c)<='Z')?((m_c)+('a'-'A')):(m_c)) +#include <wchar.h> #ifndef NO_USE_STDLIB #include <stdlib.h> @@ -50,6 +48,10 @@ #define snprintf _snprintf #endif +#define MAX_DIGITS 6 +#define UPPERCASE(m_c) (((m_c)>='a' && (m_c)<='z')?((m_c)-('a'-'A')):(m_c)) +#define LOWERCASE(m_c) (((m_c)>='A' && (m_c)<='Z')?((m_c)+('a'-'A')):(m_c)) + /** STRING **/ const char *CharString::get_data() const { @@ -1255,7 +1257,7 @@ _FORCE_INLINE static int parse_utf8_char(const char *p_utf8,unsigned int *p_ucs4 unichar=*p_utf8; else { - unichar=(0xFF >> (len +1)) & *p_utf8;; + unichar=(0xFF >> (len +1)) & *p_utf8; for (int i=1;i<len;i++) { @@ -1404,7 +1406,7 @@ bool String::parse_utf8(const char* p_utf8,int p_len) { unichar=*p_utf8; else { - unichar=(0xFF >> (len +1)) & *p_utf8;; + unichar=(0xFF >> (len +1)) & *p_utf8; for (int i=1;i<len;i++) { @@ -3408,8 +3410,17 @@ String String::c_escape() const { escaped=escaped.replace("\t","\\t"); escaped=escaped.replace("\v","\\v"); escaped=escaped.replace("\'","\\'"); - escaped=escaped.replace("\"","\\\""); escaped=escaped.replace("\?","\\?"); + escaped=escaped.replace("\"","\\\""); + + return escaped; +} + +String String::c_escape_multiline() const { + + String escaped=*this; + escaped=escaped.replace("\\","\\\\"); + escaped=escaped.replace("\"","\\\""); return escaped; } @@ -3896,10 +3907,9 @@ String String::get_extension() const { String String::plus_file(const String& p_file) const { if (empty()) return p_file; - if (operator [](length()-1)=='/' || p_file.operator [](0)=='/') + if (operator [](length()-1)=='/' || (p_file.size()>0 && p_file.operator [](0)=='/')) return *this+p_file; - else - return *this+"/"+p_file; + return *this+"/"+p_file; } String String::percent_encode() const { diff --git a/core/ustring.h b/core/ustring.h index 426762a9e1..5665a23112 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -218,6 +218,7 @@ public: String http_escape() const; String http_unescape() const; String c_escape() const; + String c_escape_multiline() const; String c_unescape() const; String json_escape() const; String word_wrap(int p_chars_per_line) const; diff --git a/core/variant.cpp b/core/variant.cpp index 5a670a2786..103c8f6746 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "variant.h" + #include "resource.h" #include "print_string.h" #include "scene/main/node.h" @@ -1764,7 +1765,7 @@ Variant::operator Transform() const { if (type==TRANSFORM2D) { return *_data._transform2d; } else if (type==TRANSFORM) { - const Transform& t = *_data._transform;; + const Transform& t = *_data._transform; Transform2D m; m.elements[0][0]=t.basis.elements[0][0]; m.elements[0][1]=t.basis.elements[1][0]; diff --git a/core/variant.h b/core/variant.h index 9d29fd64c3..5936325c1b 100644 --- a/core/variant.h +++ b/core/variant.h @@ -33,7 +33,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ -#include "aabb.h" +#include "rect3.h" #include "ustring.h" #include "vector3.h" #include "plane.h" diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 51ad115d46..022faede1e 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "variant.h" + #include "object.h" #include "os/os.h" #include "core_string_names.h" @@ -1052,32 +1053,32 @@ Variant Variant::construct(const Variant::Type p_type, const Variant** p_args, i // math types - case VECTOR2: return Vector2(); // 5 + case VECTOR2: return Vector2(); // 5 case RECT2: return Rect2(); case VECTOR3: return Vector3(); case TRANSFORM2D: return Transform2D(); case PLANE: return Plane(); case QUAT: return Quat(); - case RECT3: return Rect3(); //sorry naming convention fail :( not like it's used often // 10 + case RECT3: return Rect3(); // 10 case BASIS: return Basis(); case TRANSFORM: return Transform(); // misc types case COLOR: return Color(); - case IMAGE: return Image();; - case NODE_PATH: return NodePath();; // 15 - case _RID: return RID();; + case IMAGE: return Image(); + case NODE_PATH: return NodePath(); // 15 + case _RID: return RID(); case OBJECT: return (Object*)NULL; - case INPUT_EVENT: return InputEvent();; - case DICTIONARY: return Dictionary();; - case ARRAY: return Array();; // 20 - case POOL_BYTE_ARRAY: return PoolByteArray();; - case POOL_INT_ARRAY: return PoolIntArray();; - case POOL_REAL_ARRAY: return PoolRealArray();; - case POOL_STRING_ARRAY: return PoolStringArray();; - case POOL_VECTOR2_ARRAY: return PoolVector2Array();; // 25 - case POOL_VECTOR3_ARRAY: return PoolVector3Array();; // 25 - case POOL_COLOR_ARRAY: return PoolColorArray();; + case INPUT_EVENT: return InputEvent(); + case DICTIONARY: return Dictionary(); + case ARRAY: return Array(); // 20 + case POOL_BYTE_ARRAY: return PoolByteArray(); + case POOL_INT_ARRAY: return PoolIntArray(); + case POOL_REAL_ARRAY: return PoolRealArray(); + case POOL_STRING_ARRAY: return PoolStringArray(); + case POOL_VECTOR2_ARRAY: return PoolVector2Array(); // 25 + case POOL_VECTOR3_ARRAY: return PoolVector3Array(); + case POOL_COLOR_ARRAY: return PoolColorArray(); default: return Variant(); } @@ -1126,27 +1127,27 @@ Variant Variant::construct(const Variant::Type p_type, const Variant** p_args, i case VECTOR3: return (Vector3(*p_args[0])); case PLANE: return (Plane(*p_args[0])); case QUAT: return (Quat(*p_args[0])); - case RECT3: return (Rect3(*p_args[0])); //sorry naming convention fail :( not like it's used often // 10 + case RECT3: return (Rect3(*p_args[0])); // 10 case BASIS: return (Basis(p_args[0]->operator Basis())); case TRANSFORM: return (Transform(p_args[0]->operator Transform())); // misc types case COLOR: return p_args[0]->type == Variant::STRING ? Color::html(*p_args[0]) : Color::hex(*p_args[0]); case IMAGE: return (Image(*p_args[0])); - case NODE_PATH: return (NodePath(p_args[0]->operator NodePath())); // 15 + case NODE_PATH: return (NodePath(p_args[0]->operator NodePath())); // 15 case _RID: return (RID(*p_args[0])); case OBJECT: return ((Object*)(p_args[0]->operator Object *())); case INPUT_EVENT: return (InputEvent(*p_args[0])); case DICTIONARY: return p_args[0]->operator Dictionary(); - case ARRAY: return p_args[0]->operator Array(); + case ARRAY: return p_args[0]->operator Array(); // 20 // arrays case POOL_BYTE_ARRAY: return (PoolByteArray(*p_args[0])); case POOL_INT_ARRAY: return (PoolIntArray(*p_args[0])); case POOL_REAL_ARRAY: return (PoolRealArray(*p_args[0])); case POOL_STRING_ARRAY: return (PoolStringArray(*p_args[0])); - case POOL_VECTOR2_ARRAY: return (PoolVector2Array(*p_args[0])); // 25 - case POOL_VECTOR3_ARRAY: return (PoolVector3Array(*p_args[0])); // 25 + case POOL_VECTOR2_ARRAY: return (PoolVector2Array(*p_args[0])); // 25 + case POOL_VECTOR3_ARRAY: return (PoolVector3Array(*p_args[0])); case POOL_COLOR_ARRAY: return (PoolColorArray(*p_args[0])); default: return Variant(); } diff --git a/core/variant_construct_string.cpp b/core/variant_construct_string.cpp index 8db756aa79..56aa9891fb 100644 --- a/core/variant_construct_string.cpp +++ b/core/variant_construct_string.cpp @@ -169,7 +169,7 @@ Error VariantConstruct::_get_token(const CharType *p_str, int &idx, int p_len, T case 'r': res=13; break; case '\"': res='\"'; break; case '\\': res='\\'; break; - case '/': res='/'; break; //wtf + case '/': res='/'; break; case 'u': { //hexnumbarh - oct is deprecated diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 50f0b96715..6ed8a3dd85 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -27,9 +27,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "variant.h" + #include "object.h" #include "script_language.h" #include "core_string_names.h" + Variant::operator bool() const { bool b; diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index ca748b7fd3..3507501f27 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -27,11 +27,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "variant_parser.h" + #include "io/resource_loader.h" #include "os/keyboard.h" - CharType VariantParser::StreamFile::get_char() { return f->get_8(); @@ -430,7 +430,7 @@ Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String>& strings, Token token; get_token(p_stream,token,line,r_err_str); if (token.type!=TK_PARENTHESIS_OPEN) { - r_err_str="Expected '(' in old-style engine.cfg construct"; + r_err_str="Expected '(' in old-style godot.cfg construct"; return ERR_PARSE_ERROR; } @@ -442,7 +442,7 @@ Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String>& strings, CharType c=p_stream->get_char(); if (p_stream->is_eof()) { - r_err_str="Unexpected EOF while parsing old-style engine.cfg construct"; + r_err_str="Unexpected EOF while parsing old-style godot.cfg construct"; return ERR_PARSE_ERROR; } @@ -1328,7 +1328,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value=arr; return OK; - } else if (id=="key") { // compatibility with engine.cfg + } else if (id=="key") { // compatibility with godot.cfg Vector<String> params; Error err = _parse_enginecfg(p_stream,params,line,r_err_str); @@ -1364,7 +1364,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value=ie; return OK; - } else if (id=="mbutton") { // compatibility with engine.cfg + } else if (id=="mbutton") { // compatibility with godot.cfg Vector<String> params; Error err = _parse_enginecfg(p_stream,params,line,r_err_str); @@ -1379,7 +1379,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value=ie; return OK; - } else if (id=="jbutton") { // compatibility with engine.cfg + } else if (id=="jbutton") { // compatibility with godot.cfg Vector<String> params; Error err = _parse_enginecfg(p_stream,params,line,r_err_str); @@ -1394,7 +1394,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value=ie; return OK; - } else if (id=="jaxis") { // compatibility with engine.cfg + } else if (id=="jaxis") { // compatibility with godot.cfg Vector<String> params; Error err = _parse_enginecfg(p_stream,params,line,r_err_str); @@ -1412,19 +1412,19 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value= ie; return OK; - } else if (id=="img") { // compatibility with engine.cfg + } else if (id=="img") { // compatibility with godot.cfg Token token; get_token(p_stream,token,line,r_err_str); if (token.type!=TK_PARENTHESIS_OPEN) { - r_err_str="Expected '(' in old-style engine.cfg construct"; + r_err_str="Expected '(' in old-style godot.cfg construct"; return ERR_PARSE_ERROR; } while(true) { CharType c = p_stream->get_char(); if (p_stream->is_eof()) { - r_err_str="Unexpected EOF in old style engine.cfg img()"; + r_err_str="Unexpected EOF in old style godot.cfg img()"; return ERR_PARSE_ERROR; } if (c==')') @@ -1873,7 +1873,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str String str=p_variant; - str="\""+str.c_escape()+"\""; + str="\""+str.c_escape_multiline()+"\""; p_store_string_func(p_store_string_ud, str ); } break; case Variant::VECTOR2: { @@ -1989,7 +1989,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str PoolVector<uint8_t> data = img.get_data(); int len = data.size(); PoolVector<uint8_t>::Read r = data.read(); - const uint8_t *ptr=r.ptr();; + const uint8_t *ptr=r.ptr(); for (int i=0;i<len;i++) { if (i>0) @@ -2091,7 +2091,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str dict.get_key_list(&keys); keys.sort(); - p_store_string_func(p_store_string_ud,"{ "); + p_store_string_func(p_store_string_ud,"{\n"); for(List<Variant>::Element *E=keys.front();E;E=E->next()) { /* @@ -2099,14 +2099,14 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str continue; */ write(E->get(),p_store_string_func,p_store_string_ud,p_encode_res_func,p_encode_res_ud); - p_store_string_func(p_store_string_ud,":"); + p_store_string_func(p_store_string_ud,": "); write(dict[E->get()],p_store_string_func,p_store_string_ud,p_encode_res_func,p_encode_res_ud); if (E->next()) - p_store_string_func(p_store_string_ud,", "); + p_store_string_func(p_store_string_ud,",\n"); } - p_store_string_func(p_store_string_ud," }"); + p_store_string_func(p_store_string_ud,"\n}"); } break; @@ -2133,7 +2133,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str PoolVector<uint8_t> data = p_variant; int len = data.size(); PoolVector<uint8_t>::Read r = data.read(); - const uint8_t *ptr=r.ptr();; + const uint8_t *ptr=r.ptr(); for (int i=0;i<len;i++) { if (i>0) @@ -2152,7 +2152,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str PoolVector<int> data = p_variant; int len = data.size(); PoolVector<int>::Read r = data.read(); - const int *ptr=r.ptr();; + const int *ptr=r.ptr(); for (int i=0;i<len;i++) { @@ -2172,7 +2172,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str PoolVector<real_t> data = p_variant; int len = data.size(); PoolVector<real_t>::Read r = data.read(); - const real_t *ptr=r.ptr();; + const real_t *ptr=r.ptr(); for (int i=0;i<len;i++) { @@ -2190,7 +2190,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str PoolVector<String> data = p_variant; int len = data.size(); PoolVector<String>::Read r = data.read(); - const String *ptr=r.ptr();; + const String *ptr=r.ptr(); String s; //write_string("\n"); @@ -2213,7 +2213,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str PoolVector<Vector2> data = p_variant; int len = data.size(); PoolVector<Vector2>::Read r = data.read(); - const Vector2 *ptr=r.ptr();; + const Vector2 *ptr=r.ptr(); for (int i=0;i<len;i++) { @@ -2231,7 +2231,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str PoolVector<Vector3> data = p_variant; int len = data.size(); PoolVector<Vector3>::Read r = data.read(); - const Vector3 *ptr=r.ptr();; + const Vector3 *ptr=r.ptr(); for (int i=0;i<len;i++) { @@ -2250,7 +2250,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str PoolVector<Color> data = p_variant; int len = data.size(); PoolVector<Color>::Read r = data.read(); - const Color *ptr=r.ptr();; + const Color *ptr=r.ptr(); for (int i=0;i<len;i++) { diff --git a/core/vector.h b/core/vector.h index 3119657cbb..1cb3fee256 100644 --- a/core/vector.h +++ b/core/vector.h @@ -81,7 +81,7 @@ class Vector { size_t p; if (_mul_overflow(p_elements, sizeof(T), &o)) return false; *out = nearest_power_of_2(o); - if (_add_overflow(o, 32, &p)) return false; //no longer allocated here + if (_add_overflow(o, static_cast<size_t>(32), &p)) return false; //no longer allocated here return true; #else // Speed is more important than correctness here, do the operations unchecked diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 0088f576f0..8204af9fd4 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -463,7 +463,7 @@ <argument index="1" name="to" type="float"> </argument> <description> - Random range, any floating point value between 'from' and 'to' + Random range, any floating point value between 'from' and 'to'. </description> </method> <method name="rand_seed"> @@ -472,28 +472,28 @@ <argument index="0" name="seed" type="int"> </argument> <description> - Random from seed, pass a seed and an array with both number and new seed is returned. + Random from seed: pass a seed, and an array with both number and new seed is returned. "Seed" here refers to the internal state of the pseudo random number generator. The internal state of the current implementation is 64 bits. </description> </method> <method name="randf"> <return type="float"> </return> <description> - Random value (0 to 1 float). + Return a random floating point value between 0 and 1. </description> </method> <method name="randi"> <return type="int"> </return> <description> - Random 32 bits value (integer). To obtain a value from 0 to N, you can use remainder, like (for random from 0 to 19): randi() % 20. + Return a random 32 bits integer value. To obtain a random value between 0 to N (where N is smaller than 2^32 - 1), you can use remainder. For example, to get a random integer between 0 and 19 inclusive, you can use randi() % 20. </description> </method> <method name="randomize"> <return type="Nil"> </return> <description> - Reset the seed of the random number generator with a new, different one. + Randomize the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time. </description> </method> <method name="range"> @@ -667,7 +667,7 @@ </methods> <constants> <constant name="PI" value="3.141593"> - Constant that represents how many times the diameter of a circumference fits around it's perimeter. + Constant that represents how many times the diameter of a circumference fits around its perimeter. </constant> </constants> </class> @@ -8025,7 +8025,7 @@ Circular Shape for 2D Physics. </brief_description> <description> - Circular Shape for 2D Physics. This shape is useful for modeling balls or small characters and it's collision detection with everything else is very fast. + Circular Shape for 2D Physics. This shape is useful for modeling balls or small characters and its collision detection with everything else is very fast. </description> <methods> <method name="get_radius" qualifiers="const"> @@ -11258,7 +11258,7 @@ This function is called for each file exported and depending from the return value one of many things might happen. 1) If returned value is null, the file is exported as is. 2) If the returned value is a RawAray (array of bytes), the content of that array becomes the new file being exported. - 3) If the file must also change it's name when exported, then a [Dictionary] must be returned with two fields: 'name' with the new filename and 'data' with a [RawArray] containing the raw contents of the file. Even if the name is changed, the run-time will redirect the old file to the new file automatically when accessed. + 3) If the file must also change its name when exported, then a [Dictionary] must be returned with two fields: 'name' with the new filename and 'data' with a [RawArray] containing the raw contents of the file. Even if the name is changed, the run-time will redirect the old file to the new file automatically when accessed. </description> </method> </methods> @@ -11706,7 +11706,7 @@ </class> <class name="EditorPlugin" inherits="Node" category="Core"> <brief_description> - Used by the editor to extend it's functionality. + Used by the editor to extend its functionality. </brief_description> <description> Plugins are used by the editor to extend functionality. The most common types of plugins are those which edit a given node or resource type, import plugins and export plugins. @@ -12005,7 +12005,7 @@ </method> <method name="save_external_data" qualifiers="virtual"> <description> - This method is called after the editor save the project or when the it's closed. It asks the plugin to save edited external scenes/resources. + This method is called after the editor saves the project or when it's closed. It asks the plugin to save edited external scenes/resources. </description> </method> <method name="set_state" qualifiers="virtual"> @@ -14300,7 +14300,7 @@ Contains global variables accessible from everywhere. </brief_description> <description> - Contains global variables accessible from everywhere. Use the normal [Object] API, such as "Globals.get(variable)", "Globals.set(variable,value)" or "Globals.has(variable)" to access them. Variables stored in engine.cfg are also loaded into globals, making this object very useful for reading custom game configuration options. + Contains global variables accessible from everywhere. Use the normal [Object] API, such as "Globals.get(variable)", "Globals.set(variable,value)" or "Globals.has(variable)" to access them. Variables stored in godot.cfg are also loaded into globals, making this object very useful for reading custom game configuration options. </description> <methods> <method name="add_property_info"> @@ -15970,7 +15970,7 @@ Request does not have a response(yet). </constant> <constant name="RESULT_BODY_SIZE_LIMIT_EXCEEDED" value="7"> - Request exceded it's maximum size limit, see [method set_body_size_limit]. + Request exceded its maximum size limit, see [method set_body_size_limit]. </constant> <constant name="RESULT_REQUEST_FAILED" value="8"> Request failed. (unused) @@ -15982,7 +15982,7 @@ HTTPRequest couldn't write to the download file. </constant> <constant name="RESULT_REDIRECT_LIMIT_REACHED" value="11"> - Request reached it's maximum redirect limit, see [method set_max_redirects]. + Request reached its maximum redirect limit, see [method set_max_redirects]. </constant> </constants> </class> @@ -16088,7 +16088,7 @@ <argument index="0" name="id" type="int"> </argument> <description> - Return the status of hostname queued for resolving, given it's queue ID. Returned status can be any of the RESOLVER_STATUS_* enumeration. + Return the status of hostname queued for resolving, given its queue ID. Returned status can be any of the RESOLVER_STATUS_* enumeration. </description> </method> <method name="resolve_hostname"> @@ -22660,7 +22660,7 @@ Nodes can also process input events. When set, the [method _input] function will be called for each input that the program receives. In many cases, this can be overkill (unless used for simple projects), and the [method _unhandled_input] function might be preferred; it is called when the input event was not handled by anyone else (typically, GUI [Control] nodes), ensuring that the node only receives the events that were meant for it. To keep track of the scene hierarchy (especially when instancing scenes into other scenes), an "owner" can be set for the node with [method set_owner]. This keeps track of who instanced what. This is mostly useful when writing editors and tools, though. Finally, when a node is freed with [method free] or [method queue_free], it will also free all its children. - [b]Networking with nodes:[/b] After connecting to a server (or making one, see [NetworkedMultiplayerENet]) it is possible to use the built-in RPC (remote procedure call) system to easily communicate over the network. By calling [method rpc] with a method name, it will be called locally, and in all connected peers (peers = clients and the server that accepts connections), with behaviour varying depending on the network mode ([method set_network_mode]) on the receiving peer. To identify which [Node] receives the RPC call Godot will use it's [NodePath] (make sure node names are the same on all peers). + [b]Networking with nodes:[/b] After connecting to a server (or making one, see [NetworkedMultiplayerENet]) it is possible to use the built-in RPC (remote procedure call) system to easily communicate over the network. By calling [method rpc] with a method name, it will be called locally, and in all connected peers (peers = clients and the server that accepts connections), with behaviour varying depending on the network mode ([method set_network_mode]) on the receiving peer. To identify which [Node] receives the RPC call Godot will use its [NodePath] (make sure node names are the same on all peers). </description> <methods> <method name="_enter_tree" qualifiers="virtual"> @@ -33832,7 +33832,7 @@ </signal> <signal name="sleeping_state_changed"> <description> - Emitted when the body changes it's sleeping state. Either by sleeping or waking up. + Emitted when the body changes its sleeping state. Either by sleeping or waking up. </description> </signal> </signals> @@ -34227,7 +34227,7 @@ </signal> <signal name="sleeping_state_changed"> <description> - Emitted when the body changes it's sleeping state. Either by sleeping or waking up. + Emitted when the body changes its sleeping state. Either by sleeping or waking up. </description> </signal> </signals> @@ -35889,7 +35889,7 @@ <return type="Error"> </return> <description> - Tries to wait for the [Semaphore], if it's value is zero, blocks until non-zero. + Tries to wait for the [Semaphore], if its value is zero, blocks until non-zero. </description> </method> </methods> diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp index b026241579..8984d412a3 100644 --- a/drivers/alsa/audio_driver_alsa.cpp +++ b/drivers/alsa/audio_driver_alsa.cpp @@ -30,11 +30,9 @@ #ifdef ALSA_ENABLED -#include <errno.h> #include "globals.h" - - +#include <errno.h> Error AudioDriverALSA::init() { @@ -46,7 +44,7 @@ Error AudioDriverALSA::init() { samples_out = NULL; mix_rate = GLOBAL_DEF("audio/mix_rate",44100); - output_format = OUTPUT_STEREO; + speaker_mode = SPEAKER_MODE_STEREO; channels = 2; @@ -205,16 +203,18 @@ int AudioDriverALSA::get_mix_rate() const { return mix_rate; }; -AudioDriverSW::OutputFormat AudioDriverALSA::get_output_format() const { +AudioDriver::SpeakerMode AudioDriverALSA::get_speaker_mode() const { - return output_format; + return speaker_mode; }; + void AudioDriverALSA::lock() { if (!thread || !mutex) return; mutex->lock(); }; + void AudioDriverALSA::unlock() { if (!thread || !mutex) diff --git a/drivers/alsa/audio_driver_alsa.h b/drivers/alsa/audio_driver_alsa.h index df28294f56..6ab98312b2 100644 --- a/drivers/alsa/audio_driver_alsa.h +++ b/drivers/alsa/audio_driver_alsa.h @@ -26,7 +26,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #ifdef ALSA_ENABLED @@ -35,7 +35,7 @@ #include <alsa/asoundlib.h> -class AudioDriverALSA : public AudioDriverSW { +class AudioDriverALSA : public AudioDriver { Thread* thread; Mutex* mutex; @@ -48,7 +48,7 @@ class AudioDriverALSA : public AudioDriverSW { static void thread_func(void* p_udata); unsigned int mix_rate; - OutputFormat output_format; + SpeakerMode speaker_mode; snd_pcm_uframes_t buffer_size; snd_pcm_uframes_t period_size; @@ -68,7 +68,7 @@ public: virtual Error init(); virtual void start(); virtual int get_mix_rate() const; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/drivers/convex_decomp/b2Polygon.cpp b/drivers/convex_decomp/b2Polygon.cpp index f45d98250a..b6ead62c63 100644 --- a/drivers/convex_decomp/b2Polygon.cpp +++ b/drivers/convex_decomp/b2Polygon.cpp @@ -353,7 +353,7 @@ bool b2Polygon::IsUsable(bool printErrors){ b2Vec2 centroid = PolyCentroid(vertices,nVertices); b2Vec2 n1 = normals[iminus]; b2Vec2 n2 = normals[i]; - b2Vec2 v = vertices[i] - centroid;; + b2Vec2 v = vertices[i] - centroid; b2Vec2 d; d.x = b2Dot(n1, v) - toiSlop; diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index fd3e5e508e..1486e85a04 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -3259,7 +3259,7 @@ void RasterizerGLES2::particles_set_emitting(RID p_particles, bool p_emitting) { Particles* particles = particles_owner.get( p_particles ); ERR_FAIL_COND(!particles); - particles->data.emitting=p_emitting;; + particles->data.emitting=p_emitting; } bool RasterizerGLES2::particles_is_emitting(RID p_particles) const { @@ -3468,7 +3468,7 @@ void RasterizerGLES2::particles_set_attractor_pos(RID p_particles, int p_attract Particles* particles = particles_owner.get( p_particles ); ERR_FAIL_COND(!particles); ERR_FAIL_INDEX(p_attractor,particles->data.attractor_count); - particles->data.attractors[p_attractor].pos=p_pos;; + particles->data.attractors[p_attractor].pos=p_pos; } Vector3 RasterizerGLES2::particles_get_attractor_pos(RID p_particles,int p_attractor) const { @@ -7855,7 +7855,7 @@ void RasterizerGLES2::_debug_draw_shadow(GLuint tex, const Rect2& p_rect) { - Matrix32 modelview; + Transform2D modelview; modelview.translate(p_rect.pos.x, p_rect.pos.y); canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX, modelview); glBindTexture(GL_TEXTURE_2D,tex); @@ -8073,8 +8073,8 @@ void RasterizerGLES2::canvas_begin() { canvas_transform.scale( Vector3( 2.0f / viewport.width, csy * -2.0f / viewport.height, 1.0f ) ); canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform); - canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,Matrix32()); - canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Matrix32()); + canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,Transform2D()); + canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D()); canvas_opacity=1.0; canvas_blend_mode=VS::MATERIAL_BLEND_MODE_MIX; @@ -8138,11 +8138,11 @@ void RasterizerGLES2::canvas_set_blend_mode(VS::MaterialBlendMode p_mode) { } -void RasterizerGLES2::canvas_begin_rect(const Matrix32& p_transform) { +void RasterizerGLES2::canvas_begin_rect(const Transform2D& p_transform) { canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,p_transform); - canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Matrix32()); + canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D()); } @@ -8670,7 +8670,7 @@ void RasterizerGLES2::canvas_draw_polygon(int p_vertex_count, const int* p_indic }; -void RasterizerGLES2::canvas_set_transform(const Matrix32& p_transform) { +void RasterizerGLES2::canvas_set_transform(const Transform2D& p_transform) { canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,p_transform); @@ -8880,7 +8880,7 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) { return canvas_light_shadow_owner.make_rid(cls); } -void RasterizerGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache) { +void RasterizerGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache) { CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_buffer); ERR_FAIL_COND(!cls); @@ -9602,7 +9602,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform); - canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Matrix32()); + canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D()); bool reclip=false; @@ -9715,7 +9715,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const } canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform); - canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Matrix32()); + canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D()); canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform); if (canvas_use_modulate) canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE,canvas_modulate); @@ -9782,7 +9782,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const } canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform); - canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Matrix32()); + canvas_shader.set_uniform(CanvasShaderGLES2::EXTRA_MATRIX,Transform2D()); if (canvas_use_modulate) canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE,canvas_modulate); diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h index c6057bfd88..ddcd97ec4a 100644 --- a/drivers/gles2/rasterizer_gles2.h +++ b/drivers/gles2/rasterizer_gles2.h @@ -1429,7 +1429,7 @@ public: virtual void multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color); virtual RID multimesh_get_mesh(RID p_multimesh) const; - virtual AABB multimesh_get_aabb(RID p_multimesh) const;; + virtual AABB multimesh_get_aabb(RID p_multimesh) const; virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const; virtual Color multimesh_instance_get_color(RID p_multimesh,int p_index) const; @@ -1630,7 +1630,7 @@ public: virtual void canvas_set_opacity(float p_opacity); virtual void canvas_set_blend_mode(VS::MaterialBlendMode p_mode); - virtual void canvas_begin_rect(const Matrix32& p_transform); + virtual void canvas_begin_rect(const Transform2D& p_transform); virtual void canvas_set_clip(bool p_clip, const Rect2& p_rect); virtual void canvas_end_rect(); virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width,bool p_antialiased); @@ -1638,7 +1638,7 @@ public: virtual void canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margins, bool p_draw_center=true,const Color& p_modulate=Color(1,1,1)); virtual void canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width); virtual void canvas_draw_polygon(int p_vertex_count, const int* p_indices, const Vector2* p_vertices, const Vector2* p_uvs, const Color* p_colors,const RID& p_texture,bool p_singlecolor); - virtual void canvas_set_transform(const Matrix32& p_transform); + virtual void canvas_set_transform(const Transform2D& p_transform); virtual void canvas_render_items(CanvasItem *p_item_list,int p_z,const Color& p_modulate,CanvasLight *p_light); virtual void canvas_debug_viewport_shadows(CanvasLight* p_lights_with_shadow); @@ -1647,7 +1647,7 @@ public: //buffer virtual RID canvas_light_shadow_buffer_create(int p_width); - virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache); + virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache); //occluder virtual RID canvas_light_occluder_create(); diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp index 247a35141e..a5aa570e33 100644 --- a/drivers/gles2/shader_compiler_gles2.cpp +++ b/drivers/gles2/shader_compiler_gles2.cpp @@ -441,7 +441,8 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a } else if (custom_h && callfunc=="cosh_custom") { if (!cosh_used) { - global_code= "float cosh_custom(float val)\n"\ + global_code= + "float cosh_custom(float val)\n"\ "{\n"\ " float tmp = exp(val);\n"\ " float cosH = (tmp + 1.0 / tmp) / 2.0;\n"\ @@ -453,7 +454,8 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a } else if (custom_h && callfunc=="sinh_custom") { if (!sinh_used) { - global_code= "float sinh_custom(float val)\n"\ + global_code= + "float sinh_custom(float val)\n"\ "{\n"\ " float tmp = exp(val);\n"\ " float sinH = (tmp - 1.0 / tmp) / 2.0;\n"\ @@ -465,7 +467,8 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a } else if (custom_h && callfunc=="tanh_custom") { if (!tanh_used) { - global_code= "float tanh_custom(float val)\n"\ + global_code= + "float tanh_custom(float val)\n"\ "{\n"\ " float tmp = exp(val);\n"\ " float tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);\n"\ diff --git a/drivers/gles2/shader_gles2.h b/drivers/gles2/shader_gles2.h index ea9958741a..509f9a82b4 100644 --- a/drivers/gles2/shader_gles2.h +++ b/drivers/gles2/shader_gles2.h @@ -213,7 +213,7 @@ private: case Variant::MATRIX32: { - Matrix32 tr=p_value; + Transform2D tr=p_value; GLfloat matrix[16]={ /* build a 16x16 matrix */ tr.elements[0][0], tr.elements[0][1], diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index e658fbbe88..2923dfff9f 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -1,6 +1,10 @@ #include "rasterizer_canvas_gles3.h" #include "os/os.h" +#ifndef GLES_OVER_GL +#define glClearDepth glClearDepthf +#endif + static _FORCE_INLINE_ void store_transform2d(const Transform2D& p_mtx, float* p_array) { p_array[ 0]=p_mtx.elements[0][0]; @@ -87,7 +91,7 @@ void RasterizerCanvasGLES3::light_internal_update(RID p_rid, Light* p_light) { if (p_light->radius_cache==0) li->ubo_data.shadow_gradient=0; else - li->ubo_data.shadow_gradient=p_light->shadow_gradient_length/(p_light->radius_cache*1.1);; + li->ubo_data.shadow_gradient=p_light->shadow_gradient_length/(p_light->radius_cache*1.1); li->ubo_data.shadow_distance_mult=(p_light->radius_cache*1.1); @@ -1138,7 +1142,7 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list,int p_z,const state.canvas_shader.set_uniform(CanvasShaderGLES3::MODELVIEW_MATRIX,state.final_transform); - state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Matrix32()); + state.canvas_shader.set_uniform(CanvasShaderGLES3::EXTRA_MATRIX,Transform2D()); state.canvas_shader.set_uniform(CanvasShaderGLES3::FINAL_MODULATE,state.canvas_item_modulate); glBlendEquation(GL_FUNC_ADD); diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index b7616db8b1..e1ddad0dc9 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -167,6 +167,7 @@ void RasterizerGLES3::initialize() { void RasterizerGLES3::begin_frame(){ + uint64_t tick = OS::get_singleton()->get_ticks_usec(); double time_total = double(tick)/1000000.0; @@ -237,7 +238,7 @@ void RasterizerGLES3::set_current_render_target(RID p_render_target){ storage->frame.current_rt=NULL; storage->frame.clear_request=false; glViewport(0,0,OS::get_singleton()->get_window_size().width,OS::get_singleton()->get_window_size().height); - glBindFramebuffer(GL_FRAMEBUFFER,storage->config.system_fbo); + glBindFramebuffer(GL_FRAMEBUFFER,RasterizerStorageGLES3::system_fbo); } } @@ -268,7 +269,7 @@ void RasterizerGLES3::blit_render_target_to_screen(RID p_render_target,const Rec canvas->canvas_begin(); glDisable(GL_BLEND); - glBindFramebuffer(GL_FRAMEBUFFER,storage->config.system_fbo); + glBindFramebuffer(GL_FRAMEBUFFER,RasterizerStorageGLES3::system_fbo); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,rt->color); canvas->draw_generic_textured_rect(p_screen_rect,Rect2(0,0,1,-1)); diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index a026199bc7..b504ef819f 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -3,6 +3,10 @@ #include "os/os.h" #include "rasterizer_canvas_gles3.h" +#ifndef GLES_OVER_GL +#define glClearDepth glClearDepthf +#endif + static const GLenum _cube_side_enum[6]={ GL_TEXTURE_CUBE_MAP_NEGATIVE_X, @@ -141,9 +145,12 @@ void RasterizerSceneGLES3::shadow_atlas_set_size(RID p_atlas,int p_size){ GL_TEXTURE_2D, shadow_atlas->depth, 0); glViewport(0,0,shadow_atlas->size,shadow_atlas->size); - glClearDepth(0); + glClearDepth(0.0f); glClear(GL_DEPTH_BUFFER_BIT); + glBindFramebuffer(GL_FRAMEBUFFER,0); + + } } @@ -161,7 +168,7 @@ void RasterizerSceneGLES3::shadow_atlas_set_quadrant_subdivision(RID p_atlas,int subdiv<<=1; } - subdiv=int(Math::sqrt(subdiv)); + subdiv=int(Math::sqrt((float)subdiv)); //obtain the number that will be x*x @@ -553,6 +560,8 @@ void RasterizerSceneGLES3::reflection_atlas_set_size(RID p_ref_atlas,int p_size) } + + void RasterizerSceneGLES3::reflection_atlas_set_subdivision(RID p_ref_atlas,int p_subdiv) { ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(p_ref_atlas); @@ -563,7 +572,7 @@ void RasterizerSceneGLES3::reflection_atlas_set_subdivision(RID p_ref_atlas,int subdiv<<=1; } - subdiv=int(Math::sqrt(subdiv)); + subdiv=int(Math::sqrt((float)subdiv)); if (reflection_atlas->subdiv==subdiv) return; @@ -1077,6 +1086,18 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m state.current_line_width=p_material->line_width; } + if (state.current_depth_test!=(!p_material->shader->spatial.ontop)) { + if (p_material->shader->spatial.ontop) { + glDisable(GL_DEPTH_TEST); + + } else { + glEnable(GL_DEPTH_TEST); + + } + + state.current_depth_test=!p_material->shader->spatial.ontop; + } + if (state.current_depth_draw!=p_material->shader->spatial.depth_draw_mode) { switch(p_material->shader->spatial.depth_draw_mode) { case RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS: @@ -1200,6 +1221,11 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m } else { +#ifdef TOOLS_ENABLED + if (t->detect_3d) { + t->detect_3d(t->detect_3d_ud); + } +#endif if (storage->config.srgb_decode_supported) { //if SRGB decode extension is present, simply switch the texture to whathever is needed bool must_srgb=false; @@ -1212,9 +1238,8 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material* p_m if (must_srgb) { glTexParameteri(t->target,_TEXTURE_SRGB_DECODE_EXT,_DECODE_EXT); #ifdef TOOLS_ENABLED - if (!(t->flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)) { - t->flags|=VS::TEXTURE_FLAG_CONVERT_TO_LINEAR; - //notify that texture must be set to linear beforehand, so it works in other platforms when exported + if (t->detect_srgb) { + t->detect_srgb(t->detect_srgb_ud); } #endif @@ -1710,6 +1735,9 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements,int p_e state.cull_front=false; glCullFace(GL_BACK); + state.current_depth_test=true; + glEnable(GL_DEPTH_TEST); + state.scene_shader.set_conditional(SceneShaderGLES3::USE_SKELETON,false); state.current_blend_mode=-1; @@ -2270,9 +2298,9 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index,const Transform& float sign = li->light_ptr->negative?-1:1; Color linear_col = li->light_ptr->color.to_linear(); - ubo_data.light_color_energy[0]=linear_col.r*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];; - ubo_data.light_color_energy[1]=linear_col.g*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];; - ubo_data.light_color_energy[2]=linear_col.b*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];; + ubo_data.light_color_energy[0]=linear_col.r*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY]; + ubo_data.light_color_energy[1]=linear_col.g*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY]; + ubo_data.light_color_energy[2]=linear_col.b*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY]; ubo_data.light_color_energy[3]=0; //omni, keep at 0 @@ -2293,10 +2321,10 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index,const Transform& ubo_data.light_params[3]=0; Color shadow_color = li->light_ptr->shadow_color.to_linear(); - ubo_data.light_shadow_color[0]=shadow_color.r; - ubo_data.light_shadow_color[1]=shadow_color.g; - ubo_data.light_shadow_color[2]=shadow_color.b; - ubo_data.light_shadow_color[3]=1.0; + ubo_data.light_shadow_color_contact[0]=shadow_color.r; + ubo_data.light_shadow_color_contact[1]=shadow_color.g; + ubo_data.light_shadow_color_contact[2]=shadow_color.b; + ubo_data.light_shadow_color_contact[3]=li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE]; if (p_use_shadows && li->light_ptr->shadow) { @@ -2427,9 +2455,9 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result,int p_light_cu float sign = li->light_ptr->negative?-1:1; Color linear_col = li->light_ptr->color.to_linear(); - ubo_data.light_color_energy[0]=linear_col.r*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];; - ubo_data.light_color_energy[1]=linear_col.g*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];; - ubo_data.light_color_energy[2]=linear_col.b*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];; + ubo_data.light_color_energy[0]=linear_col.r*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY]; + ubo_data.light_color_energy[1]=linear_col.g*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY]; + ubo_data.light_color_energy[2]=linear_col.b*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY]; ubo_data.light_color_energy[3]=0; @@ -2452,10 +2480,10 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result,int p_light_cu ubo_data.light_params[3]=0; Color shadow_color = li->light_ptr->shadow_color.to_linear(); - ubo_data.light_shadow_color[0]=shadow_color.r; - ubo_data.light_shadow_color[1]=shadow_color.g; - ubo_data.light_shadow_color[2]=shadow_color.b; - ubo_data.light_shadow_color[3]=1.0; + ubo_data.light_shadow_color_contact[0]=shadow_color.r; + ubo_data.light_shadow_color_contact[1]=shadow_color.g; + ubo_data.light_shadow_color_contact[2]=shadow_color.b; + ubo_data.light_shadow_color_contact[3]=li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE]; if (li->light_ptr->shadow && shadow_atlas && shadow_atlas->shadow_owners.has(li->self)) { // fill in the shadow information @@ -2520,9 +2548,9 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result,int p_light_cu float sign = li->light_ptr->negative?-1:1; Color linear_col = li->light_ptr->color.to_linear(); - ubo_data.light_color_energy[0]=linear_col.r*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];; - ubo_data.light_color_energy[1]=linear_col.g*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];; - ubo_data.light_color_energy[2]=linear_col.b*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY];; + ubo_data.light_color_energy[0]=linear_col.r*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY]; + ubo_data.light_color_energy[1]=linear_col.g*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY]; + ubo_data.light_color_energy[2]=linear_col.b*sign*li->light_ptr->param[VS::LIGHT_PARAM_ENERGY]; ubo_data.light_color_energy[3]=0; Vector3 pos = p_camera_inverse_transform.xform(li->transform.origin); @@ -2545,10 +2573,10 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result,int p_light_cu ubo_data.light_params[3]=0; Color shadow_color = li->light_ptr->shadow_color.to_linear(); - ubo_data.light_shadow_color[0]=shadow_color.r; - ubo_data.light_shadow_color[1]=shadow_color.g; - ubo_data.light_shadow_color[2]=shadow_color.b; - ubo_data.light_shadow_color[3]=1.0; + ubo_data.light_shadow_color_contact[0]=shadow_color.r; + ubo_data.light_shadow_color_contact[1]=shadow_color.g; + ubo_data.light_shadow_color_contact[2]=shadow_color.b; + ubo_data.light_shadow_color_contact[3]=li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE]; if (li->light_ptr->shadow && shadow_atlas && shadow_atlas->shadow_owners.has(li->self)) { // fill in the shadow information @@ -3732,14 +3760,20 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C state.ubo_data.shadow_dual_paraboloid_render_side=0; state.ubo_data.shadow_dual_paraboloid_render_zfar=0; + if (storage->frame.current_rt) { + state.ubo_data.screen_pixel_size[0]=1.0/storage->frame.current_rt->width; + state.ubo_data.screen_pixel_size[1]=1.0/storage->frame.current_rt->height; + } + _setup_environment(env,p_cam_projection,p_cam_transform); bool fb_cleared=false; glDepthFunc(GL_LEQUAL); + state.used_contact_shadows=true; - if (storage->frame.current_rt && true) { + if (storage->frame.current_rt && true) { //detect with state.used_contact_shadows too //pre z pass @@ -3753,8 +3787,7 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C glViewport(0,0,storage->frame.current_rt->width,storage->frame.current_rt->height); glColorMask(0,0,0,0); - - glClearDepth(1.0); + glClearDepth(1.0f); glClear(GL_DEPTH_BUFFER_BIT); @@ -3767,6 +3800,19 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C glColorMask(1,1,1,1); + if (state.used_contact_shadows) { + + glBindFramebuffer(GL_READ_FRAMEBUFFER, storage->frame.current_rt->buffers.fbo); + glReadBuffer(GL_COLOR_ATTACHMENT0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, storage->frame.current_rt->fbo); + glBlitFramebuffer(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, 0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height, GL_DEPTH_BUFFER_BIT, GL_NEAREST); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + //bind depth for read + glActiveTexture(GL_TEXTURE0+storage->config.max_texture_image_units-8); + glBindTexture(GL_TEXTURE_2D,storage->frame.current_rt->depth); + } + fb_cleared=true; render_pass++; } @@ -3866,7 +3912,7 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C } if (!fb_cleared) { - glClearDepth(1.0); + glClearDepth(1.0f); glClear(GL_DEPTH_BUFFER_BIT); } @@ -3973,7 +4019,6 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C _render_mrts(env,p_cam_projection); } - glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glEnable(GL_BLEND); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); @@ -4401,25 +4446,25 @@ void RasterizerSceneGLES3::render_shadow(RID p_light,RID p_shadow_atlas,int p_pa render_list.sort_by_depth(false); //shadow is front to back for performance - glDepthMask(true); - glColorMask(1,1,1,1); glDisable(GL_BLEND); glDisable(GL_DITHER); glEnable(GL_DEPTH_TEST); glBindFramebuffer(GL_FRAMEBUFFER,fbo); + glDepthMask(true); + glColorMask(0,0,0,0); + if (custom_vp_size) { glViewport(0,0,custom_vp_size,custom_vp_size); glScissor(0,0,custom_vp_size,custom_vp_size); - } else { glViewport(x,y,width,height); glScissor(x,y,width,height); } glEnable(GL_SCISSOR_TEST); - glClearDepth(1.0); + glClearDepth(1.0f); glClear(GL_DEPTH_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); @@ -4432,7 +4477,7 @@ void RasterizerSceneGLES3::render_shadow(RID p_light,RID p_shadow_atlas,int p_pa state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH,true); - _render_list(render_list.elements,render_list.element_count,light_transform,light_projection,0,!flip_facing,false,true,false,false); + _render_list(render_list.elements,render_list.element_count,light_transform,light_projection,0,flip_facing,false,true,false,false); state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH,false); state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH_DUAL_PARABOLOID,false); @@ -4472,7 +4517,7 @@ void RasterizerSceneGLES3::render_shadow(RID p_light,RID p_shadow_atlas,int p_pa glViewport(local_x,local_y,local_width,local_height); glScissor(local_x,local_y,local_width,local_height); glEnable(GL_SCISSOR_TEST); - glClearDepth(1.0); + glClearDepth(1.0f); glClear(GL_DEPTH_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); //glDisable(GL_DEPTH_TEST); @@ -4564,7 +4609,7 @@ static _FORCE_INLINE_ Vector3 ImportanceSampleGGX(Vector2 Xi, float Roughness, V // Compute distribution direction float Phi = 2.0f * Math_PI * Xi.x; - float CosTheta = Math::sqrt((1.0f - Xi.y) / (1.0f + (a*a - 1.0f) * Xi.y)); + float CosTheta = Math::sqrt((float)(1.0f - Xi.y) / (1.0f + (a*a - 1.0f) * Xi.y)); float SinTheta = Math::sqrt((float)Math::abs(1.0f - CosTheta * CosTheta)); // Convert to spherical direction @@ -4612,7 +4657,7 @@ void RasterizerSceneGLES3::_generate_brdf() { float NoV = float(i+1)/(brdf_size); //avoid storing nov0 Vector3 V; - V.x = Math::sqrt( 1.0 - NoV * NoV ); + V.x = Math::sqrt( 1.0f - NoV * NoV ); V.y = 0.0; V.z = NoV; @@ -4991,12 +5036,12 @@ void RasterizerSceneGLES3::initialize() { void RasterizerSceneGLES3::iteration() { shadow_filter_mode=ShadowFilterMode(int(GlobalConfig::get_singleton()->get("rendering/gles3/shadow_filter_mode"))); - subsurface_scatter_follow_surface=GlobalConfig::get_singleton()->get("rendering/gles3/subsurface_scattering/follow_surface"); - subsurface_scatter_quality=SubSurfaceScatterQuality(int(GlobalConfig::get_singleton()->get("rendering/gles3/subsurface_scattering/quality"))); - subsurface_scatter_size=GlobalConfig::get_singleton()->get("rendering/gles3/subsurface_scattering/max_size"); + subsurface_scatter_follow_surface=GlobalConfig::get_singleton()->get("rendering/ssurf_scattering/follow_surface"); + subsurface_scatter_quality=SubSurfaceScatterQuality(int(GlobalConfig::get_singleton()->get("rendering/ssurf_scattering/quality"))); + subsurface_scatter_size=GlobalConfig::get_singleton()->get("rendering/ssurf_scattering/max_size"); - state.scene_shader.set_conditional(SceneShaderGLES3::VCT_QUALITY_HIGH,GlobalConfig::get_singleton()->get("rendering/gles3/high_quality_vct_gi")); + state.scene_shader.set_conditional(SceneShaderGLES3::VCT_QUALITY_HIGH,GlobalConfig::get_singleton()->get("rendering/reflections/high_quality_vct_gi")); } void RasterizerSceneGLES3::finalize(){ @@ -5007,5 +5052,4 @@ void RasterizerSceneGLES3::finalize(){ RasterizerSceneGLES3::RasterizerSceneGLES3() { - } diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index 7838345e59..81dfa1bf46 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -61,6 +61,7 @@ public: int current_blend_mode; float current_line_width; int current_depth_draw; + bool current_depth_test; GLuint current_main_tex; SceneShaderGLES3 scene_shader; @@ -90,6 +91,7 @@ public: float shadow_slope_scale; float shadow_dual_paraboloid_render_zfar; float shadow_dual_paraboloid_render_side; + float screen_pixel_size[2]; float shadow_atlas_pixel_size[2]; float shadow_directional_pixel_size[2]; float reflection_multiplier; @@ -135,6 +137,7 @@ public: int max_ubo_reflections; int max_skeleton_bones; + bool used_contact_shadows; int spot_light_count; @@ -209,7 +212,6 @@ public: bool _shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int *p_in_quadrants, int p_quadrant_count, int p_current_subdiv, uint64_t p_tick, int &r_quadrant, int &r_shadow); bool shadow_atlas_update_light(RID p_atlas,RID p_light_intance,float p_coverage,uint64_t p_light_version); - struct DirectionalShadow { GLuint fbo; GLuint depth; @@ -467,7 +469,7 @@ public: float light_color_energy[4]; float light_params[4]; //spot attenuation, spot angle, specular, shadow enabled float light_clamp[4]; - float light_shadow_color[4]; + float light_shadow_color_contact[4]; float shadow_matrix1[16]; //up to here for spot and omni, rest is for directional float shadow_matrix2[16]; float shadow_matrix3[16]; diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index f096719988..06daebbf82 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -78,6 +78,8 @@ #define _EXT_COMPRESSED_RGB_BPTC_SIGNED_FLOAT 0x8E8E #define _EXT_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT 0x8E8F +GLuint RasterizerStorageGLES3::system_fbo = 0; + Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,GLenum& r_gl_internal_format,GLenum &r_gl_type,bool &r_compressed,bool &srgb) { @@ -133,8 +135,12 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima } break; case Image::FORMAT_RGB565: { +#ifndef GLES_OVER_GL + r_gl_internal_format=GL_RGB565; +#else //#warning TODO: Convert tod 555 if 565 is not supported (GLES3.3-) r_gl_internal_format=GL_RGB5; +#endif //r_gl_internal_format=GL_RGB565; r_gl_format=GL_RGB; r_gl_type=GL_UNSIGNED_SHORT_5_6_5; @@ -212,7 +218,7 @@ Image RasterizerStorageGLES3::_get_gl_image_and_format(const Image& p_image, Ima if (config.s3tc_supported) { - r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT; + r_gl_internal_format=(config.srgb_decode_supported || p_flags&VS::TEXTURE_FLAG_CONVERT_TO_LINEAR)?_EXT_COMPRESSED_SRGB_S3TC_DXT1_NV:_EXT_COMPRESSED_RGBA_S3TC_DXT1_EXT; r_gl_format=GL_RGBA; r_gl_type=GL_UNSIGNED_BYTE; r_compressed=true; @@ -779,7 +785,7 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image if (texture->compressed) { glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - glCompressedTexImage2D( blit_target, i, format,w,h,0,size,&read[ofs] ); + glCompressedTexImage2D( blit_target, i, internal_format,w,h,0,size,&read[ofs] ); } else { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -808,6 +814,10 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && mipmaps==1 && !texture->ignore_mipmaps && (!(texture->flags&VS::TEXTURE_FLAG_CUBEMAP) || texture->stored_cube_sides==(1<<6)-1)) { //generate mipmaps if they were requested and the image does not contain them glGenerateMipmap(texture->target); + } else if (mipmaps>1) { + glTexParameteri(texture->target, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(texture->target, GL_TEXTURE_MAX_LEVEL, mipmaps-1); + } texture->mipmaps=mipmaps; @@ -1060,6 +1070,26 @@ void RasterizerStorageGLES3::textures_keep_original(bool p_enable) { config.keep_original_textures=p_enable; } +void RasterizerStorageGLES3::texture_set_detect_3d_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata) { + + Texture * texture = texture_owner.get(p_texture); + ERR_FAIL_COND(!texture); + + texture->detect_3d=p_callback; + texture->detect_3d_ud=p_userdata; +} + +void RasterizerStorageGLES3::texture_set_detect_srgb_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata){ + Texture * texture = texture_owner.get(p_texture); + ERR_FAIL_COND(!texture); + + texture->detect_srgb=p_callback; + texture->detect_srgb_ud=p_userdata; + +} + + + RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source,int p_resolution) const { Texture * texture = texture_owner.get(p_source); @@ -1186,7 +1216,7 @@ RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source,int p_r glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); glDeleteFramebuffers(1, &tmp_fb); Texture * ctex = memnew( Texture ); @@ -1351,7 +1381,7 @@ void RasterizerStorageGLES3::skybox_set_texture(RID p_skybox, RID p_cube_map, in glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); glDeleteFramebuffers(1, &tmp_fb); } @@ -1509,12 +1539,12 @@ void RasterizerStorageGLES3::_update_shader(Shader* p_shader) const { actions->uniforms=&p_shader->uniforms; - } + } break; case VS::SHADER_PARTICLES: { actions=&shaders.actions_particles; actions->uniforms=&p_shader->uniforms; - } + } break; } @@ -2465,6 +2495,7 @@ RID RasterizerStorageGLES3::mesh_create(){ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const PoolVector<uint8_t>& p_array,int p_vertex_count,const PoolVector<uint8_t>& p_index_array,int p_index_count,const Rect3& p_aabb,const Vector<PoolVector<uint8_t> >& p_blend_shapes,const Vector<Rect3>& p_bone_aabbs){ + PoolVector<uint8_t> array = p_array; Mesh *mesh = mesh_owner.getornull(p_mesh); @@ -2663,8 +2694,6 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::P int array_size = stride * p_vertex_count; int index_array_size=0; - - print_line("desired size: "+itos(array_size)+" vcount "+itos(p_vertex_count)+" should be: "+itos(array.size()+p_vertex_count*2)+" but is "+itos(array.size())); if (array.size()!=array_size && array.size()+p_vertex_count*2 == array_size) { //old format, convert array = PoolVector<uint8_t>(); @@ -4261,6 +4290,7 @@ RID RasterizerStorageGLES3::light_create(VS::LightType p_type){ light->param[VS::LIGHT_PARAM_SPECULAR]=0.5; light->param[VS::LIGHT_PARAM_RANGE]=1.0; light->param[VS::LIGHT_PARAM_SPOT_ANGLE]=45; + light->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE]=45; light->param[VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE]=0; light->param[VS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET]=0.1; light->param[VS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET]=0.3; @@ -4747,6 +4777,7 @@ RID RasterizerStorageGLES3::gi_probe_create() { gip->bounds=Rect3(Vector3(),Vector3(1,1,1)); gip->dynamic_range=1.0; gip->energy=1.0; + gip->propagation=1.0; gip->interior=false; gip->compress=false; gip->version=1; @@ -4852,6 +4883,15 @@ void RasterizerStorageGLES3::gi_probe_set_energy(RID p_probe,float p_range){ } +void RasterizerStorageGLES3::gi_probe_set_propagation(RID p_probe,float p_range){ + + GIProbe *gip = gi_probe_owner.getornull(p_probe); + ERR_FAIL_COND(!gip); + + gip->propagation=p_range; + +} + void RasterizerStorageGLES3::gi_probe_set_interior(RID p_probe,bool p_enable) { GIProbe *gip = gi_probe_owner.getornull(p_probe); @@ -4896,6 +4936,16 @@ float RasterizerStorageGLES3::gi_probe_get_energy(RID p_probe) const{ return gip->energy; } +float RasterizerStorageGLES3::gi_probe_get_propagation(RID p_probe) const{ + + const GIProbe *gip = gi_probe_owner.getornull(p_probe); + ERR_FAIL_COND_V(!gip,0); + + return gip->propagation; +} + + + uint32_t RasterizerStorageGLES3::gi_probe_get_version(RID p_probe) { @@ -5250,7 +5300,7 @@ void RasterizerStorageGLES3::update_particles() { shaders.particles.set_uniform(ParticlesShaderGLES3::ORIGIN,particles->origin); - float new_phase = Math::fmod(particles->phase+(frame.delta/particles->lifetime),1.0); + float new_phase = Math::fmod((float)particles->phase+(frame.delta/particles->lifetime),(float)1.0); shaders.particles.set_uniform(ParticlesShaderGLES3::SYSTEM_PHASE,new_phase); shaders.particles.set_uniform(ParticlesShaderGLES3::PREV_SYSTEM_PHASE,particles->phase); @@ -5397,12 +5447,14 @@ void RasterizerStorageGLES3::instance_remove_dependency(RID p_base,RasterizerSce void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { + if (rt->fbo) { glDeleteFramebuffers(1,&rt->fbo); glDeleteTextures(1,&rt->color); rt->fbo=0; } + if (rt->buffers.fbo) { glDeleteFramebuffers(1,&rt->buffers.fbo); glDeleteRenderbuffers(1,&rt->buffers.depth); @@ -5416,11 +5468,13 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { rt->buffers.fbo=0; } + if (rt->depth) { glDeleteTextures(1,&rt->depth); rt->depth=0; } + if (rt->effects.ssao.blur_fbo[0]) { glDeleteFramebuffers(1,&rt->effects.ssao.blur_fbo[0]); glDeleteTextures(1,&rt->effects.ssao.blur_red[0]); @@ -5433,11 +5487,16 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { rt->effects.ssao.depth_mipmap_fbos.clear(); glDeleteTextures(1,&rt->effects.ssao.linear_depth); + + rt->effects.ssao.blur_fbo[0]=0; + rt->effects.ssao.blur_fbo[1]=0; } + if (rt->exposure.fbo) { glDeleteFramebuffers(1,&rt->exposure.fbo); glDeleteTextures(1,&rt->exposure.color); + rt->exposure.fbo=0; } Texture *tex = texture_owner.get(rt->texture); tex->alloc_height=0; @@ -5445,6 +5504,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { tex->width=0; tex->height=0; + for(int i=0;i<2;i++) { for(int j=0;j<rt->effects.mip_maps[i].sizes.size();j++) { glDeleteFramebuffers(1,&rt->effects.mip_maps[i].sizes[j].fbo); @@ -5454,6 +5514,8 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { rt->effects.mip_maps[i].sizes.clear(); rt->effects.mip_maps[i].levels=0; } + + /* if (rt->effects.screen_space_depth) { glDeleteTextures(1,&rt->effects.screen_space_depth); @@ -5468,7 +5530,6 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ if (rt->width<=0 || rt->height<=0) return; - GLuint color_internal_format; GLuint color_format; GLuint color_type; @@ -5523,7 +5584,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->color, 0); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE ); @@ -5610,7 +5671,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); if (status != GL_FRAMEBUFFER_COMPLETE) { printf("err status: %x\n",status); @@ -5643,7 +5704,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ ERR_FAIL_COND( status != GL_FRAMEBUFFER_COMPLETE ); } - glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); if (status != GL_FRAMEBUFFER_COMPLETE) { _render_target_clear(rt); @@ -5712,7 +5773,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt){ } - glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); rt->effects.mip_maps[i].levels=level; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -5941,7 +6002,7 @@ RID RasterizerStorageGLES3::canvas_light_shadow_buffer_create(int p_width) { GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); //printf("errnum: %x\n",status); - glBindFramebuffer(GL_FRAMEBUFFER, config.system_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo); ERR_FAIL_COND_V( status != GL_FRAMEBUFFER_COMPLETE, RID() ); @@ -6288,6 +6349,25 @@ bool RasterizerStorageGLES3::free(RID p_rid){ return true; } + +bool RasterizerStorageGLES3::has_os_feature(const String& p_feature) const { + + if (p_feature=="s3tc") + return config.s3tc_supported; + + if (p_feature=="etc") + return config.etc_supported; + + if (p_feature=="etc2") + return config.etc2_supported; + + if (p_feature=="pvrtc") + return config.pvrtc_supported; + + return false; + +} + //////////////////////////////////////////// @@ -6296,7 +6376,7 @@ void RasterizerStorageGLES3::initialize() { config.render_arch=RENDER_ARCH_DESKTOP; //config.fbo_deferred=int(Globals::get_singleton()->get("rendering/gles3/lighting_technique")); - config.system_fbo=0; + RasterizerStorageGLES3::system_fbo=0; //// extensions config @@ -6463,7 +6543,7 @@ void RasterizerStorageGLES3::initialize() { glBufferData(GL_ARRAY_BUFFER,xf_feedback_size*1024,NULL,GL_STREAM_DRAW); } - shaders.blend_shapes.init();; + shaders.blend_shapes.init(); glGenVertexArrays(1,&resources.transform_feedback_array); diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index f9e440288f..07998886a8 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -24,6 +24,7 @@ public: RasterizerCanvasGLES3 *canvas; RasterizerSceneGLES3 *scene; + static GLuint system_fbo; //on some devices, such as apple, screen is rendered to yet another fbo. enum RenderArchitecture { RENDER_ARCH_MOBILE, @@ -34,8 +35,6 @@ public: RenderArchitecture render_arch; - GLuint system_fbo; //on some devices, such as apple, screen is rendered to yet another fbo. - bool shrink_textures_x2; bool use_fast_texture_filter; bool use_anisotropic_filter; @@ -229,6 +228,12 @@ public: Image images[6]; + VisualServer::TextureDetectCallback detect_3d; + void *detect_3d_ud; + + VisualServer::TextureDetectCallback detect_srgb; + void *detect_srgb_ud; + Texture() { using_srgb=false; @@ -244,6 +249,10 @@ public: total_data_size=0; target=GL_TEXTURE_2D; mipmaps=0; + detect_3d=NULL; + detect_3d_ud=NULL; + detect_srgb=NULL; + detect_srgb_ud=NULL; } @@ -282,6 +291,10 @@ public: virtual void textures_keep_original(bool p_enable); + virtual void texture_set_detect_3d_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata); + virtual void texture_set_detect_srgb_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata); + + /* SKYBOX API */ struct SkyBox : public RID_Data { @@ -908,6 +921,7 @@ public: int dynamic_range; float energy; + float propagation; bool interior; bool compress; @@ -940,6 +954,9 @@ public: virtual void gi_probe_set_energy(RID p_probe,float p_range); virtual float gi_probe_get_energy(RID p_probe) const; + virtual void gi_probe_set_propagation(RID p_probe,float p_range); + virtual float gi_probe_get_propagation(RID p_probe) const; + virtual void gi_probe_set_interior(RID p_probe,bool p_enable); virtual bool gi_probe_is_interior(RID p_probe) const; @@ -1011,7 +1028,7 @@ public: Particles() : particle_element(this) { emitting=false; amount=0; - lifetime=1.0;; + lifetime=1.0; pre_process_time=0.0; explosiveness=0.0; randomness=0.0; @@ -1161,9 +1178,11 @@ public: height=0; depth=0; fbo=0; + exposure.fbo=0; buffers.fbo=0; used_in_frame=false; + flags[RENDER_TARGET_VFLIP]=false; flags[RENDER_TARGET_TRANSPARENT]=false; flags[RENDER_TARGET_NO_3D]=false; @@ -1238,6 +1257,7 @@ public: void initialize(); void finalize(); + virtual bool has_os_feature(const String& p_feature) const; RasterizerStorageGLES3(); diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp index 97872226a4..12aac79912 100644 --- a/drivers/gles3/shader_compiler_gles3.cpp +++ b/drivers/gles3/shader_compiler_gles3.cpp @@ -582,6 +582,7 @@ Error ShaderCompilerGLES3::compile(VS::ShaderMode p_mode, const String& p_code, used_name_defines.clear(); used_rmode_defines.clear(); + used_flag_pointers.clear(); _dump_node_code(parser.get_shader(),1,r_gen_code,*p_actions,actions[p_mode]); diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 66123193e6..200c0c0cac 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -71,6 +71,7 @@ layout(std140) uniform SceneData { //ubo:0 float shadow_dual_paraboloid_render_zfar; float shadow_dual_paraboloid_render_side; + highp vec2 screen_pixel_size; vec2 shadow_atlas_pixel_size; vec2 directional_shadow_pixel_size; @@ -91,7 +92,7 @@ layout(std140) uniform DirectionalLightData { //ubo:3 mediump vec4 light_color_energy; mediump vec4 light_params; //cone attenuation, angle, specular, shadow enabled, mediump vec4 light_clamp; - mediump vec4 shadow_color; + mediump vec4 shadow_color_contact; highp mat4 shadow_matrix1; highp mat4 shadow_matrix2; highp mat4 shadow_matrix3; @@ -126,13 +127,6 @@ out vec3 binormal_interp; #endif -#if !defined(USE_DEPTH_SHADOWS) && defined(USE_SHADOW_PASS) - -varying vec4 position_interp; - -#endif - - VERTEX_SHADER_GLOBALS @@ -161,6 +155,8 @@ layout(std140) uniform SkeletonData { //ubo:7 #endif +out highp vec4 position_interp; + void main() { highp vec4 vertex = vertex_attrib; // vec4(vertex_attrib.xyz * data_attrib.x,1.0); @@ -293,7 +289,7 @@ VERTEX_SHADER_CODE gl_Position = vertex; #endif - + position_interp=gl_Position; } @@ -375,6 +371,8 @@ layout(std140) uniform SceneData { highp vec4 ambient_light_color; highp vec4 bg_color; + + float ambient_energy; float bg_energy; @@ -383,6 +381,7 @@ layout(std140) uniform SceneData { float shadow_dual_paraboloid_render_zfar; float shadow_dual_paraboloid_render_side; + highp vec2 screen_pixel_size; vec2 shadow_atlas_pixel_size; vec2 directional_shadow_pixel_size; @@ -403,7 +402,7 @@ layout(std140) uniform DirectionalLightData { mediump vec4 light_color_energy; mediump vec4 light_params; //cone attenuation, angle, specular, shadow enabled, mediump vec4 light_clamp; - mediump vec4 shadow_color; + mediump vec4 shadow_color_contact; highp mat4 shadow_matrix1; highp mat4 shadow_matrix2; highp mat4 shadow_matrix3; @@ -425,7 +424,7 @@ struct LightData { mediump vec4 light_color_energy; mediump vec4 light_params; //cone attenuation, angle, specular, shadow enabled, mediump vec4 light_clamp; - mediump vec4 shadow_color; + mediump vec4 shadow_color_contact; highp mat4 shadow_matrix; }; @@ -493,6 +492,69 @@ layout(location=0) out vec4 frag_color; #endif +in highp vec4 position_interp; +uniform highp sampler2D depth_buffer; //texunit:-8 + +float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) { + + if (abs(dir.z)>0.99) + return 1.0; + + vec3 endpoint = pos+dir*max_distance; + vec4 source = position_interp; + vec4 dest = projection_matrix * vec4(endpoint, 1.0); + + vec2 from_screen = (source.xy / source.w) * 0.5 + 0.5; + vec2 to_screen = (dest.xy / dest.w) * 0.5 + 0.5; + + vec2 screen_rel = to_screen - from_screen; + + /*float pixel_size; //approximate pixel size + + if (screen_rel.x > screen_rel.y) { + + pixel_size = abs((pos.x-endpoint.x)/(screen_rel.x/screen_pixel_size.x)); + } else { + pixel_size = abs((pos.y-endpoint.y)/(screen_rel.y/screen_pixel_size.y)); + + }*/ + vec4 bias = projection_matrix * vec4(pos+vec3(0.0,0.0,0.04), 1.0); //todo un-harcode the 0.04 + + + + vec2 pixel_incr = normalize(screen_rel)*screen_pixel_size; + + float steps = length(screen_rel) / length(pixel_incr); + + //steps=10.0; + + vec4 incr = (dest - source)/steps; + float ratio=0.0; + float ratio_incr = 1.0/steps; + + do { + source += incr*2; + bias+=incr*2; + + vec3 uv_depth = (source.xyz / source.w) * 0.5 + 0.5; + float depth = texture(depth_buffer,uv_depth.xy).r; + + if (depth < uv_depth.z) { + if (depth > (bias.z/bias.w) * 0.5 + 0.5) { + return min(pow(ratio,4.0),1.0); + } else { + return 1.0; + } + } + + + ratio+=ratio_incr; + steps-=1.0; + } while (steps>0.0); + + return 1.0; +} + // GGX Specular // Source: http://www.filmicworlds.com/images/ggx-opt/optimized-ggx.hlsl @@ -517,6 +579,8 @@ float GTR1(float NdotH, float a) return (a2-1.0) / (M_PI*log(a2)*t); } + + void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 diffuse_color, vec3 specular_color, float specular_blob_intensity, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse, inout vec3 specular) { float dotNL = max(dot(N,L), 0.0 ); @@ -660,7 +724,8 @@ vec3 light_transmittance(float translucency,vec3 light_vec, vec3 normal, vec3 po void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 binormal, vec3 tangent, vec3 albedo, vec3 specular, float roughness, float rim, float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse_light, inout vec3 specular_light) { vec3 light_rel_vec = omni_lights[idx].light_pos_inv_radius.xyz-vertex; - float normalized_distance = length( light_rel_vec )*omni_lights[idx].light_pos_inv_radius.w; + float light_length = length( light_rel_vec ); + float normalized_distance = light_length*omni_lights[idx].light_pos_inv_radius.w; vec3 light_attenuation = vec3(pow( max(1.0 - normalized_distance, 0.0), omni_lights[idx].light_direction_attenuation.w )); if (omni_lights[idx].light_params.w>0.5) { @@ -696,8 +761,15 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 bino splane.z = shadow_len * omni_lights[idx].light_pos_inv_radius.w; splane.xy = clamp_rect.xy+splane.xy*clamp_rect.zw; + float shadow = sample_shadow(shadow_atlas,shadow_atlas_pixel_size,splane.xy,splane.z,clamp_rect); + if (shadow>0.01 && omni_lights[idx].shadow_color_contact.a>0.0) { + + float contact_shadow = contact_shadow_compute(vertex,normalize(light_rel_vec),min(light_length,omni_lights[idx].shadow_color_contact.a)); + shadow=min(shadow,contact_shadow); - light_attenuation*=mix(omni_lights[idx].shadow_color.rgb,vec3(1.0),sample_shadow(shadow_atlas,shadow_atlas_pixel_size,splane.xy,splane.z,clamp_rect)); + + } + light_attenuation*=mix(omni_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow); } light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,omni_lights[idx].light_color_energy.rgb*light_attenuation,albedo,specular,omni_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); @@ -707,7 +779,8 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 bino void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent,vec3 albedo, vec3 specular, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy, inout vec3 diffuse_light, inout vec3 specular_light) { vec3 light_rel_vec = spot_lights[idx].light_pos_inv_radius.xyz-vertex; - float normalized_distance = length( light_rel_vec )*spot_lights[idx].light_pos_inv_radius.w; + float light_length = length( light_rel_vec ); + float normalized_distance = light_length*spot_lights[idx].light_pos_inv_radius.w; vec3 light_attenuation = vec3(pow( max(1.0 - normalized_distance, 0.0), spot_lights[idx].light_direction_attenuation.w )); vec3 spot_dir = spot_lights[idx].light_direction_attenuation.xyz; float spot_cutoff=spot_lights[idx].light_params.y; @@ -719,7 +792,17 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi //there is a shadowmap highp vec4 splane=(spot_lights[idx].shadow_matrix * vec4(vertex,1.0)); splane.xyz/=splane.w; - light_attenuation*=mix(spot_lights[idx].shadow_color.rgb,vec3(1.0),sample_shadow(shadow_atlas,shadow_atlas_pixel_size,splane.xy,splane.z,spot_lights[idx].light_clamp)); + + float shadow = sample_shadow(shadow_atlas,shadow_atlas_pixel_size,splane.xy,splane.z,spot_lights[idx].light_clamp); + + if (shadow>0.01 && spot_lights[idx].shadow_color_contact.a>0.0) { + + float contact_shadow = contact_shadow_compute(vertex,normalize(light_rel_vec),min(light_length,spot_lights[idx].shadow_color_contact.a)); + shadow=min(shadow,contact_shadow); + + } + + light_attenuation*=mix(spot_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow); } light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,spot_lights[idx].light_color_energy.rgb*light_attenuation,albedo,specular,spot_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); @@ -1268,6 +1351,8 @@ FRAGMENT_SHADER_CODE } } + + #endif //LIGHT_USE_PSSM4 #ifdef LIGHT_USE_PSSM2 @@ -1306,16 +1391,26 @@ FRAGMENT_SHADER_CODE //one one sample - light_attenuation=mix(shadow_color.rgb,vec3(1.0),sample_shadow(directional_shadow,directional_shadow_pixel_size,pssm_coord.xy,pssm_coord.z,light_clamp)); + float shadow = sample_shadow(directional_shadow,directional_shadow_pixel_size,pssm_coord.xy,pssm_coord.z,light_clamp); #if defined(LIGHT_USE_PSSM_BLEND) + if (use_blend) { - vec3 light_attenuation2=mix(shadow_color.rgb,vec3(1.0),sample_shadow(directional_shadow,directional_shadow_pixel_size,pssm_coord2.xy,pssm_coord2.z,light_clamp)); - light_attenuation=mix(light_attenuation,light_attenuation2,pssm_blend); + shadow=mix(shadow, sample_shadow(directional_shadow,directional_shadow_pixel_size,pssm_coord2.xy,pssm_coord2.z,light_clamp)); } #endif + if (shadow>0.01 && shadow_color_contact.a>0.0) { + + float contact_shadow = contact_shadow_compute(vertex,-light_direction_attenuation.xyz,shadow_color_contact.a); + shadow=min(shadow,contact_shadow); + + } + + light_attenuation=mix(shadow_color_contact.rgb,vec3(1.0),shadow); + + } #endif //LIGHT_DIRECTIONAL_SHADOW diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index 3a1317cbf6..5f0e647545 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -44,7 +44,7 @@ Error AudioDriverPulseAudio::init() { samples_out = NULL; mix_rate = GLOBAL_DEF("audio/mix_rate",44100); - output_format = OUTPUT_STEREO; + speaker_mode = SPEAKER_MODE_STEREO; channels = 2; pa_sample_spec spec; @@ -65,15 +65,15 @@ Error AudioDriverPulseAudio::init() { int error_code; pulse = pa_simple_new( NULL, // default server - "Godot", // application name - PA_STREAM_PLAYBACK, - NULL, // default device - "Sound", // stream description - &spec, - NULL, // use default channel map - &attr, // use buffering attributes from above - &error_code - ); + "Godot", // application name + PA_STREAM_PLAYBACK, + NULL, // default device + "Sound", // stream description + &spec, + NULL, // use default channel map + &attr, // use buffering attributes from above + &error_code + ); if (pulse == NULL) { fprintf(stderr, "PulseAudio ERR: %s\n", pa_strerror(error_code));\ @@ -103,6 +103,7 @@ float AudioDriverPulseAudio::get_latency() { void AudioDriverPulseAudio::thread_func(void* p_udata) { + print_line("thread"); AudioDriverPulseAudio* ad = (AudioDriverPulseAudio*)p_udata; while (!ad->exit_thread) { @@ -121,9 +122,9 @@ void AudioDriverPulseAudio::thread_func(void* p_udata) { for (unsigned int i=0; i < ad->buffer_size * ad->channels;i ++) { ad->samples_out[i] = ad->samples_in[i] >> 16; } - } + } - // pa_simple_write always consumes the entire buffer + // pa_simple_write always consumes the entire buffer int error_code; int byte_size = ad->buffer_size * sizeof(int16_t) * ad->channels; @@ -134,7 +135,7 @@ void AudioDriverPulseAudio::thread_func(void* p_udata) { ad->exit_thread = true; break; } - } + } ad->thread_exited = true; } @@ -149,9 +150,9 @@ int AudioDriverPulseAudio::get_mix_rate() const { return mix_rate; } -AudioDriverSW::OutputFormat AudioDriverPulseAudio::get_output_format() const { +AudioDriver::SpeakerMode AudioDriverPulseAudio::get_speaker_mode() const { - return output_format; + return speaker_mode; } void AudioDriverPulseAudio::lock() { diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.h b/drivers/pulseaudio/audio_driver_pulseaudio.h index aa7b7a9188..36ae8c2e53 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.h +++ b/drivers/pulseaudio/audio_driver_pulseaudio.h @@ -26,7 +26,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #ifdef PULSEAUDIO_ENABLED @@ -35,7 +35,7 @@ #include <pulse/simple.h> -class AudioDriverPulseAudio : public AudioDriverSW { +class AudioDriverPulseAudio : public AudioDriver{ Thread* thread; Mutex* mutex; @@ -48,7 +48,7 @@ class AudioDriverPulseAudio : public AudioDriverSW { static void thread_func(void* p_udata); unsigned int mix_rate; - OutputFormat output_format; + SpeakerMode speaker_mode; unsigned int buffer_size; int channels; @@ -69,7 +69,7 @@ public: virtual Error init(); virtual void start(); virtual int get_mix_rate() const; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/drivers/rtaudio/audio_driver_rtaudio.cpp b/drivers/rtaudio/audio_driver_rtaudio.cpp index 850e5ab053..6ada0aaa68 100644 --- a/drivers/rtaudio/audio_driver_rtaudio.cpp +++ b/drivers/rtaudio/audio_driver_rtaudio.cpp @@ -71,7 +71,7 @@ int AudioDriverRtAudio::callback( void *outputBuffer, void *inputBuffer, unsigne self->audio_server_process(nBufferFrames,buffer); - self->mutex->unlock();; + self->mutex->unlock(); return 0; } @@ -85,6 +85,8 @@ Error AudioDriverRtAudio::init() { ERR_EXPLAIN("Cannot initialize RtAudio audio driver: No devices present.") ERR_FAIL_COND_V( dac->getDeviceCount() < 1, ERR_UNAVAILABLE ); + // FIXME: Adapt to the OutputFormat -> SpeakerMode change + /* String channels = GLOBAL_DEF("audio/output","stereo"); if (channels=="5.1") @@ -95,6 +97,7 @@ Error AudioDriverRtAudio::init() { output_format=OUTPUT_MONO; else output_format=OUTPUT_STEREO; + */ RtAudio::StreamParameters parameters; parameters.deviceId = dac->getDefaultOutputDevice(); @@ -125,11 +128,10 @@ Error AudioDriverRtAudio::init() { while(true) { while( true) { - switch(output_format) { - case OUTPUT_MONO: parameters.nChannels = 1; break; - case OUTPUT_STEREO: parameters.nChannels = 2; break; - case OUTPUT_QUAD: parameters.nChannels = 4; break; - case OUTPUT_5_1: parameters.nChannels = 6; break; + switch(speaker_mode) { + case SPEAKER_MODE_STEREO: parameters.nChannels = 2; break; + case SPEAKER_SURROUND_51: parameters.nChannels = 6; break; + case SPEAKER_SURROUND_71: parameters.nChannels = 8; break; }; try { @@ -142,11 +144,10 @@ Error AudioDriverRtAudio::init() { // try with less channels ERR_PRINT("Unable to open audio, retrying with fewer channels.."); - switch(output_format) { - case OUTPUT_MONO: ERR_EXPLAIN("Unable to open audio."); ERR_FAIL_V( ERR_UNAVAILABLE ); break; - case OUTPUT_STEREO: output_format=OUTPUT_MONO; break; - case OUTPUT_QUAD: output_format=OUTPUT_STEREO; break; - case OUTPUT_5_1: output_format=OUTPUT_QUAD; break; + switch(speaker_mode) { + case SPEAKER_MODE_STEREO: speaker_mode=SPEAKER_MODE_STEREO; break; + case SPEAKER_SURROUND_51: speaker_mode=SPEAKER_SURROUND_51; break; + case SPEAKER_SURROUND_71: speaker_mode=SPEAKER_SURROUND_71; break; }; } } @@ -189,9 +190,9 @@ int AudioDriverRtAudio::get_mix_rate() const { return mix_rate; } -AudioDriverSW::OutputFormat AudioDriverRtAudio::get_output_format() const { +AudioDriver::SpeakerMode AudioDriverRtAudio::get_speaker_mode() const { - return output_format; + return speaker_mode; } void AudioDriverRtAudio::start() { @@ -229,7 +230,7 @@ AudioDriverRtAudio::AudioDriverRtAudio() mutex=NULL; mix_rate=44100; - output_format=OUTPUT_STEREO; + speaker_mode=SPEAKER_MODE_STEREO; } diff --git a/drivers/rtaudio/audio_driver_rtaudio.h b/drivers/rtaudio/audio_driver_rtaudio.h index aa7fae038a..3f293db6a6 100644 --- a/drivers/rtaudio/audio_driver_rtaudio.h +++ b/drivers/rtaudio/audio_driver_rtaudio.h @@ -31,16 +31,16 @@ #ifdef RTAUDIO_ENABLED -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #include <RtAudio.h> -class AudioDriverRtAudio : public AudioDriverSW { +class AudioDriverRtAudio : public AudioDriver { static int callback( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData ); - OutputFormat output_format; + SpeakerMode speaker_mode; Mutex *mutex; RtAudio *dac; int mix_rate; @@ -53,7 +53,7 @@ public: virtual Error init(); virtual void start(); virtual int get_mix_rate() const ; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 283cff0486..edf5f22714 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -30,6 +30,7 @@ #ifdef UNIX_ENABLED +#include "servers/visual_server.h" #include "thread_posix.h" #include "semaphore_posix.h" @@ -116,7 +117,13 @@ int OS_Unix::unix_initialize_audio(int p_audio_driver) { return 0; } - +// Very simple signal handler to reap processes where ::execute was called with +// !p_blocking +void handle_sigchld(int sig) { + int saved_errno = errno; + while (waitpid((pid_t)(-1), 0, WNOHANG) > 0) {} + errno = saved_errno; +} void OS_Unix::initialize_core() { @@ -147,6 +154,14 @@ void OS_Unix::initialize_core() { ticks_start=0; ticks_start=get_ticks_usec(); + + struct sigaction sa; + sa.sa_handler = &handle_sigchld; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART | SA_NOCLDSTOP; + if (sigaction(SIGCHLD, &sa, 0) == -1) { + perror("ERROR sigaction() failed:"); + } } void OS_Unix::finalize_core() { @@ -478,6 +493,13 @@ String OS_Unix::get_data_dir() const { } +bool OS_Unix::check_feature_support(const String& p_feature) { + + return VisualServer::get_singleton()->has_os_feature(p_feature); + +} + + String OS_Unix::get_installed_templates_path() const { String p=get_global_settings_path(); if (p!="") diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index b28adc2ee0..220f818ff6 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -117,6 +117,8 @@ public: virtual String get_executable_path() const; virtual String get_data_dir() const; + virtual bool check_feature_support(const String& p_feature); + //virtual void run( MainLoop * p_main_loop ); diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp index 82f3115f4b..ae4bf77c36 100644 --- a/drivers/unix/stream_peer_tcp_posix.cpp +++ b/drivers/unix/stream_peer_tcp_posix.cpp @@ -98,7 +98,7 @@ Error StreamPeerTCPPosix::_poll_connection(bool p_block) const { }; struct sockaddr_storage their_addr; - size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, ip_type); + size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, sock_type); if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == -1) { @@ -125,6 +125,7 @@ Error StreamPeerTCPPosix::_poll_connection(bool p_block) const { void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port, IP::Type p_ip_type) { ip_type = p_ip_type; + sock_type = p_ip_type; sockfd = p_sockfd; #ifndef NO_FCNTL fcntl(sockfd, F_SETFL, O_NONBLOCK); @@ -143,7 +144,8 @@ Error StreamPeerTCPPosix::connect_to_host(const IP_Address& p_host, uint16_t p_p ERR_FAIL_COND_V( p_host == IP_Address(), ERR_INVALID_PARAMETER); - sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP); + sock_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + sockfd = _socket_create(sock_type, SOCK_STREAM, IPPROTO_TCP); if (sockfd == -1) { ERR_PRINT("Socket creation failed!"); disconnect_from_host(); @@ -159,7 +161,7 @@ Error StreamPeerTCPPosix::connect_to_host(const IP_Address& p_host, uint16_t p_p #endif struct sockaddr_storage their_addr; - size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, ip_type); + size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, sock_type); errno = 0; if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == -1 && errno != EINPROGRESS) { @@ -340,6 +342,8 @@ void StreamPeerTCPPosix::disconnect_from_host() { if (sockfd != -1) close(sockfd); + + sock_type = IP::TYPE_NONE; sockfd=-1; status = STATUS_NONE; @@ -390,6 +394,7 @@ uint16_t StreamPeerTCPPosix::get_connected_port() const { StreamPeerTCPPosix::StreamPeerTCPPosix() { + sock_type = IP::TYPE_NONE; sockfd = -1; status = STATUS_NONE; peer_port = 0; diff --git a/drivers/unix/stream_peer_tcp_posix.h b/drivers/unix/stream_peer_tcp_posix.h index e0091d55b7..d33883b159 100644 --- a/drivers/unix/stream_peer_tcp_posix.h +++ b/drivers/unix/stream_peer_tcp_posix.h @@ -35,14 +35,13 @@ #include "core/io/stream_peer_tcp.h" #include "error_list.h" -#include "core/io/ip_address.h" - class StreamPeerTCPPosix : public StreamPeerTCP { protected: mutable Status status; + IP::Type sock_type; int sockfd; Error _block(int p_sockfd, bool p_read, bool p_write) const; diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index 183cec96ec..894b49231b 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -50,7 +50,7 @@ void FileAccessWindows::check_errors() const { if (feof(f)) { - last_error=ERR_FILE_EOF;; + last_error=ERR_FILE_EOF; } } diff --git a/drivers/xaudio2/audio_driver_xaudio2.cpp b/drivers/xaudio2/audio_driver_xaudio2.cpp index 5be857164c..fa55c97325 100644 --- a/drivers/xaudio2/audio_driver_xaudio2.cpp +++ b/drivers/xaudio2/audio_driver_xaudio2.cpp @@ -46,7 +46,8 @@ Error AudioDriverXAudio2::init() { mix_rate = 48000; - output_format = OUTPUT_STEREO; + // FIXME: speaker_mode seems unused in the Xaudio2 driver so far + speaker_mode = SPEAKER_MODE_STEREO; channels = 2; int latency = GLOBAL_DEF("audio/output_latency", 25); @@ -156,9 +157,9 @@ int AudioDriverXAudio2::get_mix_rate() const { return mix_rate; }; -AudioDriverSW::OutputFormat AudioDriverXAudio2::get_output_format() const { +AudioDriver::SpeakerMode AudioDriverXAudio2::get_speaker_mode() const { - return output_format; + return speaker_mode; }; float AudioDriverXAudio2::get_latency() { diff --git a/drivers/xaudio2/audio_driver_xaudio2.h b/drivers/xaudio2/audio_driver_xaudio2.h index ad880b24d5..afafb84c23 100644 --- a/drivers/xaudio2/audio_driver_xaudio2.h +++ b/drivers/xaudio2/audio_driver_xaudio2.h @@ -29,8 +29,7 @@ #ifndef AUDIO_DRIVER_XAUDIO2_H #define AUDIO_DRIVER_XAUDIO2_H -#include "servers/audio/audio_server_sw.h" - +#include "servers/audio_server.h" #include "core/os/thread.h" #include "core/os/mutex.h" @@ -40,7 +39,7 @@ #include <xaudio2.h> #include <wrl/client.h> -class AudioDriverXAudio2 : public AudioDriverSW { +class AudioDriverXAudio2 : public AudioDriver { enum { AUDIO_BUFFERS = 2 @@ -72,7 +71,7 @@ class AudioDriverXAudio2 : public AudioDriverSW { int buffer_size; unsigned int mix_rate; - OutputFormat output_format; + SpeakerMode speaker_mode; int channels; @@ -96,7 +95,7 @@ public: virtual Error init(); virtual void start(); virtual int get_mix_rate() const; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual float get_latency(); virtual void lock(); virtual void unlock(); diff --git a/main/input_default.cpp b/main/input_default.cpp index 50b0006438..0561f2bb34 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -277,6 +277,12 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_ emit_signal("joy_connection_changed", p_idx, p_connected); }; +Vector3 InputDefault::get_gravity() const{ + + _THREAD_SAFE_METHOD_ + return gravity; +} + Vector3 InputDefault::get_accelerometer() const{ _THREAD_SAFE_METHOD_ @@ -375,15 +381,12 @@ void InputDefault::parse_input_event(const InputEvent& p_event) { if (!p_event.is_echo()) { for (const Map<StringName,InputMap::Action>::Element *E=InputMap::get_singleton()->get_action_map().front();E;E=E->next()) { - if (InputMap::get_singleton()->event_is_action(p_event,E->key())) { - - if(is_action_pressed(E->key()) != p_event.is_pressed()) { - Action action; - action.fixed_frame=Engine::get_singleton()->get_fixed_frames(); - action.idle_frame=Engine::get_singleton()->get_idle_frames(); - action.pressed=p_event.is_pressed(); - action_state[E->key()]=action; - } + if (InputMap::get_singleton()->event_is_action(p_event,E->key()) && is_action_pressed(E->key()) != p_event.is_pressed()) { + Action action; + action.fixed_frame=Engine::get_singleton()->get_fixed_frames(); + action.idle_frame=Engine::get_singleton()->get_idle_frames(); + action.pressed=p_event.is_pressed(); + action_state[E->key()]=action; } } } @@ -423,6 +426,14 @@ void InputDefault::stop_joy_vibration(int p_device) { joy_vibration[p_device] = vibration; } +void InputDefault::set_gravity(const Vector3& p_gravity) { + + _THREAD_SAFE_METHOD_ + + gravity=p_gravity; + +} + void InputDefault::set_accelerometer(const Vector3& p_accel) { _THREAD_SAFE_METHOD_ @@ -472,7 +483,7 @@ Point2 InputDefault::get_last_mouse_speed() const { int InputDefault::get_mouse_button_mask() const { - return OS::get_singleton()->get_mouse_button_state(); + return mouse_button_mask;// do not trust OS implementaiton, should remove it - OS::get_singleton()->get_mouse_button_state(); } void InputDefault::warp_mouse_pos(const Vector2& p_to) { @@ -554,8 +565,7 @@ void InputDefault::set_mouse_in_window(bool p_in_window) { } // from github.com/gabomdq/SDL_GameControllerDB -static const char *s_ControllerMappings [] = -{ +static const char *s_ControllerMappings [] = { #ifdef WINDOWS_ENABLED "00f00300000000000000504944564944,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,", "00f0f100000000000000504944564944,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,", diff --git a/main/input_default.h b/main/input_default.h index cab505644d..3e41c494c1 100644 --- a/main/input_default.h +++ b/main/input_default.h @@ -44,6 +44,7 @@ class InputDefault : public Input { Set<int> joy_buttons_pressed; Map<int,float> _joy_axis; //Map<StringName,int> custom_action_press; + Vector3 gravity; Vector3 accelerometer; Vector3 magnetometer; Vector3 gyroscope; @@ -191,6 +192,7 @@ public: void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid = ""); void parse_joypad_mapping(String p_mapping, bool p_update_existing); + virtual Vector3 get_gravity() const; virtual Vector3 get_accelerometer() const; virtual Vector3 get_magnetometer() const; virtual Vector3 get_gyroscope() const; @@ -203,6 +205,7 @@ public: void parse_input_event(const InputEvent& p_event); + void set_gravity(const Vector3& p_gravity); void set_accelerometer(const Vector3& p_accel); void set_magnetometer(const Vector3& p_magnetometer); void set_gyroscope(const Vector3& p_gyroscope); diff --git a/main/main.cpp b/main/main.cpp index e535da3e28..21a839a25f 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -38,11 +38,11 @@ #include "script_debugger_local.h" #include "script_debugger_remote.h" #include "message_queue.h" -#include "path_remap.h" + #include "input_map.h" #include "io/resource_loader.h" #include "scene/main/scene_main_loop.h" - +#include "servers/audio_server.h" #include "script_language.h" #include "io/resource_loader.h" @@ -54,20 +54,14 @@ #include "scene/main/viewport.h" #ifdef TOOLS_ENABLED +#include "tools/editor/doc/doc_data.h" #include "tools/editor/editor_node.h" #include "tools/editor/project_manager.h" - #endif #include "io/file_access_network.h" -#include "tools/doc/doc_data.h" - - -#include "servers/spatial_sound_server.h" -#include "servers/spatial_sound_2d_server.h" #include "servers/physics_2d_server.h" - #include "core/io/stream_peer_tcp.h" #include "core/os/thread.h" #include "core/io/file_access_pack.h" @@ -83,10 +77,11 @@ static Engine *engine=NULL; static InputMap *input_map=NULL; static bool _start_success=false; static ScriptDebugger *script_debugger=NULL; +AudioServer *audio_server=NULL; static MessageQueue *message_queue=NULL; static Performance *performance = NULL; -static PathRemap *path_remap; + static PackedData *packed_data=NULL; #ifdef MINIZIP_ENABLED static ZipArchive *zip_packed_data=NULL; @@ -131,7 +126,7 @@ void Main::print_help(const char* p_binary) { OS::get_singleton()->print(VERSION_FULL_NAME" (c) 2008-2017 Juan Linietsky, Ariel Manzur.\n"); OS::get_singleton()->print("Usage: %s [options] [scene]\n",p_binary); OS::get_singleton()->print("Options:\n"); - OS::get_singleton()->print("\t-path [dir] : Path to a game, containing engine.cfg\n"); + OS::get_singleton()->print("\t-path [dir] : Path to a game, containing godot.cfg\n"); #ifdef TOOLS_ENABLED OS::get_singleton()->print("\t-e,-editor : Bring up the editor instead of running the scene.\n"); #endif @@ -184,8 +179,6 @@ void Main::print_help(const char* p_binary) { #ifdef TOOLS_ENABLED OS::get_singleton()->print("\t-doctool FILE: Dump the whole engine api to FILE in XML format. If FILE exists, it will be merged.\n"); OS::get_singleton()->print("\t-nodocbase: Disallow dump the base types (used with -doctool).\n"); - OS::get_singleton()->print("\t-optimize FILE Save an optimized copy of scene to FILE.\n"); - OS::get_singleton()->print("\t-optimize_preset [preset] Use a given preset for optimization.\n"); OS::get_singleton()->print("\t-export [target] Export the project using given export target.\n"); #endif } @@ -216,7 +209,6 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas register_core_settings(); //here globals is present - path_remap = memnew( PathRemap ); translation_server = memnew( TranslationServer ); performance = memnew( Performance ); globals->add_singleton(GlobalConfig::Singleton("Performance",performance)); @@ -596,6 +588,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas I=N; } + GLOBAL_DEF("memory/multithread/thread_rid_pool_prealloc",60); GLOBAL_DEF("network/debug/max_remote_stdout_chars_per_second",2048); GLOBAL_DEF("network/debug/remote_port",6007); @@ -710,7 +703,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas else input_map->load_from_globals(); //keys for game - if (video_driver=="") // specified in engine.cfg + if (video_driver=="") // specified in godot.cfg video_driver=GLOBAL_DEF("display/driver/name",Variant((const char*)OS::get_singleton()->get_video_driver_name(0))); if (!force_res && use_custom_res && globals->has("display/window/width")) @@ -766,7 +759,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas /* Determine Video Driver */ - if (audio_driver=="") { // specified in engine.cfg + if (audio_driver=="") { // specified in godot.cfg audio_driver=GLOBAL_DEF("audio/driver",OS::get_singleton()->get_audio_driver_name(0)); } @@ -874,8 +867,6 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas memdelete(packed_data); if (file_access_network_client) memdelete(file_access_network_client); - if(path_remap) - memdelete(path_remap); // Note 1: *zip_packed_data live into *packed_data // Note 2: PackedData::~PackedData destroy this. @@ -907,6 +898,11 @@ Error Main::setup2() { OS::get_singleton()->set_window_position(init_custom_pos); } + //right moment to create and initialize the audio server + + audio_server = memnew( AudioServer ); + audio_server->init(); + OS::get_singleton()->set_use_vsync(use_vsync); register_core_singletons(); @@ -930,8 +926,6 @@ Error Main::setup2() { } MAIN_PRINT("Main: Load Remaps"); - path_remap->load_remaps(); - Color clear = GLOBAL_DEF("rendering/viewport/default_clear_color",Color(0.3,0.3,0.3)); VisualServer::get_singleton()->set_default_clear_color(clear); @@ -1041,6 +1035,7 @@ Error Main::setup2() { translation_server->load_translations(); + audio_server->load_default_bus_layout(); if (use_debug_profiler && script_debugger) { script_debugger->profiling_start(); @@ -1073,12 +1068,9 @@ bool Main::start() { String script; String test; String screen; - String optimize; - String optimize_preset; String _export_platform; String _import; String _import_script; - String dumpstrings; bool noquit=false; bool export_debug=false; bool project_manager_request = false; @@ -1107,10 +1099,6 @@ bool Main::start() { Engine::get_singleton()->_custom_level=args[i+1]; } else if (args[i]=="-test") { test=args[i+1]; - } else if (args[i]=="-optimize") { - optimize=args[i+1]; - } else if (args[i]=="-optimize_preset") { - optimize_preset=args[i+1]; } else if (args[i]=="-export") { editor=true; //needs editor _export_platform=args[i+1]; @@ -1124,9 +1112,6 @@ bool Main::start() { } else if (args[i]=="-import_script") { editor=true; //needs editor _import_script=args[i+1]; - } else if (args[i]=="-dumpstrings") { - editor=true; //needs editor - dumpstrings=args[i+1]; } else { // The parameter does not match anything known, don't skip the next argument parsed_pair=false; @@ -1161,10 +1146,6 @@ bool Main::start() { return false; } - if (optimize!="") - editor=true; //need editor - - #endif @@ -1373,7 +1354,7 @@ bool Main::start() { DirAccess *da = DirAccess::open(local_game_path.substr(0,sep)); if (da) { - local_game_path=da->get_current_dir()+"/"+local_game_path.substr(sep+1,local_game_path.length());; + local_game_path=da->get_current_dir()+"/"+local_game_path.substr(sep+1,local_game_path.length()); memdelete(da); } } @@ -1398,22 +1379,7 @@ bool Main::start() { Error serr = editor_node->load_scene(local_game_path); - if (serr==OK) { - - if (optimize!="") { - - editor_node->save_optimized_copy(optimize,optimize_preset); - if (!noquit) - sml->quit(); - } - - if (dumpstrings!="") { - editor_node->save_translatable_strings(dumpstrings); - if (!noquit) - sml->quit(); - } - } } OS::get_singleton()->set_context(OS::CONTEXT_EDITOR); @@ -1521,7 +1487,7 @@ bool Main::start() { //sml->get_root()->add_child(scene); sml->add_current_scene(scene); - String iconpath = GLOBAL_DEF("application/icon","Variant()"""); + String iconpath = GLOBAL_DEF("application/icon","Variant()"); if (iconpath!="") { Image icon; if (icon.load(iconpath)==OK) @@ -1656,11 +1622,6 @@ bool Main::iteration() { OS::get_singleton()->get_main_loop()->idle( step*time_scale ); message_queue->flush(); - if (SpatialSoundServer::get_singleton()) - SpatialSoundServer::get_singleton()->update( step*time_scale ); - if (SpatialSound2DServer::get_singleton()) - SpatialSound2DServer::get_singleton()->update( step*time_scale ); - VisualServer::get_singleton()->sync(); //sync if still drawing from previous frames. @@ -1763,6 +1724,11 @@ void Main::cleanup() { OS::get_singleton()->_execpath=""; OS::get_singleton()->_local_clipboard=""; + if (audio_server) { + memdelete(audio_server); + } + + #ifdef TOOLS_ENABLED EditorNode::unregister_editor_types(); #endif @@ -1774,6 +1740,7 @@ void Main::cleanup() { OS::get_singleton()->finalize(); + if (packed_data) memdelete(packed_data); if (file_access_network_client) @@ -1784,8 +1751,6 @@ void Main::cleanup() { memdelete(input_map); if (translation_server) memdelete( translation_server ); - if (path_remap) - memdelete(path_remap); if (globals) memdelete(globals); if (engine) diff --git a/main/performance.cpp b/main/performance.cpp index 91df55a21c..50ca594f8e 100644 --- a/main/performance.cpp +++ b/main/performance.cpp @@ -141,9 +141,9 @@ float Performance::get_monitor(Monitor p_monitor) const { }; case RENDER_OBJECTS_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_OBJECTS_IN_FRAME); case RENDER_VERTICES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_VERTICES_IN_FRAME); - case RENDER_MATERIAL_CHANGES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_MATERIAL_CHANGES_IN_FRAME);; - case RENDER_SHADER_CHANGES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_SHADER_CHANGES_IN_FRAME);; - case RENDER_SURFACE_CHANGES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_SURFACE_CHANGES_IN_FRAME);; + case RENDER_MATERIAL_CHANGES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_MATERIAL_CHANGES_IN_FRAME); + case RENDER_SHADER_CHANGES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_SHADER_CHANGES_IN_FRAME); + case RENDER_SURFACE_CHANGES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_SURFACE_CHANGES_IN_FRAME); case RENDER_DRAW_CALLS_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_DRAW_CALLS_IN_FRAME); case RENDER_VIDEO_MEM_USED: return VS::get_singleton()->get_render_info(VS::INFO_VIDEO_MEM_USED); case RENDER_TEXTURE_MEM_USED: return VS::get_singleton()->get_render_info(VS::INFO_TEXTURE_MEM_USED); diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp index 4f4e76d517..7fdfef5f3c 100644 --- a/main/tests/test_gdscript.cpp +++ b/main/tests/test_gdscript.cpp @@ -219,7 +219,7 @@ static String _parser_expr(const GDParser::Node *p_expr) { case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: { txt=_parser_expr(c_node->arguments[0])+"&="+_parser_expr(c_node->arguments[1]); } break; case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: { txt=_parser_expr(c_node->arguments[0])+"|="+_parser_expr(c_node->arguments[1]); } break; case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: { txt=_parser_expr(c_node->arguments[0])+"^="+_parser_expr(c_node->arguments[1]); } break; - case GDParser::OperatorNode::OP_BIT_AND: { txt=_parser_expr(c_node->arguments[0])+"&"+_parser_expr(c_node->arguments[1]); } break;; + case GDParser::OperatorNode::OP_BIT_AND: { txt=_parser_expr(c_node->arguments[0])+"&"+_parser_expr(c_node->arguments[1]); } break; case GDParser::OperatorNode::OP_BIT_OR: { txt=_parser_expr(c_node->arguments[0])+"|"+_parser_expr(c_node->arguments[1]); } break; case GDParser::OperatorNode::OP_BIT_XOR: { txt=_parser_expr(c_node->arguments[0])+"^"+_parser_expr(c_node->arguments[1]); } break; default: {} @@ -947,7 +947,7 @@ MainLoop* test(TestType p_test) { if (tk.get_token_line()!=line) { int from=line+1; - line = tk.get_token_line();; + line = tk.get_token_line(); for(int i=from;i<=line;i++) { int l=i-1; diff --git a/main/tests/test_gui.cpp b/main/tests/test_gui.cpp index b0ebc20180..899bdc37b9 100644 --- a/main/tests/test_gui.cpp +++ b/main/tests/test_gui.cpp @@ -353,14 +353,14 @@ public: label = memnew( Label ); label->set_text("Some Label"); label->set_pos( Point2(20,20) ); - ctl->add_child(label);; + ctl->add_child(label); ctl= memnew( Control ); ctl->set_name("tab 3"); button = memnew( Button ); button->set_text("Some Button"); button->set_pos( Point2(30,50) ); - ctl->add_child(button);; + ctl->add_child(button); tabc->add_child(ctl); diff --git a/main/tests/test_main.cpp b/main/tests/test_main.cpp index 1f7f2d7dda..763616dd46 100644 --- a/main/tests/test_main.cpp +++ b/main/tests/test_main.cpp @@ -104,10 +104,10 @@ MainLoop* test_main(String p_test,const List<String>& p_args) { } #endif - if (p_test=="sound") { + //if (p_test=="sound") { - return TestSound::test(); - } + // return TestSound::test(); + //} if (p_test=="io") { diff --git a/main/tests/test_physics.cpp b/main/tests/test_physics.cpp index ea98da34ca..95ce540b16 100644 --- a/main/tests/test_physics.cpp +++ b/main/tests/test_physics.cpp @@ -111,7 +111,7 @@ protected: PhysicsServer * ps = PhysicsServer::get_singleton(); - RID plane_shape = ps->shape_create(PhysicsServer::SHAPE_PLANE);; + RID plane_shape = ps->shape_create(PhysicsServer::SHAPE_PLANE); ps->shape_set_data( plane_shape, p_plane ); RID b = ps->body_create( PhysicsServer::BODY_MODE_STATIC ); @@ -345,11 +345,16 @@ public: /* CAMERA */ camera = vs->camera_create(); + RID viewport = vs->viewport_create(); + Size2i screen_size = OS::get_singleton()->get_window_size(); + vs->viewport_set_size(viewport,screen_size.x,screen_size.y); + vs->viewport_attach_to_screen(viewport,Rect2(Vector2(),screen_size)); + vs->viewport_set_active(viewport,true); vs->viewport_attach_camera( viewport, camera ); - vs->viewport_attach_to_screen(viewport); vs->viewport_set_scenario( viewport, scenario ); + vs->camera_set_perspective(camera,60,0.1,40.0); vs->camera_set_transform(camera,Transform( Basis(), Vector3(0,9,12))); //vs->scenario_set_debug(scenario,VS::SCENARIO_DEBUG_WIREFRAME); diff --git a/main/tests/test_physics_2d.cpp b/main/tests/test_physics_2d.cpp index 8a6a8c78f9..76d1afd2ac 100644 --- a/main/tests/test_physics_2d.cpp +++ b/main/tests/test_physics_2d.cpp @@ -63,7 +63,7 @@ class TestPhysics2DMainLoop : public MainLoop { }; - BodyShapeData body_shape_data[6]; + BodyShapeData body_shape_data[8]; void _create_body_shape_data() { @@ -191,7 +191,7 @@ class TestPhysics2DMainLoop : public MainLoop { Image image(convex_png); - body_shape_data[Physics2DServer::SHAPE_CUSTOM+1].image=vs->texture_create_from_image(image); + body_shape_data[Physics2DServer::SHAPE_CONVEX_POLYGON].image=vs->texture_create_from_image(image); RID convex_polygon_shape = ps->shape_create(Physics2DServer::SHAPE_CONVEX_POLYGON); @@ -206,7 +206,7 @@ class TestPhysics2DMainLoop : public MainLoop { arr.push_back(Point2(11,7)-sb); ps->shape_set_data(convex_polygon_shape,arr); - body_shape_data[Physics2DServer::SHAPE_CUSTOM+1].shape = convex_polygon_shape; + body_shape_data[Physics2DServer::SHAPE_CONVEX_POLYGON].shape = convex_polygon_shape; } @@ -382,8 +382,13 @@ public: RID vp = vs->viewport_create(); canvas = vs->canvas_create(); + + Size2i screen_size = OS::get_singleton()->get_window_size(); vs->viewport_attach_canvas(vp,canvas); - vs->viewport_attach_to_screen(vp,Rect2(Vector2(),OS::get_singleton()->get_window_size())); + vs->viewport_set_size(vp,screen_size.x,screen_size.y); + vs->viewport_attach_to_screen(vp,Rect2(Vector2(),screen_size)); + vs->viewport_set_active(vp,true); + Transform2D smaller; //smaller.scale(Vector2(0.6,0.6)); //smaller.elements[2]=Vector2(100,0); diff --git a/main/tests/test_sound.cpp b/main/tests/test_sound.cpp index 44cc117e02..6b0cf0a324 100644 --- a/main/tests/test_sound.cpp +++ b/main/tests/test_sound.cpp @@ -30,11 +30,13 @@ #include "servers/visual_server.h" #include "os/main_loop.h" #include "math_funcs.h" -#include "scene/resources/sample.h" + #include "io/resource_loader.h" #include "print_string.h" #include "servers/audio_server.h" #include "os/os.h" + +#if 0 namespace TestSound { @@ -93,3 +95,4 @@ MainLoop* test() { } } +#endif diff --git a/tools/dist/docker/Dockerfile b/misc/dist/docker/Dockerfile index 428de9d1a7..428de9d1a7 100644 --- a/tools/dist/docker/Dockerfile +++ b/misc/dist/docker/Dockerfile diff --git a/tools/dist/docker/README.md b/misc/dist/docker/README.md index 7f10b46ad8..7f10b46ad8 100644 --- a/tools/dist/docker/README.md +++ b/misc/dist/docker/README.md diff --git a/tools/dist/docker/scripts/install-android-tools b/misc/dist/docker/scripts/install-android-tools index 8a617d9942..8a617d9942 100644 --- a/tools/dist/docker/scripts/install-android-tools +++ b/misc/dist/docker/scripts/install-android-tools diff --git a/tools/dist/html_fs/godotfs.js b/misc/dist/html_fs/godotfs.js index 2c59344cf5..2c59344cf5 100644 --- a/tools/dist/html_fs/godotfs.js +++ b/misc/dist/html_fs/godotfs.js diff --git a/tools/dist/ios_xcode/godot_xcode/data.pck b/misc/dist/ios_xcode/godot_xcode/data.pck index e69de29bb2..e69de29bb2 100644 --- a/tools/dist/ios_xcode/godot_xcode/data.pck +++ b/misc/dist/ios_xcode/godot_xcode/data.pck diff --git a/tools/dist/ios_xcode/godot_xcode/godot_debug.iphone b/misc/dist/ios_xcode/godot_xcode/godot_debug.iphone index e69de29bb2..e69de29bb2 100755 --- a/tools/dist/ios_xcode/godot_xcode/godot_debug.iphone +++ b/misc/dist/ios_xcode/godot_xcode/godot_debug.iphone diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios.xcodeproj/project.pbxproj b/misc/dist/ios_xcode/godot_xcode/godot_ios.xcodeproj/project.pbxproj index bdba8488c8..bdba8488c8 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios.xcodeproj/project.pbxproj +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios.xcodeproj/project.pbxproj diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/misc/dist/ios_xcode/godot_xcode/godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 3c9ba38bbe..3c9ba38bbe 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-568h@2x~iphone.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-568h@2x~iphone.png Binary files differindex 1d5e472665..1d5e472665 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-568h@2x~iphone.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-568h@2x~iphone.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-667h.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-667h.png Binary files differindex b13a399c83..b13a399c83 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-667h.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-667h.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-667h@2x.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-667h@2x.png Binary files differindex b51598fed0..b51598fed0 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-667h@2x.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-667h@2x.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-736h.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-736h.png Binary files differindex 8c44edbccd..8c44edbccd 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-736h.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-736h.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-736h@3x.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-736h@3x.png Binary files differindex 33847ac136..33847ac136 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-736h@3x.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-736h@3x.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape-736h.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape-736h.png Binary files differindex 2a025b745b..2a025b745b 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape-736h.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape-736h.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape@2x~ipad.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape@2x~ipad.png Binary files differindex 7099f3e18d..7099f3e18d 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape@2x~ipad.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape@2x~ipad.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape~ipad.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape~ipad.png Binary files differindex 4a761c339a..4a761c339a 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape~ipad.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-Landscape~ipad.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-Portrait@2x~ipad.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-Portrait@2x~ipad.png Binary files differindex b09cf21186..b09cf21186 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-Portrait@2x~ipad.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-Portrait@2x~ipad.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-Portrait~ipad.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-Portrait~ipad.png Binary files differindex fa698eb70c..fa698eb70c 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default-Portrait~ipad.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default-Portrait~ipad.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default@2x~iphone.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default@2x~iphone.png Binary files differindex ddf2861f4d..ddf2861f4d 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default@2x~iphone.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default@2x~iphone.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default~iphone.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default~iphone.png Binary files differindex c485a33b03..c485a33b03 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Default~iphone.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Default~iphone.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Contents.json b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Contents.json index a458b67873..a458b67873 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Contents.json diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-100.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-100.png Binary files differindex 165f4423b3..165f4423b3 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-100.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-100.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-114.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-114.png Binary files differindex 2e205e920c..2e205e920c 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-114.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-114.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-120.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-120.png Binary files differindex 6245f83f48..6245f83f48 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-120.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-120.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-144.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-144.png Binary files differindex 7b24e01bc6..7b24e01bc6 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-144.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-144.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-152.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-152.png Binary files differindex 344b470fa3..344b470fa3 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-152.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-152.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-180.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-180.png Binary files differindex 0dcebbc3f2..0dcebbc3f2 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-180.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-180.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-29.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-29.png Binary files differindex 9ae94e9aaf..9ae94e9aaf 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-29.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-29.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-40.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-40.png Binary files differindex 569f24df91..569f24df91 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-40.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-40.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-50.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-50.png Binary files differindex 9e69ed3121..9e69ed3121 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-50.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-50.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-57.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-57.png Binary files differindex b970fa3067..b970fa3067 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-57.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-57.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-58.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-58.png Binary files differindex 6097a6c73b..6097a6c73b 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-58.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-58.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-60.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-60.png Binary files differindex 21b9622eb6..21b9622eb6 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-60.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-60.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-72.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-72.png Binary files differindex 34dea8e6ad..34dea8e6ad 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-72.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-72.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-76.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-76.png Binary files differindex f72eb0b345..f72eb0b345 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-76.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-76.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-80.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-80.png Binary files differindex 793c9b1f5f..793c9b1f5f 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-80.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/Icon-80.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/icon-167.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/icon-167.png Binary files differindex 7cd0e054ab..7cd0e054ab 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/icon-167.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/icon-167.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/icon-87.png b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/icon-87.png Binary files differindex e9b2429754..e9b2429754 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/icon-87.png +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/icon-87.png diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/sizes b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/sizes index e328a62cb6..e328a62cb6 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/sizes +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/Images.xcassets/AppIcon.appiconset/sizes diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/en.lproj/InfoPlist.strings b/misc/dist/ios_xcode/godot_xcode/godot_ios/en.lproj/InfoPlist.strings index 477b28ff8f..477b28ff8f 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/en.lproj/InfoPlist.strings +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/en.lproj/InfoPlist.strings diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/godot_ios-Info.plist b/misc/dist/ios_xcode/godot_xcode/godot_ios/godot_ios-Info.plist index f97b0fca36..f97b0fca36 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/godot_ios-Info.plist +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/godot_ios-Info.plist diff --git a/tools/dist/ios_xcode/godot_xcode/godot_ios/main.m b/misc/dist/ios_xcode/godot_xcode/godot_ios/main.m index 88b8e60670..88b8e60670 100644 --- a/tools/dist/ios_xcode/godot_xcode/godot_ios/main.m +++ b/misc/dist/ios_xcode/godot_xcode/godot_ios/main.m diff --git a/tools/dist/ios_xcode/godot_xcode/godot_opt.iphone b/misc/dist/ios_xcode/godot_xcode/godot_opt.iphone index e69de29bb2..e69de29bb2 100755 --- a/tools/dist/ios_xcode/godot_xcode/godot_opt.iphone +++ b/misc/dist/ios_xcode/godot_xcode/godot_opt.iphone diff --git a/tools/dist/osx_template.app/Contents/Info.plist b/misc/dist/osx_template.app/Contents/Info.plist index eee787bdaf..eee787bdaf 100755 --- a/tools/dist/osx_template.app/Contents/Info.plist +++ b/misc/dist/osx_template.app/Contents/Info.plist diff --git a/tools/dist/osx_template.app/Contents/PkgInfo b/misc/dist/osx_template.app/Contents/PkgInfo index 6f749b0f37..6f749b0f37 100644 --- a/tools/dist/osx_template.app/Contents/PkgInfo +++ b/misc/dist/osx_template.app/Contents/PkgInfo diff --git a/tools/dist/osx_template.app/Contents/Resources/icon.icns b/misc/dist/osx_template.app/Contents/Resources/icon.icns Binary files differindex 375f61437d..375f61437d 100644 --- a/tools/dist/osx_template.app/Contents/Resources/icon.icns +++ b/misc/dist/osx_template.app/Contents/Resources/icon.icns diff --git a/tools/dist/osx_tools.app/Contents/Info.plist b/misc/dist/osx_tools.app/Contents/Info.plist index 4d88e97503..4d88e97503 100755 --- a/tools/dist/osx_tools.app/Contents/Info.plist +++ b/misc/dist/osx_tools.app/Contents/Info.plist diff --git a/tools/dist/osx_tools.app/Contents/PkgInfo b/misc/dist/osx_tools.app/Contents/PkgInfo index 6f749b0f37..6f749b0f37 100644 --- a/tools/dist/osx_tools.app/Contents/PkgInfo +++ b/misc/dist/osx_tools.app/Contents/PkgInfo diff --git a/tools/dist/osx_tools.app/Contents/Resources/Godot.icns b/misc/dist/osx_tools.app/Contents/Resources/Godot.icns Binary files differindex 375f61437d..375f61437d 100644 --- a/tools/dist/osx_tools.app/Contents/Resources/Godot.icns +++ b/misc/dist/osx_tools.app/Contents/Resources/Godot.icns diff --git a/tools/dist/uwp_template/AppxManifest.xml b/misc/dist/uwp_template/AppxManifest.xml index d5e653708c..d5e653708c 100644 --- a/tools/dist/uwp_template/AppxManifest.xml +++ b/misc/dist/uwp_template/AppxManifest.xml diff --git a/tools/dist/uwp_template/Assets/SplashScreen.scale-100.png b/misc/dist/uwp_template/Assets/SplashScreen.scale-100.png Binary files differindex 540bfb1c01..540bfb1c01 100644 --- a/tools/dist/uwp_template/Assets/SplashScreen.scale-100.png +++ b/misc/dist/uwp_template/Assets/SplashScreen.scale-100.png diff --git a/tools/dist/uwp_template/Assets/Square150x150Logo.scale-100.png b/misc/dist/uwp_template/Assets/Square150x150Logo.scale-100.png Binary files differindex 6cff663eb5..6cff663eb5 100644 --- a/tools/dist/uwp_template/Assets/Square150x150Logo.scale-100.png +++ b/misc/dist/uwp_template/Assets/Square150x150Logo.scale-100.png diff --git a/tools/dist/uwp_template/Assets/Square310x310Logo.scale-100.png b/misc/dist/uwp_template/Assets/Square310x310Logo.scale-100.png Binary files differindex 12ec232c87..12ec232c87 100644 --- a/tools/dist/uwp_template/Assets/Square310x310Logo.scale-100.png +++ b/misc/dist/uwp_template/Assets/Square310x310Logo.scale-100.png diff --git a/tools/dist/uwp_template/Assets/Square44x44Logo.scale-100.png b/misc/dist/uwp_template/Assets/Square44x44Logo.scale-100.png Binary files differindex ad059994ed..ad059994ed 100644 --- a/tools/dist/uwp_template/Assets/Square44x44Logo.scale-100.png +++ b/misc/dist/uwp_template/Assets/Square44x44Logo.scale-100.png diff --git a/tools/dist/uwp_template/Assets/Square71x71Logo.scale-100.png b/misc/dist/uwp_template/Assets/Square71x71Logo.scale-100.png Binary files differindex b1bf331365..b1bf331365 100644 --- a/tools/dist/uwp_template/Assets/Square71x71Logo.scale-100.png +++ b/misc/dist/uwp_template/Assets/Square71x71Logo.scale-100.png diff --git a/tools/dist/uwp_template/Assets/StoreLogo.scale-100.png b/misc/dist/uwp_template/Assets/StoreLogo.scale-100.png Binary files differindex 8d7a625c82..8d7a625c82 100644 --- a/tools/dist/uwp_template/Assets/StoreLogo.scale-100.png +++ b/misc/dist/uwp_template/Assets/StoreLogo.scale-100.png diff --git a/tools/dist/uwp_template/Assets/Wide310x150Logo.scale-100.png b/misc/dist/uwp_template/Assets/Wide310x150Logo.scale-100.png Binary files differindex b06f1ad50f..b06f1ad50f 100644 --- a/tools/dist/uwp_template/Assets/Wide310x150Logo.scale-100.png +++ b/misc/dist/uwp_template/Assets/Wide310x150Logo.scale-100.png diff --git a/tools/scripts/addheader.py b/misc/scripts/addheader.py index 056e807c81..056e807c81 100644 --- a/tools/scripts/addheader.py +++ b/misc/scripts/addheader.py diff --git a/tools/scripts/file-hex-array.py b/misc/scripts/file-hex-array.py index a6cdfe541f..a6cdfe541f 100755 --- a/tools/scripts/file-hex-array.py +++ b/misc/scripts/file-hex-array.py diff --git a/tools/scripts/make_bmfhdr.py b/misc/scripts/make_bmfhdr.py index 1d3c40f9c6..1d3c40f9c6 100644 --- a/tools/scripts/make_bmfhdr.py +++ b/misc/scripts/make_bmfhdr.py diff --git a/tools/scripts/make_glwrapper.py b/misc/scripts/make_glwrapper.py index 5694d2327e..5694d2327e 100644 --- a/tools/scripts/make_glwrapper.py +++ b/misc/scripts/make_glwrapper.py diff --git a/tools/scripts/make_icons.sh b/misc/scripts/make_icons.sh index 71037cd1c3..71037cd1c3 100644 --- a/tools/scripts/make_icons.sh +++ b/misc/scripts/make_icons.sh diff --git a/tools/scripts/makeargs.py b/misc/scripts/makeargs.py index 2cd47ae087..2cd47ae087 100644 --- a/tools/scripts/makeargs.py +++ b/misc/scripts/makeargs.py diff --git a/tools/scripts/memsort.py b/misc/scripts/memsort.py index fb636b0f78..fb636b0f78 100644 --- a/tools/scripts/memsort.py +++ b/misc/scripts/memsort.py diff --git a/tools/scripts/sort-demos.sh b/misc/scripts/sort-demos.sh index d4770b337e..2121d78c15 100644 --- a/tools/scripts/sort-demos.sh +++ b/misc/scripts/sort-demos.sh @@ -1,7 +1,7 @@ #!/bin/bash # When scanning for demos, the project manager sorts them based on their # timestamp, i.e. last modification date. This can make for a pretty -# messy output, so this script 'touches' each engine.cfg file in reverse +# messy output, so this script 'touches' each godot.cfg file in reverse # alphabetical order to ensure a nice listing. # # It's good practice to run it once before packaging demos on the build @@ -17,7 +17,7 @@ if [ -e demos.list ]; then fi for dir in 2d 3d gui misc viewport; do - find "demos/$dir" -name "engine.cfg" |sort >> demos.list + find "demos/$dir" -name "godot.cfg" |sort >> demos.list done cat demos.list |sort -r > demos_r.list diff --git a/tools/scripts/svgs_2_pngs.py b/misc/scripts/svgs_2_pngs.py index b24324dcd7..b24324dcd7 100644 --- a/tools/scripts/svgs_2_pngs.py +++ b/misc/scripts/svgs_2_pngs.py diff --git a/modules/chibi/SCsub b/modules/chibi/SCsub deleted file mode 100644 index dffd966753..0000000000 --- a/modules/chibi/SCsub +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python - -Import('env') -Import('env_modules') - -env_chibi = env_modules.Clone() - -# Godot source files -env_chibi.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/chibi/cp_config.h b/modules/chibi/cp_config.h deleted file mode 100644 index 35312b68be..0000000000 --- a/modules/chibi/cp_config.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************/ -/* cp_config.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_CONFIG_H -#define CP_CONFIG_H - - -#include "typedefs.h" -#include "error_macros.h" -#include "math_funcs.h" -#include "os/memory.h" -#include "os/copymem.h" - -#define CP_PRINTERR(m_err) ERR_PRINT(m_err) -#define CP_ERR_COND(m_cond) ERR_FAIL_COND(m_cond) -#define CP_ERR_COND_V(m_cond,m_ret) ERR_FAIL_COND_V(m_cond,m_ret) -#define CP_FAIL_INDEX(m_index,m_size) ERR_FAIL_INDEX(m_index,m_size) -#define CP_FAIL_INDEX_V(m_index,m_size,m_ret) ERR_FAIL_INDEX_V(m_index,m_size,m_ret) -#define cp_intabs(m_val) ABS(m_val) - -#define CP_ALLOC(m_mem) memalloc(m_mem) -#define CP_REALLOC(m_mem,m_size) memrealloc(m_mem,m_size) -#define CP_FREE(m_mem) memfree(m_mem) - -#define cp_memzero(m_mem,m_size) zeromem(m_mem,m_size) - -#endif // CP_CONFIG_H diff --git a/modules/chibi/cp_envelope.cpp b/modules/chibi/cp_envelope.cpp deleted file mode 100644 index 36259e8d63..0000000000 --- a/modules/chibi/cp_envelope.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/*************************************************************************/ -/* cp_envelope.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_envelope.h" - - -CPEnvelope::CPEnvelope() { - - - reset(); -} - -void CPEnvelope::reset() { - - - - on=false; - carry=false; - loop_on=false; - loop_begin_node=0; - loop_end_node=0; - sustain_loop_on=false; - sustain_loop_begin_node=0; - sustain_loop_end_node=0; - node_count=0; - -} - -int CPEnvelope::get_height_at_pos(int pos) { - - if (node_count && pos>node[node_count-1].tick_offset) - return node[node_count-1].value; - - int begin_x,begin_y; - int end_x,end_y,xdif; - int count=0; - int limit=-1; - - if (node_count<2) return NO_POINT; - - while ((count<node_count) && (limit==-1)) { - - if (node[count].tick_offset>=pos) limit=count; - count++; - } - - if (pos==0) return node[0].value; - - if (limit==-1) return NO_POINT; - - begin_x=node[limit-1].tick_offset; - end_x=node[limit].tick_offset; - begin_y=node[limit-1].value; - end_y=node[limit].value; - - xdif=end_x-begin_x; - return begin_y+((pos-begin_x)*(end_y-begin_y))/(xdif?xdif:1); -} - -/* -int CPEnvelope::get_fx_height_at_pos(int pos) { - - if (node_count && pos>node[node_count-1].tick_offset) - return node[node_count-1].value<<FX_HEIGHT_BITS; - - int begin_x,begin_y; - int end_x,end_y,xdif; - int count=0; - int limit=-1; - - if (node_count<2) return NO_POINT; - - while ((count<node_count) && (limit==-1)) { - - if (node[count].tick_offset>=pos) limit=count; - count++; - } - - if (pos==0) return node[0].value<<FX_HEIGHT_BITS; - - if (limit==-1) return NO_POINT; - - begin_x=node[limit-1].tick_offset; - end_x=node[limit].tick_offset; - begin_y=node[limit-1].value; - end_y=node[limit].value; - - xdif=end_x-begin_x; - return (begin_y<<FX_HEIGHT_BITS)+((pos-begin_x)*(end_y-begin_y)*(int)(1<<FX_HEIGHT_BITS))/(xdif?xdif:1); -} -*/ - -float CPEnvelope::get_interp_height_at_pos(float pos) { - - if (node_count && pos>node[node_count-1].tick_offset) - return node[node_count-1].value; - - int begin_x,begin_y; - int end_x,end_y,xdif; - int count=0; - int limit=-1; - - if (node_count<2) return NO_POINT; - - while ((count<node_count) && (limit==-1)) { - - if (node[count].tick_offset>=pos) limit=count; - count++; - } - - if (pos==0) return node[0].value; - - if (limit==-1) return NO_POINT; - - begin_x=node[limit-1].tick_offset; - end_x=node[limit].tick_offset; - begin_y=node[limit-1].value; - end_y=node[limit].value; - - xdif=end_x-begin_x; - return begin_y+((pos-begin_x)*(end_y-begin_y))/(xdif?xdif:1); -} - -void CPEnvelope::set_position(int p_node,int p_x,int p_y) { - - if (p_node>=node_count) return; - - - - if (p_node==0) { - - p_x=0; - - } else if (p_x<=node[p_node-1].tick_offset) { - - p_x=node[p_node-1].tick_offset+1; - - } else if ((p_node<(node_count-1)) && (p_x>=node[p_node+1].tick_offset)) { - - p_x=node[p_node+1].tick_offset-1; - } - - if (p_x>=9999) p_x=9999; - - if (p_y>max_value) p_y=max_value; - if (p_y<min_value) p_y=min_value; - - - node[p_node].tick_offset=p_x; - node[p_node].value=p_y; - - - -} - -int CPEnvelope::add_position(int p_x,int p_y,bool p_move_loops) { - - if (node_count==MAX_POINTS) return -1; - - - int i,new_node; - - // if this is assigning an existing node, let's quit. - for (i=0;i<node_count;i++) if (p_x==node[i].tick_offset) return -1; - - - i=0; - while ((i<node_count) && (p_x>=node[i].tick_offset)) i++; - - new_node=i; - node_count++; - - if (p_move_loops) { - if (loop_begin_node>=new_node) loop_begin_node++; - if (loop_end_node>=new_node) loop_end_node++; - if (sustain_loop_begin_node>=new_node) sustain_loop_begin_node++; - if (sustain_loop_end_node>=new_node) sustain_loop_end_node++; - } - for (i=node_count-1;i>new_node;i--) node[i]=node[i-1]; - - - - set_position(new_node,p_x,p_y); - - - - return new_node; - -} - -void CPEnvelope::set_loop_begin(int pos) { - - if ((pos<0) || (pos>=node_count)) return; - - - - loop_begin_node=pos; - - if (loop_end_node<loop_begin_node) loop_end_node=loop_begin_node; - - - -} - -void CPEnvelope::set_loop_end(int pos) { - - if ((pos<0) || (pos>=node_count)) return; - - - - loop_end_node=pos; - - if (loop_end_node<loop_begin_node) loop_begin_node=loop_end_node; - - - - -} - - -void CPEnvelope::set_sustain_loop_begin(int pos) { - - if ((pos<0) || (pos>=node_count)) return; - - - - sustain_loop_begin_node=pos; - - if (sustain_loop_end_node<sustain_loop_begin_node) sustain_loop_end_node=sustain_loop_begin_node; - - - -} - -void CPEnvelope::set_sustain_loop_end(int pos) { - - if ((pos<0) || (pos>=node_count)) return; - - - - sustain_loop_end_node=pos; - - if (sustain_loop_end_node<sustain_loop_begin_node) sustain_loop_begin_node=sustain_loop_end_node; - - - -} - -void CPEnvelope::set_loop_enabled(bool p_enabled) { - - loop_on=p_enabled; -} -bool CPEnvelope::is_loop_enabled() { - - return loop_on; -} - - -void CPEnvelope::set_sustain_loop_enabled(bool p_enabled) { - - sustain_loop_on=p_enabled; -} -bool CPEnvelope::is_sustain_loop_enabled() { - - return sustain_loop_on; -} - -void CPEnvelope::del_position(int p_node) { - - if ((node_count<3) || (p_node<=0) || (p_node>=node_count)) return; - - - - int i; - - if (loop_begin_node>=p_node) loop_begin_node--; - if (loop_end_node>=p_node) loop_end_node--; - if (sustain_loop_begin_node>=p_node) sustain_loop_begin_node--; - if (sustain_loop_end_node>=p_node) sustain_loop_end_node--; - - for (i=p_node;i<node_count-1;i++) node[i]=node[i+1]; - - node_count--; - - - -} - -uint8_t CPEnvelope::get_loop_begin() { - - - return loop_begin_node; -} -uint8_t CPEnvelope::get_loop_end() { - - return loop_end_node; -} - -uint8_t CPEnvelope::get_sustain_loop_begin() { - - - return sustain_loop_begin_node; -} -uint8_t CPEnvelope::get_sustain_loop_end() { - - return sustain_loop_end_node; -} - - - -void CPEnvelope::set_enabled(bool p_enabled) { - - on=p_enabled; -} - -bool CPEnvelope::is_enabled() { - - return on; -} - -void CPEnvelope::set_carry_enabled(bool p_enabled) { - - carry=p_enabled; -} -bool CPEnvelope::is_carry_enabled() { - - return carry; -} - -uint8_t CPEnvelope::get_node_count() { - - return node_count; -} - -const CPEnvelope::Point& CPEnvelope::get_node(int p_idx) { - - if (p_idx<0 || p_idx>=node_count) - return node[node_count-1]; - - return node[p_idx]; - -} - - diff --git a/modules/chibi/cp_envelope.h b/modules/chibi/cp_envelope.h deleted file mode 100644 index af27f5f185..0000000000 --- a/modules/chibi/cp_envelope.h +++ /dev/null @@ -1,129 +0,0 @@ -/*************************************************************************/ -/* cp_envelope.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_ENVELOPE_H -#define CP_ENVELOPE_H - -#include "cp_config.h" - -/**envelope? - *@author Juan Linietsky - */ - -/****************************** - envelope.h - ---------- - -Proovides an envelope, and basic functions -for it that can be used for both player -and interface -********************************/ - - -class CPEnvelope { - enum { - - MAX_POINTS=25 - }; - - struct Point { - - uint16_t tick_offset; - int16_t value; - }; - - Point node[MAX_POINTS]; - - int8_t node_count; - - bool on; - bool carry; - - bool loop_on; - - uint8_t loop_begin_node; - uint8_t loop_end_node; - - bool sustain_loop_on; - uint8_t sustain_loop_begin_node; - uint8_t sustain_loop_end_node; - - - int8_t max_value; - int8_t min_value; - - -public: - enum { - - NO_POINT=-5000, - }; - - void set_max(int8_t p_max) { max_value=p_max; } - int8_t get_max() { return max_value; } - void set_min(int8_t p_min) { min_value=p_min; } - int8_t get_min() { return min_value; } - - uint8_t get_node_count(); - const Point& get_node(int p_idx); - - void set_position(int p_node,int p_x,int p_y); - int add_position(int p_x,int p_y,bool p_move_loops=true); - void del_position(int p_node); - - void set_loop_enabled(bool p_enabled); - bool is_loop_enabled(); - void set_loop_begin(int pos); - void set_loop_end(int pos); - uint8_t get_loop_begin(); - uint8_t get_loop_end(); - - void set_sustain_loop_enabled(bool p_enabled); - bool is_sustain_loop_enabled(); - void set_sustain_loop_begin(int pos); - void set_sustain_loop_end(int pos); - uint8_t get_sustain_loop_begin(); - uint8_t get_sustain_loop_end(); - - void set_enabled(bool p_enabled); - bool is_enabled(); - - void set_carry_enabled(bool p_enabled); - bool is_carry_enabled(); - - void reset(); - int get_height_at_pos(int pos); - float get_interp_height_at_pos(float pos); - - - CPEnvelope(); - -}; - -#endif diff --git a/modules/chibi/cp_file_access_wrapper.h b/modules/chibi/cp_file_access_wrapper.h deleted file mode 100644 index ade077c1ef..0000000000 --- a/modules/chibi/cp_file_access_wrapper.h +++ /dev/null @@ -1,96 +0,0 @@ -/*************************************************************************/ -/* cp_file_access_wrapper.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_FILE_ACCESS_WRAPPER_H -#define CP_FILE_ACCESS_WRAPPER_H - -#include "cp_config.h" - -class CPFileAccessWrapper { -public: - - enum ModeFlags { - - READ=1, - WRITE=2, - READ_WRITE=3, - }; - - enum Error { - - OK, - ERROR_FILE_NOT_FOUND, - ERROR_FILE_BAD_DRIVE, - ERROR_FILE_BAD_PATH, - ERROR_FILE_NO_PERMISSION, - ERROR_ALREADY_IN_USE, - ERROR_INVALID_PARAMETERS, - ERROR_OPENING_FILE, - ERROR_READING_FILE, - ERROR_WRITING_FILE - }; - - virtual Error open(const char *p_filename, int p_mode_flags)=0; - virtual void close()=0; - - virtual void seek(uint32_t p_position)=0; - virtual void seek_end()=0; - virtual uint32_t get_pos()=0; - - virtual bool eof_reached()=0; - - virtual uint8_t get_byte()=0; - virtual void get_byte_array(uint8_t *p_dest,int p_elements)=0; - virtual void get_word_array(uint16_t *p_dest,int p_elements)=0; - - virtual uint16_t get_word()=0; - virtual uint32_t get_dword()=0; - - // use this for files WRITTEN in _big_ endian machines (ie, amiga/mac) - // It's not about the current CPU type but file formats. - // this flags get reset to false (little endian) on each open - virtual void set_endian_conversion(bool p_swap)=0; - virtual bool is_open()=0; - - virtual Error get_error()=0; - - virtual void store_byte(uint8_t p_dest)=0; - virtual void store_byte_array(const uint8_t *p_dest,int p_elements)=0; - - virtual void store_word(uint16_t p_dest)=0; - virtual void store_dword(uint32_t p_dest)=0; - - - - virtual ~CPFileAccessWrapper(){} - -}; - - - -#endif diff --git a/modules/chibi/cp_instrument.cpp b/modules/chibi/cp_instrument.cpp deleted file mode 100644 index 606a4217e0..0000000000 --- a/modules/chibi/cp_instrument.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/*************************************************************************/ -/* cp_instrument.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_instrument.h" -#include "cp_song.h" -#include "cp_note.h" - - - -const char *CPInstrument::get_name() { - - return name; - -} -void CPInstrument::set_name(const char *p_name) { - - - if (p_name==NULL) { - name[0]=0; - return; - } - - - bool done=false; - for (int i=0;i<MAX_NAME_LEN;i++) { - - - name[i]=done?0:p_name[i]; - if (!done && p_name[i]==0) - done=true; - } - - name[MAX_NAME_LEN-1]=0; /* just in case */ - - -} - -void CPInstrument::set_sample_number(uint8_t p_note,uint8_t p_sample_id) { - - CP_ERR_COND(p_note>=CPNote::NOTES); - CP_ERR_COND(p_sample_id>CPSong::MAX_SAMPLES && p_sample_id!=CPNote::EMPTY); - data.sample_number[p_note]=p_sample_id; - - -} -uint8_t CPInstrument::get_sample_number(uint8_t p_note) { - - CP_ERR_COND_V(p_note>=CPNote::NOTES,0); - return data.sample_number[p_note]; -} - -void CPInstrument::set_note_number(uint8_t p_note,uint8_t p_note_id) { - - CP_ERR_COND(p_note>=CPNote::NOTES); - CP_ERR_COND(p_note_id>=CPNote::NOTES && p_note_id!=CPNote::EMPTY); - data.note_number[p_note]=p_note_id; - -} -uint8_t CPInstrument::get_note_number(uint8_t p_note) { - - CP_ERR_COND_V(p_note>=CPNote::NOTES,0); - return data.note_number[p_note]; - -} - -void CPInstrument::set_NNA_type(NNA_Type p_NNA_type) { - - data.NNA_type=p_NNA_type; -} -CPInstrument::NNA_Type CPInstrument::get_NNA_type() { - - return data.NNA_type; -} - -void CPInstrument::set_DC_type(DC_Type p_DC_type) { - - data.DC_type=p_DC_type; -} -CPInstrument::DC_Type CPInstrument::get_DC_type() { - - return data.DC_type; - -} - -void CPInstrument::set_DC_action(DC_Action p_DC_action) { - - data.DC_action=p_DC_action; -} -CPInstrument::DC_Action CPInstrument::get_DC_action() { - - return data.DC_action; -} - -/* Volume */ - -void CPInstrument::set_volume_global_amount(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_VOLUME); - data.volume.global_amount=p_amount; - -} -uint8_t CPInstrument::get_volume_global_amount() { - - return data.volume.global_amount; -} - -void CPInstrument::set_volume_fadeout(uint16_t p_amount) { - CP_ERR_COND(p_amount>MAX_FADEOUT); - data.volume.fadeout=p_amount; -} -uint16_t CPInstrument::get_volume_fadeout() { - - return data.volume.fadeout; -} -void CPInstrument::set_volume_random_variation(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_VOLUME_RANDOM); - data.volume.random_variation=p_amount; -} -uint8_t CPInstrument::get_volume_random_variation() { - - return data.volume.random_variation; -} - -/* Panning */ - -void CPInstrument::set_pan_default_amount(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_PAN); - data.pan.default_amount=p_amount; -} -uint8_t CPInstrument::get_pan_default_amount() { - - return data.pan.default_amount; -} - -void CPInstrument::set_pan_default_enabled(bool p_enabled) { - - data.pan.use_default=p_enabled; -} -bool CPInstrument::is_pan_default_enabled() { - - return data.pan.use_default; - -} - -void CPInstrument::set_pan_pitch_separation(int8_t p_amount) { - - CP_ERR_COND(p_amount<-32); - CP_ERR_COND(p_amount>32); - data.pan.pitch_separation=p_amount; -} -int8_t CPInstrument::get_pan_pitch_separation() { - - return data.pan.pitch_separation; -} - -void CPInstrument::set_pan_pitch_center(uint8_t p_amount) { - - CP_ERR_COND(p_amount>=CPNote::NOTES); - data.pan.pitch_center=p_amount; -} -uint8_t CPInstrument::get_pan_pitch_center() { - - return data.pan.pitch_center; -} - -void CPInstrument::set_pan_random_variation(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_PAN_RANDOM); - data.pan.random_variation=p_amount; -} -uint8_t CPInstrument::get_pan_random_variation() { - - return data.pan.random_variation; -} - -/* Pitch / Filter */ - -void CPInstrument::set_pitch_use_as_filter(bool p_enabled) { - - data.pitch.use_as_filter=p_enabled; -} -bool CPInstrument::is_pitch_use_as_filter() { - - return data.pitch.use_as_filter; -} - -void CPInstrument::set_filter_use_default_cutoff(bool p_enabled) { - - data.pitch.use_default_cutoff=p_enabled; - -} -bool CPInstrument::filter_use_default_cutoff() { - - return data.pitch.use_default_cutoff; -} - -void CPInstrument::set_filter_default_cutoff(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_FILTER_CUTOFF); - data.pitch.default_cutoff=p_amount; -} -uint8_t CPInstrument::get_filter_default_cutoff() { - - return data.pitch.default_cutoff; -} - -void CPInstrument::set_filter_use_default_resonance(bool p_enabled) { - - data.pitch.use_default_resonance=p_enabled; -} -bool CPInstrument::filter_use_default_resonance() { - - return data.pitch.use_default_resonance; -} - -void CPInstrument::set_filter_default_resonance(uint8_t p_amount) { - - CP_ERR_COND(p_amount>MAX_FILTER_RESONANCE); - data.pitch.default_resonance=p_amount; - -} -uint8_t CPInstrument::get_filter_default_resonance() { - - return data.pitch.default_resonance; -} - -/* Envelopes */ - - -CPEnvelope* CPInstrument::get_volume_envelope() { - - return &data.volume.envelope; -} -CPEnvelope* CPInstrument::get_pan_envelope() { - - return &data.pan.envelope; -} -CPEnvelope* CPInstrument::get_pitch_filter_envelope() { - - return &data.pitch.envelope; - - -} - - -void CPInstrument::reset() { - - name[0]=0; - - data.NNA_type=NNA_NOTE_CUT; - data.DC_action=DCA_NOTE_CUT; - data.DC_type=DCT_DISABLED; - - for (int i=0;i<CPNote::NOTES;i++) { - - data.sample_number[i]=CPNote::EMPTY; - data.note_number[i]=i; - } - - data.volume.envelope.reset(); - data.volume.envelope.set_max(64); - data.volume.envelope.set_min(0); - data.volume.envelope.add_position(0,64,false); - data.volume.envelope.add_position(30,64,false); - - data.volume.global_amount=MAX_VOLUME; - data.volume.fadeout=0; - data.volume.random_variation=0; - - data.pan.envelope.reset(); - data.pan.envelope.set_max(32); - data.pan.envelope.set_min(-32); - data.pan.envelope.add_position(0,0,false); - data.pan.envelope.add_position(30,0,false); - - data.pan.default_amount=32; - data.pan.pitch_center=48; - data.pan.pitch_separation=0; - data.pan.use_default=false; - data.pan.random_variation=0; - - - data.pitch.envelope.reset(); - data.pitch.envelope.set_max(32); - data.pitch.envelope.set_min(-32); - data.pitch.envelope.add_position(0,0,false); - data.pitch.envelope.add_position(30,0,false); - data.pitch.use_as_filter=false; - data.pitch.use_default_cutoff=false; - data.pitch.use_default_resonance=false; - data.pitch.default_cutoff=0; - data.pitch.default_resonance=0; - -} - -bool CPInstrument::is_empty() { - - bool has_sample=false; - - for (int i=0;i<CPNote::NOTES;i++) { - - if (data.sample_number[i]!=CPNote::EMPTY) { - - has_sample=true; - break; - } - } - - return !has_sample; -} - -CPInstrument::CPInstrument() { - - reset(); - -} - diff --git a/modules/chibi/cp_instrument.h b/modules/chibi/cp_instrument.h deleted file mode 100644 index e51612a38d..0000000000 --- a/modules/chibi/cp_instrument.h +++ /dev/null @@ -1,219 +0,0 @@ -/*************************************************************************/ -/* cp_instrument.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_INSTRUMENT_H -#define CP_INSTRUMENT_H - - -#include "cp_config.h" -#include "cp_note.h" -#include "cp_envelope.h" - -class CPInstrument { -public: - - - enum NNA_Type { - - NNA_NOTE_CUT, - NNA_NOTE_CONTINUE, - NNA_NOTE_OFF, - NNA_NOTE_FADE - }; - - enum DC_Type { - - DCT_DISABLED, - DCT_NOTE, - DCT_SAMPLE, - DCT_INSTRUMENT - }; - - enum DC_Action - { - - DCA_NOTE_CUT, - DCA_NOTE_OFF, - DCA_NOTE_FADE, - }; - - enum EnvelopeType { - VOLUME_ENVELOPE, - PAN_ENVELOPE, - PITCH_ENVELOPE - }; - - - enum { - MAX_NAME_LEN=26, - MAX_ENVELOPE_NODES=25, - ENVELOPE_FRAC_BITS=8, - MAX_VOLUME=128, - MAX_FADEOUT=256, - MAX_PAN=128, - MAX_VOLUME_RANDOM=100, - MAX_PAN_RANDOM=64, //what did this guy have inside his head? - - MAX_FILTER_CUTOFF=127, - MAX_FILTER_RESONANCE=127 - - }; - - - struct Data { - - - uint8_t sample_number[CPNote::NOTES]; - uint8_t note_number[CPNote::NOTES]; - - NNA_Type NNA_type; - DC_Type DC_type; - DC_Action DC_action; - - struct Volume { - - CPEnvelope envelope; - uint8_t global_amount; - uint16_t fadeout; - uint8_t random_variation; - - } volume; - - struct Pan { - - CPEnvelope envelope; - bool use_default; - uint8_t default_amount; - int8_t pitch_separation; - uint8_t pitch_center; - uint8_t random_variation; - - } pan; - - struct Pitch { - - CPEnvelope envelope; - bool use_as_filter; - bool use_default_cutoff; - uint8_t default_cutoff; - bool use_default_resonance; - uint8_t default_resonance; - } pitch; - - }; - -private: - - - - Data data; - char name[MAX_NAME_LEN]; - -public: - - /* CPInstrument General */ - - const char *get_name(); - void set_name(const char *p_name); - - void set_sample_number(uint8_t p_note,uint8_t p_sample_id); - uint8_t get_sample_number(uint8_t p_note); - - void set_note_number(uint8_t p_note,uint8_t p_note_id); - uint8_t get_note_number(uint8_t p_note); - - void set_NNA_type(NNA_Type p_NNA_type); - NNA_Type get_NNA_type(); - - void set_DC_type(DC_Type p_DC_type); - DC_Type get_DC_type(); - - void set_DC_action(DC_Action p_DC_action); - DC_Action get_DC_action(); - - /* Volume */ - - void set_volume_global_amount(uint8_t p_amount); - uint8_t get_volume_global_amount(); - - void set_volume_fadeout(uint16_t p_amount); - uint16_t get_volume_fadeout(); - - void set_volume_random_variation(uint8_t p_amount); - uint8_t get_volume_random_variation(); - - /* Panning */ - - void set_pan_default_amount(uint8_t p_amount); - uint8_t get_pan_default_amount(); - - void set_pan_default_enabled(bool p_enabled); - bool is_pan_default_enabled(); - - void set_pan_pitch_separation(int8_t p_amount); - int8_t get_pan_pitch_separation(); - - void set_pan_pitch_center(uint8_t p_amount); - uint8_t get_pan_pitch_center(); - - void set_pan_random_variation(uint8_t p_amount); - uint8_t get_pan_random_variation(); - - /* Pitch / Filter */ - - void set_pitch_use_as_filter(bool p_enabled); - bool is_pitch_use_as_filter(); - - void set_filter_use_default_cutoff(bool p_enabled); - bool filter_use_default_cutoff(); - - void set_filter_default_cutoff(uint8_t p_amount); - uint8_t get_filter_default_cutoff(); - - void set_filter_use_default_resonance(bool p_enabled); - bool filter_use_default_resonance(); - - void set_filter_default_resonance(uint8_t p_amount); - uint8_t get_filter_default_resonance(); - - CPEnvelope* get_volume_envelope(); - CPEnvelope* get_pan_envelope(); - CPEnvelope* get_pitch_filter_envelope(); - - bool is_empty(); - - void reset(); - CPInstrument(); - -}; - - - -#endif - - diff --git a/modules/chibi/cp_loader.h b/modules/chibi/cp_loader.h deleted file mode 100644 index 1630444481..0000000000 --- a/modules/chibi/cp_loader.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************/ -/* cp_loader.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_LOADER_H -#define CP_LOADER_H - - -#include "cp_song.h" -#include "cp_file_access_wrapper.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ -class CPLoader { - -public: - - enum Error { - FILE_OK, - FILE_UNRECOGNIZED, - FILE_CANNOT_OPEN, - FILE_CORRUPTED, - FILE_OUT_OF_MEMORY, - }; - - - virtual bool can_load_song()=0; - virtual bool can_load_sample()=0; - virtual bool can_load_instrument()=0; - - virtual Error load_song(const char *p_file,CPSong *p_song,bool p_sampleset)=0; - virtual Error load_sample(const char *p_file,CPSample *p_sample)=0; - virtual Error load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx)=0; - - - virtual ~CPLoader() {} - -}; - -#endif diff --git a/modules/chibi/cp_loader_it.cpp b/modules/chibi/cp_loader_it.cpp deleted file mode 100644 index bfffd9b509..0000000000 --- a/modules/chibi/cp_loader_it.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_loader_it.h" - -bool CPLoader_IT::can_load_song() { return true; } -bool CPLoader_IT::can_load_sample() { return true; } -bool CPLoader_IT::can_load_instrument() { return true; } - -CPLoader::Error CPLoader_IT::load_song(const char *p_file,CPSong *p_song, bool p_sampleset) { - - - song=p_song; - - if (file->open( p_file, CPFileAccessWrapper::READ )!=CPFileAccessWrapper::OK) - return CPLoader::FILE_CANNOT_OPEN; - - - Error err; - - char aux_identifier[4]; - file->get_byte_array((uint8_t*)aux_identifier,4); - - if ( aux_identifier[0]!='I' || - aux_identifier[1]!='M' || - aux_identifier[2]!='P' || - aux_identifier[3]!='M') { - - - CP_PRINTERR("IT CPLoader CPSong: Failed Identifier"); - return FILE_UNRECOGNIZED; - } - - - if (p_sampleset) { - - song->reset(false,true,true,false); - - if ((err=load_header(true))) { - file->close(); - return err; - } - - if ((err=load_samples())) { - file->close(); - return err; - } - - if ((err=load_instruments())) { - file->close(); - return err; - } - - return FILE_OK; - } - - song->reset(); - - if ((err=load_header(false))) { - file->close(); - return err; - } - - if ((err=load_orders())) { - file->close(); - return err; - } - - if ((err=load_patterns())) { - file->close(); - return err; - } - - if ((err=load_samples())) { - file->close(); - return err; - } - - if ((err=load_effects())) { - file->close(); - return err; - } - - if ((err=load_instruments())) { - file->close(); - return err; - } - - if ((err=load_message())) { - file->close(); - return err; - } - - file->close(); - return FILE_OK; - -} - - - - -CPLoader::Error CPLoader_IT::load_sample(const char *p_file,CPSample *p_sample) { - - if (file->open( p_file, CPFileAccessWrapper::READ )!=CPFileAccessWrapper::OK) - return CPLoader::FILE_CANNOT_OPEN; - - p_sample->reset(); - CPLoader::Error res=load_sample(p_sample); - - file->close(); - - return res; -} -CPLoader::Error CPLoader_IT::load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx) { - - CP_FAIL_INDEX_V(p_instr_idx,CPSong::MAX_INSTRUMENTS,CPLoader::FILE_CANNOT_OPEN); - - if (file->open( p_file, CPFileAccessWrapper::READ )!=CPFileAccessWrapper::OK) - return CPLoader::FILE_CANNOT_OPEN; - - - p_song->get_instrument( p_instr_idx )->reset(); - - - int samples=0; - CPLoader::Error res=load_instrument( p_song->get_instrument( p_instr_idx ), &samples ); - - if (res) { - file->close(); - return res; - } - - - char exchange[CPSong::MAX_SAMPLES]; - for (int i=0;i<CPSong::MAX_SAMPLES;i++) - exchange[i]=0; - - for (int i=0;i<samples;i++) { - - file->seek( 554+i*80 ); //i think this should work?! seems to.. but i'm not sure - - /* find free sample */ - - int free_idx=-1; - for (int s=0;s<CPSong::MAX_SAMPLES;s++) { - - if (p_song->get_sample( s )->get_sample_data().is_null()) { - free_idx=s; - break; - } - } - if (free_idx==-1) - break; //can't seem to be able to load more samples - - exchange[i]=free_idx; - res=load_sample( p_song->get_sample( free_idx ) ); - - if (res) { - - file->close(); - return res; - } - } - - for (int i=0;i<CPNote::NOTES;i++) { - - int smp=song->get_instrument(p_instr_idx)->get_sample_number(i); - - if (smp>=CPSong::MAX_SAMPLES) - continue; - - if (smp<0) - continue; - - smp=exchange[smp]; - - song->get_instrument(p_instr_idx)->set_sample_number(i,smp); - - } - - file->close(); - - return res; - -} - -CPLoader_IT::CPLoader_IT(CPFileAccessWrapper *p_file) { - - file=p_file; - -} diff --git a/modules/chibi/cp_loader_it.h b/modules/chibi/cp_loader_it.h deleted file mode 100644 index 5ce62a6a49..0000000000 --- a/modules/chibi/cp_loader_it.h +++ /dev/null @@ -1,125 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_LOADER_IT_H -#define CP_LOADER_IT_H - -#include "cp_loader.h" -/** - *@author Juan Linietsky - */ - -/****************************** - loader_it.h - ---------- -Impulse Tracker Module CPLoader! -It lacks support for old -instrument files methinks... -and some other things like -midi. -********************************/ - -class AuxSampleData; //used for internal crap - -class CPLoader_IT : public CPLoader { - - - - CPFileAccessWrapper *file; - CPSong *song; - - struct IT_Header { - uint8_t blank01[2]; - uint16_t ordnum; - uint16_t insnum; - uint16_t smpnum; - uint16_t patnum; - uint16_t cwt; /* Created with tracker (y.xx = 0x0yxx) */ - uint16_t cmwt; /* Compatible with tracker ver > than val. */ - uint16_t flags; - uint16_t special; /* bit 0 set = song message attached */ - uint16_t msglength; - uint32_t msgoffset; - bool is_chibi; - }; - - /* Variables to store temp data */ - IT_Header header; - - /* CPSong Info Methods */ - Error load_header(bool p_dont_set); - Error load_orders(); - Error load_message(); - - /* CPPattern Methods */ - Error load_patterns(); - - /* CPSample Methods */ - - Error load_samples(); - Error load_sample(CPSample *p_sample); - CPSample_ID load_sample_data(AuxSampleData& p_sample_data); - - // CPSample decompression - - uint32_t read_n_bits_from_IT_compressed_block(uint8_t p_bits_to_read); - bool read_IT_compressed_block (bool p_16bits); - void free_IT_compressed_block (); - bool load_sample_8bits_IT_compressed(void *p_dest_buffer,int p_buffsize); - bool load_sample_16bits_IT_compressed(void *p_dest_buffer,int p_buffsize); - uint32_t *source_buffer; /* source buffer */ - uint32_t *source_position; /* actual reading position */ - uint8_t source_remaining_bits; /* bits remaining in read dword */ - uint8_t* pat_data; - - /* CPInstruments Methods */ - Error load_effects(); - Error load_instruments(); - Error load_instrument(CPInstrument *p_instrument,int *p_samples=0); - void load_envelope(CPEnvelope *p_envelope,bool*p_has_filter_flag=0); - - -public: - - - bool can_load_song(); - bool can_load_sample(); - bool can_load_instrument(); - - Error load_song(const char *p_file,CPSong *p_song, bool p_sampleset=false); - Error load_sample(const char *p_file,CPSample *p_sample); - Error load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx); - - CPLoader_IT(CPFileAccessWrapper *p_file); - -}; - - - -#endif diff --git a/modules/chibi/cp_loader_it_info.cpp b/modules/chibi/cp_loader_it_info.cpp deleted file mode 100644 index a474fcd2f9..0000000000 --- a/modules/chibi/cp_loader_it_info.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it_info.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_loader_it.h" - - - -CPLoader::Error CPLoader_IT::load_header(bool p_dont_set) { - - - char aux_songname[26]; - - file->get_byte_array((uint8_t*)aux_songname,26); - if (!p_dont_set) - song->set_name( aux_songname ); - - uint8_t aux_hlmin=file->get_byte(); - uint8_t aux_hlmaj=file->get_byte(); - - if (aux_hlmin==0) aux_hlmin=4; - if (aux_hlmaj==0) aux_hlmaj=16; - - if (!p_dont_set) { - song->set_row_highlight_minor( aux_hlmin ); - song->set_row_highlight_major( aux_hlmaj ); - } - - header.ordnum=file->get_word(); - header.insnum=file->get_word(); - header.smpnum=file->get_word(); - header.patnum=file->get_word(); - - header.cwt=file->get_word(); /* Created with tracker (y.xx = 0x0yxx) */ - header.cmwt=file->get_word(); /* Compatible with tracker ver > than val. */ - header.flags=file->get_word(); - - if (!p_dont_set) { - song->set_stereo( header.flags & 1 ); - song->set_linear_slides( header.flags & 8 ); - song->set_old_effects( header.flags & 16 ); - song->set_compatible_gxx( header.flags & 32 ); - song->set_instruments( header.flags & 4 ); - } - - - header.special=file->get_word(); - if (!p_dont_set) { - - song->set_global_volume( file->get_byte() ); - song->set_mixing_volume( file->get_byte() ); - song->set_speed( file->get_byte() ); - song->set_tempo( file->get_byte() ); - song->set_stereo_separation( file->get_byte() ); - - } else { - - file->get_byte(); // skip - file->get_byte(); // skip - file->get_byte(); // skip - file->get_byte(); // skip - file->get_byte(); // skip - } - file->get_byte(); // ZERO Byte - header.msglength=file->get_word(); - header.msgoffset=file->get_dword(); - char chibi[4]; - file->get_byte_array((uint8_t*)chibi,4); - header.is_chibi=(chibi[0]=='C' && chibi[1]=='H' && chibi[2]=='B' && chibi[3]=='I'); - - for (int i=0;i<64;i++) { - - uint8_t panbyte=file->get_byte(); - - uint8_t pan_dst=(panbyte<65) ? panbyte : 32; - bool surround_dst=(panbyte==100); - bool mute_dst=(panbyte>=128); - - if (!p_dont_set) { - song->set_channel_pan( i, pan_dst ); - song->set_channel_surround( i, surround_dst ); - song->set_channel_mute( i, mute_dst ); - } - } - for (int i=0;i<64;i++) { - unsigned char cv = file->get_byte(); - if (!p_dont_set) - song->set_channel_volume( i, cv ); - } - - CP_ERR_COND_V( file->eof_reached(),FILE_CORRUPTED ); - CP_ERR_COND_V( file->get_error(),FILE_CORRUPTED ); - - return FILE_OK; -} - -CPLoader::Error CPLoader_IT::load_effects() { - - if (!header.is_chibi) - return FILE_OK; //no effects, regular IT file - - /* GOTO End of IT header */ - file->seek(0xC0+header.ordnum+header.insnum*4+header.smpnum*4+header.patnum*4); - - - if (file->get_byte()>0) //not made with this version, ignore extended info - return FILE_OK; - - /* Chibitracker Extended info */ - - switch(file->get_byte()) { - - case CPSong::REVERB_MODE_ROOM: { - - song->set_reverb_mode( CPSong::REVERB_MODE_ROOM ); - } break; - case CPSong::REVERB_MODE_STUDIO_SMALL: { - - song->set_reverb_mode( CPSong::REVERB_MODE_STUDIO_SMALL ); - - } break; - case CPSong::REVERB_MODE_STUDIO_MEDIUM: { - - song->set_reverb_mode( CPSong::REVERB_MODE_STUDIO_MEDIUM ); - - } break; - case CPSong::REVERB_MODE_STUDIO_LARGE: { - - song->set_reverb_mode( CPSong::REVERB_MODE_STUDIO_LARGE ); - - } break; - case CPSong::REVERB_MODE_HALL: { - - song->set_reverb_mode( CPSong::REVERB_MODE_HALL ); - - } break; - case CPSong::REVERB_MODE_SPACE_ECHO: { - - song->set_reverb_mode( CPSong::REVERB_MODE_SPACE_ECHO ); - - } break; - - case CPSong::REVERB_MODE_ECHO: { - - song->set_reverb_mode( CPSong::REVERB_MODE_ECHO ); - - } break; - case CPSong::REVERB_MODE_DELAY: { - - song->set_reverb_mode( CPSong::REVERB_MODE_DELAY ); - - } break; - case CPSong::REVERB_MODE_HALF_ECHO: { - - song->set_reverb_mode( CPSong::REVERB_MODE_HALF_ECHO ); - - } break; - - } - - //chorus - song->set_chorus_speed_hz10( file->get_byte() ); - song->set_chorus_delay_ms( file->get_byte() ); - song->set_chorus_depth_ms10( file->get_byte() ); - song->set_chorus_separation_ms( file->get_byte() ); - - for (int i=0;i<CPPattern::WIDTH;i++) { - song->set_channel_reverb(i,file->get_byte()); - } - for (int i=0;i<CPPattern::WIDTH;i++) { - song->set_channel_chorus(i,file->get_byte()); - } - - return FILE_OK; - -} - -CPLoader::Error CPLoader_IT::load_message() { - - - if (!(header.special & 1)) { - - return FILE_OK; - } - - - file->seek(header.msgoffset); - - //(void*)tmpmsg=malloc(header.msglength+1); - - char message[8000]; - - - char *tmpmsg = message; - - file->get_byte_array((uint8_t*)tmpmsg,header.msglength); - tmpmsg[header.msglength]=0; - - for (int i=0;i<header.msglength;i++) if (tmpmsg[i]=='\r') tmpmsg[i]='\n'; - - song->set_message(tmpmsg); - - return FILE_OK; -} - -CPLoader::Error CPLoader_IT::load_orders() { - - file->seek(0xC0); - - - for (int i=0;i<header.ordnum;i++) { - - uint8_t aux_order=file->get_byte(); - CPOrder order=CP_ORDER_NONE; - - - if (i>=CPSong::MAX_ORDERS) - continue; - if (aux_order==254) { - - order=CP_ORDER_BREAK; - - } else if (aux_order<200) { - - order=aux_order; - //nothing! - - } - song->set_order(i,order); - - } - - if (file->eof_reached() || file->get_error()) { - - - return FILE_CORRUPTED; - - } - - return FILE_OK; -} - - - diff --git a/modules/chibi/cp_loader_it_instruments.cpp b/modules/chibi/cp_loader_it_instruments.cpp deleted file mode 100644 index 446e841c5f..0000000000 --- a/modules/chibi/cp_loader_it_instruments.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it_instruments.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_loader_it.h" - -enum EnvFlags { - ENV_ON=1, - ENV_LOOP=2, - ENV_SUSLOOP=4, - ENV_CARRY=8, - ENV_FILTER=128 -}; - -void CPLoader_IT::load_envelope(CPEnvelope *p_envelope,bool*p_has_filter_flag) { - - uint8_t flags=file->get_byte(); - uint8_t points=file->get_byte(); - uint8_t begin=file->get_byte(); - uint8_t end=file->get_byte(); - uint8_t susbegin=file->get_byte(); - uint8_t susend=file->get_byte(); - - p_envelope->reset(); - - for (int i=0;i<25;i++) { - - uint8_t height=file->get_byte(); - int8_t &signed_height=(int8_t&)height; - uint16_t tick=file->get_word(); - - if (i>=points) - continue; - p_envelope->add_position( tick, signed_height ); - - } - - p_envelope->set_enabled( flags & ENV_ON ); - p_envelope->set_carry_enabled( flags & ENV_CARRY); - - p_envelope->set_loop_enabled( flags & ENV_LOOP ); - p_envelope->set_loop_begin( begin ); - p_envelope->set_loop_end( end ); - - p_envelope->set_sustain_loop_enabled( flags & ENV_SUSLOOP ); - p_envelope->set_sustain_loop_begin( susbegin ); - p_envelope->set_sustain_loop_end( susend ); - - if (p_has_filter_flag) - *p_has_filter_flag=flags&ENV_FILTER; - - file->get_byte(); //zerobyte - - //fill with stuff if the envelope hass less than 2 points - while(p_envelope->get_node_count()<2) { - - p_envelope->add_position( 30*p_envelope->get_node_count(), p_envelope->get_min()==0 ? 64 : 0, false ); - } -} - - -CPLoader::Error CPLoader_IT::load_instrument(CPInstrument *p_instrument,int *p_samples) { - - - - char aux_header[4]; - - file->get_byte_array((uint8_t*)aux_header,4); - - - if ( aux_header[0]!='I' || - aux_header[1]!='M' || - aux_header[2]!='P' || - aux_header[3]!='I') { - CP_PRINTERR("IT CPLoader CPInstrument: Failed Identifier"); - - return FILE_UNRECOGNIZED; - } - - - - // Ignore deprecated 8.3 filename field - for (int i=0;i<12;i++) file->get_byte(); - - //Ignore zerobyte - file->get_byte(); /* (byte) CPInstrument type (always 0) */ - - switch( file->get_byte() ) { /* New CPNote Action [0,1,2,3] */ - case 0: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_CUT ) ; break; - case 1: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_CONTINUE ) ; break; - case 2: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_OFF ) ; break; - case 3: p_instrument->set_NNA_type( CPInstrument::NNA_NOTE_FADE ) ; break; - }; - switch( file->get_byte() ) { // Duplicate Check Type - case 0: p_instrument->set_DC_type( CPInstrument::DCT_DISABLED ); break ; - case 1: p_instrument->set_DC_type( CPInstrument::DCT_NOTE ); break ; - case 2: p_instrument->set_DC_type( CPInstrument::DCT_SAMPLE ); break ; - case 3: p_instrument->set_DC_type( CPInstrument::DCT_INSTRUMENT ); break ; - } - switch( file->get_byte() ) { //Duplicate Check Action - case 0: p_instrument->set_DC_action( CPInstrument::DCA_NOTE_CUT ); break ; - case 1: p_instrument->set_DC_action( CPInstrument::DCA_NOTE_OFF ); break ; - case 2: p_instrument->set_DC_action( CPInstrument::DCA_NOTE_FADE ); break ; - } - - int fade = file->get_word(); - //intf("AFADE: %i\n",fade); - if (fade>CPInstrument::MAX_FADEOUT) //needs to be clipped because of horrible modplug doings - fade=CPInstrument::MAX_FADEOUT; - - p_instrument->set_volume_fadeout( fade ); - p_instrument->set_pan_pitch_separation( file->get_byte() ); - p_instrument->set_pan_pitch_center( file->get_byte() ); - p_instrument->set_volume_global_amount( file->get_byte() ); - uint8_t pan=file->get_byte(); - p_instrument->set_pan_default_amount(pan&0x7F); - p_instrument->set_pan_default_enabled( !(pan&0x80) ); - p_instrument->set_volume_random_variation( file->get_byte() ); - p_instrument->set_pan_random_variation( file->get_byte() ); - - - - file->get_word(); //empty (version) - uint8_t samples=file->get_byte(); - if (p_samples) - *p_samples=samples; - file->get_byte(); //empty - char aux_name[26]; - file->get_byte_array((uint8_t*)aux_name,26); - p_instrument->set_name(aux_name); - - uint8_t cutoff=file->get_byte(); - - p_instrument->set_filter_default_cutoff(cutoff&0x7F); - p_instrument->set_filter_use_default_cutoff(cutoff&0x80); - - uint8_t resonance=file->get_byte(); - - p_instrument->set_filter_default_resonance(resonance&0x7F); - p_instrument->set_filter_use_default_resonance(resonance&0x80); - - file->get_dword(); //MIDI, IGNORED! - - /* CPNote -> CPSample table */ - for (uint8_t i=0;i<CPNote::NOTES;i++) { - - - uint8_t note=file->get_byte(); - if (note>=CPNote::NOTES) - note=0; - p_instrument->set_note_number(i,note); - - uint8_t samp=file->get_byte(); - if (samp==0 || samp>99) - samp=CPNote::EMPTY; - else - samp--; - - - p_instrument->set_sample_number(i,samp); - - - } - - - load_envelope( p_instrument->get_volume_envelope() ); - load_envelope( p_instrument->get_pan_envelope() ); - bool use_as_filter; - load_envelope( p_instrument->get_pitch_filter_envelope(), &use_as_filter ); - p_instrument->set_pitch_use_as_filter( use_as_filter ); - - return FILE_OK; - -} - - -CPLoader::Error CPLoader_IT::load_instruments() { - - - for (int i=0;i<header.insnum;i++) { - - - file->seek(0xC0+header.ordnum+i*4); - uint32_t final_location=file->get_dword(); - file->seek( final_location ); - - Error err=load_instrument( song->get_instrument( i ) ); - if (err) - return err; - - } - - return FILE_OK; - - if (file->eof_reached() || file->get_error()) - return FILE_CORRUPTED; -} - - diff --git a/modules/chibi/cp_loader_it_patterns.cpp b/modules/chibi/cp_loader_it_patterns.cpp deleted file mode 100644 index 528d99fff7..0000000000 --- a/modules/chibi/cp_loader_it_patterns.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it_patterns.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_loader_it.h" - - -CPLoader::Error CPLoader_IT::load_patterns() { - - - for (int i=0;i<header.patnum;i++) { - - if (i>=CPSong::MAX_PATTERNS) - break; - - /* Position where pattern offsets are stored */ - file->seek(0xC0+header.ordnum+header.insnum*4+header.smpnum*4+i*4); - uint32_t pattern_offset=file->get_dword(); - - if (pattern_offset==0) { - - continue; - } - - uint16_t pat_size; - uint16_t pat_length; - - int row=0,flag,channel,j; - uint8_t aux_byte; - uint32_t reserved; - uint8_t chan_mask[64]; //mask cache for each - CPNote last_value[64]; //last value of each - - for (j=0;j<64;j++) { - - chan_mask[j]=0; - last_value[j].clear(); - } - - file->seek(pattern_offset); - - pat_size=file->get_word(); - pat_length=file->get_word(); - reserved=file->get_dword(); - - song->get_pattern(i)->set_length( pat_length ); - - do { - - aux_byte=file->get_byte(); - flag=aux_byte; - - if ( flag==0 ) { - - row++; - } else { - - channel=(flag-1) & 63; - - if ( flag & 128 ) { - - aux_byte=file->get_byte(); - chan_mask[channel]=aux_byte; - } - - CPNote note; //note used for reading - - if ( chan_mask[channel]&1 ) { // read note - - aux_byte=file->get_byte(); - - if ( aux_byte<120 ) - note.note=aux_byte; - else if ( aux_byte==255 ) - note.note=CPNote::OFF; - else if ( aux_byte==254 ) - note.note=CPNote::CUT; - - last_value[channel].note=note.note; - } - - - if ( chan_mask[channel]&2 ) { - - aux_byte=file->get_byte(); - if ( aux_byte<100 ) - note.instrument=aux_byte-1; - - last_value[channel].instrument=note.instrument; - } - if ( chan_mask[channel]&4 ) { - - aux_byte=file->get_byte(); - if ( aux_byte<213 ) - note.volume=aux_byte; - - last_value[channel].volume=note.volume; - } - if ( chan_mask[channel]&8 ) { - - aux_byte=file->get_byte(); - if ( aux_byte>0 ) - note.command=aux_byte-1; - - - last_value[channel].command=note.command; - - note.parameter=file->get_byte(); - - last_value[channel].parameter=note.parameter; - } - - if ( chan_mask[channel]&16 ) { - - note.note=last_value[channel].note; - } - - if ( chan_mask[channel]&32 ) { - - note.instrument=last_value[channel].instrument; - } - if ( chan_mask[channel]&64 ) { - - note.volume=last_value[channel].volume; - } - if ( chan_mask[channel]&128 ) { - - note.command=last_value[channel].command; - note.parameter=last_value[channel].parameter; - } - - song->get_pattern(i)->set_note(channel,row,note); - } - - - } while(row<pat_length); - - } - - return FILE_OK; -} - diff --git a/modules/chibi/cp_loader_it_samples.cpp b/modules/chibi/cp_loader_it_samples.cpp deleted file mode 100644 index c736c99c0f..0000000000 --- a/modules/chibi/cp_loader_it_samples.cpp +++ /dev/null @@ -1,620 +0,0 @@ -/*************************************************************************/ -/* cp_loader_it_samples.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_loader_it.h" -#include "cp_sample.h" - -struct AuxSampleData { - - - uint32_t fileofs; - uint32_t c5spd; - uint32_t length; - uint32_t loop_begin; - uint32_t loop_end; - bool loop_enabled; - bool pingpong_enabled; - bool is16bit; - bool stereo; - bool exists; - bool compressed; - -}; - - -enum IT_Sample_Flags { - - IT_SAMPLE_EXISTS=1, - IT_SAMPLE_16BITS=2, - IT_SAMPLE_STEREO=4, - IT_SAMPLE_COMPRESSED=8, - IT_SAMPLE_LOOPED=16, - IT_SAMPLE_SUSTAIN_LOOPED=32, - IT_SAMPLE_LOOP_IS_PINGPONG=64, - IT_SAMPLE_SUSTAIN_LOOP_IS_PINGPONG=128 -}; - - -CPLoader::Error CPLoader_IT::load_sample(CPSample *p_sample) { - - - AuxSampleData aux_sample_data; - - char aux_header[4]; - - file->get_byte_array((uint8_t*)aux_header,4); - - if ( aux_header[0]!='I' || - aux_header[1]!='M' || - aux_header[2]!='P' || - aux_header[3]!='S') { - - //CP_PRINTERR("IT CPLoader CPSample: Failed Identifier"); - return FILE_UNRECOGNIZED; - } - - - // Ignore deprecated 8.3 filename - for (int i=0;i<12;i++) file->get_byte(); - - file->get_byte(); //ignore zerobyte - - p_sample->set_global_volume( file->get_byte() ); - - /* SAMPLE FLAGS */ - uint8_t flags=file->get_byte(); - aux_sample_data.loop_enabled=flags&IT_SAMPLE_LOOPED; - aux_sample_data.pingpong_enabled=flags&IT_SAMPLE_LOOP_IS_PINGPONG; - aux_sample_data.is16bit=flags&IT_SAMPLE_16BITS; - aux_sample_data.exists=flags&IT_SAMPLE_EXISTS; - aux_sample_data.stereo=flags&IT_SAMPLE_STEREO; - aux_sample_data.compressed=flags&IT_SAMPLE_COMPRESSED; - - p_sample->set_default_volume(file->get_byte()); - /* SAMPLE NAME */ - char aux_name[26]; - file->get_byte_array((uint8_t*)aux_name,26); - p_sample->set_name(aux_name); - - // ?? - uint8_t convert_flag=file->get_byte(); - // PAN - uint8_t pan=file->get_byte(); - p_sample->set_pan( pan&0x7F ); - p_sample->set_pan_enabled( pan & 0x80 ); - - aux_sample_data.length=file->get_dword(); - - - aux_sample_data.loop_begin= file->get_dword(); - aux_sample_data.loop_end= file->get_dword(); - aux_sample_data.c5spd=file->get_dword(); - /*p_sample->data.set_sustain_loop_begin=*/file->get_dword(); - /*p_sample->data.sustain_loop_end=*/file->get_dword(); - aux_sample_data.fileofs=file->get_dword(); - p_sample->set_vibrato_speed( file->get_byte() ); - p_sample->set_vibrato_depth( file->get_byte() ); - p_sample->set_vibrato_rate( file->get_byte() ); - switch( file->get_byte() ) { - /* Vibrato Wave: 0=sine, 1=rampdown, 2=square, 3=random */ - case 0: p_sample->set_vibrato_type( CPSample::VIBRATO_SINE ); break; - case 1: p_sample->set_vibrato_type( CPSample::VIBRATO_SAW ); break; - case 2: p_sample->set_vibrato_type( CPSample::VIBRATO_SQUARE ); break; - case 3: p_sample->set_vibrato_type( CPSample::VIBRATO_RANDOM ); break; - default: p_sample->set_vibrato_type( CPSample::VIBRATO_SINE ); break; - } - - //printf("Name %s - Flags: fileofs :%i - c5spd %i - len %i 16b %i - data?: %i\n",p_sample->get_name(),aux_sample_data.fileofs,aux_sample_data.c5spd, aux_sample_data.length, aux_sample_data.is16bit,aux_sample_data.exists); - CPSample_ID samp_id; - - if (aux_sample_data.exists) { - samp_id=load_sample_data(aux_sample_data); - CPSampleManager::get_singleton()->set_c5_freq(samp_id,aux_sample_data.c5spd); - CPSampleManager::get_singleton()->set_loop_begin( samp_id,aux_sample_data.loop_begin ); - CPSampleManager::get_singleton()->set_loop_end( samp_id,aux_sample_data.loop_end ); - CPSample_Loop_Type loop_type=aux_sample_data.loop_enabled?( aux_sample_data.pingpong_enabled? CP_LOOP_BIDI: CP_LOOP_FORWARD):CP_LOOP_NONE; - CPSampleManager::get_singleton()->set_loop_end( samp_id,aux_sample_data.loop_end ); - CPSampleManager::get_singleton()->set_loop_type( samp_id, loop_type); - - } - - //printf("Loaded id is null?: %i\n",samp_id.is_null()); - p_sample->set_sample_data(samp_id); - if (!samp_id.is_null()) { - - //printf("Loaded ID: stereo: %i len %i 16bit %i\n",CPSampleManager::get_singleton()->is_stereo(samp_id), CPSampleManager::get_singleton()->get_size( samp_id), CPSampleManager::get_singleton()->is_16bits( samp_id) ); - } - - CP_ERR_COND_V( file->eof_reached(),FILE_CORRUPTED ); - CP_ERR_COND_V( file->get_error(),FILE_CORRUPTED ); - - return FILE_OK; - -} - -CPSample_ID CPLoader_IT::load_sample_data(AuxSampleData& p_sample_data) { - - - int aux_sample_properties = (p_sample_data.is16bit?IT_SAMPLE_16BITS:0)|(p_sample_data.compressed?IT_SAMPLE_COMPRESSED:0)|(p_sample_data.stereo?IT_SAMPLE_STEREO:0); - - file->seek(p_sample_data.fileofs); - - CPSampleManager *sm=CPSampleManager::get_singleton(); - - CPSample_ID id; - - switch (aux_sample_properties) { - - case (0): // 8 bits, mono - case (IT_SAMPLE_16BITS): // 16 bits mono - case (IT_SAMPLE_STEREO): // 8 bits stereo - case (IT_SAMPLE_16BITS|IT_SAMPLE_STEREO): { // 16 bits mono - - id=sm->create(p_sample_data.is16bit,p_sample_data.stereo,p_sample_data.length); - if (id.is_null()) - break; - - sm->lock_data(id); - - int16_t *ptr16 = (int16_t*)sm->get_data(id); - int8_t *ptr8=(int8_t*)ptr16; - - int chans=p_sample_data.stereo?2:1; - - if (p_sample_data.is16bit) { - - for (int c=0;c<chans;c++) { - - for (int i=0;i<p_sample_data.length;i++) { - - ptr16[i*chans+c]=file->get_word(); - } - } - } else { - - for (int c=0;c<chans;c++) { - - for (int i=0;i<p_sample_data.length;i++) { - - ptr8[i*chans+c]=file->get_byte(); - } - } - - } - - sm->unlock_data(id); - - } break; - case (IT_SAMPLE_COMPRESSED): { // 8 bits compressed - - - id=sm->create(false,false,p_sample_data.length); - if (id.is_null()) - break; - sm->lock_data(id); - - if ( load_sample_8bits_IT_compressed((void*)sm->get_data( id),p_sample_data.length) ) { - - sm->unlock_data(id); - sm->destroy(id); - - break; - } - - sm->unlock_data(id); - - - } break; - case (IT_SAMPLE_16BITS|IT_SAMPLE_COMPRESSED): { // 16 bits compressed - - - id=sm->create(true,false,p_sample_data.length); - if (id.is_null()) - break; - sm->lock_data(id); - - if ( load_sample_16bits_IT_compressed((void*)sm->get_data(id),p_sample_data.length) ) { - - sm->unlock_data(id); - sm->destroy(id); - break; - } - - sm->unlock_data(id); - - } break; - default: { - - // I dont know how to handle stereo compressed, does that exist? - } break; - - } - - - return id; -} - - -CPLoader::Error CPLoader_IT::load_samples() { - - for (int i=0;i<header.smpnum;i++) { - - //seek to sample - file->seek(0xC0+header.ordnum+header.insnum*4+i*4); - - uint32_t final_location=file->get_dword(); - file->seek( final_location ); - - - Error err=load_sample(song->get_sample(i)); - CP_ERR_COND_V(err,err); - - } - - if (file->eof_reached() || file->get_error()) - return FILE_CORRUPTED; - - return FILE_OK; -} -/* * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE - - -The following sample decompression code is based on xmp's code.(http://xmp.helllabs.org) which is based in openCP code. - -* NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE */ - -uint32_t CPLoader_IT::read_n_bits_from_IT_compressed_block (uint8_t p_bits_to_read) { - - uint32_t aux_return_value; - uint32_t val; - - uint8_t *buffer=(uint8_t*)source_position; - if ( p_bits_to_read <= source_remaining_bits ) { - - val=buffer[3]; - val<<=8; - val|=buffer[2]; - val<<=8; - val|=buffer[1]; - val<<=8; - val|=buffer[0]; - - aux_return_value = val & ((1 << p_bits_to_read) - 1); - val >>= p_bits_to_read; - source_remaining_bits -= p_bits_to_read; - - buffer[3]=val>>24; - buffer[2]=(val>>16)&0xFF; - buffer[1]=(val>>8)&0xFF; - buffer[0]=(val)&0xFF; - - } else { - aux_return_value=buffer[3]; - aux_return_value<<=8; - aux_return_value|=buffer[2]; - aux_return_value<<=8; - aux_return_value|=buffer[1]; - aux_return_value<<=8; - aux_return_value|=buffer[0]; - - uint32_t nbits = p_bits_to_read - source_remaining_bits; - source_position++; - - buffer+=4; - val=buffer[3]; - val<<=8; - val|=buffer[2]; - val<<=8; - val|=buffer[1]; - val<<=8; - val|=buffer[0]; - aux_return_value |= ((val & ((1 << nbits) - 1)) << source_remaining_bits); - val >>= nbits; - source_remaining_bits = 32 - nbits; - buffer[3]=val>>24; - buffer[2]=(val>>16)&0xFF; - buffer[1]=(val>>8)&0xFF; - buffer[0]=(val)&0xFF; - - } - - return aux_return_value; -} - -bool CPLoader_IT::read_IT_compressed_block (bool p_16bits) { - - uint16_t size; - - size=file->get_word(); - - if (file->eof_reached() || file->get_error()) return true; - - pat_data = (uint8_t*)CP_ALLOC( 4* ((size >> 2) + 2) ); - if (!pat_data) - return true; - - - source_buffer=(uint32_t*)pat_data; - file->get_byte_array((uint8_t*)source_buffer,size); - - if (file->eof_reached() || file->get_error()) { - - free_IT_compressed_block(); - return true; - } - - source_position = source_buffer; - source_remaining_bits = 32; - - return false; -} - -void CPLoader_IT::free_IT_compressed_block () { - - - if (pat_data) { - CP_FREE(pat_data); - pat_data=NULL; - } - -} - -bool CPLoader_IT::load_sample_8bits_IT_compressed(void *p_dest_buffer,int p_buffsize) { - - int8_t *dest_buffer; /* destination buffer which will be returned */ - uint16_t block_length; /* length of compressed data block in samples */ - uint16_t block_position; /* position in block */ - uint8_t bit_width; /* actual "bit width" */ - uint16_t aux_value; /* value read from file to be processed */ - int8_t d1, d2; /* integrator buffers (d2 for it2.15) */ - int8_t *dest_position; /* position in output buffer */ - int8_t v; /* sample value */ - bool it215; // is this an it215 module? - - dest_buffer = (int8_t *) p_dest_buffer; - - if (dest_buffer==NULL) - return true; - - for (int i=0;i<p_buffsize;i++) - dest_buffer[i]=0; - - - dest_position = dest_buffer; - - it215=(header.cmwt==0x215); - - /* now unpack data till the dest buffer is full */ - - while (p_buffsize) { - /* read a new block of compressed data and reset variables */ - if ( read_IT_compressed_block(false) ) { - CP_PRINTERR("Out of memory decompressing IT CPSample"); - return true; - } - - - block_length = (p_buffsize < 0x8000) ? p_buffsize : 0x8000; - - block_position = 0; - - bit_width = 9; /* start with width of 9 bits */ - - d1 = d2 = 0; /* reset integrator buffers */ - - /* now uncompress the data block */ - while ( block_position < block_length ) { - - aux_value = read_n_bits_from_IT_compressed_block(bit_width); /* read bits */ - - if ( bit_width < 7 ) { /* method 1 (1-6 bits) */ - - if ( aux_value == (1 << (bit_width - 1)) ) { /* check for "100..." */ - - aux_value = read_n_bits_from_IT_compressed_block(3) + 1; /* yes -> read new width; */ - bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1; - /* and expand it */ - continue; /* ... next value */ - } - - } else if ( bit_width < 9 ) { /* method 2 (7-8 bits) */ - - uint8_t border = (0xFF >> (9 - bit_width)) - 4; - /* lower border for width chg */ - - if ( aux_value > border && aux_value <= (border + 8) ) { - - aux_value -= border; /* convert width to 1-8 */ - bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1; - /* and expand it */ - continue; /* ... next value */ - } - - - } else if ( bit_width == 9 ) { /* method 3 (9 bits) */ - - if ( aux_value & 0x100 ) { /* bit 8 set? */ - - bit_width = (aux_value + 1) & 0xff; /* new width... */ - continue; /* ... and next value */ - } - - } else { /* illegal width, abort */ - - - free_IT_compressed_block(); - CP_PRINTERR("CPSample has illegal BitWidth "); - return true; - } - - /* now expand value to signed byte */ - if ( bit_width < 8 ) { - - uint8_t tmp_shift = 8 - bit_width; - - v=(aux_value << tmp_shift); - v>>=tmp_shift; - - } else v = (int8_t) aux_value; - - /* integrate upon the sample values */ - d1 += v; - d2 += d1; - - /* ... and store it into the buffer */ - *(dest_position++) = it215 ? d2 : d1; - block_position++; - - } - - /* now subtract block lenght from total length and go on */ - free_IT_compressed_block(); - p_buffsize -= block_length; - } - - - return false; -} - -bool CPLoader_IT::load_sample_16bits_IT_compressed(void *p_dest_buffer,int p_buffsize) { - - int16_t *dest_buffer; /* destination buffer which will be returned */ - uint16_t block_length; /* length of compressed data block in samples */ - uint16_t block_position; /* position in block */ - uint8_t bit_width; /* actual "bit width" */ - uint32_t aux_value; /* value read from file to be processed */ - int16_t d1, d2; /* integrator buffers (d2 for it2.15) */ - int16_t *dest_position; /* position in output buffer */ - int16_t v; /* sample value */ - - bool it215; // is this an it215 module? - - dest_buffer = (int16_t *) p_dest_buffer; - - if (dest_buffer==NULL) - return true; - - for (int i=0;i<p_buffsize;i++) - dest_buffer[i]=0; - - dest_position = dest_buffer; - - it215=(header.cmwt==0x215); - - - while (p_buffsize) { - /* read a new block of compressed data and reset variables */ - if ( read_IT_compressed_block(true) ) { - - return true; - } - - - block_length = (p_buffsize < 0x4000) ? p_buffsize : 0x4000; - - block_position = 0; - - bit_width = 17; /* start with width of 9 bits */ - - d1 = d2 = 0; /* reset integrator buffers */ - - while ( block_position < block_length ) { - - aux_value = read_n_bits_from_IT_compressed_block(bit_width); /* read bits */ - - if ( bit_width < 7 ) { /* method 1 (1-6 bits) */ - - if ( (signed)aux_value == (1 << (bit_width - 1)) ) { /* check for "100..." */ - - aux_value = read_n_bits_from_IT_compressed_block(4) + 1; /* yes -> read new width; */ - bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1; - /* and expand it */ - continue; /* ... next value */ - } - - } else if ( bit_width < 17 ) { - - uint16_t border = (0xFFFF >> (17 - bit_width)) - 8; - - if ( (int)aux_value > (int)border && (int)aux_value <= ((int)border + 16) ) { - - aux_value -= border; /* convert width to 1-8 */ - bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1; - /* and expand it */ - continue; /* ... next value */ - } - - - } else if ( bit_width == 17 ) { - - if ( aux_value & 0x10000 ) { /* bit 8 set? */ - - bit_width = (aux_value + 1) & 0xff; /* new width... */ - continue; /* ... and next value */ - } - - } else { /* illegal width, abort */ - - CP_PRINTERR("CPSample has illegal BitWidth "); - - free_IT_compressed_block(); - - return true; - } - - /* now expand value to signed byte */ - if ( bit_width < 16 ) { - - uint8_t tmp_shift = 16 - bit_width; - - v=(aux_value << tmp_shift); - v>>=tmp_shift; - - } else v = (int16_t) aux_value; - - /* integrate upon the sample values */ - d1 += v; - d2 += d1; - - /* ... and store it into the buffer */ - *(dest_position++) = it215 ? d2 : d1; - block_position++; - - } - - /* now subtract block lenght from total length and go on */ - free_IT_compressed_block(); - p_buffsize -= block_length; - } - - - return false; - -} - - - diff --git a/modules/chibi/cp_loader_mod.cpp b/modules/chibi/cp_loader_mod.cpp deleted file mode 100644 index cfa3e34736..0000000000 --- a/modules/chibi/cp_loader_mod.cpp +++ /dev/null @@ -1,482 +0,0 @@ -/*************************************************************************/ -/* cp_loader_mod.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_loader_mod.h" - - -static bool tag_equal_to(const char *p_tag, const char *p_string) { - - return( p_tag[0]==p_string[0] && - p_tag[1]==p_string[1] && - p_tag[2]==p_string[2] && - p_tag[3]==p_string[3]); -} -/* ProTracker period table */ -uint16_t period_table[6*12] = { - 1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,907, - 856,808,762,720,678,640,604,570,538,508,480,453, - 428,404,381,360,339,320,302,285,269,254,240,226, - 214,202,190,180,170,160,151,143,135,127,120,113, - 107,101,95,90,85,80,75,71,67,63,60,56, - 53,50,47,45,42,40,37,35,33,31,30,28 -}; - - -CPLoader::Error CPLoader_MOD::load_song(const char *p_file,CPSong *p_song,bool p_sampleset) { - - if (file->open(p_file,CPFileAccessWrapper::READ)) { - //printf("Can't open file! %s\n",p_file); - return FILE_CANNOT_OPEN; - }; - - /* FIRST OF ALL, one needs to read the .mod file format tag */ - file->seek( 1080 ); //located at 1080 - - char format_tag[4]; - - file->get_byte_array( (uint8_t*)format_tag, 4 ); - - int channels=-1; - - /** THE PAIN!! - COMPARE TAGS */ - - /* Classic 4-chan */ - if (tag_equal_to(format_tag,"M.K.") ) - channels=4; - if (tag_equal_to(format_tag,"FLT4") ) - channels=4; - if (tag_equal_to(format_tag,"M!K!") ) - channels=4; - - /* 8 Channel MODS */ - - if (tag_equal_to(format_tag,"FLT8") ) - channels=2; - - if (tag_equal_to(format_tag,"CD81") ) - channels=2; - - /* Custom channel MODS */ - - for (int i=1;i<=32;i++) { - - if (i<10) { // up to 9 channels mods - - /* Old Take Tracker */ - char old_take_tracker[4]={'T','D','Z',char('0'+i)}; - - if (tag_equal_to(format_tag,old_take_tracker)) { - - channels=i; - break; - } - - /* Contemplates many XCHN Formats */ - char xchn[4]={char('0'+i),'C','H','N'}; - - if (tag_equal_to(format_tag,xchn)) { - - channels=i; - break; - } - } - - /* Fast Tracker */ - char fast_tracker[4]={char('0'+(i/10)),char('0'+(i%10)),'C','H'}; - - if (tag_equal_to(format_tag,fast_tracker)) { - - channels=i; - break; - } - - } - - - if (channels==-1) { - - file->close(); - return FILE_UNRECOGNIZED; - } - - - - /** Load CPSong INFO */ - - file->seek( 0 ); //go to begining of file - - file->set_endian_conversion( true ); - p_song->reset(); - p_song->set_instruments( false ); - - char name[21]; - - file->get_byte_array( (uint8_t*)name,20); - name[20]=0; - - p_song->set_name(name); - p_song->set_old_effects( true ); - p_song->set_linear_slides( false ); - p_song->set_compatible_gxx( true ); - - - - CPSampleManager *sm=CPSampleManager::get_singleton(); - - int instruments=31; - - for (int i=0;i<instruments;i++) { - - char sample_name[23]; - file->get_byte_array( (uint8_t*)sample_name,22); - sample_name[22]=0; - - uint32_t sample_len=file->get_word(); - sample_len<<=1; - - uint8_t fine_nibble=file->get_byte()&0xF; - - - //(int8_t)(fine_nibble & 7) - (int8_t)(fine_nibble & 8); //yesso's genius trick - // boo, I can't use it :( but i leave it here because of how cool it is - uint8_t linear_volume=file->get_byte(); //0 .. ? - - uint32_t loop_begin=file->get_word(); //0 .. ? - loop_begin<<=1; - uint32_t loop_end=file->get_word(); //0 .. ? - loop_end<<=1; - - if (sample_len>0) { - - CPSample_ID sid=sm->create( false, false, sample_len ); - - if (sid.is_null()) { - - file->close(); - return FILE_OUT_OF_MEMORY; - } - - if (loop_end>2) { - sm->set_loop_begin( sid, loop_begin ); - sm->set_loop_end( sid, loop_end+loop_begin ); - sm->set_loop_type( sid,CP_LOOP_FORWARD ); - } - static const uint16_t fine_to_freq[16]={ - 8363,8413,8463,8529,8581,8651,8723,8757, - 7895,7941,7985,8046,8107,8169,8232,8280 - }; - - sm->set_c5_freq( sid, fine_to_freq[fine_nibble] ); - p_song->get_sample(i)->set_sample_data(sid); - } - - p_song->get_sample(i)->set_name(sample_name); - p_song->get_sample(i)->set_default_volume( linear_volume ); - - - - } - - /* pan for MODs */ - for (int i=0;i<channels;i++) - p_song->set_channel_pan( i, (((i&3)==1) || ((i&3)==2)) ? 0: 64); - - - uint8_t order_count=file->get_byte(); - //uint8_t loop_to=file->get_byte(); - - - int pattern_count=0; - - for (int i=0;i<128;i++) { - - uint8_t order=file->get_byte(); - - - if (i<order_count) { - p_song->set_order(i,order); - - /* Determine the amount of patterns */ - if ((order+1)>pattern_count) - pattern_count=order+1; - } else - p_song->set_order( i, CP_ORDER_NONE ); - } - - if (instruments==31) - file->get_dword(); // identiefier, now skip it - - for (int i=0;i<pattern_count;i++) { - - for(int line=0;line<64;line++) { - - for(int column=0;column<channels;column++) { - - uint32_t note_w=file->get_dword(); - - CPNote note; - - note.instrument=(note_w>>12)&0xF; - note.instrument|=(note_w>>24)&0xF0; - - if (note.instrument==0) - note.instrument=CPNote::EMPTY; - else - note.instrument--; - - note.parameter=note_w&0xFF; - - int cmd=(note_w>>8)&0xF; - - uint32_t period=(note_w>>16)&0xFFF; - - if (period>0 && period<0xFFF) { - - //period>>=2; - //period<<=1; - for (int n=0; n<6*12; n++) { - - if (period >= period_table[n]) { - - if ((period!=period_table[n]) && (n)) - { - uint32_t p1 = period_table[n-1]; - uint32_t p2 = period_table[n]; - if (p1 - period < (period - p2)) { - - note.note=n+36; - break; - } - } - note.note=n+1+36; - break; - } - } - if (note.note==CPNote::EMPTY) - note.note=6*12+36; - - note.note--; - } - - - switch(cmd) { - - case 0x0: { - - if (note.parameter>0) - note.command='J'-'A'; - } break; - case 0x1: { - note.command='F'-'A'; - } break; - case 0x2: { - - note.command='E'-'A'; - } break; - case 0x3: { - - note.command='G'-'A'; - } break; - case 0x4: { - - note.command='H'-'A'; - } break; - case 0x5: { - note.command='L'-'A'; - } break; - case 0x6: { - - note.command='K'-'A'; - } break; - case 0x7: { - note.command='R'-'A'; - } break; - case 0x8: { - - note.command='X'-'A'; - } break; - case 0x9: { - - note.command='O'-'A'; - - } break; - case 0xA: { - - note.command='D'-'A'; - - } break; - case 0xB: { - - note.command='B'-'A'; - - } break; - case 0xC: { - - note.volume=note.parameter; - if (note.volume>64) - note.volume=64; - note.parameter=0; - - } break; - case 0xD: { - - note.command='C'-'A'; - note.parameter=(note.parameter>>4)*10 + (note.parameter&0xF); - - } break; - case 0xE: { //SPECIAL EFFECT! - - note.command='S'-'A'; - - switch(note.parameter>>4) { - - case 0x1: { - - note.command='F'-'A'; - note.parameter=0xF0|(note.parameter&0xF); - } break; - case 0x2: { - - note.command='E'-'A'; - note.parameter=0xF0|(note.parameter&0xF); - } break; - case 0x4: { - - note.command='S'-'A'; - note.parameter=0x30|(note.parameter&0x3); - - } break; - case 0x6: { - - note.command='S'-'A'; - note.parameter=0xB0|(note.parameter&0xF); - - } break; - case 0x7: { - note.command='S'-'A'; - note.parameter=0x40|(note.parameter&0x3); - - } break; - case 0x8: { - - note.command='S'-'A'; // wow, it's the same! - - } break; - case 0x9: { - note.command='Q'-'A'; - note.parameter=(note.parameter&0xF); - - } break; - case 0xA: { - - note.command='D'-'A'; - note.parameter=0xF|((note.parameter&0xF)<<4); - - } break; - case 0xB: { - note.command='D'-'A'; - note.parameter=0xF0|(note.parameter&0xF); - - } break; - case 0xC: - case 0xD: { - - note.command='S'-'A'; //wow, they are the same! - - } break; - case 0xE: { - note.command='S'-'A'; - note.parameter=0x60|(note.parameter&0xF); - - } break; - - default: { - - note.command=CPNote::EMPTY; - note.parameter=0; - } break; - - } - } break; - case 0xF: { - - if (note.parameter<32) - note.command='A'-'A'; - else - note.command='T'-'A'; - - } break; - } - - p_song->get_pattern(i)->set_note( column,line, note ); - } - } - } - - - - for (int i=0;i<instruments;i++) { - - CPSample_ID sid=p_song->get_sample(i)->get_sample_data(); - if (sid.is_null()) { - continue; //empty sample, not stored? - } - sm->lock_data(sid); - uint8_t *dataptr = (uint8_t*)sm->get_data(sid); - - int len=sm->get_size(sid); - for (int s=0;s<len;s++) { - - uint8_t d=file->get_byte(); - //d-=128; //convert to signed - int8_t*ds=(int8_t*)&d; - dataptr[s]=*ds; - - } - sm->unlock_data(sid); - } - - file->close(); - - return FILE_OK; - - -} - - -CPLoader_MOD::CPLoader_MOD(CPFileAccessWrapper *p_file) { - - file=p_file; -} - - -CPLoader_MOD::~CPLoader_MOD() -{ -} - - diff --git a/modules/chibi/cp_loader_mod.h b/modules/chibi/cp_loader_mod.h deleted file mode 100644 index 57f7128bc0..0000000000 --- a/modules/chibi/cp_loader_mod.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************/ -/* cp_loader_mod.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_LOADER_MOD_H -#define CP_LOADER_MOD_H -#include "cp_loader.h" -/** - @author Juan Linietsky <reduz@gmail.com> -*/ -class CPLoader_MOD : public CPLoader { - - CPFileAccessWrapper *file; -public: - - bool can_load_song() { return true; } - bool can_load_sample() { return false; } - bool can_load_instrument() { return false; } - - Error load_song(const char *p_file,CPSong *p_song,bool p_sampleset); - Error load_sample(const char *p_file,CPSample *p_sample) { return FILE_UNRECOGNIZED; } - Error load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx) { return FILE_UNRECOGNIZED; } - - CPLoader_MOD(CPFileAccessWrapper *p_file); - ~CPLoader_MOD(); -}; - -#endif diff --git a/modules/chibi/cp_loader_s3m.cpp b/modules/chibi/cp_loader_s3m.cpp deleted file mode 100644 index 4943e6d86c..0000000000 --- a/modules/chibi/cp_loader_s3m.cpp +++ /dev/null @@ -1,413 +0,0 @@ -/*************************************************************************/ -/* cp_loader_s3m.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_loader_s3m.h" - -#define BITBOOL(m_exp) ((m_exp)?1:0) - - -CPLoader::Error CPLoader_S3M::load_header() { - - int i; - - - file->get_byte_array((uint8_t*)header.songname,28); - header.t1a=file->get_byte(); - header.type=file->get_byte(); - file->get_byte_array((uint8_t*)header.unused1,2); - header.ordnum=file->get_word(); - header.insnum=file->get_word(); - header.patnum=file->get_word(); - header.flags=file->get_word(); - header.tracker=file->get_word(); - header.fileformat=file->get_word(); - file->get_byte_array((uint8_t*)header.scrm,4); - header.scrm[4]=0; - - if (header.scrm[0]!='S' || header.scrm[1]!='C' || header.scrm[2]!='R' || header.scrm[3]!='M') - return FILE_UNRECOGNIZED; - - header.mastervol=file->get_byte(); - header.initspeed=file->get_byte(); - header.inittempo=file->get_byte(); - header.mastermult=file->get_byte(); - header.ultraclick=file->get_byte(); - header.pantable=file->get_byte(); - file->get_byte_array((uint8_t*)header.unused2,8); - header.special=file->get_word(); - file->get_byte_array((uint8_t*)header.channels,32); - - file->get_byte_array((uint8_t*)header.orderlist,header.ordnum); - - header.scrm[4]=0; - if (header.scrm[0]!='S' || header.scrm[1]!='C' || header.scrm[2]!='R' || header.scrm[3]!='M') //again? - return FILE_UNRECOGNIZED; - //sample parapointers - for (i=0;i<header.insnum;i++) { - - int parapointer; - parapointer=file->get_word(); - parapointer=(parapointer*16); - sample_parapointers[i]=parapointer; - } - //pattern - for (i=0;i<header.patnum;i++) { - - int parapointer; - parapointer=file->get_word(); - parapointer=(parapointer*16); - pattern_parapointers[i]=parapointer; - } - - if (header.pantable==252) { - - file->get_byte_array((uint8_t*)header.pannings,32); - } - - return FILE_OK; - - -} - - -void CPLoader_S3M::set_header() { - - - - - song->set_name( header.songname ); - //song->variables.filename= - - song->set_row_highlight_minor( 4 ); - song->set_row_highlight_major( 16 ); - song->set_mixing_volume( header.mastervol ); - song->set_linear_slides( false ); - song->set_old_effects( !(header.flags&64) ); - song->set_compatible_gxx( true ); - - song->set_global_volume( header.mastermult ); - song->set_speed( header.initspeed ); - song->set_tempo( header.inittempo ); - - //[TODO] Set Panning Positions.. ? - - for (int i=0;i<header.ordnum;i++) song->set_order(i,header.orderlist[i]); - -} - -CPLoader::Error CPLoader_S3M::load_sample(CPSample *p_sample) { - - - - int type=file->get_byte(); - - char filename[13]; - file->get_byte_array((uint8_t*)filename,12); - filename[12]=0; - - - uint32_t samplepos=(uint32_t)file->get_byte() << 16; - samplepos|=file->get_word(); - samplepos*=16; - //printf("sample at %i\n",samplepos); - /**/ - int sample_size=file->get_dword(); - - - int loop_begin=file->get_dword(); - int loop_end=file->get_dword(); - - int def_volume=file->get_byte();; - int dsk=file->get_byte(); - int pack=file->get_byte(); - - int flags=file->get_byte(); - int c2speed=file->get_dword(); - - file->get_dword(); //useless crap - file->get_dword(); - file->get_dword(); - - - char name[29]; - file->get_byte_array((uint8_t*)name,28); - name[28]=0; - - p_sample->set_default_volume(def_volume); - p_sample->set_name(name); - - char scrs[5]; - file->get_byte_array((uint8_t*)scrs,4); - scrs[4]=0; - - - - bool data_is_16bits=flags&4; - bool data_is_stereo=flags&2; - - if (type==0) { - //empty sample - return FILE_OK; - } - - - if ((type!=1) || scrs[0]!='S' || scrs[1]!='C' || scrs[2]!='R' || scrs[3]!='S' ) { - //printf("type: %i, %c%c%c%c\n",type,scrs[0],scrs[1],scrs[2],scrs[3]); - CP_PRINTERR("Not an S3M CPSample!"); - return FILE_CORRUPTED; - } - - //p_sample->data.set_c5_freq(p_sample->c2spd<<1); - - file->seek(samplepos); - - int real_sample_size=sample_size<<BITBOOL(data_is_16bits); - real_sample_size<<=BITBOOL(data_is_stereo); - - CPSampleManager *sm=CPSampleManager::get_singleton(); - - CPSample_ID id =sm->create( data_is_16bits, data_is_stereo, sample_size ); - - if (id.is_null()) - return FILE_OUT_OF_MEMORY; - - sm->lock_data(id); - void *dataptr = sm->get_data(id); - - int chans = (data_is_stereo?2:1); - for (int c=0;c<chans;c++) { - for (int i=0;i<sample_size;i++) { - - if (data_is_16bits) { - - uint16_t s=file->get_word(); - s-=32768; //toggle sign - - int16_t *v=(int16_t*)&s; - ((int16_t*)dataptr)[i*chans+c]=*v; - } else { - - - int8_t *v; - uint8_t s=file->get_byte(); - s-=128; //toggle sign - v=(int8_t*)&s; - ((int8_t*)dataptr)[i*chans+c]=*v; - - } - - } - - } - - sm->unlock_data(id); - - - sm->set_loop_begin( id, loop_begin ); - sm->set_loop_end( id, loop_end ); - sm->set_loop_type( id, (flags&1) ? CP_LOOP_FORWARD : CP_LOOP_NONE ); - sm->set_c5_freq( id, c2speed << 1 ); - p_sample->set_sample_data(id); - - /* Scream tracker previous to 3.10 seems to be buggy, as in, wont save what is after the sample loop, including the loop end point. Because of this I must fix it by habd */ - if (flags&1) { - - for (int c=0;c<(data_is_stereo?2:1);c++) { - sm->set_data( id, loop_end, sm->get_data( id, loop_begin,c ),c ); - - } - } - - - return FILE_OK; - -} - - -CPLoader::Error CPLoader_S3M::load_pattern(CPPattern *p_pattern) { - - int row=0,flag,ch; - CPNote n; - int length,accum=0; - - length=file->get_word(); - p_pattern->set_length(64); - - /* clear pattern data */ - while((row<64) && (accum<=length) ) { - flag=file->get_byte(); - accum++; - - n.clear(); - if(flag) { - // ch=remap[flag&31]; -// ch=remap[flag&31]; -// if(ch!=-1) -// n=s3mbuf[(64U*ch)+row]; -// else -// n=&dummy; - - ch=flag&31; - - if(flag&32) { - n.note=file->get_byte(); - if (n.note==255) { - - n.note=CPNote::EMPTY; - } else if (n.note==254) { - - n.note=CPNote::CUT; - } else { - - n.note=((n.note>>4)*12)+(n.note&0xF); - } - - n.instrument=file->get_byte()-1; - accum+=2; - - } - if(flag&64) { - n.volume=file->get_byte(); - if (n.volume>64) n.volume=64; - accum++; - - } - if(flag&128) { - n.command=file->get_byte()-1; - n.parameter=file->get_byte(); - accum+=2; - } - - p_pattern->set_note(ch,row,n); - } else row++; - } - return FILE_OK; - - -} - -CPLoader::Error CPLoader_S3M::load_sample(const char *p_file,CPSample *p_sample) { - - return FILE_UNRECOGNIZED; -} -CPLoader::Error CPLoader_S3M::load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx) { - - return FILE_UNRECOGNIZED; - -} - - -CPLoader::Error CPLoader_S3M::load_samples() { - - int i; - - for(i=0;i<header.insnum;i++) { - - file->seek(sample_parapointers[i]); - load_sample(song->get_sample(i)); - sample_count++; - } - - return FILE_OK; -} - -CPLoader::Error CPLoader_S3M::load_patterns() { - - int i; - - Error err; - for(i=0;i<header.patnum;i++) { - - file->seek(pattern_parapointers[i]); - - err=load_pattern(song->get_pattern(i) ); - CP_ERR_COND_V(err,err); - - - pattern_count++; - } - return FILE_OK; - -} - -CPLoader::Error CPLoader_S3M::load_song(const char *p_file,CPSong *p_song,bool p_sampleset) { - - song=p_song; - - if (file->open(p_file,CPFileAccessWrapper::READ)) { - //printf("Can't open file! %s\n",p_file); - return FILE_CANNOT_OPEN; - }; - - sample_count=0; - pattern_count=0; - - //printf("LOADING HEADER\n"); - CPLoader::Error err; - if ((err=load_header())) { - file->close(); - CP_ERR_COND_V(err,err); - - } - - song->reset(); //file type recognized, reset song! - - set_header(); - - //printf("LOADING SAMPLES\n"); - - if ((err=load_samples())) { - file->close(); - - CP_ERR_COND_V(err,err); - } - - //printf("LOADING PATTERNS\n"); - - if ((err=load_patterns())) { - - file->close(); - return err; - } - - file->close(); - - return FILE_OK; -} - - - -CPLoader_S3M::CPLoader_S3M(CPFileAccessWrapper *p_file){ - - file=p_file; - -} -CPLoader_S3M::~CPLoader_S3M(){ -} - diff --git a/modules/chibi/cp_loader_s3m.h b/modules/chibi/cp_loader_s3m.h deleted file mode 100644 index 04ee0b2917..0000000000 --- a/modules/chibi/cp_loader_s3m.h +++ /dev/null @@ -1,111 +0,0 @@ -/*************************************************************************/ -/* cp_loader_s3m.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_LOADER_S3M_H -#define CP_LOADER_S3M_H - -#include "cp_loader.h" - -/** - *@author Juan Linietsky - */ -/****************************** - loader_s3m.h - ---------- -Scream Tracker Module CPLoader! -It lacks support for -individual sample loading -and reorganizing the columns. -********************************/ - - - - -class CPLoader_S3M : public CPLoader { - - struct S3M_Header { - char songname[28]; - uint8_t t1a; - uint8_t type; - uint8_t unused1[2]; - uint16_t ordnum; - uint16_t insnum; - uint16_t patnum; - uint16_t flags; - uint16_t tracker; - uint16_t fileformat; - char scrm[5]; - uint8_t mastervol; - uint8_t initspeed; - uint8_t inittempo; - uint8_t mastermult; - uint8_t ultraclick; - uint8_t pantable; - uint8_t unused2[8]; - uint16_t special; - uint8_t channels[32]; - uint8_t pannings[32]; - uint8_t orderlist[300]; - }; - - - int sample_parapointers[CPSong::MAX_SAMPLES]; - int pattern_parapointers[CPSong::MAX_PATTERNS]; - - Error load_header(); - void set_header(); - Error load_sample(CPSample *p_sample); - Error load_pattern(CPPattern *p_pattern); - Error load_patterns(); - - Error load_samples(); - - S3M_Header header; - int sample_count; - int pattern_count; - - CPFileAccessWrapper *file; - CPSong *song; -public: - - bool can_load_song() { return true; } - bool can_load_sample() { return false; } - bool can_load_instrument() { return false; } - - Error load_song(const char *p_file,CPSong *p_song,bool p_sampleset); - Error load_sample(const char *p_file,CPSample *p_sample); - Error load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx); - - CPLoader_S3M(CPFileAccessWrapper *p_file); - ~CPLoader_S3M(); -}; - - - -#endif diff --git a/modules/chibi/cp_loader_xm.cpp b/modules/chibi/cp_loader_xm.cpp deleted file mode 100644 index cbd883642c..0000000000 --- a/modules/chibi/cp_loader_xm.cpp +++ /dev/null @@ -1,752 +0,0 @@ -/*************************************************************************/ -/* cp_loader_xm.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_loader_xm.h" -#include "cp_tables.h" - -#define ABORT_LOAD { file->close(); return FILE_CORRUPTED; } - - - - -CPLoader::Error CPLoader_XM::load_song(const char *p_file,CPSong *p_song,bool p_sampleset) { - - song=p_song; - - if (file->open(p_file,CPFileAccessWrapper::READ)) { - - return FILE_CANNOT_OPEN; - }; - - - /************************************** - LOAD HEADER - ***************************************/ - - file->get_byte_array(header.idtext,17); - header.idtext[17]=0; - - file->get_byte_array(header.songname,20); - - - - header.songname[20]=0; - header.hex1a=file->get_byte(); - if (header.hex1a!=0x1A) { //XM "magic" byte.. this sucks :) - - file->close(); - return FILE_UNRECOGNIZED; - - } - - - //magic byte sucks, but can't do much about it.. - - song->reset(); //must reset the song - - song->set_name( (const char*)header.songname ); - - file->get_byte_array(header.trackername,20); - header.trackername[20]=0; - - - header.version=file->get_word(); - - header.headersize=file->get_dword(); - - header.songlength=file->get_word(); - - header.restart_pos=file->get_word(); - - header.channels_used=file->get_word(); - - header.patterns_used=file->get_word(); - - header.instruments_used=file->get_word(); - - song->set_linear_slides( file->get_word() ); - - song->set_speed( file->get_word() ); - - song->set_tempo( file->get_word() ); - song->set_instruments( true ); - - file->get_byte_array(header.orderlist,256); - - for (int i=0;i<header.songlength;i++) { - - if (i>199) - break; - song->set_order(i,header.orderlist[i]); - } - - /************************************** - LOAD PATTERNS - ***************************************/ - - for (int i=0;i<header.patterns_used;i++) { - - uint32_t aux,rows; - - aux=file->get_dword(); //length - aux=file->get_byte(); //packing type - rows=aux=file->get_word(); //rows! - - song->get_pattern(i)->set_length( aux ); - - aux=file->get_word(); //packed size - if (aux==0) - continue; - //unpaaack! - for(int j=0;j<(int)rows;j++) - for(int k=0;k<header.channels_used;k++) { - - CPNote aux_note; - uint8_t aux_byte; - //uint8_t field; - aux_byte=file->get_byte(); //packing type - if (!(aux_byte&0x80)) { - - aux_note.note=aux_byte; - aux_byte=0xFE; //if bit 7 not set, read all of them except the note - } - - if (aux_byte&1) aux_note.note=file->get_byte(); - if (aux_byte&2) aux_note.instrument=file->get_byte(); - if (aux_byte&4) aux_note.volume=file->get_byte(); - if (aux_byte&8) aux_note.command=file->get_byte(); - if (aux_byte&16) aux_note.parameter=file->get_byte(); - - if (aux_note.note!=CPNote::EMPTY) { - - if (aux_note.note==97) aux_note.note=CPNote::OFF; - else { - aux_note.note+=11; //octave minus one (XM C-0 is 1, not zero ) - } - } - if (aux_note.instrument!=CPNote::EMPTY) { - - if ((aux_note.instrument>0) && (aux_note.instrument<100)) - aux_note.instrument--; - else - aux_note.instrument=CPNote::EMPTY; - } - if (aux_note.volume!=CPNote::EMPTY) { - - if (aux_note.volume<0x10) {} - else if (aux_note.volume<0x50) { - - aux_note.volume-=0x10; - - } else if (aux_note.volume<0x60) { - // - aux_note.volume=CPNote::EMPTY; - - } else if (aux_note.volume<0x70) { - //60 -- volume slide down - aux_note.volume-=0x60; - if (aux_note.volume>9) aux_note.volume=9; - aux_note.volume+=95; - - } else if (aux_note.volume<0x80) { - //70 -- volume slide up - aux_note.volume-=0x70; - if (aux_note.volume>9) aux_note.volume=9; - aux_note.volume+=85; - - - } else if (aux_note.volume<0x90) { - //80 -- fine volume slide down - aux_note.volume-=0x80; - if (aux_note.volume>9) aux_note.volume=9; - aux_note.volume+=75; - - - } else if (aux_note.volume<0xA0) { - //9 -- fine volume slide up - - aux_note.volume-=0x90; - if (aux_note.volume>9) aux_note.volume=9; - - aux_note.volume+=65; - - - - } else if (aux_note.volume<0xB0) { - //A -- set vibrato speed - aux_note.volume=CPNote::EMPTY; - - } else if (aux_note.volume<0xC0) { - //B -- vibrato - aux_note.volume-=0xB0; - if (aux_note.volume>9) aux_note.volume=9; - aux_note.volume+=203; - - - } else if (aux_note.volume<0xD0) { - //C -- set panning - int aux=aux_note.volume-=0xC0; - aux=aux*65/0xF; - aux_note.volume=128+aux; - - } else if (aux_note.volume<0xE0) { - aux_note.volume=CPNote::EMPTY; - - - } else if (aux_note.volume<0xF0) { - aux_note.volume=CPNote::EMPTY; - - - } else { - //F -- tone porta - aux_note.volume-=0xF0; - aux_note.volume*=9; - aux_note.volume/=0xF; - aux_note.volume+=193; - } - } - if (aux_note.command!=CPNote::EMPTY) { - - switch(aux_note.command) { - - case 0x0: - aux_note.command='J'-'A'; - break; - case 0x1: - aux_note.command='F'-'A'; - break; - case 0x2: - aux_note.command='E'-'A'; - break; - case 0x3: - aux_note.command='G'-'A'; - break; - case 0x4: - aux_note.command='H'-'A'; - break; - case 0x5: - aux_note.command='L'-'A'; - break; - case 0x6: - aux_note.command='K'-'A'; - break; - case 0x7: - aux_note.command='R'-'A'; - break; - case 0x8: - aux_note.command='X'-'A'; - break; - case 0x9: - aux_note.command='O'-'A'; - break; - case 0xa: - aux_note.command='D'-'A'; - break; - case 0xb: - aux_note.command='B'-'A'; - break; - case 0xc: - //printf("XM Import: Warning! effect C (set volume) not implemented!\n"); - break; - case 0xd: - aux_note.command='C'-'A'; - break; - - case 0xe: /* Extended effects */ - - aux_note.command='S'-'A'; - switch(aux_note.parameter>>4) { - case 0x1: /* XM fine porta up */ - if (!(aux_note.parameter&0xF)) { aux_note.command=CPNote::EMPTY; aux_note.parameter=0; break; } - aux_note.command='F'-'A'; - aux_note.parameter=0xF0|(aux_note.parameter&0xF); - break; - case 0x2: /* XM fine porta down */ - if (!(aux_note.parameter&0xF)) { aux_note.command=CPNote::EMPTY; aux_note.parameter=0; break; } - aux_note.command='E'-'A'; - aux_note.parameter=0xF0|(aux_note.parameter&0xF); - break; - case 0xa: /* XM fine volume up */ - if (!(aux_note.parameter&0xF)) { aux_note.command=CPNote::EMPTY; aux_note.parameter=0; break; } - aux_note.command='D'-'A'; - aux_note.parameter=0x0F|((aux_note.parameter&0xF)<<4); - - break; - case 0xb: /* XM fine volume down */ - if (!(aux_note.parameter&0xF)) { aux_note.command=CPNote::EMPTY; aux_note.parameter=0; break; } - aux_note.command='D'-'A'; - aux_note.parameter=0xF0|(aux_note.parameter&0xF); - - break; - case 0x9: /* XM fine volume down */ - if (!(aux_note.parameter&0xF)) { aux_note.command=CPNote::EMPTY; aux_note.parameter=0; break; } - aux_note.command='Q'-'A'; - aux_note.parameter=0x00|(aux_note.parameter&0xF); - break; - - case 0xc: //notecut - - aux_note.parameter=0xC0|(aux_note.parameter&0xF); - break; - - case 0xd: //notedelay - - aux_note.parameter=0xD0|(aux_note.parameter&0xF); - break; - - case 0xe: //patterndelay - - aux_note.parameter=0xE0|(aux_note.parameter&0xF); - break; - } - - break; - case 0xf: - if (aux_note.parameter<32) { - aux_note.command='A'-'A'; - } else { - aux_note.command='T'-'A'; - } - break; - case 'G'-55: - aux_note.command='V'-'A'; - break; - case 'H'-55: - aux_note.command='W'-'A'; - break; - case 'K'-55: - if (aux_note.note!=CPNote::EMPTY) break; - aux_note.note=CPNote::OFF; - break; - case 'P'-55: - aux_note.command='P'-'A'; - break; - case 'R'-55: - aux_note.command='Q'-'A'; - break; - case 'T'-55: - aux_note.command='I'-'A'; - break; - default: { - - aux_note.command=CPNote::EMPTY; - } - } - - - } - - song->get_pattern( i)->set_note( k,j,aux_note ); - } - } - - /************************************** - LOAD INSTRUMENTS! - ***************************************/ - - for (int i=0;i<header.instruments_used;i++) { - - - uint32_t aux; - int sampnum; - - CPInstrument &instrument=*song->get_instrument(i); - uint32_t cpos=file->get_pos(); - //printf("pos is %i\n",cpos); - - - -/* +4 */ uint32_t hsize=file->get_dword(); //header length - - char instrname[23]; - instrname[22]=0; - - file->get_byte_array((uint8_t*)instrname,22); -//XM_LOAD_DEBUG printf("name is %s\n",instrname); - -/* +27 */ aux=file->get_byte(); //byte that must be ignored -//XM_LOAD_DEBUG printf("header size is %i\n",hsize); - -/* +29 */ sampnum=file->get_word(); - -//XM_LOAD_DEBUG printf("samples %i\n",sampnum); - - - instrument.set_name( instrname ); - //printf("Header Len: %i, CPInstrument %i, %i samples , name: s,\n",hsize,i,sampnum,instrname); - - if (sampnum==0) { - //aux=file->get_dword(); //Why is this for? -- for nothing, skipped - if (hsize) { - - file->seek( cpos+hsize ); //skip header if size has been specified - } - continue; - } - -/* +33 */ file->get_dword(); - - if (Error result=load_instrument_internal(&instrument,false,cpos,hsize,sampnum)) { - - CP_PRINTERR("Error loading instrument"); - file->close(); - return result; - } - - } -// - file->close(); - return FILE_OK; -} - -CPLoader::Error CPLoader_XM::load_instrument_internal(CPInstrument *p_instr,bool p_xi,int p_cpos, int p_hsize, int p_sampnum) { - - int sampnum; - uint32_t aux; - uint8_t notenumb[96]; - uint16_t panenv[24],volenv[24]; - int volpoints,panpoints; - int vol_loop_begin,vol_loop_end,vol_sustain_loop; - int pan_loop_begin,pan_loop_end,pan_sustain_loop; - char instrname[23]; - int sample_index[16]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; //-1 means no index! - - instrname[22]=0; - - -/* +129 */ file->get_byte_array((uint8_t*)notenumb,96); - for (int j=0;j<24;j++) { - volenv[j]=file->get_word(); - } - for (int j=0;j<24;j++) { - panenv[j]=file->get_word(); - } - -/* +177 */ -/* +225 */ -/* +226 */ volpoints=file->get_byte(); -/* +227 */ panpoints=file->get_byte(); -/* +230 */ vol_sustain_loop=file->get_byte(); -/* +228 */ vol_loop_begin=file->get_byte(); -/* +229 */ vol_loop_end=file->get_byte(); - -//XM_LOAD_DEBUG printf("1- volpoints: %i, panpoints: %i, susloop: %i, loop begin: %i, loop end %i\n",volpoints,panpoints,vol_sustain_loop,vol_loop_begin,vol_loop_end); - pan_sustain_loop=file->get_byte(); -/* +231 */ pan_loop_begin=file->get_byte(); -/* +232 */ pan_loop_end=file->get_byte(); - - - -/* +234 */ aux=file->get_byte(); - p_instr->get_volume_envelope()->reset(); - p_instr->get_volume_envelope()->set_enabled(aux&1); - p_instr->get_volume_envelope()->set_sustain_loop_enabled((aux&2)?true:false); - p_instr->get_volume_envelope()->set_loop_enabled((aux&4)?true:false); -/* +235 */ aux=file->get_byte(); - p_instr->get_pan_envelope()->reset(); - p_instr->get_pan_envelope()->set_enabled(aux&1); - p_instr->get_pan_envelope()->set_sustain_loop_enabled((aux&2)?true:false); - p_instr->get_pan_envelope()->set_loop_enabled((aux&4)?true:false); - -/* +239 */ aux=file->get_dword(); // sadly, cant use those -/* +241 */ p_instr->set_volume_fadeout( file->get_word() >> 4 ); -/* +243 */ aux=file->get_word(); // reserved! - - - - for (int j=0;j<volpoints;j++) { - int ofs=volenv[j*2]; - int val=volenv[j*2+1]; - p_instr->get_volume_envelope()->add_position(ofs,val); - - } - - //make sure minimum is 2 - while (p_instr->get_volume_envelope()->get_node_count()<2) { - - p_instr->get_volume_envelope()->add_position( p_instr->get_volume_envelope()->get_node_count()*20,64 ); - } - - for (int j=0;j<panpoints;j++) { - int ofs=panenv[j*2]; - int val=panenv[j*2+1]; - p_instr->get_pan_envelope()->add_position(ofs,val-32); - } - - //make sure minimum is 2 - while (p_instr->get_pan_envelope()->get_node_count()<2) { - - p_instr->get_pan_envelope()->add_position( p_instr->get_pan_envelope()->get_node_count()*20,0 ); - } - - - p_instr->get_volume_envelope()->set_loop_begin(vol_loop_begin); - p_instr->get_volume_envelope()->set_loop_end(vol_loop_end); - p_instr->get_volume_envelope()->set_sustain_loop_end(vol_sustain_loop); - p_instr->get_volume_envelope()->set_sustain_loop_begin(vol_sustain_loop); - p_instr->get_pan_envelope()->set_loop_begin(pan_loop_begin); - p_instr->get_pan_envelope()->set_loop_end(pan_loop_end); - p_instr->get_pan_envelope()->set_sustain_loop_end(pan_sustain_loop); - p_instr->get_pan_envelope()->set_sustain_loop_begin(pan_sustain_loop); - - - if (!p_xi) { - - if ((file->get_pos()-p_cpos)<p_hsize) { - - uint8_t junkbuster[500]; - - //printf("extra junk XM instrument in header! hsize is %i, extra junk: %i\n",p_hsize,(file->get_pos()-p_cpos)); - //printf("extra: %i\n",p_hsize-(file->get_pos()-p_cpos)); - file->get_byte_array((uint8_t*)junkbuster,p_hsize-(file->get_pos()-p_cpos)); - } - - sampnum=p_sampnum; - } else { - - uint8_t junkbuster[500]; - file->get_byte_array((uint8_t*)junkbuster,20); //14 bytes? - - sampnum=file->get_word(); - - } - - - CPSampleManager *sm=CPSampleManager::get_singleton(); - - /*SAMPLE!!*/ - - for (int j=0;j<sampnum;j++) { - - if (j>16) ABORT_LOAD; - - - int s_idx=-1; - for (int s=0;s<CPSong::MAX_SAMPLES;s++) { - - if (song->get_sample(s)->get_sample_data().is_null()) { - //empty sample! - s_idx=s; - break; - } - } - - if (s_idx==-1) ABORT_LOAD; - //printf("free sample: %i\n",s_idx); - - - CPSample& sample=*song->get_sample(s_idx); - - int sample_size=file->get_dword(); - int tmp_loop_begin=file->get_dword(); - - int tmp_loop_end=file->get_dword(); - - sample.set_default_volume(file->get_byte()); - - uint8_t ftb=file->get_byte(); - int8_t *fts=(int8_t*)&ftb; - int finetune=*fts; - uint32_t flags=file->get_byte(); - - if (flags&16) { // is 16 bits.. at flag 16.. fun :) - - tmp_loop_end/=2; - tmp_loop_begin/=2; - sample_size/=2; - } - - - CPSample_ID sample_data=sm->create( flags&16, false, sample_size ); - - sample.set_sample_data(sample_data); - sm->set_loop_begin(sample_data,tmp_loop_begin); - sm->set_loop_end(sample_data,tmp_loop_end+tmp_loop_begin); - - sm->set_loop_type( sample_data, (flags&3)?( (flags&2) ? CP_LOOP_BIDI : CP_LOOP_FORWARD ):CP_LOOP_NONE ); - - - - sample.set_pan_enabled(true); - sample.set_pan(file->get_byte()*64/255); - uint8_t noteb=file->get_byte(); - int8_t *notes=(int8_t*)¬eb; - int note_offset=*notes; - note_offset+=48; - //note_offset+=60; - - - - //int linear_period=10*12*16*4 - (note_offset)*16*4 - finetune/2; - //int freq=(int)(8363*pow(2.0,(double)(6*12*16*4 - linear_period) / (double)(12*16*4))); - - //sm->set_c5_freq( sample_data, freq); - sm->set_c5_freq( sample_data, CPTables::get_linear_frequency(CPTables::get_linear_period(note_offset<<1,finetune)) ); - //printf("NOTE %i,fine %i\n",note_offset,finetune); - - char auxb; - auxb=file->get_byte(); //reserved? - file->get_byte_array((uint8_t*)instrname,22); - sample.set_name(instrname); - - sample_index[j]=s_idx; - } - - /*SAMPLE __DATA__!!*/ - - for (int j=0;j<sampnum;j++) { - - if (sample_index[j]==-1) continue; - - CPSample *sample=song->get_sample(sample_index[j]); - CPSample_ID sid=sample->get_sample_data(); - - sm->lock_data(sid); - - void*dataptr=sm->get_data(sid); - - if (sm->is_16bits( sid)) { - - int16_t old=0; - - - for (int k=0;k<sm->get_size(sid);k++) { - - int16_t newsample; - int16_t sampleval=file->get_word(); - newsample=sampleval+old; - old=newsample; - - ((int16_t*)dataptr)[k]=newsample; - //sm->set_data( sid, k, newsample ); - } - } else { - - int8_t old=0; - - - for (int k=0;k<sm->get_size(sid);k++) { - - int8_t newsample; - int8_t sampleval=file->get_byte(); - newsample=sampleval+old; - old=newsample; - - ((int8_t*)dataptr)[k]=newsample; - - //sm->set_data( sid, k, (int16_t)newsample << 8 ); - - } - } - - sm->unlock_data(sid); - - } - - for (int j=0;j<96;j++) { - - int val=notenumb[j]; - if ((val<0) || (val>15)) continue; - else val=sample_index[val]; - if (val==-1) continue; - p_instr->set_sample_number( 12+j,val ); - } - - - return FILE_OK; -} - - - -CPLoader::Error CPLoader_XM::load_sample(const char *p_file,CPSample *p_sample) { - - return FILE_UNRECOGNIZED; -} - - -/* Compute CPInstrument Info */ -CPLoader::Error CPLoader_XM::load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx) { - - if ( file->open(p_file,CPFileAccessWrapper::READ) ) return FILE_CANNOT_OPEN; - //int i; - song=p_song; - CPInstrument& instr=*p_song->get_instrument( p_instr_idx ); - int aux; - - - char buffer[500]; - file->get_byte_array((uint8_t*)buffer,0x15); - buffer[8]=0; - if ( buffer[0]!='E' || - buffer[1]!='x' || - buffer[2]!='t' || - buffer[3]!='e' || - buffer[4]!='n' || - buffer[5]!='d' || - buffer[6]!='e' || - buffer[7]!='d') { - file->close(); - return FILE_UNRECOGNIZED; - } - - file->get_byte_array((uint8_t*)buffer,0x16); - buffer[0x16]=0; - instr.set_name(buffer); - aux=file->get_byte(); //says ignore ti - /*if(aux!=0x1a) { I'm not sure. this is supposed to be ignored... - - file->close(); - return FILE_UNRECOGNIZED; - } */ - - file->get_byte_array((uint8_t*)buffer,0x14); //somethingaboutthename - aux=file->get_word(); //version or blahblah - - if (load_instrument_internal(&instr,true,0,0)) { - - file->close(); - return FILE_CORRUPTED; - } - - file->close(); //ook, we got it.. - - - return FILE_OK; - -} - - - -CPLoader_XM::CPLoader_XM(CPFileAccessWrapper *p_file){ - - file=p_file; -} -CPLoader_XM::~CPLoader_XM(){ -} - diff --git a/modules/chibi/cp_loader_xm.h b/modules/chibi/cp_loader_xm.h deleted file mode 100644 index 0889569b38..0000000000 --- a/modules/chibi/cp_loader_xm.h +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************/ -/* cp_loader_xm.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_LOADER_XM_H -#define CP_LOADER_XM_H - -#include "cp_loader.h" - - -/** - *@author red - */ - - - - -class CPLoader_XM : public CPLoader { - - - struct XM_Header { - - uint8_t idtext[18]; - uint8_t songname[21]; - uint8_t hex1a; // ? - uint8_t trackername[21]; - uint16_t version; - uint32_t headersize; //from here - - uint16_t songlength; //pattern ordertable - uint16_t restart_pos; - uint16_t channels_used; - uint16_t patterns_used; - uint16_t instruments_used; - uint16_t use_linear_freq; - uint16_t tempo; - uint16_t speed; - uint8_t orderlist[256]; - - } header; - - CPFileAccessWrapper *file; - - Error load_instrument_internal(CPInstrument *pint,bool p_xi,int p_cpos, int p_hsize, int p_sampnumb=-1); - CPSong *song; - -public: - - bool can_load_song() { return true; } - bool can_load_sample() { return false; } - bool can_load_instrument() { return true; } - - Error load_song(const char *p_file,CPSong *p_song,bool p_sampleset); - Error load_sample(const char *p_file,CPSample *p_sample); - Error load_instrument(const char *p_file,CPSong *p_song,int p_instr_idx); - - - CPLoader_XM(CPFileAccessWrapper *p_file); - ~CPLoader_XM(); -}; - - - -#endif diff --git a/modules/chibi/cp_mixer.h b/modules/chibi/cp_mixer.h deleted file mode 100644 index d8564bae00..0000000000 --- a/modules/chibi/cp_mixer.h +++ /dev/null @@ -1,115 +0,0 @@ -/*************************************************************************/ -/* cp_mixer.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_MIXER_H -#define CP_MIXER_H - -#include "cp_sample_defs.h" - -/**Abstract base class representing a mixer - *@author Juan Linietsky - */ - - -/****************************** - mixer.h - ---------- - -Abstract base class for the mixer. -This is what the player uses to setup -voices and stuff.. this way -it can be abstracted to hardware -devices or other stuff.. -********************************/ - -class CPSample_ID; /* need this */ - -class CPMixer { -public: - - enum { - - FREQUENCY_BITS=8 - - }; - - enum ReverbMode { - REVERB_MODE_ROOM, - REVERB_MODE_STUDIO_SMALL, - REVERB_MODE_STUDIO_MEDIUM, - REVERB_MODE_STUDIO_LARGE, - REVERB_MODE_HALL, - REVERB_MODE_SPACE_ECHO, - REVERB_MODE_ECHO, - REVERB_MODE_DELAY, - REVERB_MODE_HALF_ECHO - }; - - /* Callback */ - - virtual void set_callback_interval(int p_interval_us)=0; //in usecs, for tracker it's 2500000/tempo - virtual void set_callback(void (*p_callback)(void*),void *p_userdata)=0; - - /* Voice Control */ - - virtual void setup_voice(int p_voice_index,CPSample_ID p_sample_id,int32_t p_start_index) =0; - virtual void stop_voice(int p_voice_index) =0; - virtual void set_voice_frequency(int p_voice_index,int32_t p_freq) =0; //in freq*FREQUENCY_BITS - virtual void set_voice_panning(int p_voice_index,int p_pan) =0; - virtual void set_voice_volume(int p_voice_index,int p_vol) =0; - virtual void set_voice_filter(int p_filter,bool p_enabled,uint8_t p_cutoff, uint8_t p_resonance )=0; - virtual void set_voice_reverb_send(int p_voice_index,int p_reverb)=0; - virtual void set_voice_chorus_send(int p_voice_index,int p_chorus)=0; /* 0 - 255 */ - - virtual void set_reverb_mode(ReverbMode p_mode)=0; - virtual void set_chorus_params(unsigned int p_delay_ms,unsigned int p_separation_ms,unsigned int p_depth_ms10,unsigned int p_speed_hz10)=0; - - - /* Info retrieving */ - - virtual int32_t get_voice_sample_pos_index(int p_voice_index) =0; - virtual int get_voice_panning(int p_voice_index) =0; - virtual int get_voice_volume(int p_voice_index) =0; - virtual CPSample_ID get_voice_sample_id(int p_voice_index) =0; - virtual bool is_voice_active(int p_voice_index) =0; - virtual int get_active_voice_count()=0; - virtual int get_total_voice_count()=0; - - - virtual uint32_t get_mix_frequency()=0; //if mixer is not software, return 0 - - /* Methods below only work with software mixers, meant for software-based sound drivers, hardware mixers ignore them */ - virtual int32_t process(int32_t p_frames)=0; /* Call this to process N frames, returns how much it was processed */ - virtual int32_t *get_mixdown_buffer_ptr()=0; /* retrieve what was mixed */ - virtual void set_mix_frequency(int32_t p_mix_frequency)=0; - - virtual ~CPMixer() {} -}; - -#endif diff --git a/modules/chibi/cp_note.h b/modules/chibi/cp_note.h deleted file mode 100644 index f9a3ef39fc..0000000000 --- a/modules/chibi/cp_note.h +++ /dev/null @@ -1,102 +0,0 @@ -/*************************************************************************/ -/* cp_note.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_NOTE_H -#define CP_NOTE_H - -#include "cp_config.h" - -struct CPNote { - - enum { - - NOTES=120, - OFF=254, - CUT=253, - EMPTY=255, - SCRIPT=252, - }; - - - uint8_t note; - uint8_t instrument; - uint8_t volume; - uint8_t command; - uint8_t parameter; - unsigned int script_source_sign; - bool cloned; - - void clear() { - - note=EMPTY; - instrument=EMPTY; - volume=EMPTY; - command=EMPTY; - parameter=0; - script_source_sign='\0'; - cloned=false; - } - - void raise() { - - if (note<(NOTES-1)) - note++; - else if (note==SCRIPT && parameter<0xFF) - parameter++; - } - - void lower() { - - if ((note>0) && (note<NOTES)) - note--; - else if (note==SCRIPT && parameter>0) - parameter--; - - } - - bool operator== (const CPNote &rvalue) { - - return ( - (note==rvalue.note) && - (instrument==rvalue.instrument) && - (volume==rvalue.volume) && - (command==rvalue.command) && - (parameter==rvalue.parameter) - ); - } - - bool is_empty() const { return (note==EMPTY && instrument==EMPTY && volume==EMPTY && command==EMPTY && parameter==0 && !cloned); } - CPNote() { - - clear(); - } -}; - - -#endif - diff --git a/modules/chibi/cp_order.h b/modules/chibi/cp_order.h deleted file mode 100644 index 8df67df40c..0000000000 --- a/modules/chibi/cp_order.h +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************/ -/* cp_order.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_ORDER_H -#define CP_ORDER_H - - -#include "cp_config.h" - -enum CPOrderType { - CP_ORDER_NONE=255, - CP_ORDER_BREAK=254 -}; - -typedef uint8_t CPOrder; - -#endif - diff --git a/modules/chibi/cp_pattern.cpp b/modules/chibi/cp_pattern.cpp deleted file mode 100644 index 8671b6247d..0000000000 --- a/modules/chibi/cp_pattern.cpp +++ /dev/null @@ -1,574 +0,0 @@ -/*************************************************************************/ -/* cp_pattern.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_pattern.h" - -void CPPattern::clear() { - - if (event_count>0) { - - - CP_FREE(events); - events=NULL; - event_count=0; - } - - length=DEFAULT_LEN; - -} - - -bool CPPattern::resize_event_list_to(uint32_t p_events) { - - - //Module is slow in some cpus, so this should be fast enough - uint32_t new_size=((p_events-1)&(~((1<<RESIZE_EVERY_BITS)-1)))+(1<<RESIZE_EVERY_BITS); - - CP_ERR_COND_V(new_size<p_events,true); //bugARM_INFO - - if (event_count==0 && new_size==0) - return false; //nothing to do - - if (event_count==0) { - - events=(Event*)CP_ALLOC( new_size*sizeof(Event) ); - - } else if (new_size==0) { - - CP_FREE(events); - events=NULL; - } else { - - CP_ERR_COND_V(events==NULL,true); - events=(Event*)CP_REALLOC(events, new_size*sizeof(Event)); - - } - - event_count=p_events; - - return false; -} - - -int32_t CPPattern::get_event_pos(uint16_t p_target_pos) { - - - if (event_count==0) - return -1; - - int low = 0; - int high = event_count -1; - int middle; - - while( low <= high ) - { - middle = ( low + high ) / 2; - - if( p_target_pos == events[middle].pos ) { //match - break; - } else if( p_target_pos < events[middle].pos ) - high = middle - 1; //search low end of array - else - low = middle + 1; //search high end of array - } - - /* adapt so we are behind 2 */ - - if (events[middle].pos<p_target_pos) - middle++; - return middle; - - /* Linear search for now */ - - /* - int32_t pos_idx=0; - - for (;pos_idx<event_count;pos_idx++) { - - if (event_list[pos_idx].pos>=p_target_pos) - break; - - } */ - - //return pos_idx; -} - -bool CPPattern::erase_event_at_pos(uint16_t p_pos) { - - if (event_count==0) - return false; - - - - Event *event_list=events; - - int32_t pos_idx = get_event_pos(p_pos); - if (pos_idx==-1) { - CP_ERR_COND_V(pos_idx==-1,true); - } - - if (pos_idx==event_count || event_list[pos_idx].pos!=p_pos) { - /* Nothing to Erase */ - return false; - } - - for (int32_t i=pos_idx;i<(event_count-1);i++) { - - event_list[i]=event_list[i+1]; - } - - - resize_event_list_to(event_count-1); - - return false; -} - -bool CPPattern::set_note(uint8_t p_column, uint16_t p_row,const CPNote& p_note) { - - CP_ERR_COND_V(p_column>=WIDTH,true); - CP_ERR_COND_V(p_row>=length,true); - - int32_t new_pos; - uint16_t target_pos=p_row*WIDTH+p_column; - - - - if (p_note.is_empty()) { - bool res=erase_event_at_pos(target_pos); - - return res;; - } - - Event *event_list=0; - - if (event_count==0) { - /* If no events, create the first */ - - if (resize_event_list_to(1)) { - - CP_PRINTERR("Can't resize event list to 1"); - return true; - } - - event_list=events; - if (event_list==0) { - - - CP_PRINTERR("Can't get event list"); - return true; - } - - new_pos=0; - - } else { - /* Prepare to add */ - - event_list=events; - if (event_list==0) { - - - CP_PRINTERR("Can't get event list"); - return true; - } - - int32_t pos_idx = get_event_pos(target_pos); - - if (pos_idx==-1) { - - - CP_PRINTERR("Can't find add position"); - return true; - } - - - if (pos_idx==event_count || event_list[pos_idx].pos!=target_pos) { - /* If the note being modified didnt exist, then we add it */ - - //resize, and return if out of mem - if (resize_event_list_to( event_count+1)) { - - - CP_PRINTERR("Can't resize event list"); - return true; - } - event_list=events; - if (event_list==0) { - - - CP_PRINTERR("Can't get event list"); - return true; - } - - //make room for new pos, this wont do a thing if pos_idx was ==event_count - for(int32_t i=(event_count-1);i>pos_idx;i--) { - event_list[i]=event_list[i-1]; - - } - - } /* Else it means that position is taken, so we just modify it! */ - - - new_pos=pos_idx; - } - - event_list[new_pos].pos=target_pos; - event_list[new_pos].note=p_note.note; - event_list[new_pos].instrument=p_note.instrument; - event_list[new_pos].volume=p_note.volume; - event_list[new_pos].command=p_note.command; - event_list[new_pos].parameter=p_note.parameter; - event_list[new_pos].script_source_sign=p_note.script_source_sign; - event_list[new_pos].cloned=p_note.cloned; - - - - - return false; - -} -CPNote CPPattern::get_note(uint8_t p_column,uint16_t p_row) { - - if (p_column==CPNote::EMPTY) return CPNote(); - - CP_ERR_COND_V(p_column>=WIDTH,CPNote()); - CP_ERR_COND_V(p_row>=length,CPNote()); - - if (event_count==0) - return CPNote(); - - - Event *event_list=events; - - CP_ERR_COND_V(event_list==0,CPNote()); - - uint16_t target_pos=p_row*WIDTH+p_column; - int32_t pos_idx = get_event_pos(target_pos); - if (pos_idx==-1) { - - CP_PRINTERR("Can't find event pos"); - return CPNote(); - } - - if (pos_idx>=event_count || event_list[pos_idx].pos!=target_pos) { - /* no note found */ - - return CPNote(); - } - - CPNote n; - n.note=event_list[pos_idx].note; - n.instrument=event_list[pos_idx].instrument; - n.volume=event_list[pos_idx].volume; - n.command=event_list[pos_idx].command; - n.parameter=event_list[pos_idx].parameter; - n.script_source_sign=event_list[pos_idx].script_source_sign; - n.cloned=event_list[pos_idx].cloned; - - - return n; - -} - -CPNote CPPattern::get_transformed_script_note(uint8_t p_column,uint16_t p_row ) { - - CPNote n = get_note( p_column, p_row ); - - // get source channel and note - - int channel = get_scripted_note_target_channel( p_column, p_row ); - CPNote src_n = get_note( channel, 0 ); - - if ( src_n.note == CPNote::SCRIPT ) return CPNote(); - - script_transform_note( src_n, n ); - - return src_n; - -} - -int CPPattern::get_scripted_note_target_channel(uint8_t p_column, uint16_t p_row) { - - CPNote n = get_note( p_column, p_row ); - - if ( n.note != CPNote::SCRIPT ) return CPNote::EMPTY; - - int channel = n.instrument; - - if ( n.script_source_sign == '\0' ) { - - if ( channel < 0 || channel >= CPPattern::WIDTH ) return CPNote::EMPTY; - - } else { - - channel = p_column + ( ( n.script_source_sign=='+') ? 1 : -1 ) * (channel+1); - if ( channel < 0 || channel >= CPPattern::WIDTH ) return CPNote::EMPTY; - - } - - return channel; -} - -void CPPattern::scripted_clone(uint8_t p_column, uint16_t p_row) { - - int channel = get_scripted_note_target_channel( p_column, p_row ); - int src_row = 1; - CPNote script_n = get_note( p_column, p_row ); - - for ( int row = p_row+1; row < length; ++row ) { - - CPNote src_n = get_note( channel, src_row ); - CPNote target_n = get_note( p_column, row ); - - if ( target_n.note != CPNote::SCRIPT ) { - if ( src_n.note == CPNote::SCRIPT ) { - src_n = CPNote(); - channel = CPNote::EMPTY; - } - - script_transform_note( src_n, script_n ); - - src_n.cloned = true; - set_note( p_column, row, src_n ); - - } else { - - return; - - } - - src_row++; - } - -} - -void CPPattern::scripted_clone_remove(uint8_t p_column, uint16_t p_row) { - - if ( get_note( p_column, p_row ).cloned ) - set_note( p_column, p_row, CPNote() ); - - for ( int row = p_row+1; row < length; ++row ) { - - CPNote target_n = get_note( p_column, row ); - - if ( target_n.note != CPNote::SCRIPT ) { - - set_note( p_column, row, CPNote() ); - - } else { - - return; - - } - - } - -} - -void CPPattern::script_transform_note(CPNote& n, const CPNote& p_note) { - - // set instrument - - if ( n.note < CPNote::NOTES && p_note.volume != CPNote::EMPTY ) { - - n.instrument = p_note.volume; - - } - - // transpose - - if ( n.note < CPNote::NOTES && p_note.command != CPNote::EMPTY ) { - - int transpose = ( p_note.parameter & 0xF ) + ( p_note.parameter / 0x10 ) * 12; - - if ( p_note.command == '^' ) { - - if ( n.note >= CPNote::NOTES-transpose ) - n.note = CPNote::NOTES-1; - else - n.note += transpose; - - } else if ( p_note.command == 'v' ) { - - if ( n.note <= transpose ) - n.note = 0; - else - n.note -= transpose; - - } - } - -} - -bool CPPattern::update_scripted_clones_sourcing_channel( int channel ) { - - bool updated = false; - - for ( int x = 0; x < WIDTH; ++x ) { - - for (int y = 0; y < length; ++y ) { - - if ( channel == get_scripted_note_target_channel( x, y ) ) { - - scripted_clone( x, y ); - updated = true; - } - - } - - } - - return updated; -} - -void CPPattern::set_length(uint16_t p_rows) { - - - - if (event_count==0) { - - if (p_rows>=MIN_ROWS) - length=p_rows; - - - return; - - } - - if (p_rows<MIN_ROWS) { - - return; - } - - if (p_rows<length) { - - Event* event_list=events; - if (event_list==0) { - - CP_PRINTERR("get_event_list() Failed"); - return; - } - - - uint16_t target_pos=p_rows*WIDTH; - int32_t pos_idx = get_event_pos(target_pos); - - - if (pos_idx==-1) { - - CP_ERR_COND(pos_idx==-1); - } - - if (resize_event_list_to(pos_idx)) { - - CP_PRINTERR("resize_event_list_to(pos_idx) Failed"); - return; - } - - } - - length=p_rows; - - -} -#if 0 -void CPPattern::copy_to(CPPattern *p_pattern) const { - - - - - p_pattern->clear(); - p_pattern->length=length; - - - if (!event_count) - return; - - - - int bufsiz=MemPool_Wrapper::get_singleton()->get_mem_size( mem_handle ); - MemPool_Handle aux_mem_handle=MemPool_Wrapper::get_singleton()->alloc_mem( bufsiz ); - - if (aux_mem_handle.is_null()) { - - CP_PRINTERR("own handle is null"); - - return; - } - - - if (MemPool_Wrapper::get_singleton()->lock_mem(aux_mem_handle)) { - CP_PRINTERR("Unable to lock aux new handle"); - - return; - - } - - if (MemPool_Wrapper::get_singleton()->lock_mem(mem_handle)) { - - CP_PRINTERR("Unable to lock own handle"); - - return; - } - - uint8_t* srcuint8_tt8_t*)MemPool_Wrapper::get_singleton()->get_mem(mem_handle); - uint8_t* dstuint8_tt8_t*)MemPool_Wrapper::get_singleton()->get_mem(aux_mem_handle); - - for (int i=0;i<bufsiz;i++) - dst[i]=src[i]; - - MemPool_Wrapper::get_singleton()->unlock_mem(mem_handle); - MemPool_Wrapper::get_singleton()->unlock_mem(aux_mem_handle); - - p_pattern->mem_handle=aux_mem_handle; - p_pattern->event_count=event_count; - - -} -#endif -uint16_t CPPattern::get_length() { - - - return length; -} -CPPattern::CPPattern() { - - - length=DEFAULT_LEN; - event_count=0; - clear(); - -} -bool CPPattern::is_empty() { - - return events==NULL; -} - -CPPattern::~CPPattern() { - - clear(); -} diff --git a/modules/chibi/cp_pattern.h b/modules/chibi/cp_pattern.h deleted file mode 100644 index fc3b032523..0000000000 --- a/modules/chibi/cp_pattern.h +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************************/ -/* cp_pattern.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_PATTERN_H -#define CP_PATTERN_H - -#include "cp_note.h" - -class CPPattern { -public: - - - enum { - WIDTH=64, - DEFAULT_LEN=64, - RESIZE_EVERY_BITS=4, - MIN_ROWS=1, //otherwise clipboard wont work - MAX_LEN=256 - - }; - -private: - struct Event { - - uint16_t pos; //column*WIDTH+row - uint8_t note; - uint8_t instrument; - uint8_t volume; - uint8_t command; - uint8_t parameter; - unsigned int script_source_sign; - bool cloned; - }; - - uint16_t length; - uint32_t event_count; - Event* events; - - int32_t get_event_pos(uint16_t p_target_pos); - bool erase_event_at_pos(uint16_t p_pos); - - bool resize_event_list_to(uint32_t p_events); - - void operator=(const CPPattern& p_pattern); //no operator= -public: - - bool is_empty(); - void clear(); - - bool set_note(uint8_t p_column, uint16_t p_row,const CPNote& p_note); //true if no more memory - CPNote get_note(uint8_t p_column,uint16_t p_row); - - CPNote get_transformed_script_note(uint8_t p_column, uint16_t p_row); - int get_scripted_note_target_channel(uint8_t p_column, uint16_t p_row); - void scripted_clone(uint8_t p_column, uint16_t p_row); - void scripted_clone_remove(uint8_t p_column, uint16_t p_row); - void script_transform_note(CPNote& n, const CPNote& p_note); - bool update_scripted_clones_sourcing_channel(int channel); - - //void copy_to(CPPattern *p_pattern) const; - void set_length(uint16_t p_rows); - uint16_t get_length(); - CPPattern(); - ~CPPattern(); - - -}; - -#endif diff --git a/modules/chibi/cp_player_data.cpp b/modules/chibi/cp_player_data.cpp deleted file mode 100644 index c8cbfbd06e..0000000000 --- a/modules/chibi/cp_player_data.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/*************************************************************************/ -/* cp_player_data.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" -#include <stdio.h> - - -CPPlayer::CPPlayer(CPMixer *p_mixer,CPSong *p_song){ - - song=p_song; - mixer=p_mixer; - control.max_voices=p_mixer->get_total_voice_count()-1; //leave one for the sample - control.force_no_nna=false; - control.external_vibrato=false; - control.filters=true; - control.random_seed=128364; //anything - control.play_mode=0; - set_virtual_channels(p_mixer->get_total_voice_count()); - mixer->set_callback( &CPPlayer::callback_function, this ); - - reset(); -} -CPPlayer::~CPPlayer(){ -} - -void CPPlayer::set_virtual_channels(int p_amount) { - - if (p_amount<1) return; - if (p_amount>mixer->get_total_voice_count()) - return; - - control.max_voices=p_amount; - -} - - -void CPPlayer::callback_function(void *p_userdata) { - - CPPlayer*pd=(CPPlayer*)p_userdata; - pd->process_tick(); - -} - -void CPPlayer::process_tick() { - - handle_tick(); - mixer->set_callback_interval( 2500000/control.tempo ); - song_usecs+=2500000/control.tempo; -} - -void CPPlayer::reset() { - - if ( mixer==NULL ) return ; - if ( song==NULL ) return ; - - int i; - - for (i=0;i<control.max_voices;i++) { - - voice[i].reset(); - mixer->stop_voice(i); - } - - for (i=0;i<CPPattern::WIDTH;i++) { - - control.channel[i].reset(); - control.channel[i].channel_volume=song->get_channel_volume(i); - control.channel[i].channel_panning=((int)song->get_channel_pan( i)*PAN_RIGHT/64); - if (song->is_channel_surround(i)) - control.channel[i].channel_panning=PAN_SURROUND; - control.channel[i].mute=song->is_channel_mute( i ); - control.channel[i].chorus_send=song->get_channel_chorus(i)*0xFF/64; - control.channel[i].reverb_send=song->get_channel_reverb(i)*0xFF/64; - } - - - control.speed=song->get_speed(); - control.tempo=song->get_tempo(); - control.global_volume=song->get_global_volume(); - - control.position.current_pattern=0; - control.position.current_row=0; - control.position.current_order=0; - control.position.force_next_order=-1; - control.ticks_counter=control.speed; - control.position.forbid_jump=false; - - song_usecs=0; - -} - -int64_t CPPlayer::get_channel_last_note_time_usec(int p_channel) const { - - CP_FAIL_INDEX_V(p_channel,64,-1); - return control.channel[p_channel].last_event_usecs; - -} - -void CPPlayer::set_channel_global_volume(int p_channel,int p_volume) { - - CP_FAIL_INDEX(p_channel,64); - control.channel[p_channel].channel_global_volume=CLAMP(p_volume,0,255); - -} - -int CPPlayer::get_channel_global_volume(int p_channel) const{ - - CP_FAIL_INDEX_V(p_channel,64,-1); - return control.channel[p_channel].channel_global_volume; - -} - -bool CPPlayer::reached_end_of_song() { - - return control.reached_end; - -} -void CPPlayer::set_force_external_vibratos(bool p_force) { - - control.external_vibrato=p_force; -} -void CPPlayer::set_force_no_nna(bool p_force) { - - control.force_no_nna=p_force; -} diff --git a/modules/chibi/cp_player_data.h b/modules/chibi/cp_player_data.h deleted file mode 100644 index 2157319855..0000000000 --- a/modules/chibi/cp_player_data.h +++ /dev/null @@ -1,582 +0,0 @@ -/*************************************************************************/ -/* cp_player_data.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CP_PLAYER_DATA_H -#define CP_PLAYER_DATA_H - -#include "cp_config.h" -#include "cp_song.h" -#include "cp_mixer.h" -#include "cp_tables.h" - -/**CPPlayer Data - *@author Juan Linietsky - */ - -/****************************** - player_data.h - ------------------------ - -The player and its data. -I hope you dont get sick reading this -********************************/ - -//Default pan values - - -class CPPlayer { - - enum { - PAN_SURROUND=512, - PAN_RIGHT=255, - PAN_LEFT=0, - PAN_CENTER=128 - }; - - - CPSong *song; - - CPMixer *mixer; - - struct Filter_Control { - - int32_t it_reso; - int32_t it_cutoff; - int32_t envelope_cutoff; - int32_t final_cutoff; - - void process(); - void set_filter_parameters(int *p_cutoff,uint8_t *p_reso); - - }; - - //tells you if a channel is doing - //noteoff/notekill/notefade/etc - enum { - - END_NOTE_NOTHING=0, - END_NOTE_OFF=1, - END_NOTE_FADE=2, - END_NOTE_KILL=4 - }; - - //Tells you what should a channel restart - enum { - - KICK_NOTHING, - KICK_NOTE, - KICK_NOTEOFF, - KICK_ENVELOPE - }; - - enum { - - MAX_VOICES=256 - }; - - struct Channel_Control; - - struct Voice_Control { - - struct Envelope_Control { - - int pos_index; - int status; - int value; - bool sustain_looping; - bool looping; - bool terminated; - bool active; - bool kill; - - }; - - Filter_Control filter; - uint16_t reverb_send; - uint16_t chorus_send; - - CPInstrument* instrument_ptr; - CPSample* sample_ptr; - - //Sample_Data *sample_data; - - int32_t period; - - int32_t sample_start_index; /* The starting byte index in the sample */ - - bool has_master_channel; - int master_channel_index; - int instruement_index; - - int instrument_index; - int sample_index; - int8_t NNA_type; - - int note_end_flags; - - uint8_t sample; /* which instrument number */ - - int16_t output_volume; /* output volume (vol + sampcol + instvol) */ - int8_t channel_volume; /* channel's "global" volume */ - uint16_t fadeout_volume; /* fading volume rate */ - int32_t total_volume; /* total volume of channel (before global mixings) */ - uint8_t kick; /* if true = sample has to be restarted */ - - uint8_t note; /* the audible note (as heard, direct rep of period) */ - - int16_t panning; /* panning position */ - - uint8_t nna; /* New note action type + master/slave flags */ - uint8_t volflg; /* volume envelope settings */ - uint8_t panflg; /* panning envelope settings */ - uint8_t pitflg; /* pitch envelope settings */ - uint8_t keyoff; /* if true = fade out and stuff */ - int16_t handle; /* which sample-handle */ - int32_t start; /* The start byte index in the sample */ - - /* Below here is info NOT in MP_CONTROL!! */ - //ENVPR venv; - //ENVPR penv; - //ENVPR cenv; - - Envelope_Control volume_envelope_ctrl; - Envelope_Control panning_envelope_ctrl; - Envelope_Control pitch_envelope_ctrl; - - uint16_t auto_vibrato_pos; /* autovibrato pos */ - uint16_t auto_vibrato_sweep_pos; /* autovibrato sweep pos */ - - int16_t masterchn; - uint16_t masterperiod; - - Channel_Control* master_channel; /* index of "master" effects channel */ - - void start_envelope(CPEnvelope *p_envelope,Envelope_Control *p_envelope_ctrl,Envelope_Control *p_from_env); - bool process_envelope(CPEnvelope *p_envelope,Envelope_Control *p_envelope_ctrl); - - uint16_t display_volume; - - Voice_Control() { - - reset(); - } - - void reset(); - void update_info_from_master_channel(); - - - }; - - - struct Channel_Control { - - /* NOTE info */ - uint8_t note; /* the audible note as heard, direct rep of period */ - uint8_t real_note; /* the note that indexes the audible */ - int32_t sample_start_index; /* The starting byte index in the sample */ - uint8_t old_note; - - uint8_t kick; - - Filter_Control filter; - uint16_t reverb_send; - uint16_t chorus_send; - - - int note_end_flags; - - /* INSTRUMENT INFO */ - - CPInstrument* instrument_ptr; - CPSample* sample_ptr; - - uint8_t instrument_index; - uint8_t sample_index; - bool new_instrument; - - /* SAMPLE SPECIFIC INFO */ - int32_t base_speed; /* what finetune to use */ - - /* INSTRUMENT SPECIFIC INFO */ - - int8_t NNA_type; - int8_t duplicate_check_type; - int8_t duplicate_check_action; - - bool volume_envelope_on; - bool panning_envelope_on; - bool pitch_envelope_on; - - bool has_own_period; - - bool row_has_note; - - /* VOLUME COLUMN */ - - int16_t volume; /* amiga volume (0 t/m 64) to play the sample at */ - int16_t aux_volume; - bool has_own_volume; - bool mute; - int16_t random_volume_variation; /* 0-100 - 100 has no effect */ - - /* VOLUME/PAN/PITCH MODIFIERS */ - - int8_t default_volume; // CHANNEL default volume (0-64) - int16_t channel_volume; // CHANNEL current volume //chanvol - current! - int16_t output_volume; /* output volume (vol + sampcol + instvol) //volume */ - int16_t channel_global_volume; - - uint16_t fadeout_volume; /* fading volume rate */ - - int32_t period; /* period to play the sample at */ - - /* PAN */ - - int16_t panning; /* panning position */ - int16_t channel_panning; - int8_t sliding; - - uint16_t aux_period; /* temporary period */ - - - - /* TIMING */ - uint8_t note_delay; /* (used for note delay) */ - - /* Slave Voice Control */ - - Voice_Control *slave_voice; /* Audio Slave of current effects control channel */ - - struct Carry { - - Voice_Control::Envelope_Control vol; - Voice_Control::Envelope_Control pan; - Voice_Control::Envelope_Control pitch; - bool maybe; - - } carry; - - - - uint8_t slave_voice_index; /* Audio Slave of current effects control channel */ - - uint8_t* row; /* row currently playing on this channel */ - - /* effect memory variables */ - - uint8_t current_command; - uint8_t current_parameter; - uint8_t current_volume_command; - uint8_t current_volume_parameter; - uint8_t volcol_volume_slide; - - /* CPSample Offset */ - - int32_t lo_offset; - int32_t hi_offset; - - /* Panbrello waveform */ - uint8_t panbrello_type; /* current panbrello waveform */ - uint8_t panbrello_position; /* current panbrello position */ - int8_t panbrello_speed; /* "" speed */ - uint8_t panbrello_depth; /* "" depth */ - uint8_t panbrello_info; - /* Arpegio */ - - uint8_t arpegio_info; - /* CPPattern Loop */ - - int pattern_loop_position; - int8_t pattern_loop_count; - - /* Vibrato */ - bool doing_vibrato; - int8_t vibrato_position; /* current vibrato position */ - uint8_t vibrato_speed; /* "" speed */ - uint8_t vibrato_depth; /* "" depth */ - uint8_t vibrato_type; - /* Tremor */ - int8_t tremor_position; - uint8_t tremor_speed; /* s3m tremor ontime/offtime */ - uint8_t tremor_depth; - uint8_t tremor_info; - - /* Tremolo */ - int8_t tremolo_position; - uint8_t tremolo_speed; /* s3m tremor ontime/offtime */ - uint8_t tremolo_depth; - uint8_t tremolo_info; - uint8_t tremolo_type; - - /* Retrig */ - int8_t retrig_counter; /* retrig value (0 means don't retrig) */ - uint8_t retrig_speed; /* last used retrig speed */ - uint8_t retrig_volslide; /* last used retrig slide */ - - /* CPSample Offset */ - int32_t sample_offset_hi; /* last used high order of sample offset */ - uint16_t sample_offset; /* last used low order of sample-offset (effect 9) */ - uint16_t sample_offset_fine; /* fine sample offset memory */ - - /* Portamento */ - uint16_t slide_to_period; /* period to slide to (with effect 3 or 5) */ - uint8_t portamento_speed; - - /* Volume Slide */ - - uint8_t volume_slide_info; - - /* Channel Volume Slide */ - - uint8_t channel_volume_slide_info; - - /* Global Volume Slide */ - - uint8_t global_volume_slide_info; - - /* Channel Pan Slide */ - - uint8_t channel_pan_slide_info; - - /* Pitch Slide */ - - uint8_t pitch_slide_info; - /* Tempo Slide */ - - uint8_t tempo_slide_info; - - /* S effects memory */ - - uint8_t current_S_effect; - uint8_t current_S_data; - - /* Volume column memory */ - - uint8_t volume_column_effect_mem; - uint8_t volume_column_data_mem; - - int64_t last_event_usecs; - bool reserved; - - void reset(); - - Channel_Control() { channel_global_volume=255; last_event_usecs=-1; } - }; - - struct Control_Variables { // control variables (dynamic version) of initial variables - - bool reached_end; - - char play_mode; - bool filters; - int global_volume; - int speed; - int tempo; - - int ticks_counter; - - int pattern_delay_1; - int pattern_delay_2; - - Channel_Control channel[CPPattern::WIDTH]; - - int max_voices; - - int voices_used; /* reference value */ - - bool force_no_nna; - bool external_vibrato; - - struct Position { - - int current_order; - int current_pattern; - int current_row; - int force_next_order; - bool forbid_jump; - }; - - int32_t random_seed; - - Position position; - Position previous_position; - - }; - - - Voice_Control voice[MAX_VOICES]; - - Control_Variables control; - - /* VOICE SETUP */ - - void setup_voices(); - - /* MIXER SETUP */ - void handle_tick(); - void update_mixer(); - - /* NOTE / INSTRUMENT PROCESSING */ - - void process_new_note(int p_track,uint8_t p_note); - bool process_new_instrument(int p_track,uint8_t p_instrument); - bool process_note_and_instrument(int p_track,int p_note,int p_instrument); - - /* EFFECT PROCESSING */ - void do_effect_S(int p_track); - void do_panbrello(int p_track); - void do_global_volume_slide(int p_track); - void do_tremolo(int p_track); - void do_retrig(int p_track); - void do_pan_slide(int p_track); - void do_channel_volume_slide(int p_track); - void do_volume_slide(int p_track,int inf); - void do_pitch_slide_down(int p_track,uint8_t inf); - void do_pitch_slide_up(int p_track,uint8_t inf); - void do_tremor(int p_track); - void do_vibrato(int p_track,bool fine); - void do_pitch_slide_to_note(int p_track); - void run_effects(int p_track); - void run_volume_column_effects(int p_track); - void pre_process_effects(); - void do_arpegio(int p_track); - uint64_t song_usecs; - /* NNA */ - - void process_NNAs(); - - - /* MISC UTILS */ - - - int find_empty_voice(); - void process_volume_column(int p_track,uint8_t p_volume); - void process_note(int p_track,CPNote p_note); - - /* CPTables */ - static uint8_t auto_vibrato_table[128]; - static uint8_t vibrato_table[32]; - static int8_t panbrello_table[256]; - - static void callback_function(void *p_userdata); - -public: - //Play modes - - enum { - - PLAY_NOTHING =0, - PLAY_PATTERN =1, - PLAY_SONG =2 - }; - - - int32_t get_frequency(int32_t period); - int32_t get_period(uint16_t note,int32_t p_c5freq); - - - int get_current_tempo() { return control.tempo; }; - int get_current_speed() { return control.speed; }; - - int get_voices_used() { return control.voices_used;}; - int get_voice_envelope_pos(int p_voice,CPEnvelope *p_envelope); - int get_voice_amount_limit() { return control.max_voices; }; - void set_voice_amount_limit(int p_limit); - void set_reserved_voices(int p_amount); - int get_reserved_voices_amount(); - - bool is_voice_active(int p_voice); - int get_channel_voice(int p_channel); - const char* get_voice_sample_name(int p_voice); - const char* get_voice_instrument_name(int p_voice); - CPEnvelope* get_voice_envelope(int p_voice,CPInstrument::EnvelopeType p_env_type); - int get_voice_envelope_pos(int p_voice,CPInstrument::EnvelopeType p_env_type); - int get_voice_volume(int p_voice); - - int get_voice_sample_index(int p_voice); - - void set_virtual_channels(int p_amount); - int get_virtual_channels() { return control.max_voices; }; - - - /* Play Info/Position */ - bool is_playing() { return (control.play_mode>0); }; - int get_play_mode() {return (control.play_mode);}; - int get_current_order() { return control.position.current_order; }; - int get_current_row() { return control.position.current_row; }; - int get_current_pattern() { return control.position.current_pattern; }; - - void goto_next_order(); - void goto_previous_order(); - - void process_tick(); - - - CPMixer* get_mixer_ptr() { - - return mixer; - } - - - void reset(); - - - - /* External player control - editor - */ - - void play_start_pattern(int p_pattern); - void play_start_song(); - void play_start_song_from_order(int p_order); - void play_start_song_from_order_and_row(int p_order,int p_row); - void play_start(int p_pattern, int p_order, int p_row,bool p_lock=true); - - void play_stop(); - void play_note(int p_channel,CPNote note,bool p_reserve=false); - - bool reached_end_of_song(); - - void set_force_no_nna(bool p_force); - void set_force_external_vibratos(bool p_force); - - void set_filters_enabled(bool p_enable); - bool are_filters_enabled() { return control.filters; } - - void set_channel_global_volume(int p_channel,int p_volume); //0-255 - int get_channel_global_volume(int p_channel) const; - - int64_t get_channel_last_note_time_usec(int p_channel) const; - - CPSong *get_song() { return song; }; - - - CPPlayer(CPMixer *p_mixer,CPSong *p_song); - ~CPPlayer(); -}; - -#endif diff --git a/modules/chibi/cp_player_data_control.cpp b/modules/chibi/cp_player_data_control.cpp deleted file mode 100644 index 2ef1c1de8c..0000000000 --- a/modules/chibi/cp_player_data_control.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_control.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" - -void CPPlayer::play_start_pattern(int p_pattern) { - - play_start(p_pattern,-1,-1); -} - -void CPPlayer::play_start_song() { - - play_start(-1,-1,-1); -} - -void CPPlayer::play_start_song_from_order(int p_order) { - - play_start(-1,p_order,-1); -} - -void CPPlayer::play_start_song_from_order_and_row(int p_order,int p_row) { - - play_start(-1,p_order,p_row); -} - -void CPPlayer::play_start(int p_pattern, int p_order, int p_row,bool p_lock) { - - - if (control.play_mode!=PLAY_NOTHING) play_stop(); - - - reset(); - - if (p_pattern!=-1) { - - control.play_mode=PLAY_PATTERN; - control.position.current_pattern=p_pattern; - control.position.current_row=(p_row!=-1)?p_row:0; - - } else { - - control.position.current_order=get_song_next_order_idx(song,(p_order==-1)?p_order:p_order-1); - if (control.position.current_order!=-1) { - - control.play_mode=PLAY_SONG; - control.position.current_pattern=song->get_order(control.position.current_order); - control.position.current_row=(p_row!=-1)?p_row:0; - } - } - - - control.reached_end=(control.play_mode==PLAY_NOTHING); - - -} - -void CPPlayer::play_stop() { - - int i; - - - control.play_mode=PLAY_NOTHING; - - for (i=0;i<control.max_voices;i++) { - - voice[i].reset(); - mixer->stop_voice(i); - } - - for (i=0;i<CPPattern::WIDTH;i++) { - - control.channel[i].reset(); - } - - reset(); - -} - -void CPPlayer::play_note(int p_channel,CPNote note,bool p_reserve) { - - - - if (control.play_mode==PLAY_NOTHING) { - - control.ticks_counter=0; - } - - /*control.channel[p_channel].reset(); - control.channel[p_channel].channel_volume=song->get_channel_volume(p_channel); - control.channel[p_channel].channel_panning=((int)song->get_channel_pan( p_channel)*255/64);*/ - if (p_reserve) { - control.channel[p_channel].mute=false; - control.channel[p_channel].reserved=true; - } else { - - control.channel[p_channel].reserved=false; - - } - process_note(p_channel,note); - - - -} - - -int CPPlayer::get_voice_volume(int p_voice) { - - return voice[p_voice].display_volume; -} - - -int CPPlayer::get_voice_envelope_pos(int p_voice,CPEnvelope *p_envelope) { - - int i,tmp_index=-1; - - i=p_voice; - - - - - if ((song->has_instruments()) && (voice[i].instrument_ptr!=NULL) && (voice[i].fadeout_volume>0)) { - - if ((p_envelope==voice[i].instrument_ptr->get_volume_envelope()) && (voice[i].instrument_ptr->get_volume_envelope()->is_enabled())) { - - tmp_index=voice[i].volume_envelope_ctrl.pos_index; - } - - if ((p_envelope==voice[i].instrument_ptr->get_pan_envelope()) && (voice[i].instrument_ptr->get_pan_envelope()->is_enabled())) { - - tmp_index=voice[i].panning_envelope_ctrl.pos_index; - } - - if ((p_envelope==voice[i].instrument_ptr->get_pitch_filter_envelope()) && (voice[i].instrument_ptr->get_pitch_filter_envelope()->is_enabled())) { - - - tmp_index=voice[i].pitch_envelope_ctrl.pos_index; - } - - } - - - - return tmp_index; -} - -void CPPlayer::goto_next_order() { - - - if (control.play_mode!=PLAY_SONG) return; - - - - control.position.current_row=0; - - - control.position.current_order=get_song_next_order_idx(song, control.position.current_order); - - - - if (control.position.current_order==-1) { - - reset(); - } - - control.position.current_pattern=song->get_order(control.position.current_order); - - -} -void CPPlayer::goto_previous_order() { - - if (control.play_mode!=PLAY_SONG) return; - - - int next_order,current_order; - - control.position.current_row=0; - - current_order=control.position.current_order; - - next_order=get_song_next_order_idx(song, current_order); - - while ((next_order!=control.position.current_order) && (next_order!=-1)) { - - current_order=next_order; - next_order=get_song_next_order_idx(song, current_order); - } - - if (next_order==-1) { - - reset(); - } else { - - control.position.current_order=current_order; - control.position.current_pattern=song->get_order(control.position.current_order); - - } - - - -} - -int CPPlayer::get_channel_voice(int p_channel) { - - if (control.channel[p_channel].slave_voice==NULL) return -1; - else return control.channel[p_channel].slave_voice_index; -} - -const char* CPPlayer::get_voice_sample_name(int p_voice) { - - const char *name = NULL; - - - - if (!voice[p_voice].sample_ptr) name=voice[p_voice].sample_ptr->get_name(); - - - - return name; - -} - - -bool CPPlayer::is_voice_active(int p_voice) { - - return !( ((voice[p_voice].kick==KICK_NOTHING)||(voice[p_voice].kick==KICK_ENVELOPE))&&!mixer->is_voice_active(p_voice) ); - -} - - - -int CPPlayer::get_voice_envelope_pos(int p_voice,CPInstrument::EnvelopeType p_env_type) { - - if (!is_voice_active(p_voice)) - return -1; - - Voice_Control::Envelope_Control *env=0; - - switch (p_env_type) { - - case CPInstrument::VOLUME_ENVELOPE: env=&voice[p_voice].volume_envelope_ctrl; break; - case CPInstrument::PAN_ENVELOPE: env=&voice[p_voice].panning_envelope_ctrl; break; - case CPInstrument::PITCH_ENVELOPE: env=&voice[p_voice].pitch_envelope_ctrl; break; - - } - - if (!env) - return -1; - - if (!env->active || env->terminated) - return -1; - - return env->pos_index; -} - - -CPEnvelope* CPPlayer::get_voice_envelope(int p_voice,CPInstrument::EnvelopeType p_env_type) { - - CPInstrument *ins=voice[p_voice].instrument_ptr; - - if (!ins) - return 0; - - switch( p_env_type ) { - - - case CPInstrument::VOLUME_ENVELOPE: return ins->get_volume_envelope(); - case CPInstrument::PAN_ENVELOPE: return ins->get_pan_envelope(); - case CPInstrument::PITCH_ENVELOPE: return ins->get_pitch_filter_envelope(); - }; - - return 0; - -} - -const char * CPPlayer::get_voice_instrument_name(int p_voice) { - - - - const char *name = NULL; - - - - if (voice[p_voice].instrument_ptr!=NULL) name=voice[p_voice].instrument_ptr->get_name(); - - - - return name; - -} -void CPPlayer::set_filters_enabled(bool p_enable){ - - control.filters=p_enable; -} - -int CPPlayer::get_voice_sample_index(int p_voice) { - - return voice[p_voice].sample_index; -} diff --git a/modules/chibi/cp_player_data_effects.cpp b/modules/chibi/cp_player_data_effects.cpp deleted file mode 100644 index 56fb7a2905..0000000000 --- a/modules/chibi/cp_player_data_effects.cpp +++ /dev/null @@ -1,1232 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_effects.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" - - - -/********************** - complex effects -***********************/ -#define RANDOM_MAX 2147483647 - -static inline int32_t cp_random_generate(int32_t *seed) { - int32_t k; - int32_t s = (int32_t)(*seed); - if (s == 0) - s = 0x12345987; - k = s / 127773; - s = 16807 * (s - k * 127773) - 2836 * k; - if (s < 0) - s += 2147483647; - (*seed) = (int32_t)s; - return (int32_t)(s & RANDOM_MAX); -} - - - -void CPPlayer::do_vibrato(int p_track,bool fine) { - - uint8_t q; - uint16_t temp=0; - - if ((control.ticks_counter==0) && control.channel[p_track].row_has_note) control.channel[p_track].vibrato_position=0; - - q=(control.channel[p_track].vibrato_position>>2)&0x1f; - - switch (control.channel[p_track].vibrato_type) { - case 0: /* sine */ - temp=vibrato_table[q]; - break; - case 1: /* square wave */ - temp=255; - break; - case 2: /* ramp down */ - q<<=3; - if (control.channel[p_track].vibrato_position<0) q=255-q; - temp=q; - break; - case 3: /* random */ - temp=cp_random_generate(&control.random_seed) %256;//getrandom(256); - break; - } - - temp*=control.channel[p_track].vibrato_depth; - - if (song->has_old_effects()) { - - temp>>=7; - } else { - - temp>>=8; - } - - if (!fine) temp<<=2; - - if (control.channel[p_track].vibrato_position>=0) { - - control.channel[p_track].period=control.channel[p_track].aux_period+temp; - } else { - - control.channel[p_track].period=control.channel[p_track].aux_period-temp; - } - - if (!song->has_old_effects() || control.ticks_counter) control.channel[p_track].vibrato_position+=control.channel[p_track].vibrato_speed; -} - - -void CPPlayer::do_pitch_slide_down(int p_track,uint8_t inf) { - - uint8_t hi,lo; - - if (inf) control.channel[p_track].pitch_slide_info=inf; - else inf=control.channel[p_track].pitch_slide_info; - - hi=inf>>4; - lo=inf&0xf; - - if (hi==0xf) { - - if (!control.ticks_counter) control.channel[p_track].aux_period+=(uint16_t)lo<<2; - } else if (hi==0xe) { - - if (!control.ticks_counter) control.channel[p_track].aux_period+=lo; - } else { - - if (control.ticks_counter) control.channel[p_track].aux_period+=(uint16_t)inf<<2; - } -} - -void CPPlayer::do_pitch_slide_up(int p_track,uint8_t inf) { - - uint8_t hi,lo; - - if (inf) control.channel[p_track].pitch_slide_info=inf; - else inf=control.channel[p_track].pitch_slide_info; - - hi=inf>>4; - lo=inf&0xf; - - if (hi==0xf) { - - if (!control.ticks_counter) control.channel[p_track].aux_period-=(uint16_t)lo<<2; - } else if (hi==0xe) { - - if (!control.ticks_counter) control.channel[p_track].aux_period-=lo; - } else { - - if (control.ticks_counter) control.channel[p_track].aux_period-=(uint16_t)inf<<2; - } -} - -void CPPlayer::do_pitch_slide_to_note(int p_track) { - - if (control.ticks_counter) { - int dist; - - /* We have to slide a->period towards a->wantedperiod, compute the - difference between those two values */ - dist=control.channel[p_track].period-control.channel[p_track].slide_to_period; - - /* if they are equal or if portamentospeed is too big... */ - if ((!dist)||((control.channel[p_track].portamento_speed<<2)>cp_intabs(dist))) { - /* ... make tmpperiod equal tperiod */ - control.channel[p_track].aux_period=control.channel[p_track].period=control.channel[p_track].slide_to_period; - } else { - - if (dist>0) { - - control.channel[p_track].aux_period-=control.channel[p_track].portamento_speed<<2; - control.channel[p_track].period-=control.channel[p_track].portamento_speed<<2; /* dist>0 slide up */ - } else { - control.channel[p_track].aux_period+=control.channel[p_track].portamento_speed<<2; - control.channel[p_track].period+=control.channel[p_track].portamento_speed<<2; /* dist<0 slide down */ - } - } - - } else { - - control.channel[p_track].aux_period=control.channel[p_track].period; - } -} - -void CPPlayer::do_tremor(int p_track) { - - uint8_t on,off,inf; - - inf=control.channel[p_track].current_parameter; - - if (inf) { - control.channel[p_track].tremor_info=inf; - } else { - inf= control.channel[p_track].tremor_info; - if (!inf) return; - } - - //if (!control.ticks_counter) return; - - on=(inf>>4); - off=(inf&0xf); - - control.channel[p_track].tremor_position%=(on+off); - control.channel[p_track].volume=(control.channel[p_track].tremor_position<on)?control.channel[p_track].aux_volume:0; - control.channel[p_track].tremor_position++; -} - -void CPPlayer::do_pan_slide(int p_track) { - - uint8_t lo,hi,inf; - int16_t pan; - - inf=control.channel[p_track].current_parameter; - - if (inf) control.channel[p_track].channel_pan_slide_info=inf; - else inf=control.channel[p_track].channel_pan_slide_info; - - lo=inf&0xf; - hi=inf>>4; - - pan=(control.channel[p_track].panning==PAN_SURROUND)?PAN_CENTER:control.channel[p_track].panning; - - if (!hi) - pan+=lo<<2; - else - if (!lo) { - pan-=hi<<2; - } else - if (hi==0xf) { - if (!control.ticks_counter) pan+=lo<<2; - } else - if (lo==0xf) { - if (!control.ticks_counter) pan-=hi<<2; - } - //this sets both chan & voice paning - control.channel[p_track].panning=(pan<PAN_LEFT)?PAN_LEFT:(pan>PAN_RIGHT?PAN_RIGHT:pan); - control.channel[p_track].channel_panning=control.channel[p_track].panning; -} - -void CPPlayer::do_volume_slide(int p_track,int inf) { - - uint8_t hi,lo; - - lo=inf&0xf; - hi=inf>>4; - - if (!lo) { - - if ((control.ticks_counter)) control.channel[p_track].aux_volume+=hi; - - } else if (!hi) { - - if ((control.ticks_counter)) control.channel[p_track].aux_volume-=lo; - - } else if (lo==0xf) { - - if (!control.ticks_counter) control.channel[p_track].aux_volume+=(hi?hi:0xf); - } else if (hi==0xf) { - - if (!control.ticks_counter) control.channel[p_track].aux_volume-=(lo?lo:0xf); - } else return; - - if (control.channel[p_track].aux_volume<0) { - - control.channel[p_track].aux_volume=0; - } else if (control.channel[p_track].aux_volume>64) { - - control.channel[p_track].aux_volume=64; - } -} - -void CPPlayer::do_channel_volume_slide(int p_track) { - - uint8_t lo, hi,inf; - - inf=control.channel[p_track].current_parameter; - - if (inf) control.channel[p_track].channel_volume_slide_info=inf; - inf=control.channel[p_track].channel_volume_slide_info; - - lo=inf&0xf; - hi=inf>>4; - - if (!hi) - control.channel[p_track].channel_volume-=lo; - else - if (!lo) { - control.channel[p_track].channel_volume+=hi; - } else - if (hi==0xf) { - if (!control.ticks_counter) control.channel[p_track].channel_volume-=lo; - } else - if (lo==0xf) { - if (!control.ticks_counter) control.channel[p_track].channel_volume+=hi; - } - - if (control.channel[p_track].channel_volume<0) control.channel[p_track].channel_volume=0; - if (control.channel[p_track].channel_volume>64) control.channel[p_track].channel_volume=64; -} - -void CPPlayer::do_tremolo(int p_track) { - - uint8_t q; - int16_t temp=0; - - if ((control.ticks_counter==0) && control.channel[p_track].row_has_note) control.channel[p_track].tremolo_position=0; - - q=(control.channel[p_track].tremolo_position>>2)&0x1f; - - switch (control.channel[p_track].tremolo_type) { - case 0: /* sine */ - temp=vibrato_table[q]; - break; - case 1: /* ramp down */ - q<<=3; - if (control.channel[p_track].tremolo_position<0) q=255-q; - temp=q; - break; - case 2: /* square wave */ - temp=255; - break; - case 3: /* random */ - temp=cp_random_generate(&control.random_seed) % 256;//getrandom(256); - break; - } - - temp*=control.channel[p_track].tremolo_depth; - temp>>=7; - - - - if (control.channel[p_track].tremolo_position>=0) { - - - control.channel[p_track].volume=control.channel[p_track].aux_volume+temp; - if (control.channel[p_track].volume>64) control.channel[p_track].volume=64; - } else { - - control.channel[p_track].volume=control.channel[p_track].aux_volume-temp; - if (control.channel[p_track].volume<0) control.channel[p_track].volume=0; - } - - /*if (control.ticks_counter)*/ control.channel[p_track].tremolo_position+=control.channel[p_track].tremolo_speed; - -} - -void CPPlayer::do_arpegio(int p_track) { - - uint8_t note,dat; - //note=control.channel[p_track].note; - note=0; - - if (control.channel[p_track].current_parameter) { - - control.channel[p_track].arpegio_info=control.channel[p_track].current_parameter; - } - - dat=control.channel[p_track].arpegio_info; - - if (dat) { - - switch (control.ticks_counter%3) { - - case 1: { - - note+=(dat>>4); - - } break; - case 2: { - - note+=(dat&0xf); - } break; - } - - if (song->has_linear_slides()) { - - control.channel[p_track].period=control.channel[p_track].aux_period-cp_intabs(get_period((uint16_t)46,0)-get_period((uint16_t)44,0))*note; - } else if (control.channel[p_track].sample_ptr) { - - control.channel[p_track].period=get_period( (((uint16_t)control.channel[p_track].note)+note)<<1,CPSampleManager::get_singleton()->get_c5_freq( (control.channel[p_track].sample_ptr->get_sample_data()))); - } - - control.channel[p_track].has_own_period=true; - } - - -} - - -void CPPlayer::do_retrig(int p_track) { - - uint8_t inf; - - inf=control.channel[p_track].current_parameter; - - if (inf) { - - control.channel[p_track].retrig_volslide=inf>>4; - control.channel[p_track].retrig_speed=inf&0xf; - } - - /* only retrigger if low nibble > 0 */ - if ( control.channel[p_track].retrig_speed>0) { - - if ( !control.channel[p_track].retrig_counter ) { - /* when retrig counter reaches 0, reset counter and restart the - sample */ - if (control.channel[p_track].kick!=KICK_NOTE) control.channel[p_track].kick=KICK_NOTEOFF; - control.channel[p_track].retrig_counter=control.channel[p_track].retrig_speed; - - - if ((control.ticks_counter)/*||(pf->flags&UF_S3MSLIDES)*/) { - switch (control.channel[p_track].retrig_volslide) { - case 1: - case 2: - case 3: - case 4: - case 5: - control.channel[p_track].aux_volume-=(1<<(control.channel[p_track].retrig_volslide-1)); - break; - case 6: - control.channel[p_track].aux_volume=(2*control.channel[p_track].aux_volume)/3; - break; - case 7: - control.channel[p_track].aux_volume>>=1; - break; - case 9: - case 0xa: - case 0xb: - case 0xc: - case 0xd: - control.channel[p_track].aux_volume+=(1<<(control.channel[p_track].retrig_volslide-9)); - break; - case 0xe: - control.channel[p_track].aux_volume=(3*control.channel[p_track].aux_volume)>>1; - break; - case 0xf: - control.channel[p_track].aux_volume=control.channel[p_track].aux_volume<<1; - break; - } - if (control.channel[p_track].aux_volume<0) control.channel[p_track].aux_volume=0; - else if (control.channel[p_track].aux_volume>64) control.channel[p_track].aux_volume=64; - } - } - control.channel[p_track].retrig_counter--; /* countdown */ - } -} - -void CPPlayer::do_global_volume_slide(int p_track) { - - uint8_t lo,hi,inf; - - inf=control.channel[p_track].current_parameter; - - if (inf) control.channel[p_track].global_volume_slide_info=inf; - inf=control.channel[p_track].global_volume_slide_info; - - lo=inf&0xf; - hi=inf>>4; - - if (!lo) { - if (control.ticks_counter) control.global_volume+=hi; - } else - if (!hi) { - if (control.ticks_counter) control.global_volume-=lo; - } else - if (lo==0xf) { - if (!control.ticks_counter) control.global_volume+=hi; - } else - if (hi==0xf) { - if (!control.ticks_counter) control.global_volume-=lo; - } - - if (control.global_volume<0) control.global_volume=0; - if (control.global_volume>128) control.global_volume=128; -} - -void CPPlayer::do_panbrello(int p_track) { - - uint8_t q; - int32_t temp=0; - - q=control.channel[p_track].panbrello_position; - - switch (control.channel[p_track].panbrello_type) { - case 0: {/* sine */ - temp=panbrello_table[q]; - } break; - case 1: {/* square wave */ - temp=(q<0x80)?64:0; - } break; - case 2: {/* ramp down */ - q<<=3; - temp=q; - } break; - case 3: {/* random */ - if (control.channel[p_track].panbrello_position>=control.channel[p_track].panbrello_speed) { - control.channel[p_track].panbrello_position=0; - temp=cp_random_generate(&control.random_seed)%256;//getrandom(256); - } - } break; - } - - - - temp=temp*(int)control.channel[p_track].panbrello_depth/0xF; - temp<<=1; - if (control.channel[p_track].channel_panning!=PAN_SURROUND) - temp+=control.channel[p_track].channel_panning; - - control.channel[p_track].panning=(temp<PAN_LEFT)?PAN_LEFT:(temp>PAN_RIGHT?PAN_RIGHT:temp); - control.channel[p_track].panbrello_position+=control.channel[p_track].panbrello_speed; -} - -/****************** - S effect -*******************/ - - -void CPPlayer::do_effect_S(int p_track) { - - uint8_t inf,c,dat; - - dat=control.channel[p_track].current_parameter; - - inf=dat&0xf; - c=dat>>4; - - if (!dat) { - c=control.channel[p_track].current_S_effect; - inf=control.channel[p_track].current_S_data; - } else { - control.channel[p_track].current_S_effect=c; - control.channel[p_track].current_S_data=inf; - } - - switch (c) { - case 1: {/* S1x set glissando voice */ - // this is unsupported in IT! - - control.channel[p_track].chorus_send=inf*0xFF/0xF; - - }break; - case 2: /* S2x set finetune */ - //Also not supported! - break; - case 3: /* S3x set vibrato waveform */ - if (inf<4) control.channel[p_track].vibrato_type=inf; - break; - case 4: /* S4x set tremolo waveform */ - if (inf<4) control.channel[p_track].tremolo_type=inf; - break; - case 5: /* S5x panbrello */ - if (inf<4) control.channel[p_track].panbrello_type=inf; - break; - case 6: {/* S6x delay x number of frames (patdly) */ - - if (control.ticks_counter) break; - if (!control.pattern_delay_2) control.pattern_delay_1=inf+1; /* only once, when vbtick=0 */ - - } break; - case 7: /* S7x instrument / NNA commands */ - - if (!song->has_instruments()) - break; - switch(inf) { - - case 0x3: { - - control.channel[p_track].NNA_type=CPInstrument::NNA_NOTE_CUT; - } break; - case 0x4: { - - control.channel[p_track].NNA_type=CPInstrument::NNA_NOTE_CONTINUE; - } break; - case 0x5: { - - control.channel[p_track].NNA_type=CPInstrument::NNA_NOTE_OFF; - } break; - case 0x6: { - - control.channel[p_track].NNA_type=CPInstrument::NNA_NOTE_FADE; - } break; - case 0x7: { - - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->volume_envelope_ctrl.active=false; - } break; - case 0x8: { - - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->volume_envelope_ctrl.active=true; - - } break; - case 0x9: { - - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->panning_envelope_ctrl.active=false; - - } break; - case 0xA: { - - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->panning_envelope_ctrl.active=true; - - } break; - case 0xB: { - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->pitch_envelope_ctrl.active=false; - - } break; - case 0xC: { - - if (control.channel[p_track].slave_voice) - control.channel[p_track].slave_voice->pitch_envelope_ctrl.active=true; - - } break; - - } break; - - break; - case 8: {/* S8x set panning position */ - - //if (pf->panflag) { - if (inf<=8) inf<<=4; - else inf*=17; - control.channel[p_track].panning=control.channel[p_track].channel_panning=inf; -// } - } break; - - case 9: { /* S9x set surround sound */ - //if (pf->panflag) - control.channel[p_track].panning=control.channel[p_track].channel_panning=PAN_SURROUND; - } break; - case 0xA:{ /* SAy set high order sample offset yxx00h */ - - if (control.channel[p_track].current_parameter) control.channel[p_track].hi_offset=(int32_t)inf<<16; - control.channel[p_track].sample_start_index=control.channel[p_track].hi_offset|control.channel[p_track].lo_offset; - } break; - case 0xB: { /* SBx pattern loop */ - if (control.ticks_counter) break; - - if (inf) { /* set reppos or repcnt ? */ - /* set repcnt, so check if repcnt already is set, which means we - are already looping */ - if (control.channel[p_track].pattern_loop_count>0) - control.channel[p_track].pattern_loop_count--; /* already looping, decrease counter */ - else { - control.channel[p_track].pattern_loop_count=inf; /* not yet looping, so set repcnt */ - } - - if (control.channel[p_track].pattern_loop_count>0) { /* jump to reppos if repcnt>0 */ - - control.position=control.previous_position; // This will also anulate any Cxx or break.. - - control.position.current_row=control.channel[p_track].pattern_loop_position; - control.position.forbid_jump=true; - } - - } else { - - - control.channel[p_track].pattern_loop_position=control.position.current_row-1; - } - - } break; - case 0xC: { /* SCx notecut */ - - if (control.ticks_counter>=inf) { - - control.channel[p_track].aux_volume=0; - control.channel[p_track].note_end_flags|=END_NOTE_OFF; - control.channel[p_track].note_end_flags|=END_NOTE_KILL; - } - } break; - case 0xD: {/* SDx notedelay */ - - if (!control.ticks_counter) { - - control.channel[p_track].note_delay=inf; - - } else if (control.channel[p_track].note_delay) { - - control.channel[p_track].note_delay--; - } - - } break; - case 0xF: {/* SEx patterndelay */ - - if (control.ticks_counter) break; - if (!control.pattern_delay_2) control.pattern_delay_1=inf+1; /* only once, when vbtick=0 */ - - } break; - } -} - - - - - - - - -/********************* - volume effects -**********************/ - -void CPPlayer::run_volume_column_effects(int p_track) { - - uint8_t param=control.channel[p_track].current_volume_parameter; - - - switch ('A'+control.channel[p_track].current_volume_command) { - - case 'A': { - - if (param>0) control.channel[p_track].volcol_volume_slide=param; - else param=control.channel[p_track].volcol_volume_slide; - - do_volume_slide(p_track,param*0x10+0xF); - - } break; - case 'B': { - - if (param>0) control.channel[p_track].volcol_volume_slide=param; - else param=control.channel[p_track].volcol_volume_slide; - - do_volume_slide(p_track,0xF0+param); - - } break; - case 'C': { - - if (param>0) control.channel[p_track].volcol_volume_slide=param; - else param=control.channel[p_track].volcol_volume_slide; - - do_volume_slide(p_track,param*0x10); - } break; - case 'D': { - - if (param>0) control.channel[p_track].volcol_volume_slide=param; - else param=control.channel[p_track].volcol_volume_slide; - do_volume_slide(p_track,param); - - } break; - case 'E': { - - do_pitch_slide_down(p_track,param<<2); - } break; - case 'F': { - - do_pitch_slide_up(p_track,param<<2); - } break; - case 'G': { - - const uint8_t slide_table[]={0,1,4,8,16,32,64,96,128,255}; - if (param) { - - control.channel[p_track].portamento_speed=slide_table[param]; - } - - if (control.channel[p_track].period && (control.channel[p_track].old_note<=120)) { - - if ( (!control.ticks_counter) && (control.channel[p_track].new_instrument) ){ - - //control.channel[p_track].kick=KICK_NOTE; - //control.channel[p_track].sample_start_index=0; // < am i stupid? - } else { - - control.channel[p_track].kick=(control.channel[p_track].kick==KICK_NOTE)?KICK_ENVELOPE:KICK_NOTHING; - do_pitch_slide_to_note(p_track); - control.channel[p_track].has_own_period=true; - } - - } - } break; - case 'H': { - - - if (!control.ticks_counter) { - if (param&0x0f) control.channel[p_track].vibrato_depth=param; - } - control.channel[p_track].doing_vibrato=true; - if (control.external_vibrato) break; - if (control.channel[p_track].period) { - - do_vibrato(p_track,false); - control.channel[p_track].has_own_period=true; - } - - } break; - } -} -/********************* - table -**********************/ - - -void CPPlayer::run_effects(int p_track) { - - switch ('A'+control.channel[p_track].current_command) { - - case 'A': { - - if ((control.ticks_counter>0) || (control.pattern_delay_2>0)) break; - - int new_speed; - - new_speed=control.channel[p_track].current_parameter % 128; - - if (new_speed>0) { - control.speed=new_speed; - control.ticks_counter=0; - } - } break; - case 'B': { - - int next_order; - - if (control.ticks_counter || control.position.forbid_jump) break; - - control.position.current_row=0; - - if (control.play_mode==PLAY_PATTERN) break; - - next_order=get_song_next_order_idx(song, (int)control.channel[p_track].current_parameter-1); - - if (next_order!=-1) { - // Do we have a "next order?" - control.position.current_pattern=song->get_order(next_order); - control.position.force_next_order=next_order; - - } else { - // no, probably the user deleted the orderlist. - control.play_mode=PLAY_NOTHING; - reset(); - } - } break; - case 'C': { - - int next_order; - - if (control.ticks_counter || control.position.forbid_jump) break; - - control.position.current_row=control.channel[p_track].current_parameter; - - if (control.play_mode==PLAY_PATTERN) { - - if (control.position.current_row>=song->get_pattern(control.position.current_pattern)->get_length()) { - - control.position.current_row=0; - } - - break; - } - - next_order=get_song_next_order_idx(song, (int)control.position.current_order); - - if (next_order!=-1) { - // Do we have a "next order?" - control.position.current_pattern=song->get_order(next_order); - - if (control.position.current_row>=song->get_pattern(song->get_order(next_order))->get_length()) { - - control.position.current_row=0; - } - - control.position.force_next_order=next_order; - - } else { - // no, probably the user deleted the orderlist. - control.play_mode=PLAY_NOTHING; - reset(); - } - - } break; - case 'D': { - - uint8_t inf ; - //explicitslides=1; - inf=control.channel[p_track].current_parameter; - - if (inf) control.channel[p_track].volume_slide_info=inf; - else inf=control.channel[p_track].volume_slide_info; - - do_volume_slide(p_track,inf); - - } break; - case 'E': { - - uint8_t inf; - - inf=control.channel[p_track].current_parameter; - do_pitch_slide_down(p_track,inf); - - } break; - case 'F': { - - uint8_t inf; - - inf=control.channel[p_track].current_parameter; - do_pitch_slide_up(p_track,inf); - - } break; - case 'G': { - - if (control.channel[p_track].current_parameter) { - - control.channel[p_track].portamento_speed=control.channel[p_track].current_parameter; - } - - if (control.channel[p_track].period && (control.channel[p_track].old_note<=120)) { - - if ( (!control.ticks_counter) && (control.channel[p_track].new_instrument) ){ - - - control.channel[p_track].kick=KICK_NOTE; - control.channel[p_track].sample_start_index=0; - - } else { - - control.channel[p_track].kick=(control.channel[p_track].kick==KICK_NOTE)?KICK_ENVELOPE:KICK_NOTHING; - } - - do_pitch_slide_to_note(p_track); - control.channel[p_track].has_own_period=true; - } - - } break; - case 'H': { - - uint8_t dat; - - control.channel[p_track].doing_vibrato=true; - - dat=control.channel[p_track].current_parameter; - - if (!control.ticks_counter) { - if (dat&0x0f) control.channel[p_track].vibrato_depth=dat&0xf; - if (dat&0xf0) control.channel[p_track].vibrato_speed=(dat&0xf0)>>2; - } - - if (control.external_vibrato) break; - - if (control.channel[p_track].period) { - - do_vibrato(p_track,false); - control.channel[p_track].has_own_period=true; - } - - } break; - case 'I': { - - do_tremor(p_track); - control.channel[p_track].has_own_volume=true; - } break; - case 'J': { - - do_arpegio(p_track); - } break; - case 'K': { - - uint8_t inf ; - //explicitslides=1; - inf=control.channel[p_track].current_parameter; - - control.channel[p_track].doing_vibrato=true; - - - if (inf) control.channel[p_track].volume_slide_info=inf; - else inf=control.channel[p_track].volume_slide_info; - - do_volume_slide(p_track,inf); - - if (control.external_vibrato) break; - - if (control.channel[p_track].period) { - - do_vibrato(p_track,false); - control.channel[p_track].has_own_period=true; - } - - } break; - case 'L': { - uint8_t inf ; - //explicitslides=1; - inf=control.channel[p_track].current_parameter; - - if (inf) control.channel[p_track].volume_slide_info=inf; - else inf=control.channel[p_track].volume_slide_info; - - do_volume_slide(p_track,inf); - - if (control.channel[p_track].period && (control.channel[p_track].old_note<=120)) { - if ( (!control.ticks_counter) && (control.channel[p_track].new_instrument) ){ - - control.channel[p_track].kick=KICK_NOTE; - control.channel[p_track].sample_start_index=0; - - } else { - - control.channel[p_track].kick=(control.channel[p_track].kick==KICK_NOTE)?KICK_ENVELOPE:KICK_NOTHING; - } - - do_pitch_slide_to_note(p_track); - control.channel[p_track].has_own_period=true; - } - } break; - case 'M': { - control.channel[p_track].channel_volume=control.channel[p_track].current_parameter; - if (control.channel[p_track].channel_volume>64) control.channel[p_track].channel_volume=64; - else if (control.channel[p_track].channel_volume<0) control.channel[p_track].channel_volume=0; - } break; - case 'N': { - - do_channel_volume_slide(p_track); - } - case 'O': { - - if (!control.ticks_counter) { - - if (control.channel[p_track].current_parameter) control.channel[p_track].lo_offset=(uint16_t)control.channel[p_track].current_parameter<<8; - control.channel[p_track].sample_start_index=control.channel[p_track].hi_offset|control.channel[p_track].lo_offset; - - //if ((control.channel[p_track].sample_ptr!=NULL)&&(control.channel[p_track].sample_start_index>control.channel[p_track].sample_ptr->data.size)) { - //TODO, O effect - //a->start=a->s->flags&(SF_LOOP|SF_BIDI)?a->s->loopstart:a->s->length; - //} - } - } break; - case 'P': { - - do_pan_slide(p_track); - } break; - case 'Q': { - do_retrig(p_track); - - } break; - case 'R': { - - - uint8_t dat; - - if (control.channel[p_track].current_parameter) { - - control.channel[p_track].tremolo_info=control.channel[p_track].current_parameter; - } - - dat=control.channel[p_track].tremolo_info; - - if (!control.ticks_counter && dat) { - - if (dat&0x0f) control.channel[p_track].tremolo_depth=dat&0xf; - if (dat&0xf0) control.channel[p_track].tremolo_speed=(dat&0xf0)>>2; - } - - do_tremolo(p_track); - control.channel[p_track].has_own_volume=true; - - } break; - case 'S': { - - do_effect_S(p_track); - } break; - case 'T': { - uint8_t dat; - int16_t temp=control.tempo; - - if (control.pattern_delay_2) return; - - if (control.channel[p_track].current_parameter) { - - control.channel[p_track].tempo_slide_info=control.channel[p_track].current_parameter; - } - - dat=control.channel[p_track].tempo_slide_info; - - if (dat>=0x20) { - - if (control.ticks_counter) break; - control.tempo=dat; - } else { - - if (!control.ticks_counter) break; - - if (dat&0x10) { - - temp+=(dat&0x0f); - } else { - - temp-=dat; - } - control.tempo=(temp>255)?255:(temp<0x20?0x20:temp); - } - - } break; - case 'U': { - - uint8_t dat; - - dat=control.channel[p_track].current_parameter; - control.channel[p_track].doing_vibrato=true; - if (!control.ticks_counter) { - if (dat&0x0f) control.channel[p_track].vibrato_depth=dat&0xf; - if (dat&0xf0) control.channel[p_track].vibrato_speed=(dat&0xf0)>>2; - } - - if (control.external_vibrato) break; - - if (control.channel[p_track].period) { - - do_vibrato(p_track,true); - control.channel[p_track].has_own_period=true; - } - } break; - case 'V': { - - control.global_volume=control.channel[p_track].current_parameter; - if (control.global_volume>128) control.global_volume=128; - } break; - case 'W': { - do_global_volume_slide(p_track); - } break; - case 'X': { - //sets both channel and current - control.channel[p_track].channel_panning=control.channel[p_track].current_parameter; - control.channel[p_track].panning=control.channel[p_track].current_parameter; - } break; - case 'Y': { - - uint8_t dat; - - if (control.channel[p_track].current_parameter) { - - control.channel[p_track].panbrello_info=control.channel[p_track].current_parameter; - } - - dat=control.channel[p_track].panbrello_info; - - if (!control.ticks_counter) { - - if (dat&0x0f) control.channel[p_track].panbrello_depth=(dat&0xf); - if (dat&0xf0) control.channel[p_track].panbrello_speed=(dat&0xf0)>>4; - } - - //if (pf->panflag) - if (control.channel[p_track].panning!=PAN_SURROUND)do_panbrello(p_track); - - } break; - case 'Z': { - //I DO! cuttoff! - uint16_t dat=control.channel[p_track].current_parameter; - - if (dat<0x80) { - - control.channel[p_track].filter.it_cutoff=dat*2; - if (control.channel[p_track].filter.it_cutoff>0x80) - control.channel[p_track].filter.it_cutoff++; - } else if (dat<0x90) { - - control.channel[p_track].filter.it_reso=(dat-0x80)*0x10; - } else { - - control.channel[p_track].reverb_send=(dat-0x90)*255/0x6F; - } - - } break; - - } - -} - -void CPPlayer::pre_process_effects() { - -// MP_VOICE *aout; - int i; - - for (i=0;i<CPPattern::WIDTH;i++) { - - //a=&pf->control[mp_channel]; - - // if ((aout=a->slave)) { - // a->fadevol=aout->fadevol; - // a->period=aout->period; - // if (a->kick==KICK_KEYOFF) a->keyoff=aout->keyoff; - //} - - //if (!a->row) continue; - //UniSetRow(a->row); - control.channel[i].has_own_period=false; - control.channel[i].has_own_volume=false; - control.channel[i].doing_vibrato=false; - //explicitslides=0; - //pt_playeffects(); - if (control.ticks_counter<control.speed) { - - run_effects(i); - run_volume_column_effects(i); - } - - /* continue volume slide if necessary for XM and IT */ - //if (pf->flags&UF_BGSLIDES) { - // if (!explicitslides && a->sliding) - // DoS3MVolSlide(0); - // else if (a->tmpvolume) a->sliding=explicitslides; - //} - - if (!control.channel[i].has_own_period) control.channel[i].period=control.channel[i].aux_period; - if (!control.channel[i].has_own_volume) control.channel[i].volume=control.channel[i].aux_volume; - - if ((control.channel[i].sample_ptr!=NULL) && !(song->has_instruments() && (control.channel[i].instrument_ptr==NULL))) { - - if (song->has_instruments()) { - - control.channel[i].output_volume= - (control.channel[i].volume*control.channel[i].sample_ptr->get_global_volume()*control.channel[i].instrument_ptr->get_volume_global_amount())/2048; - control.channel[i].output_volume=control.channel[i].output_volume*control.channel[i].random_volume_variation/100; - - } else { - - control.channel[i].output_volume= - (control.channel[i].volume*control.channel[i].sample_ptr->get_global_volume())>>4; - - } - - if (control.channel[i].output_volume>256) { - - control.channel[i].output_volume=256; - - } else if (control.channel[i].output_volume<0) { - - control.channel[i].output_volume=0; - } - - - } - } - -} diff --git a/modules/chibi/cp_player_data_envelopes.cpp b/modules/chibi/cp_player_data_envelopes.cpp deleted file mode 100644 index a720eaf734..0000000000 --- a/modules/chibi/cp_player_data_envelopes.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_envelopes.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" - - -void CPPlayer::Voice_Control::start_envelope(CPEnvelope *p_envelope,Envelope_Control *p_envelope_ctrl,Envelope_Control *p_from_env) { - - - if (p_from_env && p_envelope->is_carry_enabled() && !p_from_env->terminated) { - - - *p_envelope_ctrl=*p_from_env; - } else { - p_envelope_ctrl->pos_index=0; - p_envelope_ctrl->status=1; - p_envelope_ctrl->sustain_looping=p_envelope->is_sustain_loop_enabled(); - p_envelope_ctrl->looping=p_envelope->is_loop_enabled(); - p_envelope_ctrl->terminated=false; - p_envelope_ctrl->kill=false; - p_envelope_ctrl->value=p_envelope->get_height_at_pos(p_envelope_ctrl->pos_index); - } -} - -bool CPPlayer::Voice_Control::process_envelope(CPEnvelope *p_envelope,Envelope_Control *p_envelope_ctrl) { - - if (!p_envelope_ctrl->active) - return false; - - if (note_end_flags&END_NOTE_OFF) p_envelope_ctrl->sustain_looping=false; - - p_envelope_ctrl->value=p_envelope->get_height_at_pos(p_envelope_ctrl->pos_index); - if (p_envelope_ctrl->value==CPEnvelope::NO_POINT) - return false; - - - p_envelope_ctrl->pos_index++; - - if (p_envelope_ctrl->sustain_looping) { - - if (p_envelope_ctrl->pos_index>p_envelope->get_node(p_envelope->get_sustain_loop_end()).tick_offset) { - - p_envelope_ctrl->pos_index=p_envelope->get_node(p_envelope->get_sustain_loop_begin()).tick_offset; - } - - } else if (p_envelope_ctrl->looping) { - - if (p_envelope_ctrl->pos_index>p_envelope->get_node(p_envelope->get_loop_end()).tick_offset) { - - p_envelope_ctrl->pos_index=p_envelope->get_node(p_envelope->get_loop_begin()).tick_offset; - } - - } - - if (p_envelope_ctrl->pos_index>p_envelope->get_node(p_envelope->get_node_count()-1).tick_offset) { - - p_envelope_ctrl->terminated=true; - p_envelope_ctrl->pos_index=p_envelope->get_node(p_envelope->get_node_count()-1).tick_offset; - if (p_envelope->get_node(p_envelope->get_node_count()-1).value==0) p_envelope_ctrl->kill=true; - } - - return true; -} diff --git a/modules/chibi/cp_player_data_events.cpp b/modules/chibi/cp_player_data_events.cpp deleted file mode 100644 index 94a048ab2f..0000000000 --- a/modules/chibi/cp_player_data_events.cpp +++ /dev/null @@ -1,681 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_events.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" -#include "cp_sample_manager.h" -#include "stdio.h" -/* - setup_voices(): - -This will go throught all the REAL channels, if it finds a channel -that needs to be restarted or assigned a new VIRTUAL channel, then it -will just find one and do it. - -*/ - - -#define C5FREQ 261.6255653006 -static const int32_t C5FREQ_MIXER = ((int32_t)(C5FREQ*(float)(1<<CPMixer::FREQUENCY_BITS))); - - -void CPPlayer::setup_voices() { - - int i,voice_index; - - - - - for (i=0;i<CPPattern::WIDTH;i++) { - - voice_index=-1; - - if (control.channel[i].note_delay) continue; - - - // check if we need a new empty voice - if (control.channel[i].kick==KICK_NOTE) { - - /* if no channel was cut above, find an empty or quiet channel - here */ - if ( song->has_instruments() && !control.force_no_nna) { - - if (control.channel[i].slave_voice==NULL) { // no slave?? - - int newchn; - if ((newchn=find_empty_voice())!=-1) { - - control.channel[i].slave_voice_index=newchn; - control.channel[i].slave_voice=&voice[newchn]; - } - } - - } else { - if (i<control.max_voices) { - - control.channel[i].slave_voice_index=i; - control.channel[i].slave_voice=&voice[i]; - } else { - //This is a _DIRTY_ hack, but i cant think a better way. - control.channel[i].slave_voice_index=control.max_voices-1; - control.channel[i].slave_voice=&voice[control.max_voices-1]; - } - - } - - - /* assign parts of MP_VOICE only done for a KICK_NOTE */ - if ( ( control.channel[i].slave_voice!=NULL ) ) { - - voice_index=control.channel[i].slave_voice_index; - Voice_Control &v=voice[voice_index]; - - if (v.has_master_channel && (v.master_channel!=NULL) ) { - // If this voice already has a master channel, make sure to remove the reference to it. - v.master_channel->slave_voice=NULL; - - } - //notify the voice that the current channel is the master - v.master_channel=&control.channel[i]; - //set the voice as slave of the current channel - control.channel[i].slave_voice=&v; - //master channel index of the voice - v.master_channel_index=i; - v.has_master_channel=true; - } - - } else { - // nope.. - // so if we DO have a slave voice then use it. - if ( control.channel[i].slave_voice!=NULL ) { - - voice_index=control.channel[i].slave_voice_index; - } - } - //assuming this channel has a slave voice.. - if (voice_index>=0) { - - // IMPROVE: Code a method for this: - voice[voice_index].update_info_from_master_channel(); - } - - control.channel[i].kick=KICK_NOTHING; - } -} -void CPPlayer::Voice_Control::reset() { - - cp_memzero(this,sizeof(*this)); - - instrument_ptr=NULL; - sample_ptr=NULL; - has_master_channel=false; - instrument_index=-1; - reverb_send=0; - chorus_send=0; - filter.it_cutoff=255; - filter.it_reso=0; - display_volume=0; - - -} - -void CPPlayer::Channel_Control::reset() { - - int prev_gv =channel_global_volume; - cp_memzero(this,sizeof(*this)); - - slave_voice=NULL; - slave_voice_index=255; - - mute=false; - old_note=255; - real_note=255; - instrument_index=255; - filter.it_cutoff=255; - filter.it_reso=0; - reverb_send=0; - chorus_send=0; - reserved=false; - carry.maybe=false; - last_event_usecs=-1; - channel_global_volume=prev_gv; -} - -void CPPlayer::Voice_Control::update_info_from_master_channel() { - - instrument_ptr=master_channel->instrument_ptr; - sample_ptr=master_channel->sample_ptr; - - instrument_index=master_channel->instrument_index; - sample_index=master_channel->sample_index; - - note=master_channel->note; - output_volume=master_channel->output_volume; - - channel_volume=master_channel->channel_volume; - - panning=master_channel->panning; - - kick=master_channel->kick; - note_end_flags=master_channel->note_end_flags; - period=master_channel->period; - - volume_envelope_ctrl.active=master_channel->volume_envelope_on; - panning_envelope_ctrl.active=master_channel->panning_envelope_on; - pitch_envelope_ctrl.active=master_channel->pitch_envelope_on; - - - NNA_type=master_channel->NNA_type; - reverb_send=master_channel->reverb_send; - chorus_send=master_channel->chorus_send; - - //last_note_type=master_channel->last_note_type; - - sample_start_index=master_channel->sample_start_index; - filter=master_channel->filter; - -} - - -void CPPlayer::update_mixer() { - - int tmp_mixer_period; - int32_t tmp_vibrato_value,tmp_vibrato_depth,tmp_volenv_value; - uint64_t tmpvol; // 64bits should be the only way to avoid getting notes raped out - int i; - - - control.voices_used=0; - - for (i=0;i<control.max_voices;i++) { - - - int filter_env=-1; - Voice_Control &v=voice[i]; - - if ( !((v.kick==KICK_NOTE)||(v.kick==KICK_NOTEOFF)) && !is_voice_active(i)) - continue; - - //if voice doesnt have a sample set or size is 0.. forget it - if ( v.sample_ptr==NULL) continue; - - - //TODO set limits somewhere else - - if (v.period<40) { - - v.period=40; - - } else if (v.period>50000) { - - v.period=50000; - } - - - if ((v.kick==KICK_NOTE)||(v.kick==KICK_NOTEOFF)) { - - int real_start_index; - - if (v.sample_start_index==-1) { - - real_start_index=0; - - } else { - - real_start_index=v.sample_start_index; - } - - mixer->setup_voice(i,v.sample_ptr->get_sample_data(),real_start_index); - v.fadeout_volume=1024; //IT Docs it is 1024 internally - v.auto_vibrato_sweep_pos=0; - - - - } - - - /* Start Envelopes */ - if ( song->has_instruments() && ((v.kick==KICK_NOTE)||(v.kick==KICK_ENVELOPE))) { - - //Voice_Control *carry=0; - - - if (v.has_master_channel && v.master_channel->carry.maybe) { - - v.start_envelope(v.instrument_ptr->get_volume_envelope(),&v.volume_envelope_ctrl,&v.master_channel->carry.vol); - v.start_envelope(v.instrument_ptr->get_pan_envelope(),&v.panning_envelope_ctrl,&v.master_channel->carry.pan); - v.start_envelope(v.instrument_ptr->get_pitch_filter_envelope(),&v.pitch_envelope_ctrl,&v.master_channel->carry.pitch); - - } else { - - v.start_envelope(v.instrument_ptr->get_volume_envelope(),&v.volume_envelope_ctrl,NULL); - v.start_envelope(v.instrument_ptr->get_pan_envelope(),&v.panning_envelope_ctrl,NULL); - v.start_envelope(v.instrument_ptr->get_pitch_filter_envelope(),&v.pitch_envelope_ctrl,NULL); - - } - - - } - - v.kick=KICK_NOTHING; - - if (song->has_instruments()) { - - if (!v.process_envelope(v.instrument_ptr->get_volume_envelope(),&v.volume_envelope_ctrl)) - v.volume_envelope_ctrl.value=64; - - if (!v.process_envelope(v.instrument_ptr->get_pan_envelope(),&v.panning_envelope_ctrl)) - v.panning_envelope_ctrl.value=0; - - if (!v.process_envelope(v.instrument_ptr->get_pitch_filter_envelope(),&v.pitch_envelope_ctrl)) - v.pitch_envelope_ctrl.value=0; - - - if (v.volume_envelope_ctrl.terminated) { - - if (v.volume_envelope_ctrl.kill) { - - v.fadeout_volume=0; - } else { - - v.note_end_flags|=END_NOTE_FADE; - } - } - - } - - if (song->has_instruments()) { - - tmp_volenv_value=v.volume_envelope_ctrl.value; - } else { - - tmp_volenv_value=64; - - } - - /*printf("fadeout %i\n",(int)v.fadeout_volume); - printf("channel %i\n",(int)v.channel_volume); - printf("output %i\n",(int)v.output_volume); - printf("env %i\n",(int)tmp_volenv_value); - printf("cgb %i\n",(int)v.master_channel->channel_global_volume); -*/ - - - tmpvol=(uint64_t)v.fadeout_volume; /* max 1024 - 10 bits */ - tmpvol*=(uint64_t)v.channel_volume; /* * max 64 - 6 bits */ - tmpvol*=(uint64_t)v.output_volume; /* * max 256 - 8 bits */ - tmpvol*=(uint64_t)tmp_volenv_value; /* max 64 - 6 bits*/ - tmpvol*=(uint64_t)v.master_channel->channel_global_volume; - v.display_volume=tmpvol>>22; //volume used for display purposes , 0 -- 256 - - tmpvol*=(uint64_t)song->get_mixing_volume(); /* max 128 - 7 bits */ - tmpvol*=(uint64_t)control.global_volume; /* max 128 - 7 bits*/ - /* total 10+6+8+6+7+7=44 bits */ - - tmpvol>>=43; /* Move back to 8 bits range , 44-19+8=43*/ - - if (tmpvol>CP_VOL_MAX) - tmpvol=CP_VOL_MAX; - - //printf("volume check - fade %i, channel %i, output %i, env %i, mix %i, global %i -- final %i\n",v.fadeout_volume, v.channel_volume,v.output_volume,tmp_volenv_value, song->get_mixing_volume(),control.global_volume,tmpvol); - - v.total_volume=tmpvol; - - - if ((v.master_channel!=NULL) && song->is_channel_mute( v.master_channel_index ) && !v.master_channel->reserved) { - - mixer->set_voice_volume(i,0); - } else { - mixer->set_voice_volume(i,tmpvol); - if (v.fadeout_volume>0) control.voices_used++; - } - - - if (!song->is_stereo()) { - - mixer->set_voice_panning(i,PAN_CENTER); - - } else if (v.panning==PAN_SURROUND) { - - mixer->set_voice_panning(i,PAN_SURROUND); - } else if (song->has_instruments()) { - - int newpan,real_modifier; - - - real_modifier=(v.panning_envelope_ctrl.value*(PAN_CENTER-cp_intabs(v.panning-PAN_CENTER)))/32; - - newpan=v.panning+real_modifier; - - newpan=(newpan<PAN_LEFT)?PAN_LEFT:(newpan>PAN_RIGHT)?PAN_RIGHT:newpan; - //printf("panenv val: %i, finalpan val %i\n",v.panning_envelope_ctrl.value,newpan); - - mixer->set_voice_panning(i,newpan); - } else { - mixer->set_voice_panning(i,v.panning); - } - - - - /* VIBRATO */ - - if ( (v.period>0) && (v.sample_ptr->get_vibrato_depth()>0) ) { - - switch (v.sample_ptr->get_vibrato_type()) { - case CPSample::VIBRATO_SINE: - tmp_vibrato_value=auto_vibrato_table[v.auto_vibrato_pos&127]; - if (v.auto_vibrato_pos & 0x80) tmp_vibrato_value=-tmp_vibrato_value; - break; - case CPSample::VIBRATO_SQUARE: - tmp_vibrato_value=64; - if (v.auto_vibrato_pos & 0x80) tmp_vibrato_value=-tmp_vibrato_value; - break; - case CPSample::VIBRATO_SAW: - tmp_vibrato_value=63-(((v.auto_vibrato_pos+128)&255)>>1); - break; - default: - tmp_vibrato_value=(((v.auto_vibrato_pos+128)&255)>>1)-64; - break; - } - } else { - - tmp_vibrato_value=0; - } - - if ((v.auto_vibrato_sweep_pos>>8)<v.sample_ptr->get_vibrato_depth()) { - - v.auto_vibrato_sweep_pos+=v.sample_ptr->get_vibrato_speed(); //FIXME - speed? i think so - tmp_vibrato_depth=v.auto_vibrato_sweep_pos; - - } else { - - tmp_vibrato_depth=v.sample_ptr->get_vibrato_depth()<<8; - } - - tmp_vibrato_value=(tmp_vibrato_value*tmp_vibrato_depth)>>16; - if (song->has_linear_slides()) - tmp_vibrato_value>>=1; - v.period-=tmp_vibrato_value; - - - /* update vibrato position */ - v.auto_vibrato_pos=(v.auto_vibrato_pos+v.sample_ptr->get_vibrato_rate())&0xff; - - - /* process pitch envelope */ - tmp_mixer_period=v.period; - - if (v.pitch_envelope_ctrl.active) { - - long aux_pitch_diff; - int pe_value=v.pitch_envelope_ctrl.value; - - if (!v.instrument_ptr->is_pitch_use_as_filter()) { - - - if (((uint16_t)v.note<<1)+pe_value<=0) - pe_value=-(v.note<<1); - - int smp_c5=CPSampleManager::get_singleton()->get_c5_freq( v.sample_ptr->get_sample_data()); - - int base=get_period(((uint16_t)v.note<<1),smp_c5); - int env=get_period(((uint16_t)v.note<<1)+pe_value,smp_c5); - /* - int env_next=(pe_value<0)?get_period(((uint16_t)(v.note-1)<<1)+pe_value,smp_c5):get_period(((uint16_t)(v.note+1)<<1)+pe_value,smp_c5); - - env=env+(abs(v.pitch_envelope_ctrl.value)&((1<<CPEnvelope::FX_HEIGHT_BITS)-1))*(env_next-env)/(1<<CPEnvelope::FX_HEIGHT_BITS); - - printf("env %i\n",env); - */ - aux_pitch_diff=env-base; - - - if ( ((int)tmp_mixer_period-aux_pitch_diff)<0 ) aux_pitch_diff=0; - - tmp_mixer_period+=aux_pitch_diff; - - } else { - - filter_env=pe_value+32; //max 64 - //printf("pitch envelope at %i",filter_env); - - } - } - - if (v.fadeout_volume==0 || (v.note_end_flags & END_NOTE_KILL)) { /* check for a dead note (fadevol=0) */ - - mixer->stop_voice(i); - - } else { - - - int32_t freq=get_frequency(tmp_mixer_period); - int32_t tracker_c5=get_frequency(get_period(60<<1,CPSampleManager::get_singleton()->get_c5_freq( v.sample_ptr->get_sample_data()))); - - freq=(int32_t)((uint64_t)freq*(uint64_t)C5FREQ_MIXER/(uint64_t)tracker_c5); //numbers may become very high - mixer->set_voice_frequency(i,freq); - - /* if keyfade, start substracting fadeoutspeed from fadevol: */ - if ((song->has_instruments())&&(v.note_end_flags & END_NOTE_FADE)) { - - if (v.fadeout_volume>=(v.instrument_ptr->get_volume_fadeout())) { - - v.fadeout_volume-=(v.instrument_ptr->get_volume_fadeout()); - } else { - - v.fadeout_volume=0; - } - } - - /*FILTARSSSSSSSS*/ - - - - v.filter.envelope_cutoff=filter_env; - v.filter.process(); - - if ((v.filter.final_cutoff<0xFF) && (control.filters)) { - - //int final_cutoff; - //uint8_t final_reso; - - //v.filter.set_filter_parameters( &final_cutoff, &final_reso ); - - mixer->set_voice_filter(i,true,v.filter.final_cutoff,v.filter.it_reso); - } else { - - - mixer->set_voice_filter(i,false,0,0); - } - - /* RAIVERV */ - - mixer->set_voice_reverb_send(i,v.reverb_send); - - /* CHAURUZ */ - - mixer->set_voice_chorus_send(i,v.chorus_send); - - } - } - - - switch(song->get_reverb_mode()) { - - case CPSong::REVERB_MODE_ROOM: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_ROOM ); - } break; - case CPSong::REVERB_MODE_STUDIO_SMALL: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_STUDIO_SMALL ); - - } break; - case CPSong::REVERB_MODE_STUDIO_MEDIUM: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_STUDIO_MEDIUM ); - - } break; - case CPSong::REVERB_MODE_STUDIO_LARGE: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_STUDIO_LARGE ); - - } break; - case CPSong::REVERB_MODE_HALL: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_HALL ); - - } break; - case CPSong::REVERB_MODE_SPACE_ECHO: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_SPACE_ECHO ); - - } break; - case CPSong::REVERB_MODE_ECHO: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_ECHO ); - - } break; - case CPSong::REVERB_MODE_DELAY: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_DELAY ); - - } break; - case CPSong::REVERB_MODE_HALF_ECHO: { - - mixer->set_reverb_mode( CPMixer::REVERB_MODE_HALF_ECHO ); - - } break; - - } - - mixer->set_chorus_params(song->get_chorus_delay_ms(),song->get_chorus_separation_ms(),song->get_chorus_depth_ms10(),song->get_chorus_speed_hz10() ); - - -} - - - - - - - - -void CPPlayer::handle_tick() { - - int i; - - - if ( mixer==NULL ) return; - if ( song==NULL ) return; - - - /* update time counter (sngtime is in milliseconds (in fact 2^-10)) */ - - if (control.ticks_counter>=control.speed) { // time to process... ***THE ROW***! - - /* process pattern-delay. pf->patdly2 is the counter and pf->patdly is - the command memory. */ - - /* - if (control.pattern_delay_1) { - - control.pattern_delay_2=control.pattern_delay_1; - control.pattern_delay_1=0; - } - if (control.pattern_delay_2) { - patterndelay active - if (--control.pattern_delay_2) - // so turn back pf->patpos by 1 - if (pf->patpos) pf->patpos--; - } - */ - - if (control.play_mode!=PLAY_NOTHING) { - - control.ticks_counter=0; - - - if (control.position.force_next_order>=0) { - - control.position.current_order=control.position.force_next_order; - } - - control.position.force_next_order=-1; - - control.previous_position=control.position; // for those special cases... - control.position.forbid_jump=false; - - for (i=0;i<CPPattern::WIDTH;i++) { - - process_note(i,song->get_pattern(control.position.current_pattern)->get_note(i,control.position.current_row)); - } - - control.position.current_row++; - - if ( control.position.current_row>=song->get_pattern(control.position.current_pattern)->get_length() ) { - - if (control.play_mode==PLAY_SONG) { - - int next_order; - - next_order=get_song_next_order_idx(song,control.position.current_order); - - if (next_order!=-1) { - // Do we have a "next order?" - control.position.current_pattern=song->get_order(next_order); - if (next_order<=control.position.current_order) - control.reached_end=true; - control.position.current_order=next_order; - - } else { - // no, probably the user deleted the orderlist. - control.play_mode=PLAY_NOTHING; - reset(); - control.reached_end=true; - } - } - control.position.current_row=0; - } - - } - - - } - - - - pre_process_effects(); - process_NNAs(); - setup_voices(); - - /* now set up the actual hardware channel playback information */ - update_mixer(); - - control.ticks_counter++; -} diff --git a/modules/chibi/cp_player_data_filter.cpp b/modules/chibi/cp_player_data_filter.cpp deleted file mode 100644 index e04ae126fd..0000000000 --- a/modules/chibi/cp_player_data_filter.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_filter.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - - -#include "cp_player_data.h" - -static float filter_cutoff[256] = { - 130, 132, 134, 136, 138, 140, 142, 144, - 146, 148, 151, 153, 155, 157, 160, 162, - 164, 167, 169, 172, 174, 177, 179, 182, - 184, 187, 190, 193, 195, 198, 201, 204, - 207, 210, 213, 216, 220, 223, 226, 229, - 233, 236, 239, 243, 246, 250, 254, 257, - 261, 265, 269, 273, 277, 281, 285, 289, - 293, 297, 302, 306, 311, 315, 320, 324, - 329, 334, 339, 344, 349, 354, 359, 364, - 369, 375, 380, 386, 391, 397, 403, 409, - 415, 421, 427, 433, 440, 446, 452, 459, - 466, 472, 479, 486, 493, 501, 508, 515, - 523, 530, 538, 546, 554, 562, 570, 578, - 587, 595, 604, 613, 622, 631, 640, 649, - 659, 668, 678, 688, 698, 708, 718, 729, - 739, 750, 761, 772, 783, 795, 806, 818, - 830, 842, 854, 867, 880, 892, 905, 918, - 932, 945, 959, 973, 987, 1002, 1016, 1031, - 1046, 1061, 1077, 1092, 1108, 1124, 1141, 1157, - 1174, 1191, 1209, 1226, 1244, 1262, 1280, 1299, - 1318, 1337, 1357, 1376, 1396, 1417, 1437, 1458, - 1479, 1501, 1523, 1545, 1567, 1590, 1613, 1637, - 1661, 1685, 1709, 1734, 1760, 1785, 1811, 1837, - 1864, 1891, 1919, 1947, 1975, 2004, 2033, 2062, - 2093, 2123, 2154, 2185, 2217, 2249, 2282, 2315, - 2349, 2383, 2418, 2453, 2489, 2525, 2561, 2599, - 2637, 2675, 2714, 2753, 2793, 2834, 2875, 2917, - 2959, 3003, 3046, 3091, 3135, 3181, 3227, 3274, - 3322, 3370, 3419, 3469, 3520, 3571, 3623, 3675, - 3729, 3783, 3838, 3894, 3951, 4008, 4066, 4125, - 4186, 4246, 4308, 4371, 4434, 4499, 4564, 4631, - 4698, 4766, 4836, 4906, 4978, 5050, 5123, 5198 -}; - - -void CPPlayer::Filter_Control::process() { - - - final_cutoff=it_cutoff; - if (envelope_cutoff>=0) { - - envelope_cutoff=envelope_cutoff*255/64; - final_cutoff=final_cutoff*envelope_cutoff/255; - if (final_cutoff>=0xFF) final_cutoff=0xFE; - - } - -} - -void CPPlayer::Filter_Control::set_filter_parameters(int *p_cutoff,uint8_t *p_reso) { - - - - *p_cutoff=filter_cutoff[final_cutoff]; - *p_reso=it_reso; -} diff --git a/modules/chibi/cp_player_data_nna.cpp b/modules/chibi/cp_player_data_nna.cpp deleted file mode 100644 index 3c50bfb01f..0000000000 --- a/modules/chibi/cp_player_data_nna.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_nna.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" - -void CPPlayer::process_NNAs() { - - int i; - - if (!song->has_instruments()) return; - - for (i=0;i<CPPattern::WIDTH;i++) { - - Channel_Control *aux_chn_ctrl = &control.channel[i]; - - if (aux_chn_ctrl->kick==KICK_NOTE) { - - bool k=false; - - if (aux_chn_ctrl->slave_voice!=NULL) { - - Voice_Control *aux_voc_ctrl; - - aux_voc_ctrl=aux_chn_ctrl->slave_voice; - - if (aux_chn_ctrl->instrument_index==aux_chn_ctrl->slave_voice->instrument_index) { //maybe carry - - aux_chn_ctrl->carry.pan=aux_chn_ctrl->slave_voice->panning_envelope_ctrl; - aux_chn_ctrl->carry.vol=aux_chn_ctrl->slave_voice->volume_envelope_ctrl; - aux_chn_ctrl->carry.pitch=aux_chn_ctrl->slave_voice->pitch_envelope_ctrl; - aux_chn_ctrl->carry.maybe=true; - } else - aux_chn_ctrl->carry.maybe=false; - - if (aux_voc_ctrl->NNA_type != CPInstrument::NNA_NOTE_CUT) { - /* Make sure the old MP_VOICE channel knows it has no - master now ! */ - - - - aux_chn_ctrl->slave_voice=NULL; - /* assume the channel is taken by NNA */ - aux_voc_ctrl->has_master_channel=false; - - switch (aux_voc_ctrl->NNA_type) { - case CPInstrument::NNA_NOTE_CONTINUE: { - - } break; - case CPInstrument::NNA_NOTE_OFF: { - - - aux_voc_ctrl->note_end_flags|=END_NOTE_OFF; - - if (!aux_voc_ctrl->volume_envelope_ctrl.active || aux_voc_ctrl->instrument_ptr->get_volume_envelope()->is_loop_enabled()) { - aux_voc_ctrl->note_end_flags|=END_NOTE_FADE; - } - } break; - case CPInstrument::NNA_NOTE_FADE: { - - aux_voc_ctrl->note_end_flags|=END_NOTE_FADE; - } break; - } - } - } - - if (aux_chn_ctrl->duplicate_check_type!=CPInstrument::DCT_DISABLED) { - int i; - - for (i=0;i<control.max_voices;i++) { - if (!mixer->is_voice_active(i)|| - (voice[i].master_channel!=aux_chn_ctrl) || - (aux_chn_ctrl->instrument_index!=voice[i].instrument_index)) - continue; - - Voice_Control *aux_voc_ctrl; - - aux_voc_ctrl=&voice[i]; - - k=false; - switch (aux_chn_ctrl->duplicate_check_type) { - case CPInstrument::DCT_NOTE: - if (aux_chn_ctrl->note==aux_voc_ctrl->note) - k=true; - break; - case CPInstrument::DCT_SAMPLE: - if (aux_chn_ctrl->sample_ptr==aux_voc_ctrl->sample_ptr) - k=true; - break; - case CPInstrument::DCT_INSTRUMENT: - k=true; - break; - } - if (k) { - switch (aux_chn_ctrl->duplicate_check_action) { - case CPInstrument::DCA_NOTE_CUT: { - aux_voc_ctrl->fadeout_volume=0; - } break; - case CPInstrument::DCA_NOTE_OFF: { - - aux_voc_ctrl->note_end_flags|=END_NOTE_OFF; - - if (!aux_voc_ctrl->volume_envelope_ctrl.active || aux_chn_ctrl->instrument_ptr->get_volume_envelope()->is_loop_enabled()) { - - aux_voc_ctrl->note_end_flags|=END_NOTE_FADE; - } - - } break; - case CPInstrument::DCA_NOTE_FADE: { - aux_voc_ctrl->note_end_flags|=END_NOTE_FADE; - } break; - } - } - } - - } - } /* if (aux_chn_ctrl->kick==KICK_NOTE) */ - } -} diff --git a/modules/chibi/cp_player_data_notes.cpp b/modules/chibi/cp_player_data_notes.cpp deleted file mode 100644 index 189403343c..0000000000 --- a/modules/chibi/cp_player_data_notes.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_notes.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" -#include "cp_sample_manager.h" - -#define RANDOM_MAX 2147483647 - -static inline int32_t cp_random_generate(int32_t *seed) { - int32_t k; - int32_t s = (int32_t)(*seed); - if (s == 0) - s = 0x12345987; - k = s / 127773; - s = 16807 * (s - k * 127773) - 2836 * k; - if (s < 0) - s += 2147483647; - (*seed) = (int32_t)s; - return (int32_t)(s & RANDOM_MAX); -} - - -void CPPlayer::process_new_note(int p_track,uint8_t p_note) { // if there's really a new note.... - - if (control.channel[p_track].real_note!=255) { - control.channel[p_track].old_note=control.channel[p_track].real_note; - - } - - control.channel[p_track].real_note=p_note; - - control.channel[p_track].kick=KICK_NOTE; - - control.channel[p_track].sample_start_index=-1; - control.channel[p_track].sliding=0; - control.channel[p_track].row_has_note=true; - control.channel[p_track].last_event_usecs=song_usecs; - - if (control.channel[p_track].panbrello_type) control.channel[p_track].panbrello_position=0; -} - -bool CPPlayer::process_new_instrument(int p_track,uint8_t p_instrument) { - - //bool different_instrument=false; - ERR_FAIL_INDEX_V(p_instrument,CPSong::MAX_INSTRUMENTS,false); - - if ( song->has_instruments() ) { - - - control.channel[p_track].instrument_ptr=song->get_instrument(p_instrument); - } else { - - control.channel[p_track].instrument_ptr=NULL; - } - - control.channel[p_track].retrig_counter=0; - control.channel[p_track].tremor_position=0; - control.channel[p_track].sample_offset_fine=0; - int old_instr_index=control.channel[p_track].instrument_index; - control.channel[p_track].instrument_index=p_instrument; - - return (old_instr_index!=p_instrument); - - -} - - - // returns if it was able to process -bool CPPlayer::process_note_and_instrument(int p_track,int p_note,int p_instrument) { - - bool aux_result; - aux_result=false; - CPSample *aux_sample=0; // current sample - int dest_sample_index; - bool new_instrument=false; - - control.channel[p_track].row_has_note=false; // wise man says.. "we dont have a note... until we really know we have a note". - control.channel[p_track].new_instrument=false; - - if ( (p_note<0) && (p_instrument<0) ) return aux_result; // nothing to do here - if ( (p_note==255) && (p_instrument==255) ) return aux_result; - - if ( (p_note>=0) && (p_note<120) ) { - - process_new_note(p_track,p_note); - - } else if (p_note==CPNote::CUT) { - - control.channel[p_track].aux_volume=0; - control.channel[p_track].note_end_flags|=END_NOTE_OFF; - control.channel[p_track].note_end_flags|=END_NOTE_KILL; - return aux_result; - - } else if ((p_note==CPNote::OFF) && (song->has_instruments())) { - - if (control.channel[p_track].instrument_ptr!=NULL) { - - control.channel[p_track].note_end_flags|=END_NOTE_OFF; - - if (!control.channel[p_track].instrument_ptr->get_volume_envelope()->is_enabled() || control.channel[p_track].instrument_ptr->get_volume_envelope()->is_loop_enabled()) { - - control.channel[p_track].note_end_flags|=END_NOTE_FADE; - } - } - - return aux_result; - } else return aux_result; // invalid note! - - - if ( (p_instrument>=0) && (p_instrument<CPSong::MAX_INSTRUMENTS)) { - new_instrument=process_new_instrument(p_track,p_instrument); - - if ( song->has_instruments() ) { - // If we're in instrument mode... - if ( control.channel[p_track].instrument_ptr->get_sample_number(control.channel[p_track].real_note) >= CPSong::MAX_SAMPLES) { - - control.channel[p_track].kick=KICK_NOTHING; - return aux_result; - - } else { - dest_sample_index=control.channel[p_track].instrument_ptr->get_sample_number(control.channel[p_track].real_note); - control.channel[p_track].note=control.channel[p_track].instrument_ptr->get_note_number(control.channel[p_track].real_note); - } - - } else { - // If we're in sample mode... - dest_sample_index=control.channel[p_track].instrument_index; - control.channel[p_track].note=control.channel[p_track].real_note; - } - - control.channel[p_track].sample_index=dest_sample_index; - aux_sample=song->get_sample(dest_sample_index); - - if (!CPSampleManager::get_singleton()->check( aux_sample->get_sample_data() )) { - /* INVALID SAMPLE */ - control.channel[p_track].kick=KICK_NOTHING; - return aux_result; - - } - - aux_sample=song->get_sample(dest_sample_index); - } else { - - - if (!control.channel[p_track].sample_ptr) - return aux_result; - - if (song->has_instruments()) { - - if (!control.channel[p_track].instrument_ptr) - return aux_result; - - control.channel[p_track].note=control.channel[p_track].instrument_ptr->get_note_number(control.channel[p_track].real_note); - - } else { - - control.channel[p_track].note=control.channel[p_track].real_note; - - } - - aux_sample=control.channel[p_track].sample_ptr; - - } - - - - if (p_instrument>=CPSong::MAX_INSTRUMENTS && control.channel[p_track].sample_ptr!=aux_sample) { - - control.channel[p_track].new_instrument=(control.channel[p_track].period>0); - } - - control.channel[p_track].sample_ptr=aux_sample; - - /* channel or instrument determined panning ? */ - - control.channel[p_track].panning=control.channel[p_track].channel_panning; - - /* set filter,if any ? */ - - - if (aux_sample->is_pan_enabled()) { - - control.channel[p_track].panning=(int)aux_sample->get_pan()*255/64; - - } else if ( song->has_instruments() && (control.channel[p_track].instrument_ptr->is_pan_default_enabled()) ) { - - control.channel[p_track].panning=(int)control.channel[p_track].instrument_ptr->get_pan_default_amount()*255/64; - } - - - if (song->has_instruments()) { - - - /* Pitch-Pan Separation */ - if ((control.channel[p_track].instrument_ptr->get_pan_pitch_separation()!=0) && (control.channel[p_track].channel_panning!=PAN_SURROUND)){ - - control.channel[p_track].panning+=((control.channel[p_track].real_note-control.channel[p_track].instrument_ptr->get_pan_pitch_center())*control.channel[p_track].instrument_ptr->get_pan_pitch_separation())/8; - - if (control.channel[p_track].panning<PAN_LEFT) control.channel[p_track].panning=PAN_LEFT; - if (control.channel[p_track].panning>PAN_RIGHT) control.channel[p_track].panning=PAN_RIGHT; - } - - /* Random Volume Variation */ - if (control.channel[p_track].instrument_ptr->get_volume_random_variation()>0) { - - control.channel[p_track].random_volume_variation=100-(cp_random_generate(&control.random_seed) % control.channel[p_track].instrument_ptr->get_volume_random_variation()); - - } else { - - control.channel[p_track].random_volume_variation=100; - } - - - /* Random Pan Variation */ - if ((control.channel[p_track].instrument_ptr->get_pan_random_variation()>0) && (control.channel[p_track].panning!=PAN_SURROUND)){ - - int aux_pan_modifier; - - aux_pan_modifier=(cp_random_generate(&control.random_seed) % (control.channel[p_track].instrument_ptr->get_pan_random_variation() << 2)); - if ((cp_random_generate(&control.random_seed) % 2)==1) aux_pan_modifier=0-aux_pan_modifier; /* it's 5am, let me sleep :) */ - - control.channel[p_track].panning+=aux_pan_modifier; - - if (control.channel[p_track].panning<PAN_LEFT) control.channel[p_track].panning=PAN_LEFT; - if (control.channel[p_track].panning>PAN_RIGHT) control.channel[p_track].panning=PAN_RIGHT; - - - } - - /*filter*/ - - if (control.channel[p_track].instrument_ptr->filter_use_default_cutoff()) { - - control.channel[p_track].filter.it_cutoff=control.channel[p_track].instrument_ptr->get_filter_default_cutoff()*2; - - } - - if (control.channel[p_track].instrument_ptr->filter_use_default_resonance()) { - - control.channel[p_track].filter.it_reso=control.channel[p_track].instrument_ptr->get_filter_default_resonance()*2; - - } - - /*envelopes*/ - - - control.channel[p_track].volume_envelope_on=control.channel[p_track].instrument_ptr->get_volume_envelope()->is_enabled(); - control.channel[p_track].panning_envelope_on=control.channel[p_track].instrument_ptr->get_pan_envelope()->is_enabled(); - control.channel[p_track].pitch_envelope_on=control.channel[p_track].instrument_ptr->get_pitch_filter_envelope()->is_enabled(); - control.channel[p_track].NNA_type=control.channel[p_track].instrument_ptr->get_NNA_type(); - control.channel[p_track].duplicate_check_type=control.channel[p_track].instrument_ptr->get_DC_type(); - control.channel[p_track].duplicate_check_action=control.channel[p_track].instrument_ptr->get_DC_action(); - - - } else { - - control.channel[p_track].NNA_type=CPInstrument::NNA_NOTE_CUT; - control.channel[p_track].duplicate_check_type=CPInstrument::DCT_DISABLED; - control.channel[p_track].duplicate_check_action=CPInstrument::DCA_NOTE_CUT; - } - - - if (p_instrument<CPSong::MAX_INSTRUMENTS) { // instrument change - - control.channel[p_track].volume=control.channel[p_track].aux_volume=aux_sample->get_default_volume(); - - } - - - control.channel[p_track].slide_to_period=control.channel[p_track].aux_period=get_period((uint16_t)(control.channel[p_track].note)<<1,CPSampleManager::get_singleton()->get_c5_freq( (aux_sample->get_sample_data()))); - - control.channel[p_track].note_end_flags=END_NOTE_NOTHING; /* clears flags */ - - return true; -} - -void CPPlayer::process_volume_column(int p_track,uint8_t p_volume) { - - control.channel[p_track].current_volume_command=CPNote::EMPTY; - control.channel[p_track].current_volume_parameter=CPNote::EMPTY; - - if (p_volume<65) { // VOLUME - - control.channel[p_track].aux_volume=p_volume; - } else if (p_volume<125) { // Volume Command - - - control.channel[p_track].current_volume_command=(p_volume-65) / 10; - control.channel[p_track].current_volume_parameter=(p_volume-65) % 10; - } else if (p_volume<193) { // PAN - - control.channel[p_track].channel_panning=(p_volume-128)*PAN_RIGHT/64; - control.channel[p_track].panning=control.channel[p_track].channel_panning; - - } else if (p_volume<213) { //More volume Commands - - control.channel[p_track].current_volume_command=((p_volume-193) / 10)+6; - control.channel[p_track].current_volume_parameter=(p_volume-193) % 10; - } -} - - -void CPPlayer::process_note(int p_track,CPNote p_note) { - - if ( p_note.note!=CPNote::SCRIPT ) { - - process_note_and_instrument(p_track,p_note.note,p_note.instrument); - process_volume_column(p_track,p_note.volume); - control.channel[p_track].current_command=p_note.command; - control.channel[p_track].current_parameter=p_note.parameter; - - } else { - - CPNote n = song->get_pattern( control.position.current_pattern )->get_transformed_script_note( p_track, control.position.current_row ); - process_note( p_track, n ); - - song->get_pattern( control.position.current_pattern )->scripted_clone( p_track, control.position.current_row ); - } -} diff --git a/modules/chibi/cp_player_data_utils.cpp b/modules/chibi/cp_player_data_utils.cpp deleted file mode 100644 index b99dbfcb99..0000000000 --- a/modules/chibi/cp_player_data_utils.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/*************************************************************************/ -/* cp_player_data_utils.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_player_data.h" -uint8_t CPPlayer::vibrato_table[32]={ - 0, 24, 49, 74, 97,120,141,161,180,197,212,224,235,244,250,253, - 255,253,250,244,235,224,212,197,180,161,141,120, 97, 74, 49, 24 -}; - -uint8_t CPPlayer::auto_vibrato_table[128]={ - 0, 1, 3, 4, 6, 7, 9,10,12,14,15,17,18,20,21,23, - 24,25,27,28,30,31,32,34,35,36,38,39,40,41,42,44, - 45,46,47,48,49,50,51,52,53,54,54,55,56,57,57,58, - 59,59,60,60,61,61,62,62,62,63,63,63,63,63,63,63, - 64,63,63,63,63,63,63,63,62,62,62,61,61,60,60,59, - 59,58,57,57,56,55,54,54,53,52,51,50,49,48,47,46, - 45,44,42,41,40,39,38,36,35,34,32,31,30,28,27,25, - 24,23,21,20,18,17,15,14,12,10, 9, 7, 6, 4, 3, 1 -}; - - -int8_t CPPlayer::panbrello_table[256]={ - 0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 16, 17, 19, 20, 22, 23, - 24, 26, 27, 29, 30, 32, 33, 34, 36, 37, 38, 39, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, - 59, 60, 60, 61, 61, 62, 62, 62, 63, 63, 63, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 63, 63, 63, 62, 62, 62, 61, 61, 60, 60, - 59, 59, 58, 57, 56, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, - 45, 44, 43, 42, 41, 39, 38, 37, 36, 34, 33, 32, 30, 29, 27, 26, - 24, 23, 22, 20, 19, 17, 16, 14, 12, 11, 9, 8, 6, 5, 3, 2, - 0,- 2,- 3,- 5,- 6,- 8,- 9,-11,-12,-14,-16,-17,-19,-20,-22,-23, - -24,-26,-27,-29,-30,-32,-33,-34,-36,-37,-38,-39,-41,-42,-43,-44, - -45,-46,-47,-48,-49,-50,-51,-52,-53,-54,-55,-56,-56,-57,-58,-59, - -59,-60,-60,-61,-61,-62,-62,-62,-63,-63,-63,-64,-64,-64,-64,-64, - -64,-64,-64,-64,-64,-64,-63,-63,-63,-62,-62,-62,-61,-61,-60,-60, - -59,-59,-58,-57,-56,-56,-55,-54,-53,-52,-51,-50,-49,-48,-47,-46, - -45,-44,-43,-42,-41,-39,-38,-37,-36,-34,-33,-32,-30,-29,-27,-26, - -24,-23,-22,-20,-19,-17,-16,-14,-12,-11,- 9,- 8,- 6,- 5,- 3,- 2 -}; - - - - - - -int32_t CPPlayer::get_period(uint16_t p_note,int32_t p_c5speed) { - - if (song->has_linear_slides()) { - - return CPTables::get_linear_period(p_note,0); - } else { - - - return CPTables::get_log_period(p_note>>1,p_c5speed >>1); - } -} - - -int32_t CPPlayer::get_frequency(int32_t period) { - - if (song->has_linear_slides()) { - - return CPTables::get_linear_frequency(period); - } else { - - return CPTables::get_old_frequency(period); - } -} - -int CPPlayer::find_empty_voice() { - - int i; - int min_priority,min_priority_chan=0,priority; - - for (i=0;i<control.max_voices;i++) { - - if ( ((voice[i].kick==KICK_NOTHING)||(voice[i].kick==KICK_ENVELOPE))&&!mixer->is_voice_active(i) ) { - - return i; - - } - } - - // todo more - - for (i=0;i<control.max_voices;i++) { - /* allow us to take over a nonexisting sample */ - /* - if ((voice[i].s==NULL) - return k; - */ - - if ((voice[i].kick==KICK_NOTHING)||(voice[i].kick==KICK_ENVELOPE)) { - - priority=voice[i].total_volume<<((CPSampleManager::get_singleton()->get_loop_type( voice[i].sample_ptr->get_sample_data())!=CP_LOOP_NONE)?1:0); - - if ((voice[i].has_master_channel)&&(&voice[i]==voice[i].master_channel->slave_voice)) { - - priority<<=2; - - } - - if ((i==0) || (priority<min_priority)) { - min_priority=priority; - min_priority_chan=i; - } - } - } - - if (min_priority>8000*7) return -1; /* what the fuck is this? */ - - return min_priority_chan; -} - diff --git a/modules/chibi/cp_sample.cpp b/modules/chibi/cp_sample.cpp deleted file mode 100644 index bea8835548..0000000000 --- a/modules/chibi/cp_sample.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/*************************************************************************/ -/* cp_sample.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_sample.h" - -const char * CPSample::get_name() const { - - return name; -} -void CPSample::set_name(const char *p_name) { - - if (p_name==NULL) { - name[0]=0; - return; - } - - - bool done=false; - for (int i=0;i<NAME_MAX_LEN;i++) { - - - name[i]=done?0:p_name[i]; - if (!done && p_name[i]==0) - done=true; - } - - name[NAME_MAX_LEN-1]=0; /* just in case */ - -} - -void CPSample::set_default_volume(uint8_t p_vol) { - - default_volume=p_vol; -} -uint8_t CPSample::get_default_volume() const{ - - return default_volume; -} - -void CPSample::set_global_volume(uint8_t p_vol) { - - global_volume=p_vol; -} -uint8_t CPSample::get_global_volume() const{ - - return global_volume; -} - -void CPSample::set_pan_enabled(bool p_vol) { - - pan_enabled=p_vol; -} -bool CPSample::is_pan_enabled() const{ - - return pan_enabled; -} - -void CPSample::set_pan(uint8_t p_pan) { - - pan=p_pan; - -} -uint8_t CPSample::get_pan() const{ - - return pan; -} - - -void CPSample::set_vibrato_type(VibratoType p_vibrato_type) { - - vibrato_type=p_vibrato_type; -} -CPSample::VibratoType CPSample::get_vibrato_type() const{ - - return vibrato_type; -} - -void CPSample::set_vibrato_speed(uint8_t p_vibrato_speed) { - - vibrato_speed=p_vibrato_speed; -} -uint8_t CPSample::get_vibrato_speed() const { - - return vibrato_speed; -} - -void CPSample::set_vibrato_depth(uint8_t p_vibrato_depth) { - - vibrato_depth=p_vibrato_depth; -} -uint8_t CPSample::get_vibrato_depth() const{ - - return vibrato_depth; -} - -void CPSample::set_vibrato_rate(uint8_t p_vibrato_rate) { - - vibrato_rate=p_vibrato_rate; -} -uint8_t CPSample::get_vibrato_rate() const{ - - return vibrato_rate; -} - -void CPSample::set_sample_data(CPSample_ID p_ID) { - - id=p_ID; -} -CPSample_ID CPSample::get_sample_data() const{ - - return id; -} - -void CPSample::operator=(const CPSample &p_sample) { - - copy_from(p_sample); -} -void CPSample::copy_from(const CPSample &p_sample) { - - reset(); - set_name(p_sample.get_name()); - - default_volume=p_sample.default_volume; - global_volume=p_sample.global_volume; - - pan_enabled=p_sample.pan_enabled; - pan=p_sample.pan; - - vibrato_type=p_sample.vibrato_type; - vibrato_speed=p_sample.vibrato_speed; - vibrato_depth=p_sample.vibrato_depth; - vibrato_rate=p_sample.vibrato_rate; - - if (CPSampleManager::get_singleton() && !p_sample.id.is_null()) - CPSampleManager::get_singleton()->copy_to( p_sample.id, id ); -} - - - - - -void CPSample::reset() { - - - name[0]=0; - - default_volume=64; - global_volume=64; - - pan_enabled=false; - pan=32; - - vibrato_type=VIBRATO_SINE; - vibrato_speed=0; - vibrato_depth=0; - vibrato_rate=0; - - if (!id.is_null() && CPSampleManager::get_singleton()) - CPSampleManager::get_singleton()->destroy( id ); - - id=CPSample_ID(); - -} - -CPSample::CPSample(const CPSample&p_from) { - - reset(); - copy_from(p_from); -} -CPSample::CPSample() { - - reset(); -} - -CPSample::~CPSample() { - - reset(); -} diff --git a/modules/chibi/cp_sample.h b/modules/chibi/cp_sample.h deleted file mode 100644 index c02b220c84..0000000000 --- a/modules/chibi/cp_sample.h +++ /dev/null @@ -1,112 +0,0 @@ -/*************************************************************************/ -/* cp_sample.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CPSAMPLE_H -#define CPSAMPLE_H - - -#include "cp_config.h" -#include "cp_sample_manager.h" -class CPSample { - -public: - enum VibratoType { - VIBRATO_SINE, - VIBRATO_SAW, - VIBRATO_SQUARE, - VIBRATO_RANDOM - - }; - -private: - - enum { NAME_MAX_LEN=26 }; - - char name[NAME_MAX_LEN]; - - uint8_t default_volume; /* 0.. 64 */ - uint8_t global_volume; /* 0.. 64 */ - - bool pan_enabled; - uint8_t pan; /* 0.. 64 */ - - VibratoType vibrato_type; - uint8_t vibrato_speed; /* 0.. 64 */ - uint8_t vibrato_depth; /* 0.. 64 */ - uint8_t vibrato_rate; /* 0.. 64 */ - - CPSample_ID id; - - void copy_from(const CPSample &p_sample); -public: - - - void operator=(const CPSample &p_sample); - - const char * get_name() const; - void set_name(const char *p_name); - - void set_default_volume(uint8_t p_vol); - uint8_t get_default_volume() const; - - void set_global_volume(uint8_t p_vol); - uint8_t get_global_volume() const; - - void set_pan_enabled(bool p_vol); - bool is_pan_enabled() const; - - void set_pan(uint8_t p_pan); - uint8_t get_pan() const; - - void set_vibrato_type(VibratoType p_vibrato_type); - VibratoType get_vibrato_type() const; - - void set_vibrato_speed(uint8_t p_vibrato_speed) ; - uint8_t get_vibrato_speed() const; - - void set_vibrato_depth(uint8_t p_vibrato_depth); - uint8_t get_vibrato_depth() const; - - void set_vibrato_rate(uint8_t p_vibrato_rate); - uint8_t get_vibrato_rate() const; - - void set_sample_data(CPSample_ID); - CPSample_ID get_sample_data() const; - - void reset(); - - CPSample(const CPSample&p_from); - CPSample(); - ~CPSample(); - -}; - - - - -#endif diff --git a/modules/chibi/cp_sample_defs.h b/modules/chibi/cp_sample_defs.h deleted file mode 100644 index 5ae57aed82..0000000000 --- a/modules/chibi/cp_sample_defs.h +++ /dev/null @@ -1,97 +0,0 @@ -/*************************************************************************/ -/* cp_sample_defs.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_SAMPLE_DEFS_H -#define CP_SAMPLE_DEFS_H - -#include "cp_config.h" - -enum CPSample_Loop_Type { - - CP_LOOP_NONE, - CP_LOOP_FORWARD, - CP_LOOP_BIDI -}; - -//#define INVALID_SAMPLE_ID -1 - -#define CP_MIXING_FRAC_BITS_MACRO 13 -#define CP_MIXING_FRAC_BITS_TEXT "13" -// 1<<9 - 1 -#define CP_MIXING_FRAC_BITS_MASK_TEXT "8191" - -enum CPMixConstants { - CP_MIXING_FRAC_BITS=CP_MIXING_FRAC_BITS_MACRO, - CP_MIXING_FRAC_LENGTH=(1<<CP_MIXING_FRAC_BITS), - CP_MIXING_FRAC_MASK=CP_MIXING_FRAC_LENGTH-1, - CP_MIXING_VOL_FRAC_BITS=8, - CP_MIXING_FREQ_FRAC_BITS=8 -}; - -enum CPFilterConstants { - CP_FILTER_SHIFT=16, - CP_FILTER_LENGTH=(1<<CP_FILTER_SHIFT) -}; - - -enum CPInterpolationType { - CP_INTERPOLATION_RAW, - CP_INTERPOLATION_LINEAR, - CP_INTERPOLATION_CUBIC -}; - -enum CPPanConstants { - - CP_PAN_BITS=8, // 0 .. 256 - CP_PAN_LEFT=0, - CP_PAN_RIGHT=((1<<CP_PAN_BITS)-1), // 255 - CP_PAN_CENTER=CP_PAN_RIGHT/2, // 128 - CP_PAN_SURROUND=512 -}; - -enum CPMixerVolConstants { - CP_VOL_MAX=512, - CP_VOL_RAMP_BITS=9, - CP_VOL_SHIFT=2 - - -}; - -enum CPStereoCannels { - CP_CHAN_LEFT, - CP_CHAN_RIGHT -}; - -#define CP_FIRST_SAMPLE_DECLICK_THRESHOLD 1000 -#define CP_FIRST_SAMPLE_RAMP_LEN 32 - -typedef signed char CPFrame8; -typedef signed short CPFrame16; - - -#endif diff --git a/modules/chibi/cp_sample_manager.cpp b/modules/chibi/cp_sample_manager.cpp deleted file mode 100644 index 2ad0a720b4..0000000000 --- a/modules/chibi/cp_sample_manager.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************/ -/* cp_sample_manager.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_sample_manager.h" - - -CPSampleManager * CPSampleManager::singleton=NULL; - - -void CPSampleManager::copy_to(CPSample_ID p_from,CPSample_ID &p_to) { - - ERR_FAIL_COND(!check( p_from )); - - - if (p_to.is_null()) { - - p_to=create( is_16bits( p_from), is_stereo( p_from), get_size(p_from)); - } else { - - recreate( p_to, is_16bits( p_from), is_stereo( p_from), get_size(p_from)); - - } - - int len=get_size( p_from ); - int ch=is_stereo( p_from ) ? 2 : 1; - - for (int c=0;c<ch;c++) { - - for (int i=0;i<len;i++) { - - int16_t s=get_data( p_from, i, c ); - set_data( p_to, i, s, c ); - } - } - - set_loop_type( p_to, get_loop_type( p_from ) ); - set_loop_begin( p_to, get_loop_begin( p_from ) ); - set_loop_end( p_to, get_loop_end( p_from ) ); - set_c5_freq( p_to, get_c5_freq( p_from ) ); - - - -} - -CPSampleManager::CPSampleManager() { - - singleton=this; -} - -CPSampleManager *CPSampleManager::get_singleton() { - - return singleton; -} diff --git a/modules/chibi/cp_sample_manager.h b/modules/chibi/cp_sample_manager.h deleted file mode 100644 index b6d47a3013..0000000000 --- a/modules/chibi/cp_sample_manager.h +++ /dev/null @@ -1,99 +0,0 @@ -/*************************************************************************/ -/* cp_sample_manager.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CP_SAMPLE_MANAGER_H -#define CP_SAMPLE_MANAGER_H - -#include "cp_config.h" -#include "cp_sample_defs.h" - - - -/** -@author Juan Linietsky -*/ - - -/* abstract base CPSample_ID class */ - -struct CPSample_ID { - - void *_private; - - bool operator==(const CPSample_ID&p_other) const { return _private==p_other._private; } - bool operator!=(const CPSample_ID&p_other) const { return _private!=p_other._private; } - bool is_null() const { return _private==0; } - CPSample_ID(void *p_private=0) { _private=p_private; }; -}; - - -class CPSampleManager { - - static CPSampleManager * singleton; - -public: - - /* get the singleton instance */ - static CPSampleManager *get_singleton(); - - virtual void copy_to(CPSample_ID p_from,CPSample_ID &p_to); ///< if p_to is null, it gets created - - virtual CPSample_ID create(bool p_16bits,bool p_stereo,int32_t p_len)=0; - virtual void recreate(CPSample_ID p_id,bool p_16bits,bool p_stereo,int32_t p_len)=0; - virtual void destroy(CPSample_ID p_id)=0; - virtual bool check(CPSample_ID p_id)=0; // return false if invalid - - virtual void set_c5_freq(CPSample_ID p_id,int32_t p_freq)=0; - virtual void set_loop_begin(CPSample_ID p_id,int32_t p_begin)=0; - virtual void set_loop_end(CPSample_ID p_id,int32_t p_end)=0; - virtual void set_loop_type(CPSample_ID p_id,CPSample_Loop_Type p_type)=0; - virtual void set_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len)=0; - - - virtual int32_t get_loop_begin(CPSample_ID p_id)=0; - virtual int32_t get_loop_end(CPSample_ID p_id)=0; - virtual CPSample_Loop_Type get_loop_type(CPSample_ID p_id)=0; - virtual int32_t get_c5_freq(CPSample_ID p_id)=0; - virtual int32_t get_size(CPSample_ID p_id)=0; - virtual bool is_16bits(CPSample_ID p_id)=0; - virtual bool is_stereo(CPSample_ID p_id)=0; - virtual bool lock_data(CPSample_ID p_id)=0; - virtual void *get_data(CPSample_ID p_id)=0; /* WARNING: Not all sample managers -may be able to implement this, it depends on the mixer in use! */ - virtual int16_t get_data(CPSample_ID p_id, int p_sample, int p_channel=0)=0; /// Does not need locking - virtual void set_data(CPSample_ID p_id, int p_sample, int16_t p_data,int p_channel=0)=0; /// Does not need locking - virtual void unlock_data(CPSample_ID p_id)=0; - - virtual void get_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len)=0; - - CPSampleManager(); - virtual ~CPSampleManager(){} - -}; - -#endif diff --git a/modules/chibi/cp_song.cpp b/modules/chibi/cp_song.cpp deleted file mode 100644 index 197e44f69d..0000000000 --- a/modules/chibi/cp_song.cpp +++ /dev/null @@ -1,957 +0,0 @@ -/*************************************************************************/ -/* cp_song.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "cp_song.h" - -void CPSong::set_name(const char *p_name) { - - if (p_name==NULL) { - variables.name[0]=0; - return; - } - - - bool done=false; - for (int i=0;i<MAX_SONG_NAME;i++) { - - - variables.name[i]=done?0:p_name[i]; - if (!done && p_name[i]==0) - done=true; - } - - variables.name[MAX_SONG_NAME-1]=0; /* just in case */ -} - -const char * CPSong::get_name() { - - return variables.name; - -} - -void CPSong::set_message(const char *p_message) { - - if (p_message==NULL) { - variables.message[0]=0; - return; - } - - bool done=false; - for (int i=0;i<MAX_MESSAGE_LEN;i++) { - - - variables.message[i]=done?0:p_message[i]; - if (!done && p_message[i]==0) - done=true; - } - - variables.message[MAX_MESSAGE_LEN-1]=0; /* just in case */ -} - -const char * CPSong::get_message() { - - return variables.message; - -} - -void CPSong::set_row_highlight_minor(int p_hl_minor) { - - variables.row_highlight_minor=p_hl_minor; -} -int CPSong::get_row_highlight_minor() { - - return variables.row_highlight_minor; -} - -void CPSong::set_row_highlight_major(int p_hl_major) { - - variables.row_highlight_major=p_hl_major; - - -} /* 0 .. 256 */ -int CPSong::get_row_highlight_major() { - - return variables.row_highlight_major; - - -} /* 0 .. 256 */ - -void CPSong::set_mixing_volume(int p_mix_volume) { - - - variables.mixing_volume=p_mix_volume; -} /* 0 .. 128 */ -int CPSong::get_mixing_volume() { - - return variables.mixing_volume; - -} /* 0 .. 128 */ - -void CPSong::set_global_volume(int p_global_volume) { - - - initial_variables.global_volume=p_global_volume; - -} /* 0 .. 128 */ -int CPSong::get_global_volume() { - - return initial_variables.global_volume; - -} /* 0 .. 128 */ - -void CPSong::set_stereo_separation(int p_separation) { - - variables.stereo_separation=p_separation; - -} /* 0 .. 128 */ -int CPSong::get_stereo_separation() { - - return variables.stereo_separation; -} /* 0 .. 128 */ - -void CPSong::set_stereo(bool p_stereo) { - - variables.use_stereo=p_stereo; - -} -bool CPSong::is_stereo() { - - return variables.use_stereo; -} - -void CPSong::set_instruments(bool p_instruments) { - - variables.use_instruments=p_instruments; - - -} -bool CPSong::has_instruments() { - - - return variables.use_instruments; - -} - -void CPSong::set_linear_slides(bool p_linear_slides) { - - variables.use_linear_slides=p_linear_slides; - - -} -bool CPSong::has_linear_slides() { - - return variables.use_linear_slides; - - -} - -void CPSong::set_old_effects(bool p_old_effects) { - - variables.old_effects=p_old_effects; - - -} -bool CPSong::has_old_effects() { - - return variables.old_effects; -} - -void CPSong::set_compatible_gxx(bool p_compatible_gxx) { - - - variables.compatible_gxx=p_compatible_gxx; -} -bool CPSong::has_compatible_gxx() { - - return variables.compatible_gxx; - -} - -void CPSong::set_speed(int p_speed) { - - CP_ERR_COND(p_speed<MIN_SPEED); - CP_ERR_COND(p_speed>MAX_SPEED); - - initial_variables.speed=p_speed; - -} /* 1 .. 255 */ -int CPSong::get_speed() { - - return initial_variables.speed; - -} /* 1 .. 255 */ - -void CPSong::set_tempo(int p_tempo) { - - CP_ERR_COND( p_tempo<MIN_TEMPO ); - CP_ERR_COND( p_tempo>MAX_TEMPO ); - - initial_variables.tempo=p_tempo; - -} /* MIN_TEMPO .. MAX_TEMPO */ -int CPSong::get_tempo() { - - return initial_variables.tempo; - - -} /* MIN_TEMPO .. MAX_TEMPO */ - -void CPSong::set_channel_pan(int p_channel,int p_pan) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - CP_FAIL_INDEX(p_pan,CHANNEL_MAX_PAN+1); - - initial_variables.channel[p_channel].pan=p_pan; - -} /* 0 .. CHANNEL_MAX_PAN */ -int CPSong::get_channel_pan(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,-1); - - return initial_variables.channel[p_channel].pan; -} - -void CPSong::set_channel_volume(int p_channel,int p_volume) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - CP_FAIL_INDEX(p_volume,CHANNEL_MAX_VOLUME+1); - - - initial_variables.channel[p_channel].volume=p_volume; - - -} /* 0 .. CHANNEL_MAX_VOLUME */ - - -int CPSong::get_channel_volume(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,-1); - - return initial_variables.channel[p_channel].volume; - -} - -void CPSong::set_channel_chorus(int p_channel,int p_chorus) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - CP_FAIL_INDEX(p_chorus,CHANNEL_MAX_CHORUS+1); - - - initial_variables.channel[p_channel].chorus=p_chorus; - - -} /* 0 .. CHANNEL_MAX_CHORUS */ - - -int CPSong::get_channel_chorus(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,-1); - - return initial_variables.channel[p_channel].chorus; - -} - -void CPSong::set_channel_reverb(int p_channel,int p_reverb) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - CP_FAIL_INDEX(p_reverb,CHANNEL_MAX_REVERB+1); - - - initial_variables.channel[p_channel].reverb=p_reverb; - - -} /* 0 .. CHANNEL_MAX_CHORUS */ - - -int CPSong::get_channel_reverb(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,-1); - - return initial_variables.channel[p_channel].reverb; - -} - -void CPSong::set_channel_surround(int p_channel,bool p_surround) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - initial_variables.channel[p_channel].surround=p_surround; - -} -bool CPSong::is_channel_surround(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,false); - - return initial_variables.channel[p_channel].surround; - - -} - -void CPSong::set_channel_mute(int p_channel,bool p_mute) { - - CP_FAIL_INDEX(p_channel,CPPattern::WIDTH); - - initial_variables.channel[p_channel].mute=p_mute; - -} -bool CPSong::is_channel_mute(int p_channel) { - - CP_FAIL_INDEX_V(p_channel,CPPattern::WIDTH,false); - - return initial_variables.channel[p_channel].mute; - -} - -/* arrays of stuff */ - -CPPattern* CPSong::get_pattern(int p_pattern) { - - CP_FAIL_INDEX_V(p_pattern,MAX_PATTERNS, NULL); - - return &pattern[p_pattern]; - -} -CPSample* CPSong::get_sample(int p_sample) { - - CP_FAIL_INDEX_V(p_sample,MAX_SAMPLES,NULL); - - return &sample[p_sample]; - - -} -CPInstrument* CPSong::get_instrument(int p_instrument) { - - - CP_FAIL_INDEX_V(p_instrument,MAX_INSTRUMENTS,NULL); - - return &instrument[p_instrument]; - -} - -int CPSong::get_order(int p_order) { - - CP_FAIL_INDEX_V(p_order,MAX_ORDERS,CP_ORDER_NONE); - - - return order[p_order]; - -} -void CPSong::set_order(int p_order,int p_pattern) { - - CP_FAIL_INDEX(p_order,MAX_ORDERS); - - order[p_order]=p_pattern; - -} - - -void CPSong::clear_instrument_with_samples(int p_instrument) { - - CPInstrument *ins = get_instrument( p_instrument ); - if (!ins) - return; - - for (int i=0;i<CPNote::NOTES;i++) { - - CPSample *s=get_sample( ins->get_sample_number( i ) ); - - if (!s) - continue; - - if (s->get_sample_data().is_null()) - continue; - - s->reset(); - } - ins->reset(); -} - -void CPSong::make_instrument_from_sample(int p_sample) { - - if (!has_instruments()) - return; - CP_ERR_COND(!get_sample( p_sample )); - - for (int i=0;i<MAX_INSTRUMENTS;i++) { - - - CPInstrument *ins=get_instrument(i); - - bool empty_slot=true; - for (int n=0;n<CPNote::NOTES;n++) { - - if (ins->get_sample_number(n)<MAX_SAMPLES) { - - empty_slot=false; - break; - } - } - - if (!empty_slot) - continue; - - for (int n=0;n<CPNote::NOTES;n++) { - - ins->set_sample_number(n,p_sample); - ins->set_note_number(n,n); - } - - ins->set_name( get_sample( p_sample )->get_name() ); - break; - } - -} - -void CPSong::make_instruments_from_samples() { - - for (int i=0;i<MAX_SAMPLES;i++) { - - CPInstrument *ins=get_instrument( i ); - - if (!ins) - continue; - - ins->reset(); - - CPSample *s=get_sample( i ); - - if (!s) - continue; - - ins->set_name( s->get_name() ); - - if (s->get_sample_data().is_null()) - continue; - - - - - for(int j=0;j<CPNote::NOTES;j++) - ins->set_sample_number( j, i ); - - - - } -} - -void CPSong::reset(bool p_clear_patterns,bool p_clear_samples,bool p_clear_instruments,bool p_clear_variables) { - - if (p_clear_variables) { - variables.name[0]=0; - variables.message[0]=0; - variables.row_highlight_major=16; - variables.row_highlight_minor=4; - variables.mixing_volume=48; - variables.old_effects=false; - if (p_clear_instruments) //should not be cleared, if not clearing instruments!! - variables.use_instruments=false; - variables.stereo_separation=128; - variables.use_linear_slides=true; - variables.use_stereo=true; - - initial_variables.global_volume=128; - initial_variables.speed=6; - initial_variables.tempo=125; - - for (int i=0;i<CPPattern::WIDTH;i++) { - - initial_variables.channel[i].pan=32; - initial_variables.channel[i].volume=CHANNEL_MAX_VOLUME; - initial_variables.channel[i].mute=false; - initial_variables.channel[i].surround=false; - initial_variables.channel[i].chorus=0; - initial_variables.channel[i].reverb=0; - - } - - effects.chorus.delay_ms=6; - effects.chorus.separation_ms=3; - effects.chorus.depth_ms10=6, - effects.chorus.speed_hz10=5; - effects.reverb_mode=REVERB_MODE_ROOM; - } - - if (p_clear_samples) { - for (int i=0;i<MAX_SAMPLES;i++) - get_sample(i)->reset(); - } - - if (p_clear_instruments) { - for (int i=0;i<MAX_INSTRUMENTS;i++) - get_instrument(i)->reset(); - } - - if (p_clear_patterns) { - for (int i=0;i<MAX_PATTERNS;i++) - get_pattern(i)->clear(); - - for (int i=0;i<MAX_ORDERS;i++) - set_order( i, CP_ORDER_NONE ); - } - - -} - - -CPSong::ReverbMode CPSong::get_reverb_mode() { - - return effects.reverb_mode; -} -void CPSong::set_reverb_mode(ReverbMode p_mode) { - - effects.reverb_mode=p_mode; -} - -void CPSong::set_chorus_delay_ms(int p_amount) { - - effects.chorus.delay_ms=p_amount; -} -void CPSong::set_chorus_separation_ms(int p_amount) { - - effects.chorus.separation_ms=p_amount; - -} -void CPSong::set_chorus_depth_ms10(int p_amount) { - - effects.chorus.depth_ms10=p_amount; - -} -void CPSong::set_chorus_speed_hz10(int p_amount) { - - effects.chorus.speed_hz10=p_amount; - -} - -int CPSong::get_chorus_delay_ms() { - - return effects.chorus.delay_ms; - -} -int CPSong::get_chorus_separation_ms() { - - return effects.chorus.separation_ms; -} -int CPSong::get_chorus_depth_ms10() { - - return effects.chorus.depth_ms10; - -} -int CPSong::get_chorus_speed_hz10() { - - return effects.chorus.speed_hz10; - -} - -void CPSong::cleanup_unused_patterns() { - - for (int i=0;i<MAX_PATTERNS;i++) { - - bool used=false; - if (get_pattern(i)->is_empty()) - continue; - - for (int j=0;j<MAX_ORDERS;j++) { - - if (get_order(j)==i) { - used=true; - - } - } - - if (!used) - get_pattern(i)->clear(); - } - -} -void CPSong::cleanup_unused_instruments(){ - - if (!has_instruments()) - return; - - bool instr_found[MAX_INSTRUMENTS]; - for (int i=0;i<MAX_INSTRUMENTS;i++) - instr_found[i]=false; - - for (int i=0;i<MAX_PATTERNS;i++) { - - if (get_pattern(i)->is_empty()) - continue; - - for (int row=0;row<get_pattern(i)->get_length();row++) { - - - for (int col=0;col<CPPattern::WIDTH;col++) { - - CPNote n; - n=get_pattern(i)->get_note( col,row ); - - if (n.instrument<MAX_INSTRUMENTS) - instr_found[n.instrument]=true; - - } - - } - - } - - for (int i=0;i<MAX_INSTRUMENTS;i++) - if (!instr_found[i]) - get_instrument(i)->reset(); - - -} -void CPSong::cleanup_unused_samples(){ - - if (!has_instruments()) - return; - - bool sample_found[MAX_SAMPLES]; - for (int i=0;i<MAX_INSTRUMENTS;i++) - sample_found[i]=false; - - for (int i=0;i<MAX_PATTERNS;i++) { - - if (get_pattern(i)->is_empty()) - continue; - - - for (int row=0;row<get_pattern(i)->get_length();row++) { - - - for (int col=0;col<CPPattern::WIDTH;col++) { - - CPNote n; - n=get_pattern(i)->get_note( col,row ); - - if (n.instrument>=MAX_SAMPLES) - continue; - - if (has_instruments()) { - - for (int nt=0;nt<CPNote::NOTES;nt++) { - - int smp=get_instrument(n.instrument)->get_sample_number(nt); - if (smp<MAX_SAMPLES) - sample_found[smp]=true; - } - - } else { - if (n.instrument<MAX_SAMPLES) - sample_found[n.instrument]=true; - } - - } - - } - - } - - for (int i=0;i<MAX_SAMPLES;i++) - if (!sample_found[i]) - get_sample(i)->reset(); - -} -void CPSong::cleanup_unused_orders(){ - - bool finito=false; - for (int j=0;j<MAX_ORDERS;j++) { - - - if (get_order(j)==CP_ORDER_NONE) - finito=true; - if (finito) - set_order(j,CP_ORDER_NONE); - - } - -} - -void CPSong::clear_all_default_pan() { - - for (int i=0;i<MAX_INSTRUMENTS;i++) - get_instrument(i)->set_pan_default_enabled( false ); //die! - - for (int i=0;i<MAX_SAMPLES;i++) - get_sample(i)->set_pan_enabled( false ); //die! - -} - - -void CPSong::clear_all_default_vol(){ - - for (int i=0;i<MAX_SAMPLES;i++) - get_sample(i)->set_default_volume( 64 ); //die! - for (int i=0;i<MAX_INSTRUMENTS;i++) - get_instrument(i)->set_volume_global_amount( CPInstrument::MAX_VOLUME ); - -} - - -int CPSong::get_order_in_use_count() { - - - int order_count = 0; - - for (int i=(MAX_ORDERS-1);i>=0;i--) { - - - if (get_order(i)!=CP_ORDER_NONE) { - order_count=i+1; - break; - } - } - - return order_count; -} -int CPSong::get_pattern_in_use_count() { - - - int pattern_count=0; - - for (int i=(CPSong::MAX_PATTERNS-1);i>=0;i--) { - - - if (!get_pattern(i)->is_empty()) { - pattern_count=i+1; - break; - } - } - - return pattern_count; -} - -int CPSong::get_instrument_in_use_count() { - - int instrument_count=0; - - for (int i=(CPSong::MAX_INSTRUMENTS-1);i>=0;i--) { - - CPInstrument *ins = get_instrument(i); - bool in_use=false; - - for (int s = 0 ; s < CPNote::NOTES ; s++ ) { - - int smp_idx = ins->get_sample_number(s); - if (smp_idx<0 || smp_idx>=CPSong::MAX_SAMPLES) - continue; - - if (!get_sample(smp_idx)->get_sample_data().is_null()) { - in_use=true; - break; - } - - } - - if (in_use) { - instrument_count=i+1; - break; - } - } - - return instrument_count; -} -#include <stdio.h> -int CPSong::get_channels_in_use() { - - int max=0; - - for (int p=0;p<CPSong::MAX_PATTERNS;p++) { - - CPPattern *pat = get_pattern(p); - if (pat->is_empty()) - continue; - - - for (int c=(CPPattern::WIDTH-1);c>=0;c--) { - - if (c<max) - break; - - bool has_note=false; - for (int r=0;r<pat->get_length();r++) { - - CPNote n = pat->get_note( c, r ); - if (!n.is_empty()) { - has_note=true; - break; - } - } - - if (has_note) { - - max=c+1; - } - } - } - - return max; -} - - -void CPSong::separate_in_one_sample_instruments(int p_instrument) { - - CP_ERR_COND( !variables.use_instruments ); - CP_FAIL_INDEX( p_instrument, MAX_INSTRUMENTS ); - - int remapped_count=0; - - signed char remap[MAX_SAMPLES]; - - for (int i=0;i<MAX_SAMPLES;i++) { - - remap[i]=-1; - } - - /* Find remaps */ - CPInstrument *ins=get_instrument(p_instrument); - for (int i=0;i<CPNote::NOTES;i++) { - - int sn = ins->get_sample_number(i); - - // check for unusable sample - if (sn<0 || sn>=MAX_SAMPLES || get_sample(sn)->get_sample_data().is_null()) - continue; - printf("sample %i\n",sn); - if ( remap[sn] !=-1 ) { - printf("already mapped to %i\n",remap[sn]); - continue; - } - - printf("isn't remapped\n"); - - // find remap - - for (int j=0;j<MAX_INSTRUMENTS;j++) { - - if (!get_instrument(j)->is_empty()) - continue; - - printf("map to %i\n",j); - - //copy - *get_instrument(j)=*ins; - - // assign samples - for (int k=0;k<CPNote::NOTES;k++) { - - get_instrument(j)->set_note_number(k,k); - get_instrument(j)->set_sample_number(k,sn); - } - remap[sn]=j; - remapped_count++; - break; - } - - CP_ERR_COND(remap[sn]==-1); // no more free instruments - } - - printf("remapped %i\n",remapped_count); - - if (remapped_count<2) { - //undo if only one is remapped - for (int i=0;i<MAX_SAMPLES;i++) { - - if (remap[i]!=-1) { - - get_instrument(remap[i])->reset(); - } - } - return; - } - - /* remap all song */ - - for (int p=0;p<CPSong::MAX_PATTERNS;p++) { - - CPPattern *pat = get_pattern(p); - if (pat->is_empty()) - continue; - - - for (int c=0;c<CPPattern::WIDTH;c++) { - - for (int r=0;r<pat->get_length();r++) { - - CPNote n = pat->get_note(c,r); - if (n.note<CPNote::NOTES && n.instrument==p_instrument) { - - int sn = ins->get_sample_number(n.note); - if (remap[sn]==-1) - pat->set_note(c,r,CPNote()); - else { - - n.instrument=remap[sn]; - pat->set_note(c,r,n); - } - } - } - } - } - - ins->reset(); - -} - - -CPSong::CPSong() { - - reset(); -} -CPSong::~CPSong() { - -} - - - - -int get_song_next_order_idx(CPSong *p_song, int p_order_idx) { - - int baseorder,order_counter; - - order_counter=-1; - - baseorder=p_order_idx; - - do { - - baseorder++; - if ( baseorder>(CPSong::MAX_ORDERS-1) ) baseorder=0; - order_counter++; - - } while ( (p_song->get_order(baseorder)>=(CPSong::MAX_PATTERNS) ) && (order_counter<CPSong::MAX_ORDERS) ); - - - if (order_counter==CPSong::MAX_ORDERS) { - - return -1; - - } else { - - return baseorder; - } - -} diff --git a/modules/chibi/cp_song.h b/modules/chibi/cp_song.h deleted file mode 100644 index ba0fa3e80a..0000000000 --- a/modules/chibi/cp_song.h +++ /dev/null @@ -1,261 +0,0 @@ -/*************************************************************************/ -/* cp_song.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef CPSONG_H -#define CPSONG_H - - -/**CPSong Class - *@author Juan Linietsky - */ - -#include "cp_order.h" -#include "cp_pattern.h" -#include "cp_sample.h" -#include "cp_instrument.h" - -class CPSong { -public: - enum { - MAX_SONG_NAME=26, - MAX_ORDERS=200, - MAX_PATTERNS=200, - MAX_SAMPLES=99, - MAX_INSTRUMENTS=99, - - CHANNEL_MAX_PAN=64, - CHANNEL_MAX_VOLUME=64, - CHANNEL_MAX_CHORUS=64, - CHANNEL_MAX_REVERB=64, - - MIN_TEMPO=31, - MAX_TEMPO=255, - MIN_SPEED=1, - MAX_SPEED=255, - MAX_MESSAGE_LEN=8000, - - - - }; - - enum ReverbMode { - REVERB_MODE_ROOM, - REVERB_MODE_STUDIO_SMALL, - REVERB_MODE_STUDIO_MEDIUM, - REVERB_MODE_STUDIO_LARGE, - REVERB_MODE_HALL, - REVERB_MODE_SPACE_ECHO, - REVERB_MODE_ECHO, - REVERB_MODE_DELAY, - REVERB_MODE_HALF_ECHO - }; - -private: - CPOrder order[MAX_ORDERS]; - CPPattern pattern[MAX_PATTERNS]; - CPSample sample[MAX_SAMPLES]; - CPInstrument instrument[MAX_INSTRUMENTS]; - - - - struct Song_Variables { // variables that wont change in playback - - char name[MAX_SONG_NAME]; - char message[MAX_MESSAGE_LEN]; - /* string message; */ - - int row_highlight_minor; - int row_highlight_major; - - int mixing_volume; - int stereo_separation; - - bool use_stereo; - bool use_instruments; - bool use_linear_slides; - - bool old_effects; - bool compatible_gxx; - - } variables; - - struct Initial_Variables { // Initial values used for playback - - struct Channel_State { - - int pan,volume; // 0-- CHANNEL_MAX_PAN, CHANNEL_MAX_VOLUME - bool surround; - bool mute; - int chorus; //0 - 64 - int reverb; //0 - 64 - }; - - int global_volume; - int speed; - int tempo; - - Channel_State channel[CPPattern::WIDTH]; - } initial_variables; - - struct Effects { - - ReverbMode reverb_mode; - - struct Chorus { - - int delay_ms; - int separation_ms; - int depth_ms10; - int speed_hz10; - } chorus; - - } effects; - -public: - - /* Properties */ - - const char *get_name(); - void set_name(const char *p_name); - - const char *get_message(); - void set_message(const char *p_message); - - void set_row_highlight_minor(int p_hl_minor); /* 0 .. 256 */ - int get_row_highlight_minor(); /* 0 .. 256 */ - - void set_row_highlight_major(int p_hl_major); /* 0 .. 256 */ - int get_row_highlight_major(); /* 0 .. 256 */ - - void set_mixing_volume(int p_mix_volume); /* 0 .. 128 */ - int get_mixing_volume(); /* 0 .. 128 */ - - void set_global_volume(int p_global_volume); /* 0 .. 128 */ - int get_global_volume(); /* 0 .. 128 */ - - void set_stereo_separation(int p_separation); /* 0 .. 128 */ - int get_stereo_separation(); /* 0 .. 128 */ - - void set_stereo(bool p_stereo); - bool is_stereo(); - - void set_instruments(bool p_instruments); - bool has_instruments(); - - void set_linear_slides(bool p_linear_slides); - bool has_linear_slides(); - - void set_old_effects(bool p_old_effects); - bool has_old_effects(); - - void set_compatible_gxx(bool p_compatible_gxx); - bool has_compatible_gxx(); - - void set_speed(int p_speed); /* 1 .. 255 */ - int get_speed(); /* 1 .. 255 */ - - void set_tempo(int p_tempo); /* 31 .. 255 */ - int get_tempo(); /* 31 .. 255 */ - - void set_channel_pan(int p_channel,int p_pan); /* 0 .. 64 */ - int get_channel_pan(int p_channel); - - void set_channel_volume(int p_channel,int p_volume); /* 0 .. 64 */ - int get_channel_volume(int p_channel); - - void set_channel_surround(int p_channel,bool p_surround); - bool is_channel_surround(int p_channel); - - void set_channel_mute(int p_channel,bool p_mute); - bool is_channel_mute(int p_channel); - - void set_channel_chorus(int p_channel,int p_chorus); /* 0 .. 64 */ - int get_channel_chorus(int p_channel); - - void set_channel_reverb(int p_channel,int p_reverb); /* 0 .. 64 */ - int get_channel_reverb(int p_channel); - - /* arrays of stuff */ - - CPPattern* get_pattern(int p_pattern); - CPSample* get_sample(int p_sample); - CPInstrument* get_instrument(int p_instrument); - - int get_order(int p_position); - void set_order(int p_position,int p_order); - - - /* Effects */ - - ReverbMode get_reverb_mode(); - void set_reverb_mode(ReverbMode p_mode); - - void set_chorus_delay_ms(int p_amount); - void set_chorus_separation_ms(int p_amount); - void set_chorus_depth_ms10(int p_amount); - void set_chorus_speed_hz10(int p_amount); - - int get_chorus_delay_ms(); - int get_chorus_separation_ms(); - int get_chorus_depth_ms10(); - int get_chorus_speed_hz10(); - - /* utils */ - - void reset(bool p_clear_patterns=true,bool p_clear_samples=true,bool p_clear_instruments=true,bool p_clear_variables=true); - - void cleanup_unused_patterns(); - void cleanup_unused_instruments(); - void cleanup_unused_samples(); - void cleanup_unused_orders(); - void clear_all_default_pan(); - void clear_all_default_vol(); - - void clear_instrument_with_samples(int p_instrument); - - void make_instruments_from_samples(); - void make_instrument_from_sample(int p_sample); - - void separate_in_one_sample_instruments(int p_instrument); - - int get_order_in_use_count(); - int get_pattern_in_use_count(); - int get_instrument_in_use_count(); - int get_channels_in_use(); - - CPSong(); - ~CPSong(); - -}; - - -/* Some helper for something used a lot */ - -int get_song_next_order_idx(CPSong *p_song, int p_order_idx); - -#endif diff --git a/modules/chibi/cp_tables.cpp b/modules/chibi/cp_tables.cpp deleted file mode 100644 index a7ed34ff31..0000000000 --- a/modules/chibi/cp_tables.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/*************************************************************************/ -/* cp_tables.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "cp_tables.h" - -int32_t CPTables::linear_period_to_freq_tab[768]={ - - 535232,534749,534266,533784,533303,532822,532341,531861, - 531381,530902,530423,529944,529466,528988,528511,528034, - 527558,527082,526607,526131,525657,525183,524709,524236, - 523763,523290,522818,522346,521875,521404,520934,520464, - 519994,519525,519057,518588,518121,517653,517186,516720, - 516253,515788,515322,514858,514393,513929,513465,513002, - 512539,512077,511615,511154,510692,510232,509771,509312, - 508852,508393,507934,507476,507018,506561,506104,505647, - 505191,504735,504280,503825,503371,502917,502463,502010, - 501557,501104,500652,500201,499749,499298,498848,498398, - 497948,497499,497050,496602,496154,495706,495259,494812, - 494366,493920,493474,493029,492585,492140,491696,491253, - 490809,490367,489924,489482,489041,488600,488159,487718, - 487278,486839,486400,485961,485522,485084,484647,484210, - 483773,483336,482900,482465,482029,481595,481160,480726, - 480292,479859,479426,478994,478562,478130,477699,477268, - 476837,476407,475977,475548,475119,474690,474262,473834, - 473407,472979,472553,472126,471701,471275,470850,470425, - 470001,469577,469153,468730,468307,467884,467462,467041, - 466619,466198,465778,465358,464938,464518,464099,463681, - 463262,462844,462427,462010,461593,461177,460760,460345, - 459930,459515,459100,458686,458272,457859,457446,457033, - 456621,456209,455797,455386,454975,454565,454155,453745, - 453336,452927,452518,452110,451702,451294,450887,450481, - 450074,449668,449262,448857,448452,448048,447644,447240, - 446836,446433,446030,445628,445226,444824,444423,444022, - 443622,443221,442821,442422,442023,441624,441226,440828, - 440430,440033,439636,439239,438843,438447,438051,437656, - 437261,436867,436473,436079,435686,435293,434900,434508, - 434116,433724,433333,432942,432551,432161,431771,431382, - 430992,430604,430215,429827,429439,429052,428665,428278, - 427892,427506,427120,426735,426350,425965,425581,425197, - 424813,424430,424047,423665,423283,422901,422519,422138, - 421757,421377,420997,420617,420237,419858,419479,419101, - 418723,418345,417968,417591,417214,416838,416462,416086, - 415711,415336,414961,414586,414212,413839,413465,413092, - 412720,412347,411975,411604,411232,410862,410491,410121, - 409751,409381,409012,408643,408274,407906,407538,407170, - 406803,406436,406069,405703,405337,404971,404606,404241, - 403876,403512,403148,402784,402421,402058,401695,401333, - 400970,400609,400247,399886,399525,399165,398805,398445, - 398086,397727,397368,397009,396651,396293,395936,395579, - 395222,394865,394509,394153,393798,393442,393087,392733, - 392378,392024,391671,391317,390964,390612,390259,389907, - 389556,389204,388853,388502,388152,387802,387452,387102, - 386753,386404,386056,385707,385359,385012,384664,384317, - 383971,383624,383278,382932,382587,382242,381897,381552, - 381208,380864,380521,380177,379834,379492,379149,378807, - 378466,378124,377783,377442,377102,376762,376422,376082, - 375743,375404,375065,374727,374389,374051,373714,373377, - 373040,372703,372367,372031,371695,371360,371025,370690, - 370356,370022,369688,369355,369021,368688,368356,368023, - 367691,367360,367028,366697,366366,366036,365706,365376, - 365046,364717,364388,364059,363731,363403,363075,362747, - 362420,362093,361766,361440,361114,360788,360463,360137, - 359813,359488,359164,358840,358516,358193,357869,357547, - 357224,356902,356580,356258,355937,355616,355295,354974, - 354654,354334,354014,353695,353376,353057,352739,352420, - 352103,351785,351468,351150,350834,350517,350201,349885, - 349569,349254,348939,348624,348310,347995,347682,347368, - 347055,346741,346429,346116,345804,345492,345180,344869, - 344558,344247,343936,343626,343316,343006,342697,342388, - 342079,341770,341462,341154,340846,340539,340231,339924, - 339618,339311,339005,338700,338394,338089,337784,337479, - 337175,336870,336566,336263,335959,335656,335354,335051, - 334749,334447,334145,333844,333542,333242,332941,332641, - 332341,332041,331741,331442,331143,330844,330546,330247, - 329950,329652,329355,329057,328761,328464,328168,327872, - 327576,327280,326985,326690,326395,326101,325807,325513, - 325219,324926,324633,324340,324047,323755,323463,323171, - 322879,322588,322297,322006,321716,321426,321136,320846, - 320557,320267,319978,319690,319401,319113,318825,318538, - 318250,317963,317676,317390,317103,316817,316532,316246, - 315961,315676,315391,315106,314822,314538,314254,313971, - 313688,313405,313122,312839,312557,312275,311994,311712, - 311431,311150,310869,310589,310309,310029,309749,309470, - 309190,308911,308633,308354,308076,307798,307521,307243, - 306966,306689,306412,306136,305860,305584,305308,305033, - 304758,304483,304208,303934,303659,303385,303112,302838, - 302565,302292,302019,301747,301475,301203,300931,300660, - 300388,300117,299847,299576,299306,299036,298766,298497, - 298227,297958,297689,297421,297153,296884,296617,296349, - 296082,295815,295548,295281,295015,294749,294483,294217, - 293952,293686,293421,293157,292892,292628,292364,292100, - 291837,291574,291311,291048,290785,290523,290261,289999, - 289737,289476,289215,288954,288693,288433,288173,287913, - 287653,287393,287134,286875,286616,286358,286099,285841, - 285583,285326,285068,284811,284554,284298,284041,283785, - 283529,283273,283017,282762,282507,282252,281998,281743, - 281489,281235,280981,280728,280475,280222,279969,279716, - 279464,279212,278960,278708,278457,278206,277955,277704, - 277453,277203,276953,276703,276453,276204,275955,275706, - 275457,275209,274960,274712,274465,274217,273970,273722, - 273476,273229,272982,272736,272490,272244,271999,271753, - 271508,271263,271018,270774,270530,270286,270042,269798, - 269555,269312,269069,268826,268583,268341,268099,267857 -}; - -uint16_t CPTables::old_period_table[OCTAVE*2]={ - - 0x6b00, 0x6800, 0x6500, 0x6220, 0x5f50, 0x5c80, - 0x5a00, 0x5740, 0x54d0, 0x5260, 0x5010, 0x4dc0, - 0x4b90, 0x4960, 0x4750, 0x4540, 0x4350, 0x4160, - 0x3f90, 0x3dc0, 0x3c10, 0x3a40, 0x38b0, 0x3700 -}; - -#define LOGFAC 2*16 - -uint16_t CPTables::log_table[104]= { - LOGFAC*907,LOGFAC*900,LOGFAC*894,LOGFAC*887, - LOGFAC*881,LOGFAC*875,LOGFAC*868,LOGFAC*862, - LOGFAC*856,LOGFAC*850,LOGFAC*844,LOGFAC*838, - LOGFAC*832,LOGFAC*826,LOGFAC*820,LOGFAC*814, - LOGFAC*808,LOGFAC*802,LOGFAC*796,LOGFAC*791, - LOGFAC*785,LOGFAC*779,LOGFAC*774,LOGFAC*768, - LOGFAC*762,LOGFAC*757,LOGFAC*752,LOGFAC*746, - LOGFAC*741,LOGFAC*736,LOGFAC*730,LOGFAC*725, - LOGFAC*720,LOGFAC*715,LOGFAC*709,LOGFAC*704, - LOGFAC*699,LOGFAC*694,LOGFAC*689,LOGFAC*684, - LOGFAC*678,LOGFAC*675,LOGFAC*670,LOGFAC*665, - LOGFAC*660,LOGFAC*655,LOGFAC*651,LOGFAC*646, - LOGFAC*640,LOGFAC*636,LOGFAC*632,LOGFAC*628, - LOGFAC*623,LOGFAC*619,LOGFAC*614,LOGFAC*610, - LOGFAC*604,LOGFAC*601,LOGFAC*597,LOGFAC*592, - LOGFAC*588,LOGFAC*584,LOGFAC*580,LOGFAC*575, - LOGFAC*570,LOGFAC*567,LOGFAC*563,LOGFAC*559, - LOGFAC*555,LOGFAC*551,LOGFAC*547,LOGFAC*543, - LOGFAC*538,LOGFAC*535,LOGFAC*532,LOGFAC*528, - LOGFAC*524,LOGFAC*520,LOGFAC*516,LOGFAC*513, - LOGFAC*508,LOGFAC*505,LOGFAC*502,LOGFAC*498, - LOGFAC*494,LOGFAC*491,LOGFAC*487,LOGFAC*484, - LOGFAC*480,LOGFAC*477,LOGFAC*474,LOGFAC*470, - LOGFAC*467,LOGFAC*463,LOGFAC*460,LOGFAC*457, - LOGFAC*453,LOGFAC*450,LOGFAC*447,LOGFAC*443, - LOGFAC*440,LOGFAC*437,LOGFAC*434,LOGFAC*431 -}; - - - -int32_t CPTables::get_linear_period(uint16_t note,int32_t fine) { - - int32_t t; - - t=(24L*OCTAVE-(int32_t)note)*32L-(fine>>1); - return t; -} - -static int s3m_period_table[12]={1712,1616,1524,1440,1356,1280,1208,1140,1076,1016,960,907}; - - -int32_t CPTables::get_log_period(uint16_t note,int32_t p_c5freq) { - - return (8363L * 16 * s3m_period_table[note%12] >> (note/12)) / p_c5freq; - -} - -/* -int32_t CPTables::get_log_period(uint16_t note,int32_t p_c5freq) -{ - uint16_t n,o; - uint16_t p1,p2; - int32_t i; - - n=note%(2*OCTAVE); - o=note/(2*OCTAVE); - i=(n<<2); // n*8 + fine/16 - - if (i<0) - i=0; - - if (i>102) - i=102; - - - p1=log_table[i]; - p2=log_table[i+1]; - - - return (Interpolate(fine>>4,0,15,p1,p2)>>o); - -} */ - -int32_t CPTables::get_old_period(uint16_t note,int32_t speed) { - - uint16_t n,o,res; - -// if (!speed) { - - // return 4242; /* <- prevent divide overflow */ - // } - - n=note%(2*OCTAVE); - o=note/(2*OCTAVE); - - res=((8363L*(int32_t)old_period_table[n])>>o)/((old_period_table[17]>>1)+(speed<<2)); /*/(128-speed)*/; - - return res; -} - -int32_t CPTables::get_linear_frequency(int32_t period) { - - int32_t shift_value=(((int32_t)period/768)-2); - if (shift_value>0) { - - return linear_period_to_freq_tab[period%768]>>shift_value; - } else { - shift_value=0-shift_value; - return linear_period_to_freq_tab[period%768]<<shift_value; - } -} - -int32_t CPTables::get_old_frequency(int32_t period) { - - return (8363L*1712L)/(period?period:1); - -} - -CPTables::CPTables(){ -} -CPTables::~CPTables(){ -} diff --git a/modules/chibi/cp_tables.h b/modules/chibi/cp_tables.h deleted file mode 100644 index 4baa1c6488..0000000000 --- a/modules/chibi/cp_tables.h +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************/ -/* cp_tables.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CPTABLES_H -#define CPTABLES_H - -#include "cp_config.h" - -/**conversion CPTables/functions - *@author Juan Linietsky - */ - -/****************************** - CPTables.h - -------- - -CPTables methods for miscelaneous -conversion utilities -********************************/ - -class CPTables { -public: - - enum { OCTAVE=12 }; - - static uint16_t old_period_table[OCTAVE*2]; - static uint16_t log_table[104]; - static int32_t linear_period_to_freq_tab[768]; - - static int32_t get_old_period(uint16_t note,int32_t speed); - static int32_t get_amiga_period(uint16_t note,int32_t fine); - static int32_t get_linear_period(uint16_t note,int32_t fine); - static int32_t get_linear_frequency(int32_t period); - static int32_t get_old_frequency(int32_t period); - static int32_t get_log_period(uint16_t note,int32_t p_c5freq); - - CPTables(); - ~CPTables(); -}; - -#endif diff --git a/modules/chibi/event_stream_chibi.cpp b/modules/chibi/event_stream_chibi.cpp deleted file mode 100644 index ab34080525..0000000000 --- a/modules/chibi/event_stream_chibi.cpp +++ /dev/null @@ -1,872 +0,0 @@ -/*************************************************************************/ -/* event_stream_chibi.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "event_stream_chibi.h" -#include "cp_loader_it.h" -#include "cp_loader_xm.h" -#include "cp_loader_s3m.h" -#include "cp_loader_mod.h" - -static CPSampleManagerImpl *sample_manager; -static ResourceFormatLoaderChibi *resource_loader; - -CPSample_ID CPSampleManagerImpl::create(bool p_16bits,bool p_stereo,int32_t p_len) { - - AudioServer::SampleFormat sf=p_16bits?AudioServer::SAMPLE_FORMAT_PCM16:AudioServer::SAMPLE_FORMAT_PCM8; - - SampleData *sd = memnew( SampleData ); - sd->rid = AudioServer::get_singleton()->sample_create(sf,p_stereo,p_len); - sd->stereo=p_stereo; - sd->len=p_len; - sd->is16=p_16bits; - sd->mixfreq=44100; - sd->loop_begin=0; - sd->loop_end=0; - sd->loop_type=CP_LOOP_NONE; - sd->locks=0; -#ifdef DEBUG_ENABLED - valid.insert(sd); -#endif - CPSample_ID sid; - sid._private=sd; - return sid; -} - -void CPSampleManagerImpl::recreate(CPSample_ID p_id,bool p_16bits,bool p_stereo,int32_t p_len){ - - AudioServer::SampleFormat sf=p_16bits?AudioServer::SAMPLE_FORMAT_PCM16:AudioServer::SAMPLE_FORMAT_PCM8; - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - AudioServer::get_singleton()->free(sd->rid); - sd->rid = AudioServer::get_singleton()->sample_create(sf,p_stereo,p_len); - sd->stereo=p_stereo; - sd->len=p_len; - sd->is16=p_16bits; - sd->mixfreq=44100; - sd->loop_begin=0; - sd->loop_end=0; - sd->loop_type=CP_LOOP_NONE; -} -void CPSampleManagerImpl::destroy(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); - valid.erase(sd); -#endif - AudioServer::get_singleton()->free(sd->rid); - - memdelete(sd); -} -bool CPSampleManagerImpl::check(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - return valid.has(sd); -#else - return _getsd(p_id)!=NULL; -#endif -} - -void CPSampleManagerImpl::set_c5_freq(CPSample_ID p_id,int32_t p_freq){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - sd->mixfreq=p_freq; - AudioServer::get_singleton()->sample_set_mix_rate(sd->rid,p_freq); - -} -void CPSampleManagerImpl::set_loop_begin(CPSample_ID p_id,int32_t p_begin){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - sd->loop_begin=p_begin; - AudioServer::get_singleton()->sample_set_loop_begin(sd->rid,p_begin); - -} -void CPSampleManagerImpl::set_loop_end(CPSample_ID p_id,int32_t p_end){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - sd->loop_end=p_end; - AudioServer::get_singleton()->sample_set_loop_end(sd->rid,p_end); - -} -void CPSampleManagerImpl::set_loop_type(CPSample_ID p_id,CPSample_Loop_Type p_type){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - - sd->loop_type=p_type; - AudioServer::get_singleton()->sample_set_loop_format(sd->rid,AudioServer::SampleLoopFormat(p_type)); - - -} -void CPSampleManagerImpl::set_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - - ERR_FAIL(); -} - - -int32_t CPSampleManagerImpl::get_loop_begin(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - return sd->loop_begin; - -} -int32_t CPSampleManagerImpl::get_loop_end(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - return sd->loop_end; -} -CPSample_Loop_Type CPSampleManagerImpl::get_loop_type(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),CP_LOOP_NONE); -#endif - - return sd->loop_type; -} -int32_t CPSampleManagerImpl::get_c5_freq(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - return sd->mixfreq; -} -int32_t CPSampleManagerImpl::get_size(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - return sd->len; - -} -bool CPSampleManagerImpl::is_16bits(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),false); -#endif - - return sd->is16; - -} -bool CPSampleManagerImpl::is_stereo(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),false); -#endif - return sd->stereo; - - -} -bool CPSampleManagerImpl::lock_data(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - sd->locks++; - if (sd->locks==1) { - sd->lock=AudioServer::get_singleton()->sample_get_data(sd->rid); - sd->w=sd->lock.write(); - } - - return true; -} -void *CPSampleManagerImpl::get_data(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - ERR_FAIL_COND_V(sd->locks==0,0); - return sd->w.ptr(); -} - -int16_t CPSampleManagerImpl::get_data(CPSample_ID p_id, int p_sample, int p_channel){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND_V(!valid.has(sd),0); -#endif - - ERR_FAIL_V(0); - lock_data(p_id); - - int sofs = sd->stereo ? 2:1; - uint16_t v=0; - if (sd->is16) { - int16_t *p=(int16_t*)sd->w.ptr(); - v=p[p_sample*sofs+p_channel]; - } else { - int8_t *p=(int8_t*)sd->w.ptr(); - v=p[p_sample*sofs+p_channel]; - } - - unlock_data(p_id); - - return v; -} -void CPSampleManagerImpl::set_data(CPSample_ID p_id, int p_sample, int16_t p_data,int p_channel){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - - ERR_FAIL(); - lock_data(p_id); - - int sofs = sd->stereo ? 2:1; - if (sd->is16) { - int16_t *p=(int16_t*)sd->w.ptr(); - p[p_sample*sofs+p_channel]=p_data; - } else { - int8_t *p=(int8_t*)sd->w.ptr(); - p[p_sample*sofs+p_channel]=p_data; - } - - unlock_data(p_id); - -} -void CPSampleManagerImpl::unlock_data(CPSample_ID p_id){ - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - - ERR_FAIL_COND(sd->locks==0); - - sd->locks--; - if (sd->locks==0) { - sd->w=PoolVector<uint8_t>::Write(); - AudioServer::get_singleton()->sample_set_data(sd->rid,sd->lock); - sd->lock=PoolVector<uint8_t>(); - } -} - -void CPSampleManagerImpl::get_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len) { - - SampleData *sd=_getsd(p_id); -#ifdef DEBUG_ENABLED - ERR_FAIL_COND(!valid.has(sd)); -#endif - - ERR_FAIL(); -} - - -/** MIXER **/ - -void CPMixerImpl::set_callback_interval(int p_interval_us) { - - callback_interval=p_interval_us; -} - -void CPMixerImpl::set_callback(void (*p_callback)(void*),void *p_userdata) { - - callback=p_callback; - userdata=p_userdata; -} - -void CPMixerImpl::setup_voice(int p_voice_index,CPSample_ID p_sample_id,int32_t p_start_index) { - - Voice &v=voices[p_voice_index]; - if (v.channel!=AudioMixer::INVALID_CHANNEL) { - mixer->channel_free(v.channel); - } - v.channel=mixer->channel_alloc(sample_manager->get_rid(p_sample_id)); - v.freq_mult = sample_manager->get_c5_freq(p_sample_id)/261.6255653006; - v.sample = p_sample_id; -} - -void CPMixerImpl::stop_voice(int p_voice_index) { - - Voice &v=voices[p_voice_index]; - if (v.channel==AudioMixer::INVALID_CHANNEL) - return; - - mixer->channel_free(v.channel); - v.channel=AudioMixer::INVALID_CHANNEL; - -} - -void CPMixerImpl::set_voice_frequency(int p_voice_index,int32_t p_freq) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - float f = p_freq / 256.0; - f*=pitch_scale; - mixer->channel_set_mix_rate(v.channel,f * v.freq_mult ); -} - -void CPMixerImpl::set_voice_panning(int p_voice_index,int p_pan) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - if (p_pan==CP_PAN_SURROUND) - p_pan=CP_PAN_CENTER; - float p = p_pan / 256.0; - mixer->channel_set_pan(v.channel,p); - -} - -void CPMixerImpl::set_voice_volume(int p_voice_index,int p_vol) { - - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - float vol = p_vol/512.0; - vol*=voice_scale; - mixer->channel_set_volume(v.channel,vol); - mixer->channel_set_reverb(v.channel,reverb_type,vol*v.reverb); -} - -void CPMixerImpl::set_voice_filter(int p_voice_index,bool p_enabled,uint8_t p_cutoff, uint8_t p_resonance ){ - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - -} - -void CPMixerImpl::set_voice_reverb_send(int p_voice_index,int p_reverb){ - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - v.reverb=p_reverb/255.0; - //mixer->channel_set_reverb(v.channel,reverb_type,p_reverb/255.0); - -} - -void CPMixerImpl::set_voice_chorus_send(int p_voice_index,int p_chorus){ - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - mixer->channel_set_chorus(v.channel,p_chorus/255.0); - -} - - -void CPMixerImpl::set_reverb_mode(ReverbMode p_mode){ - - //Voice &v=voices[p_voice_index]; - //ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - switch(p_mode) { - case CPMixer::REVERB_MODE_STUDIO_SMALL: reverb_type=AudioMixer::REVERB_SMALL; break; - case CPMixer::REVERB_MODE_STUDIO_MEDIUM: reverb_type=AudioMixer::REVERB_MEDIUM; break; - case CPMixer::REVERB_MODE_STUDIO_LARGE: reverb_type=AudioMixer::REVERB_LARGE; break; - case CPMixer::REVERB_MODE_HALL: reverb_type=AudioMixer::REVERB_HALL; break; - default: reverb_type=AudioMixer::REVERB_SMALL; break; - } - -} - -void CPMixerImpl::set_chorus_params(unsigned int p_delay_ms,unsigned int p_separation_ms,unsigned int p_depth_ms10,unsigned int p_speed_hz10){ - - //Voice &v=voices[p_voice_index]; - //ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); - -} - - - -/* Info retrieving */ - -int32_t CPMixerImpl::get_voice_sample_pos_index(int p_voice_index) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND_V(v.channel==AudioMixer::INVALID_CHANNEL,0); - return 0; - -} - -int CPMixerImpl::get_voice_panning(int p_voice_index) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND_V(!is_voice_active(p_voice_index),0); - return mixer->channel_get_pan(v.channel)*CP_PAN_RIGHT; - -} - -int CPMixerImpl::get_voice_volume(int p_voice_index) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND_V(!is_voice_active(p_voice_index),0); - return mixer->channel_get_volume(v.channel); - - -} - -CPSample_ID CPMixerImpl::get_voice_sample_id(int p_voice_index) { - - Voice &v=voices[p_voice_index]; - ERR_FAIL_COND_V(v.channel==AudioMixer::INVALID_CHANNEL,CPSample_ID()); - return v.sample; - - -} - -bool CPMixerImpl::is_voice_active(int p_voice_index){ - - Voice &v=voices[p_voice_index]; - if (v.channel==AudioMixer::INVALID_CHANNEL) - return false; - if (!mixer->channel_is_valid(v.channel)) - v.channel=AudioMixer::INVALID_CHANNEL; - - return v.channel!=AudioMixer::INVALID_CHANNEL; -} - -void CPMixerImpl::process_usecs(int p_usec,float p_volume,float p_pitch_scale,float p_tempo_scale) { - - ERR_FAIL_COND(callback_interval==0); - //update this somewhere - pitch_scale=p_pitch_scale; - tempo_scale=p_tempo_scale; - voice_scale = AudioServer::get_singleton()->get_event_voice_global_volume_scale()*p_volume; - while(p_usec) { - - if (p_usec>=callback_timeout) { - - p_usec-=callback_timeout; - callback_timeout=0; - if (callback) { - callback(userdata); - } - callback_timeout=callback_interval*(1.0/p_tempo_scale); - - } else { - - callback_timeout-=p_usec; - p_usec=0; - } - } -} - - -CPMixerImpl::CPMixerImpl(AudioMixer *p_mixer) { - - callback_interval=1; - callback_timeout=0; - userdata=0; - callback=0; - tempo_scale=1.0; - pitch_scale=1.0; - mixer=p_mixer; - voice_scale = AudioServer::get_singleton()->get_event_voice_global_volume_scale(); - reverb_type = AudioMixer::REVERB_SMALL; - -} - -/** FILE ACCESS WRAPPER **/ - - -CPFileAccessWrapperImpl::Error CPFileAccessWrapperImpl::open(const char *p_filename, int p_mode_flags) { - - ERR_FAIL_COND_V(p_mode_flags&WRITE,ERROR_WRITING_FILE); - close(); - f = FileAccess::open(String::utf8(p_filename),p_mode_flags); - if (!f) - return ERROR_FILE_NOT_FOUND; - return OK; -} - -void CPFileAccessWrapperImpl::close(){ - - if (f) - memdelete(f); - f=NULL; - - -} - -void CPFileAccessWrapperImpl::seek(uint32_t p_position){ - - f->seek(p_position); -} -void CPFileAccessWrapperImpl::seek_end(){ - - f->seek_end(); -} -uint32_t CPFileAccessWrapperImpl::get_pos(){ - - return f->get_pos(); -} - -bool CPFileAccessWrapperImpl::eof_reached(){ - - return f->eof_reached(); -} - -uint8_t CPFileAccessWrapperImpl::get_byte(){ - - return f->get_8(); -} -void CPFileAccessWrapperImpl::get_byte_array(uint8_t *p_dest,int p_elements){ - - f->get_buffer(p_dest,p_elements); -} -void CPFileAccessWrapperImpl::get_word_array(uint16_t *p_dest,int p_elements){ - - for(int i=0;i<p_elements;i++) { - p_dest[i]=f->get_16(); - } - -} - -uint16_t CPFileAccessWrapperImpl::get_word(){ - - return f->get_16(); -} -uint32_t CPFileAccessWrapperImpl::get_dword(){ - - return f->get_32(); -} - -void CPFileAccessWrapperImpl::set_endian_conversion(bool p_swap){ - - f->set_endian_swap(p_swap); -} -bool CPFileAccessWrapperImpl::is_open(){ - - return f!=NULL; -} - -CPFileAccessWrapperImpl::Error CPFileAccessWrapperImpl::get_error(){ - - return (f->get_error()!=::OK)?ERROR_READING_FILE:OK; -} - -void CPFileAccessWrapperImpl::store_byte(uint8_t p_dest){ - -} -void CPFileAccessWrapperImpl::store_byte_array(const uint8_t *p_dest,int p_elements){ - -} - -void CPFileAccessWrapperImpl::store_word(uint16_t p_dest){ - -} -void CPFileAccessWrapperImpl::store_dword(uint32_t p_dest){ - -} - -//////////////////////////////////////////////// - - -Error EventStreamPlaybackChibi::_play() { - - last_order=0; - loops=0; - player->play_start_song(); - total_usec=0; - - return OK; -} - -bool EventStreamPlaybackChibi::_update(AudioMixer* p_mixer, uint64_t p_usec){ - - total_usec+=p_usec; - mixer.process_usecs(p_usec,volume,pitch_scale,tempo_scale); - int order=player->get_current_order(); - if (order<last_order) { - if (!loop) { - stop(); - } else { - loops++; - } - } - last_order=order; - return false; -} -void EventStreamPlaybackChibi::_stop(){ - - player->play_stop(); -} - -void EventStreamPlaybackChibi::set_paused(bool p_paused){ - -} -bool EventStreamPlaybackChibi::is_paused() const{ - - return false; -} -void EventStreamPlaybackChibi::set_loop(bool p_loop){ - - loop=p_loop; - -} -bool EventStreamPlaybackChibi::is_loop_enabled() const{ - - return loop; -} - -int EventStreamPlaybackChibi::get_loop_count() const{ - - //return player->is - return loops; -} - -float EventStreamPlaybackChibi::get_pos() const{ - - return double(total_usec)/1000000.0; -} -void EventStreamPlaybackChibi::seek_pos(float p_time){ - - WARN_PRINT("seek_pos unimplemented."); -} - -void EventStreamPlaybackChibi::set_volume(float p_volume) { - - volume=p_volume; -} - -float EventStreamPlaybackChibi::get_volume() const{ - - return volume; -} - -void EventStreamPlaybackChibi::set_pitch_scale(float p_pitch_scale) { - - pitch_scale=p_pitch_scale; -} - -float EventStreamPlaybackChibi::get_pitch_scale() const{ - - return pitch_scale; -} - -void EventStreamPlaybackChibi::set_tempo_scale(float p_tempo_scale) { - - tempo_scale=p_tempo_scale; -} - -float EventStreamPlaybackChibi::get_tempo_scale() const{ - - return tempo_scale; -} - - -void EventStreamPlaybackChibi::set_channel_volume(int p_channel,float p_volume) { - - - if (p_channel>=64) - return; - player->set_channel_global_volume(p_channel,p_volume*256); -} - - - -float EventStreamPlaybackChibi::get_channel_volume(int p_channel) const{ - - return player->get_channel_global_volume(p_channel)/256.0; - -} - -float EventStreamPlaybackChibi::get_last_note_time(int p_channel) const { - - - double v = (player->get_channel_last_note_time_usec(p_channel))/1000000.0; - if (v<0) - v=-1; - return v; -} - -EventStreamPlaybackChibi::EventStreamPlaybackChibi(Ref<EventStreamChibi> p_stream) : mixer(_get_mixer()) { - - stream=p_stream; - player = memnew( CPPlayer(&mixer,&p_stream->song) ); - loop=false; - last_order=0; - loops=0; - volume=1.0; - pitch_scale=1.0; - tempo_scale=1.0; -} -EventStreamPlaybackChibi::~EventStreamPlaybackChibi(){ - - player->play_stop(); - memdelete(player); -} - -//////////////////////////////////////////////////// - -Ref<EventStreamPlayback> EventStreamChibi::instance_playback() { - - return Ref<EventStreamPlayback>( memnew(EventStreamPlaybackChibi(Ref<EventStreamChibi>(this))) ); -} - -String EventStreamChibi::get_stream_name() const{ - - return song.get_name(); - -} - - - -float EventStreamChibi::get_length() const{ - - return 1; -} - - -EventStreamChibi::EventStreamChibi() { - - -} - - - -////////////////////////////////////////////////////////////////// - - - - -RES ResourceFormatLoaderChibi::load(const String &p_path, const String& p_original_path, Error *r_error) { - - if (r_error) - *r_error=ERR_FILE_CANT_OPEN; - String el = p_path.get_extension().to_lower(); - - CPFileAccessWrapperImpl f; - - if (el=="it") { - - Ref<EventStreamChibi> esc( memnew( EventStreamChibi ) ); - CPLoader_IT loader(&f); - CPLoader::Error err = loader.load_song(p_path.utf8().get_data(),&esc->song,false); - ERR_FAIL_COND_V(err!=CPLoader::FILE_OK,RES()); - if (r_error) - *r_error=OK; - - return esc; - - } else if (el=="xm") { - - Ref<EventStreamChibi> esc( memnew( EventStreamChibi ) ); - CPLoader_XM loader(&f); - CPLoader::Error err=loader.load_song(p_path.utf8().get_data(),&esc->song,false); - ERR_FAIL_COND_V(err!=CPLoader::FILE_OK,RES()); - if (r_error) - *r_error=OK; - return esc; - - } else if (el=="s3m") { - - Ref<EventStreamChibi> esc( memnew( EventStreamChibi ) ); - CPLoader_S3M loader(&f); - CPLoader::Error err=loader.load_song(p_path.utf8().get_data(),&esc->song,false); - ERR_FAIL_COND_V(err!=CPLoader::FILE_OK,RES()); - if (r_error) - *r_error=OK; - - return esc; - - } else if (el=="mod") { - - Ref<EventStreamChibi> esc( memnew( EventStreamChibi ) ); - CPLoader_MOD loader(&f); - CPLoader::Error err=loader.load_song(p_path.utf8().get_data(),&esc->song,false); - ERR_FAIL_COND_V(err!=CPLoader::FILE_OK,RES()); - if (r_error) - *r_error=OK; - return esc; - } - - return RES(); - -} - -void ResourceFormatLoaderChibi::get_recognized_extensions(List<String> *p_extensions) const { - - p_extensions->push_back("it"); - p_extensions->push_back("xm"); - p_extensions->push_back("s3m"); - p_extensions->push_back("mod"); -} -bool ResourceFormatLoaderChibi::handles_type(const String& p_type) const { - - return (p_type=="EventStreamChibi" || p_type=="EventStream"); -} - -String ResourceFormatLoaderChibi::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); - if (el=="it" || el=="s3m" || el=="xm" || el=="mod") - return "EventStreamChibi"; - return ""; -} - -///////////////////////////////////////////////////////////////// -void initialize_chibi() { - - sample_manager = memnew( CPSampleManagerImpl ); - resource_loader = memnew( ResourceFormatLoaderChibi ); - ClassDB::register_class<EventStreamChibi>(); - ResourceLoader::add_resource_format_loader( resource_loader ); -} - -void finalize_chibi() { - - memdelete( sample_manager ); - memdelete( resource_loader ); -} - diff --git a/modules/chibi/event_stream_chibi.h b/modules/chibi/event_stream_chibi.h deleted file mode 100644 index 0244ee0a95..0000000000 --- a/modules/chibi/event_stream_chibi.h +++ /dev/null @@ -1,314 +0,0 @@ -/*************************************************************************/ -/* event_stream_chibi.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef EVENT_STREAM_CHIBI_H -#define EVENT_STREAM_CHIBI_H - -#include "scene/resources/event_stream.h" -#include "cp_sample_manager.h" -#include "cp_mixer.h" -#include "cp_song.h" -#include "cp_file_access_wrapper.h" -#include "cp_player_data.h" -#include "resource.h" -#include "servers/audio_server.h" -#include "os/file_access.h" -#include "io/resource_loader.h" - -/** SAMPLE MANAGER **/ - -class CPSampleManagerImpl : public CPSampleManager { - - struct SampleData { - - RID rid; - bool stereo; - bool is16; - int len; - int mixfreq; - int loop_begin; - int loop_end; - int locks; - PoolVector<uint8_t> lock; - PoolVector<uint8_t>::Write w; - CPSample_Loop_Type loop_type; - }; - - - _FORCE_INLINE_ SampleData* _getsd(CPSample_ID p_id) { - - return ((SampleData*)p_id._private); - } - Set<SampleData*> valid; - -public: - - _FORCE_INLINE_ RID get_rid(CPSample_ID p_id) { return _getsd(p_id)->rid; } - virtual CPSample_ID create(bool p_16bits,bool p_stereo,int32_t p_len); - virtual void recreate(CPSample_ID p_id,bool p_16bits,bool p_stereo,int32_t p_len); - virtual void destroy(CPSample_ID p_id); - virtual bool check(CPSample_ID p_id); // return false if invalid - - virtual void set_c5_freq(CPSample_ID p_id,int32_t p_freq); - virtual void set_loop_begin(CPSample_ID p_id,int32_t p_begin); - virtual void set_loop_end(CPSample_ID p_id,int32_t p_end); - virtual void set_loop_type(CPSample_ID p_id,CPSample_Loop_Type p_type); - virtual void set_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len); - - - virtual int32_t get_loop_begin(CPSample_ID p_id); - virtual int32_t get_loop_end(CPSample_ID p_id); - virtual CPSample_Loop_Type get_loop_type(CPSample_ID p_id); - virtual int32_t get_c5_freq(CPSample_ID p_id); - virtual int32_t get_size(CPSample_ID p_id); - virtual bool is_16bits(CPSample_ID p_id); - virtual bool is_stereo(CPSample_ID p_id); - virtual bool lock_data(CPSample_ID p_id); - virtual void *get_data(CPSample_ID p_id); /* WARNING: Not all sample managers -may be able to implement this, it depends on the mixer in use! */ - virtual int16_t get_data(CPSample_ID p_id, int p_sample, int p_channel=0); /// Does not need locking - virtual void set_data(CPSample_ID p_id, int p_sample, int16_t p_data,int p_channel=0); /// Does not need locking - virtual void unlock_data(CPSample_ID p_id); - - virtual void get_chunk(CPSample_ID p_id,int32_t p_index,void *p_data,int p_data_len); - -}; - - -/** MIXER **/ - -class CPMixerImpl : public CPMixer { - - enum { - MAX_VOICES=64 - }; - - struct Voice { - - AudioMixer::ChannelID channel; - CPSample_ID sample; - float freq_mult; - float reverb; - Voice() { reverb=0.0; } - }; - - Voice voices[MAX_VOICES]; - - - int callback_interval; - int callback_timeout; - void (*callback)(void*); - void *userdata; - float voice_scale; - float tempo_scale; - float pitch_scale; - AudioMixer::ReverbRoomType reverb_type; - AudioMixer *mixer; -public: - - void process_usecs(int p_usec,float p_volume,float p_pitch_scale,float p_tempo_scale); - - /* Callback */ - - virtual void set_callback_interval(int p_interval_us); //in usecs, for tracker it's 2500000/tempo - virtual void set_callback(void (*p_callback)(void*),void *p_userdata); - - /* Voice Control */ - - virtual void setup_voice(int p_voice_index,CPSample_ID p_sample_id,int32_t p_start_index) ; - virtual void stop_voice(int p_voice_index) ; - virtual void set_voice_frequency(int p_voice_index,int32_t p_freq) ; //in freq*FREQUENCY_BITS - virtual void set_voice_panning(int p_voice_index,int p_pan) ; - virtual void set_voice_volume(int p_voice_index,int p_vol) ; - virtual void set_voice_filter(int p_filter,bool p_enabled,uint8_t p_cutoff, uint8_t p_resonance ); - virtual void set_voice_reverb_send(int p_voice_index,int p_reverb); - virtual void set_voice_chorus_send(int p_voice_index,int p_chorus); /* 0 - 255 */ - - virtual void set_reverb_mode(ReverbMode p_mode); - virtual void set_chorus_params(unsigned int p_delay_ms,unsigned int p_separation_ms,unsigned int p_depth_ms10,unsigned int p_speed_hz10); - - - /* Info retrieving */ - - virtual int32_t get_voice_sample_pos_index(int p_voice_index) ; - virtual int get_voice_panning(int p_voice_index) ; - virtual int get_voice_volume(int p_voice_index) ; - virtual CPSample_ID get_voice_sample_id(int p_voice_index) ; - virtual bool is_voice_active(int p_voice_index); - virtual int get_active_voice_count() { return 0; } - virtual int get_total_voice_count() { return MAX_VOICES; } - - - virtual uint32_t get_mix_frequency() { return 0; } - - /* Methods below only work with software mixers, meant for software-based sound drivers, hardware mixers ignore them */ - virtual int32_t process(int32_t p_frames) { return 0; } - virtual int32_t *get_mixdown_buffer_ptr() { return NULL; } - virtual void set_mix_frequency(int32_t p_mix_frequency) {}; - - CPMixerImpl(AudioMixer *p_mixer=NULL); - virtual ~CPMixerImpl() {} -}; - -/** FILE ACCESS **/ - -class CPFileAccessWrapperImpl : public CPFileAccessWrapper { - - FileAccess *f; -public: - - - virtual Error open(const char *p_filename, int p_mode_flags); - virtual void close(); - - virtual void seek(uint32_t p_position); - virtual void seek_end(); - virtual uint32_t get_pos(); - - virtual bool eof_reached(); - - virtual uint8_t get_byte(); - virtual void get_byte_array(uint8_t *p_dest,int p_elements); - virtual void get_word_array(uint16_t *p_dest,int p_elements); - - virtual uint16_t get_word(); - virtual uint32_t get_dword(); - - virtual void set_endian_conversion(bool p_swap); - virtual bool is_open(); - - virtual Error get_error(); - - virtual void store_byte(uint8_t p_dest); - virtual void store_byte_array(const uint8_t *p_dest,int p_elements); - - virtual void store_word(uint16_t p_dest); - virtual void store_dword(uint32_t p_dest); - - CPFileAccessWrapperImpl() { f=NULL; } - virtual ~CPFileAccessWrapperImpl(){ if (f) memdelete(f); } - -}; - - - -///////////////////// - -class EventStreamChibi; - -class EventStreamPlaybackChibi : public EventStreamPlayback { - - GDCLASS(EventStreamPlaybackChibi,EventStreamPlayback); - - CPMixerImpl mixer; - uint64_t total_usec; - Ref<EventStreamChibi> stream; - mutable CPPlayer *player; - bool loop; - int last_order; - int loops; - virtual Error _play(); - virtual bool _update(AudioMixer* p_mixer, uint64_t p_usec); - virtual void _stop(); - float volume; - float tempo_scale; - float pitch_scale; - - -public: - - - virtual void set_paused(bool p_paused); - virtual bool is_paused() const; - - virtual void set_loop(bool p_loop); - virtual bool is_loop_enabled() const; - - virtual int get_loop_count() const; - - virtual float get_pos() const; - virtual void seek_pos(float p_time); - - virtual void set_volume(float p_vol); - virtual float get_volume() const; - - virtual void set_pitch_scale(float p_pitch_scale); - virtual float get_pitch_scale() const; - - virtual void set_tempo_scale(float p_tempo_scale); - virtual float get_tempo_scale() const; - - virtual void set_channel_volume(int p_channel,float p_volume); - virtual float get_channel_volume(int p_channel) const; - - virtual float get_last_note_time(int p_channel) const; - - EventStreamPlaybackChibi(Ref<EventStreamChibi> p_stream=Ref<EventStreamChibi>()); - ~EventStreamPlaybackChibi(); -}; - - -class EventStreamChibi : public EventStream { - - GDCLASS(EventStreamChibi,EventStream); - -friend class ResourceFormatLoaderChibi; -friend class EventStreamPlaybackChibi; - //I think i didn't know what const was when i wrote this more than a decade ago - //so it goes mutable :( - mutable CPSong song; - - -public: - - virtual Ref<EventStreamPlayback> instance_playback(); - - virtual String get_stream_name() const; - - virtual float get_length() const; - - virtual int get_channel_count() const { return 64; } //tracker limit - - EventStreamChibi(); -}; - - -class ResourceFormatLoaderChibi : public ResourceFormatLoader { - -public: - virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String& p_type) const; - virtual String get_resource_type(const String &p_path) const; - -}; - -void initialize_chibi(); -void finalize_chibi(); - -#endif // EVENT_STREAM_CHIBI_H diff --git a/modules/etc1/image_etc.cpp b/modules/etc1/image_etc.cpp index 36ff1b86df..2d883bff0f 100644 --- a/modules/etc1/image_etc.cpp +++ b/modules/etc1/image_etc.cpp @@ -95,7 +95,7 @@ static void _decompress_etc(Image *p_img) { //print_line("Re Creating ETC into regular image: w "+itos(p_img->get_width())+" h "+itos(p_img->get_height())+" mm "+itos(p_img->get_mipmaps())); *p_img=Image(p_img->get_width(),p_img->get_height(),p_img->has_mipmaps(),Image::FORMAT_RGB8,dst); if (p_img->has_mipmaps()) - p_img->generate_mipmaps(true); + p_img->generate_mipmaps(); } @@ -112,16 +112,17 @@ static void _compress_etc(Image *p_img) { img.convert(Image::FORMAT_RGB8); - int mmc=img.get_mipmap_count(); - if (mmc==0) - img.generate_mipmaps(); // force mipmaps, so it works on most hardware - - PoolVector<uint8_t> res_data; PoolVector<uint8_t> dst_data; PoolVector<uint8_t>::Read r = img.get_data().read(); + int target_size = Image::get_image_data_size(p_img->get_width(),p_img->get_height(),Image::FORMAT_ETC,p_img->has_mipmaps()?-1:0); + int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(p_img->get_width(),p_img->get_height(),Image::FORMAT_ETC) : 0; + + dst_data.resize(target_size); int mc=0; + int ofs=0; + PoolVector<uint8_t>::Write w=dst_data.write(); rg_etc1::etc1_pack_params pp; @@ -133,9 +134,9 @@ static void _compress_etc(Image *p_img) { int bh=MAX(imgh/4,1); const uint8_t *src = &r[img.get_mipmap_offset(i)]; int mmsize = MAX(bw,1)*MAX(bh,1)*8; - dst_data.resize(dst_data.size()+mmsize); - PoolVector<uint8_t>::Write w=dst_data.write(); - uint8_t *dst = &w[dst_data.size()-mmsize]; + + uint8_t *dst = &w[ofs]; + ofs+=mmsize; //print_line("bh: "+itos(bh)+" bw: "+itos(bw)); diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index a5351a584b..398c2cf82a 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -1576,7 +1576,7 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode * //funciton and class if (p_class->name) { - signature+="::"+String(p_class->name)+"."+String(func_name);; + signature+="::"+String(p_class->name)+"."+String(func_name); } else { signature+="::"+String(func_name); } diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index 19472d3d46..114a25feeb 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -2914,7 +2914,7 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol Ref<GDNativeClass> gdn = t.value; if (gdn.is_valid()) { r_result.type=ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT; - r_result.class_name=gdn->get_name();; + r_result.class_name=gdn->get_name(); r_result.class_member=p_symbol; return OK; diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp index 6659988602..51e2c1e2be 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gd_function.cpp @@ -331,8 +331,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a #endif ip+=5; - - } continue; + continue; + } case OPCODE_EXTENDS_TEST: { CHECK_SPACE(4); @@ -404,8 +404,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst=extends_ok; ip+=4; - - } continue; + continue; + } case OPCODE_SET: { CHECK_SPACE(3); @@ -429,7 +429,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } ip+=4; - } continue; + continue; + } case OPCODE_GET: { CHECK_SPACE(3); @@ -460,7 +461,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst=ret; #endif ip+=4; - } continue; + continue; + } case OPCODE_SET_NAMED: { CHECK_SPACE(3); @@ -483,7 +485,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } ip+=4; - } continue; + continue; + } case OPCODE_GET_NAMED: { @@ -518,7 +521,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst=ret; #endif ip+=4; - } continue; + continue; + } case OPCODE_SET_MEMBER: { CHECK_SPACE(3); @@ -540,7 +544,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } #endif ip+=3; - } continue; + continue; + } case OPCODE_GET_MEMBER: { CHECK_SPACE(3); @@ -557,8 +562,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } #endif ip+=3; - - } continue; + continue; + } case OPCODE_ASSIGN: { CHECK_SPACE(3); @@ -568,8 +573,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst = *src; ip+=3; - - } continue; + continue; + } case OPCODE_ASSIGN_TRUE: { CHECK_SPACE(2); @@ -578,7 +583,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst = true; ip+=2; - } continue; + continue; + } case OPCODE_ASSIGN_FALSE: { CHECK_SPACE(2); @@ -587,7 +593,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst = false; ip+=2; - } continue; + continue; + } case OPCODE_CONSTRUCT: { CHECK_SPACE(2); @@ -612,7 +619,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a ip+=4+argc; //construct a basic type - } continue; + continue; + } case OPCODE_CONSTRUCT_ARRAY: { CHECK_SPACE(1); @@ -632,8 +640,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst=array; ip+=3+argc; - - } continue; + continue; + } case OPCODE_CONSTRUCT_DICTIONARY: { CHECK_SPACE(1); @@ -655,8 +663,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a *dst=dict; ip+=3+argc*2; - - } continue; + continue; + } case OPCODE_CALL_RETURN: case OPCODE_CALL: { @@ -737,8 +745,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a //_call_func(NULL,base,*methodname,ip,argc,p_instance,stack); ip+=argc+1; - - } continue; + continue; + } case OPCODE_CALL_BUILT_IN: { CHECK_SPACE(4); @@ -775,12 +783,12 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a break; } ip+=argc+1; - - } continue; + continue; + } case OPCODE_CALL_SELF: { - - } break; + break; + } case OPCODE_CALL_SELF_BASE: { CHECK_SPACE(2); @@ -857,8 +865,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } ip+=4+argc; - - } continue; + continue; + } case OPCODE_YIELD: case OPCODE_YIELD_SIGNAL: { @@ -938,8 +946,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } exit_ok=true; - - } break; + break; + } case OPCODE_YIELD_RESUME: { CHECK_SPACE(2); @@ -950,8 +958,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a GET_VARIANT_PTR(result,1); *result=p_state->result; ip+=2; - - } continue; + continue; + } case OPCODE_JUMP: { CHECK_SPACE(2); @@ -959,8 +967,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a ERR_BREAK(to<0 || to>_code_size); ip=to; - - } continue; + continue; + } case OPCODE_JUMP_IF: { CHECK_SPACE(3); @@ -983,7 +991,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a continue; } ip+=3; - } continue; + continue; + } case OPCODE_JUMP_IF_NOT: { CHECK_SPACE(3); @@ -1006,21 +1015,22 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a continue; } ip+=3; - } continue; + continue; + } case OPCODE_JUMP_TO_DEF_ARGUMENT: { CHECK_SPACE(2); ip=_default_arg_ptr[defarg]; - - } continue; + continue; + } case OPCODE_RETURN: { CHECK_SPACE(2); GET_VARIANT_PTR(r,1); retvalue=*r; exit_ok=true; - - } break; + break; + } case OPCODE_ITERATE_BEGIN: { CHECK_SPACE(8); //space for this an regular iterate @@ -1050,8 +1060,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a ip+=5; //skip regular iterate which is always next - - } continue; + continue; + } case OPCODE_ITERATE: { CHECK_SPACE(4); @@ -1079,7 +1089,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } ip+=5; //loop again - } continue; + continue; + } case OPCODE_ASSERT: { CHECK_SPACE(2); GET_VARIANT_PTR(test,1); @@ -1105,7 +1116,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a #endif ip+=2; - } continue; + continue; + } case OPCODE_BREAKPOINT: { #ifdef DEBUG_ENABLED if (ScriptDebugger::get_singleton()) { @@ -1113,7 +1125,8 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } #endif ip+=1; - } continue; + continue; + } case OPCODE_LINE: { CHECK_SPACE(2); @@ -1142,17 +1155,19 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a ScriptDebugger::get_singleton()->line_poll(); } - } continue; + continue; + } case OPCODE_END: { exit_ok=true; break; - } break; + } default: { err_text="Illegal opcode "+itos(_code_ptr[ip])+" at address "+itos(ip); - } break; + break; + } } diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index 1c41b2e73b..d0fc241734 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "gd_functions.h" #include "math_funcs.h" -#include "object_type_db.h" +#include "class_db.h" #include "reference.h" #include "gd_script.h" #include "func_ref.h" @@ -159,85 +159,85 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va case MATH_SIN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::sin(*p_args[0]); + r_ret=Math::sin((double)*p_args[0]); } break; case MATH_COS: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::cos(*p_args[0]); + r_ret=Math::cos((double)*p_args[0]); } break; case MATH_TAN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::tan(*p_args[0]); + r_ret=Math::tan((double)*p_args[0]); } break; case MATH_SINH: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::sinh(*p_args[0]); + r_ret=Math::sinh((double)*p_args[0]); } break; case MATH_COSH: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::cosh(*p_args[0]); + r_ret=Math::cosh((double)*p_args[0]); } break; case MATH_TANH: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::tanh(*p_args[0]); + r_ret=Math::tanh((double)*p_args[0]); } break; case MATH_ASIN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::asin(*p_args[0]); + r_ret=Math::asin((double)*p_args[0]); } break; case MATH_ACOS: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::acos(*p_args[0]); + r_ret=Math::acos((double)*p_args[0]); } break; case MATH_ATAN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::atan(*p_args[0]); + r_ret=Math::atan((double)*p_args[0]); } break; case MATH_ATAN2: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::atan2(*p_args[0],*p_args[1]); + r_ret=Math::atan2((double)*p_args[0],(double)*p_args[1]); } break; case MATH_SQRT: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::sqrt(*p_args[0]); + r_ret=Math::sqrt((double)*p_args[0]); } break; case MATH_FMOD: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::fmod(*p_args[0],*p_args[1]); + r_ret=Math::fmod((double)*p_args[0],(double)*p_args[1]); } break; case MATH_FPOSMOD: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::fposmod(*p_args[0],*p_args[1]); + r_ret=Math::fposmod((double)*p_args[0],(double)*p_args[1]); } break; case MATH_FLOOR: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::floor(*p_args[0]); + r_ret=Math::floor((double)*p_args[0]); } break; case MATH_CEIL: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::ceil(*p_args[0]); + r_ret=Math::ceil((double)*p_args[0]); } break; case MATH_ROUND: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::round(*p_args[0]); + r_ret=Math::round((double)*p_args[0]); } break; case MATH_ABS: { VALIDATE_ARG_COUNT(1); @@ -247,7 +247,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va r_ret=ABS(i); } else if (p_args[0]->get_type()==Variant::REAL) { - real_t r = *p_args[0]; + double r = *p_args[0]; r_ret=Math::abs(r); } else { @@ -279,58 +279,58 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::pow(*p_args[0],*p_args[1]); + r_ret=Math::pow((double)*p_args[0],(double)*p_args[1]); } break; case MATH_LOG: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::log(*p_args[0]); + r_ret=Math::log((double)*p_args[0]); } break; case MATH_EXP: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::exp(*p_args[0]); + r_ret=Math::exp((double)*p_args[0]); } break; case MATH_ISNAN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::is_nan(*p_args[0]); + r_ret=Math::is_nan((double)*p_args[0]); } break; case MATH_ISINF: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::is_inf(*p_args[0]); + r_ret=Math::is_inf((double)*p_args[0]); } break; case MATH_EASE: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::ease(*p_args[0],*p_args[1]); + r_ret=Math::ease((double)*p_args[0],(double)*p_args[1]); } break; case MATH_DECIMALS: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::step_decimals(*p_args[0]); + r_ret=Math::step_decimals((double)*p_args[0]); } break; case MATH_STEPIFY: { VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::stepify(*p_args[0],*p_args[1]); + r_ret=Math::stepify((double)*p_args[0],(double)*p_args[1]); } break; case MATH_LERP: { VALIDATE_ARG_COUNT(3); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); - r_ret=Math::lerp(*p_args[0],*p_args[1],*p_args[2]); + r_ret=Math::lerp((double)*p_args[0],(double)*p_args[1],(double)*p_args[2]); } break; case MATH_DECTIME: { VALIDATE_ARG_COUNT(3); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); - r_ret=Math::dectime(*p_args[0],*p_args[1],*p_args[2]); + r_ret=Math::dectime((double)*p_args[0],(double)*p_args[1],(double)*p_args[2]); } break; case MATH_RANDOMIZE: { Math::randomize(); @@ -346,19 +346,19 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va VALIDATE_ARG_COUNT(2); VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - r_ret=Math::random(*p_args[0],*p_args[1]); + r_ret=Math::random((double)*p_args[0],(double)*p_args[1]); } break; case MATH_SEED: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - uint32_t seed=*p_args[0]; + uint64_t seed=*p_args[0]; Math::seed(seed); r_ret=Variant(); } break; case MATH_RANDSEED: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - uint32_t seed=*p_args[0]; + uint64_t seed=*p_args[0]; int ret = Math::rand_from_seed(&seed); Array reta; reta.push_back(ret); @@ -369,22 +369,22 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va case MATH_DEG2RAD: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::deg2rad(*p_args[0]); + r_ret=Math::deg2rad((double)*p_args[0]); } break; case MATH_RAD2DEG: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::rad2deg(*p_args[0]); + r_ret=Math::rad2deg((double)*p_args[0]); } break; case MATH_LINEAR2DB: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::linear2db(*p_args[0]); + r_ret=Math::linear2db((double)*p_args[0]); } break; case MATH_DB2LINEAR: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); - r_ret=Math::db2linear(*p_args[0]); + r_ret=Math::db2linear((double)*p_args[0]); } break; case LOGIC_MAX: { VALIDATE_ARG_COUNT(2); @@ -555,7 +555,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va String str; for(int i=0;i<p_arg_count;i++) { - String os = p_args[i]->operator String();; + String os = p_args[i]->operator String(); if (i==0) str=os; diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 4a36fbb4f1..c1c1f5d5a9 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -643,7 +643,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ case GDTokenizer::TK_OP_ADD: e.op=OperatorNode::OP_POS; break; case GDTokenizer::TK_OP_SUB: e.op=OperatorNode::OP_NEG; break; case GDTokenizer::TK_OP_NOT: e.op=OperatorNode::OP_NOT; break; - case GDTokenizer::TK_OP_BIT_INVERT: e.op=OperatorNode::OP_BIT_INVERT;; break; + case GDTokenizer::TK_OP_BIT_INVERT: e.op=OperatorNode::OP_BIT_INVERT; break; default: {} } @@ -1043,8 +1043,8 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ case GDTokenizer::TK_OP_ASSIGN_MUL: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_MUL ; break; case GDTokenizer::TK_OP_ASSIGN_DIV: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_DIV ; break; case GDTokenizer::TK_OP_ASSIGN_MOD: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_MOD ; break; - case GDTokenizer::TK_OP_ASSIGN_SHIFT_LEFT: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SHIFT_LEFT; ; break; - case GDTokenizer::TK_OP_ASSIGN_SHIFT_RIGHT: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SHIFT_RIGHT; ; break; + case GDTokenizer::TK_OP_ASSIGN_SHIFT_LEFT: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SHIFT_LEFT; break; + case GDTokenizer::TK_OP_ASSIGN_SHIFT_RIGHT: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_SHIFT_RIGHT; break; case GDTokenizer::TK_OP_ASSIGN_BIT_AND: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_BIT_AND ; break; case GDTokenizer::TK_OP_ASSIGN_BIT_OR: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_BIT_OR ; break; case GDTokenizer::TK_OP_ASSIGN_BIT_XOR: _VALIDATE_ASSIGN op=OperatorNode::OP_ASSIGN_BIT_XOR ; break; @@ -1704,7 +1704,7 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) } switch (token) { - // dictionary + // array case GDTokenizer::TK_BRACKET_OPEN: { tokenizer->advance(); pattern->pt_type = GDParser::PatternNode::PT_ARRAY; @@ -1759,7 +1759,7 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) pattern->bind = tokenizer->get_token_identifier(); tokenizer->advance(); } break; - // array + // dictionary case GDTokenizer::TK_CURLY_BRACKET_OPEN: { tokenizer->advance(); pattern->pt_type = GDParser::PatternNode::PT_DICTIONARY; @@ -1826,17 +1826,16 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) } } } break; + case GDTokenizer::TK_WILDCARD: { + tokenizer->advance(); + pattern->pt_type = PatternNode::PT_WILDCARD; + } break; // all the constants like strings and numbers default: { Node *value = _parse_and_reduce_expression(pattern, p_static); if (error_set) { return NULL; } - if (value->type == Node::TYPE_IDENTIFIER && static_cast<IdentifierNode*>(value)->name == "_") { - // wildcard pattern - pattern->pt_type = PatternNode::PT_WILDCARD; - break; - } if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) { _set_error("Only constant expressions or variables allowed in a pattern"); @@ -2578,7 +2577,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { Vector<Node*> args; Vector<double> constants; - bool constant=true; + bool constant=false; for(int i=1;i<op->arguments.size();i++) { args.push_back(op->arguments[i]); @@ -2586,13 +2585,12 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { ConstantNode *c = static_cast<ConstantNode*>(op->arguments[i]); if (c->value.get_type()==Variant::REAL || c->value.get_type()==Variant::INT) { constants.push_back(c->value); - } else { - constant=false; + constant=true; } } } - if (args.size()>0 || args.size()<4) { + if (args.size()>0 && args.size()<4) { if (constant) { diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index d9a3dd13f0..89df7e962a 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -541,7 +541,7 @@ bool GDScript::_update_exports() { } } - members_cache.clear();; + members_cache.clear(); member_default_values_cache.clear(); for(int i=0;i<c->variables.size();i++) { diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 70fc991bcc..5be2a2beae 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -119,6 +119,7 @@ const char* GDTokenizer::token_names[TK_MAX]={ "':'", "'\\n'", "PI", +"_", "Error", "EOF", "Cursor"}; @@ -899,6 +900,7 @@ void GDTokenizerText::_advance() { {TK_CF_PASS,"pass"}, {TK_SELF,"self"}, {TK_CONST_PI,"PI"}, + {TK_WILDCARD,"_"}, {TK_ERROR,NULL} }; diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h index 9a6f4df9c4..5d955ff1ae 100644 --- a/modules/gdscript/gd_tokenizer.h +++ b/modules/gdscript/gd_tokenizer.h @@ -127,6 +127,7 @@ public: TK_DOLLAR, TK_NEWLINE, TK_CONST_PI, + TK_WILDCARD, TK_ERROR, TK_EOF, TK_CURSOR, //used for code completion diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 051d1d85cd..db47ee43ce 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -38,7 +38,7 @@ GDScriptLanguage *script_language_gd=NULL; ResourceFormatLoaderGDScript *resource_loader_gd=NULL; ResourceFormatSaverGDScript *resource_saver_gd=NULL; - +#if 0 #ifdef TOOLS_ENABLED #include "tools/editor/editor_import_export.h" @@ -135,7 +135,7 @@ static void register_editor_plugin() { #endif - +#endif void register_gdscript_types() { ClassDB::register_class<GDScript>(); @@ -148,11 +148,12 @@ void register_gdscript_types() { ResourceLoader::add_resource_format_loader(resource_loader_gd); resource_saver_gd=memnew( ResourceFormatSaverGDScript ); ResourceSaver::add_resource_format_saver(resource_saver_gd); - +#if 0 #ifdef TOOLS_ENABLED EditorNode::add_init_callback(register_editor_plugin); #endif +#endif } void unregister_gdscript_types() { diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 271db4babc..2dd7e951ab 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -65,7 +65,7 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { int amount=cells.size(); PoolVector<int>::Read r = cells.read(); ERR_FAIL_COND_V(amount&1,false); // not even - cell_map.clear();; + cell_map.clear(); for(int i=0;i<amount/3;i++) { @@ -90,7 +90,7 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { int amount=cells.size(); PoolVector<int>::Read r = cells.read(); ERR_FAIL_COND_V(amount%3,false); // not even - cell_map.clear();; + cell_map.clear(); for(int i=0;i<amount/3;i++) { IndexKey ik; @@ -123,7 +123,7 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { Octant &g = *octant_map[ok]; g.baked=b; - g.bake_instance=VS::get_singleton()->instance_create();; + g.bake_instance=VS::get_singleton()->instance_create(); VS::get_singleton()->instance_set_base(g.bake_instance,g.baked->get_rid()); VS::get_singleton()->instance_geometry_set_baked_light(g.bake_instance,baked_light_instance?baked_light_instance->get_baked_light_instance():RID()); } @@ -908,7 +908,7 @@ void GridMap::_octant_bake(const OctantKey &p_key, const Ref<TriangleMesh>& p_tm if (V) V=V->next(); else - V=st->get_vertex_array().front();; + V=st->get_vertex_array().front(); int lc = p_lights.size(); const BakeLight* bl = p_lights.ptr(); float ofs = cell_size*0.02; diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 109f6338db..0d57ffa394 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -903,7 +903,7 @@ void GridMapEditor::edit(GridMap *p_gridmap) { Vector3 axis; axis[i]=1; Vector3 axis_n1; - axis_n1[(i+1)%3]=cell_size[(i+1)%3];; + axis_n1[(i+1)%3]=cell_size[(i+1)%3]; Vector3 axis_n2; axis_n2[(i+2)%3]=cell_size[(i+2)%3]; @@ -1274,8 +1274,8 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { edit_mode = memnew(OptionButton); edit_mode->set_area_as_parent_rect(); - edit_mode->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_BEGIN,24);; - edit_mode->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,14);; + edit_mode->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_BEGIN,24); + edit_mode->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,14); edit_mode->add_item("Tiles"); edit_mode->add_item("Areas"); hb->add_child(edit_mode); diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp index b4a0d3b0b7..9cd70a0f9b 100644 --- a/modules/gridmap/register_types.cpp +++ b/modules/gridmap/register_types.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "register_types.h" #ifndef _3D_DISABLED -#include "object_type_db.h" +#include "class_db.h" #include "grid_map.h" #include "grid_map_editor_plugin.h" #endif diff --git a/modules/ogg/config.py b/modules/ogg/config.py index fb920482f5..ef5daca05c 100644 --- a/modules/ogg/config.py +++ b/modules/ogg/config.py @@ -1,6 +1,7 @@ def can_build(platform): - return True +# return True + return False def configure(env): diff --git a/modules/opus/config.py b/modules/opus/config.py index fb920482f5..ef5daca05c 100644 --- a/modules/opus/config.py +++ b/modules/opus/config.py @@ -1,6 +1,7 @@ def can_build(platform): - return True +# return True + return False def configure(env): diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 0d8cabb331..9805675f2c 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -464,16 +464,19 @@ static void get_modulation_value(int x, int y, const int p_2bit, const int p_mod if(((x^y)&1)==0) mod_val = rep_vals0[p_modulation[y][x]]; else if(p_modulation_modes[y][x] == 1) { - mod_val = (rep_vals0[p_modulation[y-1][x]] + - rep_vals0[p_modulation[y+1][x]] + - rep_vals0[p_modulation[y][x-1]] + - rep_vals0[p_modulation[y][x+1]] + 2) / 4; + mod_val = ( + rep_vals0[p_modulation[y-1][x]] + + rep_vals0[p_modulation[y+1][x]] + + rep_vals0[p_modulation[y][x-1]] + + rep_vals0[p_modulation[y][x+1]] + 2) / 4; } else if(p_modulation_modes[y][x] == 2) { - mod_val = (rep_vals0[p_modulation[y][x-1]] + - rep_vals0[p_modulation[y][x+1]] + 1) / 2; + mod_val = ( + rep_vals0[p_modulation[y][x-1]] + + rep_vals0[p_modulation[y][x+1]] + 1) / 2; } else { - mod_val = (rep_vals0[p_modulation[y-1][x]] + - rep_vals0[p_modulation[y+1][x]] + 1) / 2; + mod_val = ( + rep_vals0[p_modulation[y-1][x]] + + rep_vals0[p_modulation[y+1][x]] + 1) / 2; } } else { mod_val = rep_vals1[p_modulation[y][x]]; @@ -615,11 +618,12 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int for(j = 0; j < 2; j++) { unpack_5554(p_blocks[i][j], colors5554[i][j].Reps); - unpack_modulations(p_blocks[i][j], - p_2bit, - p_modulation, - p_modulation_modes, - p_x, p_y); + unpack_modulations( + p_blocks[i][j], + p_2bit, + p_modulation, + p_modulation_modes, + p_x, p_y); p_x += x_block_size; } @@ -632,19 +636,21 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int } - interpolate_colors(colors5554[0][0].Reps[0], - colors5554[0][1].Reps[0], - colors5554[1][0].Reps[0], - colors5554[1][1].Reps[0], - p_2bit, x, y, - ASig); - - interpolate_colors(colors5554[0][0].Reps[1], - colors5554[0][1].Reps[1], - colors5554[1][0].Reps[1], - colors5554[1][1].Reps[1], - p_2bit, x, y, - BSig); + interpolate_colors( + colors5554[0][0].Reps[0], + colors5554[0][1].Reps[0], + colors5554[1][0].Reps[0], + colors5554[1][1].Reps[0], + p_2bit, x, y, + ASig); + + interpolate_colors( + colors5554[0][0].Reps[1], + colors5554[0][1].Reps[1], + colors5554[1][0].Reps[1], + colors5554[1][1].Reps[1], + p_2bit, x, y, + BSig); get_modulation_value(x,y, p_2bit, (const int (*)[16])p_modulation, (const int (*)[16])p_modulation_modes, &Mod, &DoPT); diff --git a/modules/regex/register_types.cpp b/modules/regex/register_types.cpp index d44c7e563c..c62a04d80f 100644 --- a/modules/regex/register_types.cpp +++ b/modules/regex/register_types.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "register_types.h" -#include "object_type_db.h" +#include "class_db.h" #include "regex.h" void register_regex_types() { diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index 7410658603..28c200596b 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -54,20 +54,19 @@ void image_compress_squish(Image *p_image) { if (p_image->get_format()==Image::FORMAT_LA8) { //compressed normalmap - target_format = Image::FORMAT_DXT5; squish_comp|=squish::kDxt5;; + target_format = Image::FORMAT_DXT5; squish_comp|=squish::kDxt5; } else if (p_image->detect_alpha()!=Image::ALPHA_NONE) { - target_format = Image::FORMAT_DXT3; squish_comp|=squish::kDxt3;; + target_format = Image::FORMAT_DXT3; squish_comp|=squish::kDxt3; } else { - target_format = Image::FORMAT_DXT1; shift=1; squish_comp|=squish::kDxt1;; + target_format = Image::FORMAT_DXT1; shift=1; squish_comp|=squish::kDxt1; } p_image->convert(Image::FORMAT_RGBA8); //always expects rgba - int mm_count = p_image->get_mipmap_count(); - PoolVector<uint8_t> data; - int target_size = Image::get_image_data_size(w,h,target_format,mm_count); + int target_size = Image::get_image_data_size(w,h,target_format,p_image->has_mipmaps()?-1:0); + int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w,h,target_format) : 0; data.resize(target_size); PoolVector<uint8_t>::Read rb = p_image->get_data().read(); diff --git a/modules/stb_vorbis/SCsub b/modules/stb_vorbis/SCsub new file mode 100644 index 0000000000..897d05961c --- /dev/null +++ b/modules/stb_vorbis/SCsub @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +# Thirdparty source files + +env_stb_vorbis = env_modules.Clone() + +env_stb_vorbis.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp new file mode 100644 index 0000000000..4b4c57fbdd --- /dev/null +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -0,0 +1,232 @@ + +#include "audio_stream_ogg_vorbis.h" +#include "thirdparty/stb_vorbis/stb_vorbis.c" +#include "os/file_access.h" + + +void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame* p_buffer,int p_frames) { + + ERR_FAIL_COND(!active); + + int todo=p_frames; + + while(todo) { + + int mixed = stb_vorbis_get_samples_float_interleaved(ogg_stream,2,(float*)p_buffer,todo*2); + todo-=mixed; + + if (todo) { + //end of file! + if (vorbis_stream->loop) { + //loop + seek_pos(0); + loops++; + } else { + for(int i=mixed;i<p_frames;i++) { + p_buffer[i]=AudioFrame(0,0); + } + active=false; + } + } + } + + +} + +float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() { + + return vorbis_stream->sample_rate; +} + + +void AudioStreamPlaybackOGGVorbis::start(float p_from_pos) { + + seek_pos(p_from_pos); + active=true; + loops=0; + _begin_resample(); + + +} + +void AudioStreamPlaybackOGGVorbis::stop() { + + active=false; +} +bool AudioStreamPlaybackOGGVorbis::is_playing() const { + + return active; +} + +int AudioStreamPlaybackOGGVorbis::get_loop_count() const { + + return loops; +} + +float AudioStreamPlaybackOGGVorbis::get_pos() const { + + return float(frames_mixed)/vorbis_stream->sample_rate; +} +void AudioStreamPlaybackOGGVorbis::seek_pos(float p_time) { + + if (!active) + return; + + stb_vorbis_seek(ogg_stream, uint32_t(p_time*vorbis_stream->sample_rate)); +} + +float AudioStreamPlaybackOGGVorbis::get_length() const { + + return vorbis_stream->length; +} + +AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() { + if (ogg_alloc.alloc_buffer) { + AudioServer::get_singleton()->audio_data_free(ogg_alloc.alloc_buffer); + stb_vorbis_close(ogg_stream); + } +} + +Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { + + + + Ref<AudioStreamPlaybackOGGVorbis> ovs; + printf("instance at %p, data %p\n",this,data); + + ERR_FAIL_COND_V(data==NULL,ovs); + + ovs.instance(); + ovs->vorbis_stream=Ref<AudioStreamOGGVorbis>(this); + ovs->ogg_alloc.alloc_buffer=(char*)AudioServer::get_singleton()->audio_data_alloc(decode_mem_size); + ovs->ogg_alloc.alloc_buffer_length_in_bytes=decode_mem_size; + ovs->frames_mixed=0; + ovs->active=false; + ovs->loops=0; + int error ; + ovs->ogg_stream = stb_vorbis_open_memory( (const unsigned char*)data, data_len, &error, &ovs->ogg_alloc ); + if (!ovs->ogg_stream) { + + AudioServer::get_singleton()->audio_data_free(ovs->ogg_alloc.alloc_buffer); + ovs->ogg_alloc.alloc_buffer=NULL; + ERR_FAIL_COND_V(!ovs->ogg_stream,Ref<AudioStreamPlaybackOGGVorbis>()); + } + + return ovs; +} + +String AudioStreamOGGVorbis::get_stream_name() const { + + return "";//return stream_name; +} + +void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t>& p_data) { + + int src_data_len=p_data.size(); +#define MAX_TEST_MEM (1<<20) + + uint32_t alloc_try=1024; + PoolVector<char> alloc_mem; + PoolVector<char>::Write w; + stb_vorbis * ogg_stream=NULL; + stb_vorbis_alloc ogg_alloc; + + while(alloc_try<MAX_TEST_MEM) { + + alloc_mem.resize(alloc_try); + w = alloc_mem.write(); + + ogg_alloc.alloc_buffer=w.ptr(); + ogg_alloc.alloc_buffer_length_in_bytes=alloc_try; + + PoolVector<uint8_t>::Read src_datar = p_data.read(); + + int error; + ogg_stream = stb_vorbis_open_memory( (const unsigned char*)src_datar.ptr(), src_data_len, &error, &ogg_alloc ); + + if (!ogg_stream && error==VORBIS_outofmem) { + w = PoolVector<char>::Write(); + alloc_try*=2; + } else { + + ERR_FAIL_COND(alloc_try==MAX_TEST_MEM); + ERR_FAIL_COND(ogg_stream==NULL); + + stb_vorbis_info info = stb_vorbis_get_info(ogg_stream); + + channels = info.channels; + sample_rate = info.sample_rate; + decode_mem_size = alloc_try; + //does this work? (it's less mem..) + //decode_mem_size = ogg_alloc.alloc_buffer_length_in_bytes + info.setup_memory_required + info.temp_memory_required + info.max_frame_size; + + //print_line("succeded "+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); + stb_vorbis_close(ogg_stream); + + data = AudioServer::get_singleton()->audio_data_alloc(src_data_len,src_datar.ptr()); + data_len=src_data_len; + + break; + } + } + + + printf("create at %p, data %p\n",this,data); + +} + +PoolVector<uint8_t> AudioStreamOGGVorbis::get_data() const { + + PoolVector<uint8_t> vdata; + + if (data_len && data) { + vdata.resize(data_len); + { + PoolVector<uint8_t>::Write w = vdata.write(); + copymem(w.ptr(),data,data_len); + } + + } + + return vdata; +} + +void AudioStreamOGGVorbis::set_loop(bool p_enable) { + loop=p_enable; +} + +bool AudioStreamOGGVorbis::has_loop() const { + + return loop; +} + + +void AudioStreamOGGVorbis::_bind_methods() { + + ClassDB::bind_method(_MD("set_data","data"),&AudioStreamOGGVorbis::set_data); + ClassDB::bind_method(_MD("get_data"),&AudioStreamOGGVorbis::get_data); + + ClassDB::bind_method(_MD("set_loop","enable"),&AudioStreamOGGVorbis::set_loop); + ClassDB::bind_method(_MD("has_loop"),&AudioStreamOGGVorbis::has_loop); + + ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_data"),_SCS("get_data")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"loop",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_loop"),_SCS("has_loop")); + +} + +AudioStreamOGGVorbis::AudioStreamOGGVorbis() { + + + data=NULL; + length=0; + sample_rate=1; + channels=1; + decode_mem_size=0; + loop=false; +} + + + + diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h new file mode 100644 index 0000000000..21ce23740c --- /dev/null +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -0,0 +1,83 @@ +#ifndef AUDIO_STREAM_STB_VORBIS_H +#define AUDIO_STREAM_STB_VORBIS_H + +#include "servers/audio/audio_stream.h" +#include "io/resource_loader.h" + +#define STB_VORBIS_HEADER_ONLY +#include "thirdparty/stb_vorbis/stb_vorbis.c" +#undef STB_VORBIS_HEADER_ONLY + + +class AudioStreamOGGVorbis; + +class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled { + + GDCLASS( AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled ) + + stb_vorbis * ogg_stream; + stb_vorbis_alloc ogg_alloc; + uint32_t frames_mixed; + bool active; + int loops; + +friend class AudioStreamOGGVorbis; + + Ref<AudioStreamOGGVorbis> vorbis_stream; +protected: + + virtual void _mix_internal(AudioFrame* p_buffer, int p_frames); + virtual float get_stream_sampling_rate(); + +public: + virtual void start(float p_from_pos=0.0); + virtual void stop(); + virtual bool is_playing() const; + + virtual int get_loop_count() const; //times it looped + + virtual float get_pos() const; + virtual void seek_pos(float p_time); + + virtual float get_length() const; //if supported, otherwise return 0 + + AudioStreamPlaybackOGGVorbis() { } + ~AudioStreamPlaybackOGGVorbis(); +}; + +class AudioStreamOGGVorbis : public AudioStream { + + GDCLASS( AudioStreamOGGVorbis, AudioStream ) + OBJ_SAVE_TYPE( AudioStream ) //children are all saved as AudioStream, so they can be exchanged + RES_BASE_EXTENSION("asogg"); + +friend class AudioStreamPlaybackOGGVorbis; + + void *data; + uint32_t data_len; + + int decode_mem_size; + float sample_rate; + int channels; + float length; + bool loop; +protected: + + static void _bind_methods(); +public: + + void set_loop(bool p_enable); + bool has_loop() const; + + virtual Ref<AudioStreamPlayback> instance_playback(); + virtual String get_stream_name() const; + + void set_data(const PoolVector<uint8_t>& p_data); + PoolVector<uint8_t> get_data() const; + + AudioStreamOGGVorbis(); +}; + + + +#endif diff --git a/modules/chibi/config.py b/modules/stb_vorbis/config.py index fb920482f5..fb920482f5 100644 --- a/modules/chibi/config.py +++ b/modules/stb_vorbis/config.py diff --git a/modules/chibi/register_types.cpp b/modules/stb_vorbis/register_types.cpp index 1a0c808819..41fbc6fbd7 100644 --- a/modules/chibi/register_types.cpp +++ b/modules/stb_vorbis/register_types.cpp @@ -27,15 +27,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "register_types.h" +#include "audio_stream_ogg_vorbis.h" +#include "resource_importer_ogg_vorbis.h" -#include "event_stream_chibi.h" +void register_stb_vorbis_types() { -void register_chibi_types() { - - initialize_chibi(); +#ifdef TOOLS_ENABLED + Ref<ResourceImporterOGGVorbis> ogg_import; + ogg_import.instance(); + ResourceFormatImporter::get_singleton()->add_importer(ogg_import); +#endif + ClassDB::register_class<AudioStreamOGGVorbis>(); } -void unregister_chibi_types() { +void unregister_stb_vorbis_types() { - finalize_chibi(); } diff --git a/modules/chibi/register_types.h b/modules/stb_vorbis/register_types.h index 08856c0744..2824aa9f0c 100644 --- a/modules/chibi/register_types.h +++ b/modules/stb_vorbis/register_types.h @@ -26,5 +26,5 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -void register_chibi_types(); -void unregister_chibi_types(); +void register_stb_vorbis_types(); +void unregister_stb_vorbis_types(); diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp new file mode 100644 index 0000000000..6f90c8587b --- /dev/null +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -0,0 +1,84 @@ +#include "resource_importer_ogg_vorbis.h" + +#include "io/resource_saver.h" +#include "os/file_access.h" +#include "scene/resources/texture.h" + +String ResourceImporterOGGVorbis::get_importer_name() const { + + return "ogg_vorbis"; +} + +String ResourceImporterOGGVorbis::get_visible_name() const{ + + return "OGGVorbis"; +} +void ResourceImporterOGGVorbis::get_recognized_extensions(List<String> *p_extensions) const{ + + p_extensions->push_back("ogg"); +} + +String ResourceImporterOGGVorbis::get_save_extension() const { + return "asogg"; +} + +String ResourceImporterOGGVorbis::get_resource_type() const{ + + return "AudioStreamOGGVorbis"; +} + +bool ResourceImporterOGGVorbis::get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const { + + return true; +} + +int ResourceImporterOGGVorbis::get_preset_count() const { + return 0; +} +String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const { + + return String(); +} + + +void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *r_options,int p_preset) const { + + + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"loop"),true)); + +} + + + +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"]; + + FileAccess *f = FileAccess::open(p_source_file,FileAccess::READ); + if (!f) { + ERR_FAIL_COND_V(!f,ERR_CANT_OPEN); + } + + size_t len = f->get_len(); + + PoolVector<uint8_t> data; + data.resize(len); + PoolVector<uint8_t>::Write w = data.write(); + + f->get_buffer(w.ptr(),len); + + memdelete(f); + + Ref<AudioStreamOGGVorbis> ogg_stream; + ogg_stream.instance(); + + ogg_stream->set_data(data); + ogg_stream->set_loop(loop); + + return ResourceSaver::save(p_save_path+".asogg",ogg_stream); +} + +ResourceImporterOGGVorbis::ResourceImporterOGGVorbis() +{ + +} diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.h b/modules/stb_vorbis/resource_importer_ogg_vorbis.h new file mode 100644 index 0000000000..8a3b2d8ec6 --- /dev/null +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.h @@ -0,0 +1,28 @@ +#ifndef RESOURCEIMPORTEROGGVORBIS_H +#define RESOURCEIMPORTEROGGVORBIS_H + + +#include "io/resource_import.h" +#include "audio_stream_ogg_vorbis.h" + +class ResourceImporterOGGVorbis : public ResourceImporter { + GDCLASS(ResourceImporterOGGVorbis,ResourceImporter) +public: + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const; + virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const; + + virtual Error 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=NULL); + + ResourceImporterOGGVorbis(); +}; + +#endif // RESOURCEIMPORTEROGGVORBIS_H diff --git a/modules/theora/config.py b/modules/theora/config.py index fb920482f5..8eefe81288 100644 --- a/modules/theora/config.py +++ b/modules/theora/config.py @@ -1,6 +1,7 @@ def can_build(platform): - return True +# return True + return False def configure(env): diff --git a/modules/theora/yuv2rgb.h b/modules/theora/yuv2rgb.h index 431b47e651..3b81607a65 100644 --- a/modules/theora/yuv2rgb.h +++ b/modules/theora/yuv2rgb.h @@ -3,8 +3,7 @@ #include "typedefs.h" -static const uint32_t tables[256*3] = -{ +static const uint32_t tables[256*3] = { /* y_table */ 0x7FFFFFEDU, 0x7FFFFFEFU, diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 27242384ac..a0f23a511f 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -1,6 +1,6 @@ #include "visual_script_builtin_funcs.h" #include "math_funcs.h" -#include "object_type_db.h" +#include "class_db.h" #include "reference.h" #include "func_ref.h" #include "os/os.h" @@ -610,85 +610,85 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp case VisualScriptBuiltinFunc::MATH_SIN: { VALIDATE_ARG_NUM(0); - *r_return=Math::sin(*p_inputs[0]); + *r_return=Math::sin((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_COS: { VALIDATE_ARG_NUM(0); - *r_return=Math::cos(*p_inputs[0]); + *r_return=Math::cos((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_TAN: { VALIDATE_ARG_NUM(0); - *r_return=Math::tan(*p_inputs[0]); + *r_return=Math::tan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_SINH: { VALIDATE_ARG_NUM(0); - *r_return=Math::sinh(*p_inputs[0]); + *r_return=Math::sinh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_COSH: { VALIDATE_ARG_NUM(0); - *r_return=Math::cosh(*p_inputs[0]); + *r_return=Math::cosh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_TANH: { VALIDATE_ARG_NUM(0); - *r_return=Math::tanh(*p_inputs[0]); + *r_return=Math::tanh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ASIN: { VALIDATE_ARG_NUM(0); - *r_return=Math::asin(*p_inputs[0]); + *r_return=Math::asin((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ACOS: { VALIDATE_ARG_NUM(0); - *r_return=Math::acos(*p_inputs[0]); + *r_return=Math::acos((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ATAN: { VALIDATE_ARG_NUM(0); - *r_return=Math::atan(*p_inputs[0]); + *r_return=Math::atan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ATAN2: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::atan2(*p_inputs[0],*p_inputs[1]); + *r_return=Math::atan2((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_SQRT: { VALIDATE_ARG_NUM(0); - *r_return=Math::sqrt(*p_inputs[0]); + *r_return=Math::sqrt((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_FMOD: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::fmod(*p_inputs[0],*p_inputs[1]); + *r_return=Math::fmod((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_FPOSMOD: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::fposmod(*p_inputs[0],*p_inputs[1]); + *r_return=Math::fposmod((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_FLOOR: { VALIDATE_ARG_NUM(0); - *r_return=Math::floor(*p_inputs[0]); + *r_return=Math::floor((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_CEIL: { VALIDATE_ARG_NUM(0); - *r_return=Math::ceil(*p_inputs[0]); + *r_return=Math::ceil((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ROUND: { VALIDATE_ARG_NUM(0); - *r_return=Math::round(*p_inputs[0]); + *r_return=Math::round((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ABS: { @@ -730,58 +730,58 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::pow(*p_inputs[0],*p_inputs[1]); + *r_return=Math::pow((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_LOG: { VALIDATE_ARG_NUM(0); - *r_return=Math::log(*p_inputs[0]); + *r_return=Math::log((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_EXP: { VALIDATE_ARG_NUM(0); - *r_return=Math::exp(*p_inputs[0]); + *r_return=Math::exp((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ISNAN: { VALIDATE_ARG_NUM(0); - *r_return=Math::is_nan(*p_inputs[0]); + *r_return=Math::is_nan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ISINF: { VALIDATE_ARG_NUM(0); - *r_return=Math::is_inf(*p_inputs[0]); + *r_return=Math::is_inf((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_EASE: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::ease(*p_inputs[0],*p_inputs[1]); + *r_return=Math::ease((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_DECIMALS: { VALIDATE_ARG_NUM(0); - *r_return=Math::step_decimals(*p_inputs[0]); + *r_return=Math::step_decimals((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_STEPIFY: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::stepify(*p_inputs[0],*p_inputs[1]); + *r_return=Math::stepify((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_LERP: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); - *r_return=Math::lerp(*p_inputs[0],*p_inputs[1],*p_inputs[2]); + *r_return=Math::lerp((double)*p_inputs[0],(double)*p_inputs[1],(double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_DECTIME: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); - *r_return=Math::dectime(*p_inputs[0],*p_inputs[1],*p_inputs[2]); + *r_return=Math::dectime((double)*p_inputs[0],(double)*p_inputs[1],(double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_RANDOMIZE: { Math::randomize(); @@ -797,19 +797,19 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); - *r_return=Math::random(*p_inputs[0],*p_inputs[1]); + *r_return=Math::random((double)*p_inputs[0],(double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_SEED: { VALIDATE_ARG_NUM(0); - uint32_t seed=*p_inputs[0]; + uint64_t seed=*p_inputs[0]; Math::seed(seed); } break; case VisualScriptBuiltinFunc::MATH_RANDSEED: { VALIDATE_ARG_NUM(0); - uint32_t seed=*p_inputs[0]; + uint64_t seed=*p_inputs[0]; int ret = Math::rand_from_seed(&seed); Array reta; reta.push_back(ret); @@ -820,22 +820,22 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp case VisualScriptBuiltinFunc::MATH_DEG2RAD: { VALIDATE_ARG_NUM(0); - *r_return=Math::deg2rad(*p_inputs[0]); + *r_return=Math::deg2rad((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_RAD2DEG: { VALIDATE_ARG_NUM(0); - *r_return=Math::rad2deg(*p_inputs[0]); + *r_return=Math::rad2deg((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_LINEAR2DB: { VALIDATE_ARG_NUM(0); - *r_return=Math::linear2db(*p_inputs[0]); + *r_return=Math::linear2db((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_DB2LINEAR: { VALIDATE_ARG_NUM(0); - *r_return=Math::db2linear(*p_inputs[0]); + *r_return=Math::db2linear((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::LOGIC_MAX: { diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 37ee225aeb..eadc9a8892 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -1918,7 +1918,7 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat Ref<VisualScriptFunctionCall> call; call.instance(); call->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH); - call->set_base_path(sn->get_path_to(node));; + call->set_base_path(sn->get_path_to(node)); call->set_base_type(node->get_class()); n=call; diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index c9e24fc9dc..ce33b2e5ae 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -3615,7 +3615,7 @@ void VisualScriptInputAction::_validate_property(PropertyInfo& property) const { al.push_back(name); } - al.sort();; + al.sort(); for(int i=0;i<al.size();i++) { if (actions!=String()) @@ -3705,7 +3705,7 @@ String VisualScriptDeconstruct::get_category() const { void VisualScriptDeconstruct::_update_elements() { - elements.clear();; + elements.clear(); Variant v; if (type==Variant::INPUT_EVENT) { InputEvent ie; diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp index 2b05daca16..98920954a4 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp @@ -141,7 +141,7 @@ int AudioStreamPlaybackOGGVorbis::mix(int16_t* p_bufer,int p_frames) { int errv = ov_open_callbacks(f,&vf,NULL,0,_ov_callbacks); if (errv!=0) { playing=false; - break;; // :( + break; // :( } if (loop_restart_time) { diff --git a/modules/vorbis/config.py b/modules/vorbis/config.py index fb920482f5..ef5daca05c 100644 --- a/modules/vorbis/config.py +++ b/modules/vorbis/config.py @@ -1,6 +1,7 @@ def can_build(platform): - return True +# return True + return False def configure(env): diff --git a/modules/webm/config.py b/modules/webm/config.py index fb920482f5..ef5daca05c 100644 --- a/modules/webm/config.py +++ b/modules/webm/config.py @@ -1,6 +1,7 @@ def can_build(platform): - return True +# return True + return False def configure(env): diff --git a/platform/android/audio_driver_jandroid.cpp b/platform/android/audio_driver_jandroid.cpp index d9e40a5913..e0e89e6344 100644 --- a/platform/android/audio_driver_jandroid.cpp +++ b/platform/android/audio_driver_jandroid.cpp @@ -27,9 +27,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "audio_driver_jandroid.h" + #include "globals.h" #include "os/os.h" #include "thread_jandroid.h" + #ifndef ANDROID_NATIVE_ACTIVITY AudioDriverAndroid* AudioDriverAndroid::s_ad=NULL; @@ -199,9 +201,9 @@ int AudioDriverAndroid::get_mix_rate() const { return mix_rate; } -AudioDriverSW::OutputFormat AudioDriverAndroid::get_output_format() const{ +AudioDriver::SpeakerMode AudioDriverAndroid::get_speaker_mode() const{ - return OUTPUT_STEREO; + return SPEAKER_MODE_STEREO; } void AudioDriverAndroid::lock(){ diff --git a/platform/android/audio_driver_jandroid.h b/platform/android/audio_driver_jandroid.h index 01ce31be8f..f485df2001 100644 --- a/platform/android/audio_driver_jandroid.h +++ b/platform/android/audio_driver_jandroid.h @@ -29,12 +29,13 @@ #ifndef AUDIO_DRIVER_ANDROID_H #define AUDIO_DRIVER_ANDROID_H -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" + #ifndef ANDROID_NATIVE_ACTIVITY #include "java_glue.h" -class AudioDriverAndroid : public AudioDriverSW { +class AudioDriverAndroid : public AudioDriver { static Mutex *mutex; @@ -65,7 +66,7 @@ public: virtual Error init(); virtual void start(); virtual int get_mix_rate() const ; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp index 7aec2b174e..2ec80f23c3 100644 --- a/platform/android/audio_driver_opensl.cpp +++ b/platform/android/audio_driver_opensl.cpp @@ -27,11 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "audio_driver_opensl.h" -#include <string.h> - - - +#include <string.h> #define MAX_NUMBER_INTERFACES 3 #define MAX_NUMBER_OUTPUT_DEVICES 6 @@ -373,9 +370,9 @@ int AudioDriverOpenSL::get_mix_rate() const { return 44100; } -AudioDriverSW::OutputFormat AudioDriverOpenSL::get_output_format() const{ +AudioDriver::SpeakerMode AudioDriverOpenSL::get_speaker_mode() const{ - return OUTPUT_STEREO; + return SPEAKER_MODE_STEREO; } void AudioDriverOpenSL::lock(){ diff --git a/platform/android/audio_driver_opensl.h b/platform/android/audio_driver_opensl.h index 8839d20bab..1baaa95052 100644 --- a/platform/android/audio_driver_opensl.h +++ b/platform/android/audio_driver_opensl.h @@ -29,15 +29,13 @@ #ifndef AUDIO_DRIVER_OPENSL_H #define AUDIO_DRIVER_OPENSL_H - - -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #include "os/mutex.h" -#include <SLES/OpenSLES.h> -#include "SLES/OpenSLES_Android.h" +#include <SLES/OpenSLES.h> +#include <SLES/OpenSLES_Android.h> -class AudioDriverOpenSL : public AudioDriverSW { +class AudioDriverOpenSL : public AudioDriver { bool active; Mutex *mutex; @@ -94,7 +92,7 @@ public: virtual Error init(); virtual void start(); virtual int get_mix_rate() const ; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/platform/android/build.gradle.template b/platform/android/build.gradle.template index 873eef0566..c46a15bd12 100644 --- a/platform/android/build.gradle.template +++ b/platform/android/build.gradle.template @@ -52,11 +52,10 @@ android { java.srcDirs = ['src' $$GRADLE_JAVA_DIRS$$ ] - resources.srcDirs = [ + res.srcDirs = [ 'res' $$GRADLE_RES_DIRS$$ ] - res.srcDirs = ['res'] // libs.srcDirs = ['libs'] aidl.srcDirs = [ 'aidl' diff --git a/platform/android/dir_access_android.cpp b/platform/android/dir_access_android.cpp index 42ac34a589..82b2761bb0 100644 --- a/platform/android/dir_access_android.cpp +++ b/platform/android/dir_access_android.cpp @@ -192,6 +192,6 @@ DirAccessAndroid::DirAccessAndroid() { DirAccessAndroid::~DirAccessAndroid() { - list_dir_end();; + list_dir_end(); } #endif diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 204bf684b7..8e1fda74ed 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -38,7 +38,7 @@ #include "os/os.h" #include "platform/android/logo.h" #include <string.h> - +#if 0 static const char* android_perms[]={ "ACCESS_CHECKIN_PROPERTIES", @@ -1748,6 +1748,7 @@ Error EditorExportPlatformAndroid::run(int p_device, int p_flags) { args.push_back("shell"); args.push_back("am"); args.push_back("start"); + args.push_back("--user 0"); args.push_back("-a"); args.push_back("android.intent.action.MAIN"); args.push_back("-n"); @@ -1914,4 +1915,4 @@ void register_android_exporter() { EditorImportExport::get_singleton()->add_export_platform(exporter); } - +#endif diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 562666b679..1095689a5b 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -27,18 +27,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "os_android.h" -#include "drivers/gles2/rasterizer_gles2.h" +#include "drivers/gles2/rasterizer_gles2.h" #include "core/io/file_access_buffered_fa.h" #include "drivers/unix/file_access_unix.h" #include "drivers/unix/dir_access_unix.h" - #include "servers/visual/visual_server_raster.h" #include "servers/visual/visual_server_wrap_mt.h" #include "main/main.h" - #include "file_access_android.h" - #include "core/globals.h" #ifdef ANDROID_NATIVE_ACTIVITY @@ -129,7 +126,7 @@ void OS_Android::initialize(const VideoMode& p_desired,int p_video_driver,int p_ if (gfx_init_func) gfx_init_func(gfx_init_ud,use_gl2); - AudioDriverManagerSW::add_driver(&audio_driver_android); + AudioDriverManager::add_driver(&audio_driver_android); RasterizerGLES2 *rasterizer_gles22=memnew( RasterizerGLES2(false,use_reload_hooks,false,use_reload_hooks ) ); @@ -147,26 +144,13 @@ void OS_Android::initialize(const VideoMode& p_desired,int p_video_driver,int p_ visual_server->init(); visual_server->cursor_set_visible(false, 0); - AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); + AudioDriverManager::get_driver(p_audio_driver)->set_singleton(); - if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { + if (AudioDriverManager::get_driver(p_audio_driver)->init()!=OK) { ERR_PRINT("Initializing audio failed."); } - sample_manager = memnew( SampleManagerMallocSW ); - audio_server = memnew( AudioServerSW(sample_manager) ); - - audio_server->set_mixer_params(AudioMixerSW::INTERPOLATION_LINEAR,true); - audio_server->init(); - - spatial_sound_server = memnew( SpatialSoundServerSW ); - spatial_sound_server->init(); - - spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); - spatial_sound_2d_server->init(); - - // physics_server = memnew( PhysicsServerSW ); physics_server->init(); //physics_2d_server = memnew( Physics2DServerSW ); diff --git a/platform/android/os_android.h b/platform/android/os_android.h index 9ed7ba5fac..bf1db57ba5 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -33,31 +33,20 @@ #include "drivers/unix/os_unix.h" #include "os/main_loop.h" #include "servers/physics/physics_server_sw.h" -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #include "servers/physics_2d/physics_2d_server_sw.h" #include "servers/physics_2d/physics_2d_server_wrap_mt.h" #include "servers/visual/rasterizer.h" #include "main/input_default.h" - -//#ifdef USE_JAVA_FILE_ACCESS - +#include "audio_driver_jandroid.h" +#include "audio_driver_opensl.h" #ifdef ANDROID_NATIVE_ACTIVITY - #include <android/sensor.h> #include <android/log.h> #include <android_native_app_glue.h> - -#else - - #endif -#include "audio_driver_jandroid.h" -#include "audio_driver_opensl.h" - typedef void (*GFXInitFunc)(void *ud,bool gl2); typedef int (*OpenURIFunc)(const String&); typedef String (*GetDataDirFunc)(); @@ -118,10 +107,6 @@ private: Rasterizer *rasterizer; VisualServer *visual_server; - AudioServerSW *audio_server; - SampleManagerMallocSW *sample_manager; - SpatialSoundServerSW *spatial_sound_server; - SpatialSound2DServerSW *spatial_sound_2d_server; PhysicsServer *physics_server; Physics2DServer *physics_2d_server; diff --git a/platform/bb10/audio_driver_bb10.cpp b/platform/bb10/audio_driver_bb10.cpp index 7b5c0800a8..b6ea0bc267 100644 --- a/platform/bb10/audio_driver_bb10.cpp +++ b/platform/bb10/audio_driver_bb10.cpp @@ -44,7 +44,7 @@ Error AudioDriverBB10::init(const char* p_name) { samples_out = NULL; mix_rate = 44100; - output_format = OUTPUT_STEREO; + speaker_mode = SPEAKER_MODE_STEREO; char* dev_name; if (p_name == NULL) { @@ -70,7 +70,7 @@ Error AudioDriverBB10::init(const char* p_name) { ERR_FAIL_COND_V(!(cinfo.formats & SND_PCM_FMT_S16_LE), FAILED); printf("voices %i\n", cinfo.max_voices); - output_format = cinfo.max_voices >= 2 ? OUTPUT_STEREO : OUTPUT_MONO; + speaker_mode = SPEAKER_MODE_STEREO; snd_pcm_channel_params_t cp; zeromem(&cp, sizeof(cp)); @@ -84,7 +84,7 @@ Error AudioDriverBB10::init(const char* p_name) { cp.buf.block.frags_min = 1; cp.format.interleave = 1; cp.format.rate = mix_rate; - cp.format.voices = output_format == OUTPUT_MONO ? 1 : 2; + cp.format.voices = speaker_mode; cp.format.format = SND_PCM_SFMT_S16_LE; ret = snd_pcm_plugin_params(pcm_handle, &cp); @@ -121,7 +121,7 @@ void AudioDriverBB10::thread_func(void* p_udata) { AudioDriverBB10* ad = (AudioDriverBB10*)p_udata; - int channels = (ad->output_format == OUTPUT_MONO ? 1 : 2); + int channels = speaker_mode; int frame_count = ad->sample_buf_count / channels; int bytes_out = frame_count * channels * 2; @@ -204,16 +204,18 @@ int AudioDriverBB10::get_mix_rate() const { return mix_rate; }; -AudioDriverSW::OutputFormat AudioDriverBB10::get_output_format() const { +AudioDriver::SpeakerMode AudioDriverBB10::get_speaker_mode() const { - return output_format; + return speaker_mode; }; + void AudioDriverBB10::lock() { if (!thread) return; mutex->lock(); }; + void AudioDriverBB10::unlock() { if (!thread) diff --git a/platform/bb10/audio_driver_bb10.h b/platform/bb10/audio_driver_bb10.h index 738bcf2619..efb98b1b91 100644 --- a/platform/bb10/audio_driver_bb10.h +++ b/platform/bb10/audio_driver_bb10.h @@ -26,14 +26,14 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #include "core/os/thread.h" #include "core/os/mutex.h" #include <sys/asoundlib.h> -class AudioDriverBB10 : public AudioDriverSW { +class AudioDriverBB10 : public AudioDriver { Thread* thread; Mutex* mutex; @@ -47,7 +47,7 @@ class AudioDriverBB10 : public AudioDriverSW { static void thread_func(void* p_udata); int mix_rate; - OutputFormat output_format; + SpeakerMode speaker_mode; int pcm_frag_size; int pcm_max_frags; @@ -67,7 +67,7 @@ public: virtual Error init(const char* p_name); virtual void start(); virtual int get_mix_rate() const; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/platform/bb10/bbutil.c b/platform/bb10/bbutil.c index fce52c5b81..ab3dcf69b2 100644 --- a/platform/bb10/bbutil.c +++ b/platform/bb10/bbutil.c @@ -426,7 +426,7 @@ get_window_group_id() int bbutil_rotate_screen_surface(int angle) { - int rc, rotation, skip = 1, temp;; + int rc, rotation, skip = 1, temp; EGLint interval = 1; int size[2]; diff --git a/platform/bb10/bbutil.h b/platform/bb10/bbutil.h index c2a4c5a7f5..77f4402fbd 100644 --- a/platform/bb10/bbutil.h +++ b/platform/bb10/bbutil.h @@ -13,7 +13,11 @@ extern "C" { extern EGLDisplay egl_disp; extern EGLSurface egl_surf; -enum RENDERING_API {GL_ES_1 = EGL_OPENGL_ES_BIT, GL_ES_2 = EGL_OPENGL_ES2_BIT, VG = EGL_OPENVG_BIT}; +enum RENDERING_API { + GL_ES_1 = EGL_OPENGL_ES_BIT, + GL_ES_2 = EGL_OPENGL_ES2_BIT, + VG = EGL_OPENVG_BIT +}; /** * Initializes EGL, GL and loads a default font diff --git a/platform/bb10/export/export.cpp b/platform/bb10/export/export.cpp index cc994c8f24..3e6dadb094 100644 --- a/platform/bb10/export/export.cpp +++ b/platform/bb10/export/export.cpp @@ -40,7 +40,7 @@ #include "io/xml_parser.h" #define MAX_DEVICES 5 - +#if 0 class EditorExportPlatformBB10 : public EditorExportPlatform { GDCLASS( EditorExportPlatformBB10,EditorExportPlatform ); @@ -827,3 +827,4 @@ void register_bb10_exporter() { } +#endif diff --git a/platform/bb10/os_bb10.cpp b/platform/bb10/os_bb10.cpp index ea2e326b05..c51f1c6092 100644 --- a/platform/bb10/os_bb10.cpp +++ b/platform/bb10/os_bb10.cpp @@ -31,22 +31,21 @@ #include "drivers/gles2/rasterizer_gles2.h" #include "servers/visual/visual_server_raster.h" #include "core/os/dir_access.h" - #include "core/globals.h" #include "main/main.h" #include "bbutil.h" +#include "core/os/keyboard.h" + #include <stdlib.h> #include <stdbool.h> #include <assert.h> -#include "core/os/keyboard.h" - -#include "bps/bps.h" -#include "bps/screen.h" -#include "bps/navigator.h" -#include "bps/accelerometer.h" -#include "bps/orientation.h" -#include "bps/virtualkeyboard.h" -#include "bps/audiodevice.h" +#include <bps/bps.h> +#include <bps/screen.h> +#include <bps/navigator.h> +#include <bps/accelerometer.h> +#include <bps/orientation.h> +#include <bps/virtualkeyboard.h> +#include <bps/audiodevice.h> #ifdef BB10_SCORELOOP_ENABLED #include "modules/scoreloop/scoreloop_bb10.h" @@ -141,18 +140,6 @@ void OSBB10::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi audio_driver->set_singleton(); audio_driver->init(NULL); - sample_manager = memnew( SampleManagerMallocSW ); - audio_server = memnew( AudioServerSW(sample_manager) ); - audio_server->set_mixer_params(AudioMixerSW::INTERPOLATION_LINEAR,false); - audio_server->init(); - - spatial_sound_server = memnew( SpatialSoundServerSW ); - spatial_sound_server->init(); - - spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); - spatial_sound_2d_server->init(); - - // physics_server = memnew( PhysicsServerSW ); physics_server->init(); physics_2d_server = memnew( Physics2DServerSW ); @@ -185,22 +172,12 @@ void OSBB10::finalize() { memdelete(main_loop); main_loop=NULL; - spatial_sound_server->finish(); - memdelete(spatial_sound_server); - spatial_sound_2d_server->finish(); - memdelete(spatial_sound_2d_server); - /* if (debugger_connection_console) { memdelete(debugger_connection_console); } */ - memdelete(sample_manager); - - audio_server->finish(); - memdelete(audio_server); - visual_server->finish(); memdelete(visual_server); memdelete(rasterizer); diff --git a/platform/bb10/os_bb10.h b/platform/bb10/os_bb10.h index 5c484cd120..9cf2091d49 100644 --- a/platform/bb10/os_bb10.h +++ b/platform/bb10/os_bb10.h @@ -34,9 +34,7 @@ #include "os/main_loop.h" #include "main/input_default.h" #include "servers/physics/physics_server_sw.h" -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #include "servers/physics_2d/physics_2d_server_sw.h" #include "servers/visual/rasterizer.h" #include "audio_driver_bb10.h" @@ -44,8 +42,7 @@ #include <screen/screen.h> #include <sys/platform.h> -#include "bps/event.h" - +#include <bps/event.h> #include <stdint.h> class OSBB10 : public OS_Unix { @@ -58,11 +55,6 @@ class OSBB10 : public OS_Unix { Rasterizer *rasterizer; VisualServer *visual_server; - //AudioDriverPSP audio_driver_psp; - AudioServerSW *audio_server; - SampleManagerMallocSW *sample_manager; - SpatialSoundServerSW *spatial_sound_server; - SpatialSound2DServerSW *spatial_sound_2d_server; PhysicsServer *physics_server; Physics2DServer *physics_2d_server; AudioDriverBB10* audio_driver; diff --git a/platform/haiku/audio_driver_media_kit.cpp b/platform/haiku/audio_driver_media_kit.cpp index 2af93061f8..c6afe7a261 100644 --- a/platform/haiku/audio_driver_media_kit.cpp +++ b/platform/haiku/audio_driver_media_kit.cpp @@ -38,7 +38,7 @@ Error AudioDriverMediaKit::init() { active = false; mix_rate = 44100; - output_format = OUTPUT_STEREO; + speaker_mode = SPEAKER_MODE_STEREO; channels = 2; int latency = GLOBAL_DEF("audio/output_latency", 25); @@ -99,8 +99,8 @@ int AudioDriverMediaKit::get_mix_rate() const { return mix_rate; } -AudioDriverSW::OutputFormat AudioDriverMediaKit::get_output_format() const { - return output_format; +AudioDriverSW::SpeakerMode AudioDriverMediaKit::get_speaker_mode() const { + return speaker_mode; } void AudioDriverMediaKit::lock() { diff --git a/platform/haiku/audio_driver_media_kit.h b/platform/haiku/audio_driver_media_kit.h index fbf6bc20de..ce760f8dd7 100644 --- a/platform/haiku/audio_driver_media_kit.h +++ b/platform/haiku/audio_driver_media_kit.h @@ -26,7 +26,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #ifdef MEDIA_KIT_ENABLED @@ -36,7 +36,7 @@ #include <kernel/image.h> // needed for image_id #include <SoundPlayer.h> -class AudioDriverMediaKit : public AudioDriverSW { +class AudioDriverMediaKit : public AudioDriver { Mutex* mutex; BSoundPlayer* player; @@ -45,7 +45,7 @@ class AudioDriverMediaKit : public AudioDriverSW { static void PlayBuffer(void* cookie, void* buffer, size_t size, const media_raw_audio_format& format); unsigned int mix_rate; - OutputFormat output_format; + SpeakerMode speaker_mode; unsigned int buffer_size; int channels; @@ -60,7 +60,7 @@ public: virtual Error init(); virtual void start(); virtual int get_mix_rate() const; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 176e1b0fbc..9f218aeff4 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -40,7 +40,7 @@ OS_Haiku::OS_Haiku() { #ifdef MEDIA_KIT_ENABLED - AudioDriverManagerSW::add_driver(&driver_media_kit); + AudioDriverManager::add_driver(&driver_media_kit); #endif }; @@ -138,20 +138,11 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ //physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>(); physics_2d_server->init(); - AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); + AudioDriverManager::get_driver(p_audio_driver)->set_singleton(); - if (AudioDriverManagerSW::get_driver(p_audio_driver)->init() != OK) { + if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) { ERR_PRINT("Initializing audio failed."); } - - sample_manager = memnew(SampleManagerMallocSW); - audio_server = memnew(AudioServerSW(sample_manager)); - audio_server->init(); - - spatial_sound_server = memnew(SpatialSoundServerSW); - spatial_sound_server->init(); - spatial_sound_2d_server = memnew(SpatialSound2DServerSW); - spatial_sound_2d_server->init(); } void OS_Haiku::finalize() { @@ -161,17 +152,6 @@ void OS_Haiku::finalize() { main_loop = NULL; - spatial_sound_server->finish(); - memdelete(spatial_sound_server); - - spatial_sound_2d_server->finish(); - memdelete(spatial_sound_2d_server); - - memdelete(sample_manager); - - audio_server->finish(); - memdelete(audio_server); - visual_server->finish(); memdelete(visual_server); memdelete(rasterizer); diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index fc873f49ad..531c7a56c3 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -34,12 +34,8 @@ #include "servers/visual/rasterizer.h" #include "servers/physics_server.h" #include "servers/physics_2d/physics_2d_server_sw.h" -#include "servers/audio/audio_server_sw.h" -#include "servers/audio/sample_manager_sw.h" -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" +#include "servers/audio_server.h" #include "main/input_default.h" - #include "audio_driver_media_kit.h" #include "context_gl_haiku.h" #include "haiku_application.h" @@ -57,10 +53,6 @@ private: VideoMode current_video_mode; PhysicsServer* physics_server; Physics2DServer* physics_2d_server; - AudioServerSW* audio_server; - SampleManagerMallocSW* sample_manager; - SpatialSoundServerSW* spatial_sound_server; - SpatialSound2DServerSW* spatial_sound_2d_server; #ifdef MEDIA_KIT_ENABLED AudioDriverMediaKit driver_media_kit; diff --git a/platform/iphone/app_delegate.h b/platform/iphone/app_delegate.h index 09c401b329..1b2ca42ab6 100644 --- a/platform/iphone/app_delegate.h +++ b/platform/iphone/app_delegate.h @@ -30,11 +30,11 @@ #import "gl_view.h" #import "view_controller.h" -@interface AppDelegate : NSObject <UIApplicationDelegate, UIAccelerometerDelegate, GLViewDelegate> { +#import <CoreMotion/CoreMotion.h> + +@interface AppDelegate : NSObject <UIApplicationDelegate, GLViewDelegate> { //@property (strong, nonatomic) UIWindow *window; ViewController* view_controller; - UIAccelerationValue accel[3]; - UIAccelerationValue last_accel[3]; }; @property (strong, nonatomic) UIWindow *window; diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm index feb87e742f..740f1d7edc 100644 --- a/platform/iphone/app_delegate.mm +++ b/platform/iphone/app_delegate.mm @@ -84,6 +84,9 @@ extern char** gargv; extern int iphone_main(int, int, int, char**); extern void iphone_finish(); +CMMotionManager *motionManager; +bool motionInitialised; + static ViewController* mainViewController = nil; + (ViewController*) getViewController { @@ -193,9 +196,58 @@ static int frame_count = 0; }; break; // no fallthrough default: { - if (OSIPhone::get_singleton()) { - OSIPhone::get_singleton()->update_accelerometer(accel[0], accel[1], accel[2]); +// OSIPhone::get_singleton()->update_accelerometer(accel[0], accel[1], accel[2]); + if (motionInitialised) { + // Just using polling approach for now, we can set this up so it sends data to us in intervals, might be better. + // See Apple reference pages for more details: + // https://developer.apple.com/reference/coremotion/cmmotionmanager?language=objc + + // Apple splits our accelerometer date into a gravity and user movement component. We add them back together + CMAcceleration gravity = motionManager.deviceMotion.gravity; + CMAcceleration acceleration = motionManager.deviceMotion.userAcceleration; + + ///@TODO We don't seem to be getting data here, is my device broken or is this code incorrect? + CMMagneticField magnetic = motionManager.deviceMotion.magneticField.field; + + ///@TODO we can access rotationRate as a CMRotationRate variable (processed date) or CMGyroData (raw data), have to see what works best + CMRotationRate rotation = motionManager.deviceMotion.rotationRate; + + // Adjust for screen orientation. + // [[UIDevice currentDevice] orientation] changes even if we've fixed our orientation which is not + // a good thing when you're trying to get your user to move the screen in all directions and want consistent output + + ///@TODO Using [[UIApplication sharedApplication] statusBarOrientation] is a bit of a hack. Godot obviously knows the orientation so maybe we + // can use that instead? (note that left and right seem swapped) + + switch ([[UIApplication sharedApplication] statusBarOrientation]) { + case UIDeviceOrientationLandscapeLeft: { + OSIPhone::get_singleton()->update_gravity(-gravity.y, gravity.x, gravity.z); + OSIPhone::get_singleton()->update_accelerometer(-(acceleration.y + gravity.y), (acceleration.x + gravity.x), acceleration.z + gravity.z); + OSIPhone::get_singleton()->update_magnetometer(-magnetic.y, magnetic.x, magnetic.z); + OSIPhone::get_singleton()->update_gyroscope(-rotation.y, rotation.x, rotation.z); + }; break; + case UIDeviceOrientationLandscapeRight: { + OSIPhone::get_singleton()->update_gravity(gravity.y, -gravity.x, gravity.z); + OSIPhone::get_singleton()->update_accelerometer((acceleration.y + gravity.y), -(acceleration.x + gravity.x), acceleration.z + gravity.z); + OSIPhone::get_singleton()->update_magnetometer(magnetic.y, -magnetic.x, magnetic.z); + OSIPhone::get_singleton()->update_gyroscope(rotation.y, -rotation.x, rotation.z); + }; break; + case UIDeviceOrientationPortraitUpsideDown: { + OSIPhone::get_singleton()->update_gravity(-gravity.x, gravity.y, gravity.z); + OSIPhone::get_singleton()->update_accelerometer(-(acceleration.x + gravity.x), (acceleration.y + gravity.y), acceleration.z + gravity.z); + OSIPhone::get_singleton()->update_magnetometer(-magnetic.x, magnetic.y, magnetic.z); + OSIPhone::get_singleton()->update_gyroscope(-rotation.x, rotation.y, rotation.z); + }; break; + default: { // assume portrait + OSIPhone::get_singleton()->update_gravity(gravity.x, gravity.y, gravity.z); + OSIPhone::get_singleton()->update_accelerometer(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z); + OSIPhone::get_singleton()->update_magnetometer(magnetic.x, magnetic.y, magnetic.z); + OSIPhone::get_singleton()->update_gyroscope(rotation.x, rotation.y, rotation.z); + }; break; + }; + } + bool quit_request = OSIPhone::get_singleton()->iterate(); }; @@ -232,12 +284,12 @@ static int frame_count = 0; //glView.autoresizesSubviews = YES; //[glView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth]; - int backingWidth; - int backingHeight; - glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); - glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); + int backingWidth; + int backingHeight; + glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth); + glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight); - iphone_main(backingWidth, backingHeight, gargc, gargv); + iphone_main(backingWidth, backingHeight, gargc, gargv); view_controller = [[ViewController alloc] init]; view_controller.view = glView; @@ -253,11 +305,14 @@ static int frame_count = 0; [window makeKeyAndVisible]; //Configure and start accelerometer - last_accel[0] = 0; - last_accel[1] = 0; - last_accel[2] = 0; - [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)]; - [[UIAccelerometer sharedAccelerometer] setDelegate:self]; + if (!motionInitialised) { + motionManager = [[CMMotionManager alloc] init]; + if (motionManager.deviceMotionAvailable) { + motionManager.deviceMotionUpdateInterval = 1.0/70.0; + [motionManager startDeviceMotionUpdates]; + motionInitialised = YES; + }; + }; //OSIPhone::screen_width = rect.size.width - rect.origin.x; //OSIPhone::screen_height = rect.size.height - rect.origin.y; @@ -297,12 +352,23 @@ static int frame_count = 0; - (void)applicationWillTerminate:(UIApplication*)application { printf("********************* will terminate\n"); + + if (motionInitialised) { + ///@TODO is this the right place to clean this up? + [motionManager stopDeviceMotionUpdates]; + [motionManager release]; + motionManager = nil; + motionInitialised = NO; + }; + iphone_finish(); }; - (void)applicationDidEnterBackground:(UIApplication *)application { printf("********************* did enter background\n"); + ///@TODO maybe add pause motionManager? and where would we unpause it? + if (OS::get_singleton()->get_main_loop()) OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); [view_controller.view stopAnimation]; @@ -340,13 +406,6 @@ static int frame_count = 0; }; } -- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration { - //Use a basic low-pass filter to only keep the gravity in the accelerometer values - accel[0] = acceleration.x; // * kFilteringFactor + accel[0] * (1.0 - kFilteringFactor); - accel[1] = acceleration.y; // * kFilteringFactor + accel[1] * (1.0 - kFilteringFactor); - accel[2] = acceleration.z; // * kFilteringFactor + accel[2] * (1.0 - kFilteringFactor); -} - - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { #ifdef MODULE_FACEBOOKSCORER_IOS_ENABLED return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url]; diff --git a/platform/iphone/audio_driver_iphone.cpp b/platform/iphone/audio_driver_iphone.cpp index 556576cdc3..eda3897841 100644 --- a/platform/iphone/audio_driver_iphone.cpp +++ b/platform/iphone/audio_driver_iphone.cpp @@ -155,8 +155,8 @@ int AudioDriverIphone::get_mix_rate() const { return 44100; }; -AudioDriverSW::OutputFormat AudioDriverIphone::get_output_format() const { - return OUTPUT_STEREO; +AudioDriver::SpeakerMode AudioDriverIphone::get_speaker_mode() const { + return SPEAKER_MODE_STEREO; }; void AudioDriverIphone::lock() { diff --git a/platform/iphone/audio_driver_iphone.h b/platform/iphone/audio_driver_iphone.h index cbcb0cffce..4c0cbfcb22 100644 --- a/platform/iphone/audio_driver_iphone.h +++ b/platform/iphone/audio_driver_iphone.h @@ -26,11 +26,12 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "servers/audio/audio_server_sw.h" + +#include "servers/audio_server.h" #include <AudioUnit/AudioUnit.h> -class AudioDriverIphone : public AudioDriverSW { +class AudioDriverIphone : public AudioDriver { AudioComponentInstance audio_unit; bool active; @@ -56,7 +57,7 @@ public: virtual Error init(); virtual void start(); virtual int get_mix_rate() const; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/platform/iphone/detect.py b/platform/iphone/detect.py index b92b64e9f1..20fa45d708 100644 --- a/platform/iphone/detect.py +++ b/platform/iphone/detect.py @@ -62,13 +62,13 @@ def configure(env): env['CCFLAGS'] = string.split('-arch i386 -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fasm-blocks -Wall -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -isysroot $IPHONESDK -mios-simulator-version-min=4.3 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"') elif (env["arch"] == "arm64"): # arm64 env["bits"] = "64" - env['CCFLAGS'] = string.split('-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -fvisibility=hidden -Wno-sign-conversion -MMD -MT dependencies -miphoneos-version-min=5.1.1 -isysroot $IPHONESDK') + env['CCFLAGS'] = string.split('-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -fvisibility=hidden -Wno-sign-conversion -MMD -MT dependencies -miphoneos-version-min=7.0 -isysroot $IPHONESDK') env.Append(CPPFLAGS=['-DNEED_LONG_INT']) env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON']) else: # armv7 env["arch"] = "arm" env["bits"] = "32" - env['CCFLAGS'] = string.split('-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -fvisibility=hidden -Wno-sign-conversion -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=5.1.1 -MMD -MT dependencies -isysroot $IPHONESDK') + env['CCFLAGS'] = string.split('-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -isysroot $IPHONESDK -fvisibility=hidden -Wno-sign-conversion -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=7.0 -MMD -MT dependencies -isysroot $IPHONESDK') if (env["arch"] == "x86"): env['IPHONEPLATFORM'] = 'iPhoneSimulator' @@ -83,6 +83,7 @@ def configure(env): '-framework', 'CoreAudio', '-framework', 'CoreGraphics', '-framework', 'CoreMedia', + '-framework', 'CoreMotion', '-framework', 'Foundation', '-framework', 'Security', '-framework', 'UIKit', @@ -93,7 +94,7 @@ def configure(env): '-F$IPHONESDK', ]) elif (env["arch"] == "arm64"): - env.Append(LINKFLAGS=['-arch', 'arm64', '-Wl,-dead_strip', '-miphoneos-version-min=5.1.1', + env.Append(LINKFLAGS=['-arch', 'arm64', '-Wl,-dead_strip', '-miphoneos-version-min=7.0', '-isysroot', '$IPHONESDK', #'-stdlib=libc++', '-framework', 'Foundation', @@ -109,9 +110,10 @@ def configure(env): '-framework', 'MediaPlayer', '-framework', 'AVFoundation', '-framework', 'CoreMedia', + '-framework', 'CoreMotion', ]) else: - env.Append(LINKFLAGS=['-arch', 'armv7', '-Wl,-dead_strip', '-miphoneos-version-min=5.1.1', + env.Append(LINKFLAGS=['-arch', 'armv7', '-Wl,-dead_strip', '-miphoneos-version-min=7.0', '-isysroot', '$IPHONESDK', '-framework', 'Foundation', '-framework', 'UIKit', @@ -126,6 +128,7 @@ def configure(env): '-framework', 'MediaPlayer', '-framework', 'AVFoundation', '-framework', 'CoreMedia', + '-framework', 'CoreMotion', ]) if env['game_center'] == 'yes': diff --git a/platform/iphone/game_center.mm b/platform/iphone/game_center.mm index 03ee327d65..de6ea73c20 100644 --- a/platform/iphone/game_center.mm +++ b/platform/iphone/game_center.mm @@ -182,11 +182,11 @@ void GameCenter::request_achievement_descriptions() { ret["type"] = "achievement_descriptions"; if (error == nil) { ret["result"] = "ok"; - StringArray names; - StringArray titles; - StringArray unachieved_descriptions; - StringArray achieved_descriptions; - IntArray maximum_points; + PoolStringArray names; + PoolStringArray titles; + PoolStringArray unachieved_descriptions; + PoolStringArray achieved_descriptions; + PoolIntArray maximum_points; Array hidden; Array replayable; @@ -239,8 +239,8 @@ void GameCenter::request_achievements() { ret["type"] = "achievements"; if (error == nil) { ret["result"] = "ok"; - StringArray names; - RealArray percentages; + PoolStringArray names; + PoolRealArray percentages; for (int i=0; i<[achievements count]; i++) { diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm index 3df29c5178..a3af8f4aa8 100755 --- a/platform/iphone/gl_view.mm +++ b/platform/iphone/gl_view.mm @@ -274,7 +274,7 @@ static void clear_touches() { nil]; // Create our EAGLContext, and if successful make it current and create our framebuffer. - context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer]) { diff --git a/platform/iphone/icloud.mm b/platform/iphone/icloud.mm index de70bb7e14..0d1825dd6b 100644 --- a/platform/iphone/icloud.mm +++ b/platform/iphone/icloud.mm @@ -78,12 +78,12 @@ Variant nsobject_to_variant(NSObject* object) { return String::utf8(str != NULL ? str : ""); } else if ([object isKindOfClass:[NSData class]]) { - ByteArray ret; + PoolByteArray ret; NSData* data = (NSData*)object; if ([data length] > 0) { ret.resize([data length]); { - ByteArray::Write w = ret.write(); + PoolByteArray::Write w = ret.write(); copymem(w.ptr(), [data bytes], [data length]); } } @@ -199,9 +199,9 @@ NSObject* variant_to_nsobject(Variant v) { } return result; } - else if (v.get_type() == Variant::RAW_ARRAY) { - ByteArray arr = v; - ByteArray::Read r = arr.read(); + else if (v.get_type() == Variant::POOL_BYTE_ARRAY) { + PoolByteArray arr = v; + PoolByteArray::Read r = arr.read(); NSData* result = [NSData dataWithBytes:r.ptr() length:arr.size()]; return result; } @@ -333,7 +333,7 @@ ICloud::ICloud() { Dictionary ret; ret["type"] = "key_value_changed"; - //StringArray result_keys; + //PoolStringArray result_keys; //Array result_values; Dictionary keyValues; String reason = ""; diff --git a/platform/iphone/in_app_store.mm b/platform/iphone/in_app_store.mm index 49026ceb0a..050498c125 100644 --- a/platform/iphone/in_app_store.mm +++ b/platform/iphone/in_app_store.mm @@ -89,11 +89,11 @@ void InAppStore::_bind_methods() { Dictionary ret; ret["type"] = "product_info"; ret["result"] = "ok"; - StringArray titles; - StringArray descriptions; - RealArray prices; - StringArray ids; - StringArray localized_prices; + PoolStringArray titles; + PoolStringArray descriptions; + PoolRealArray prices; + PoolStringArray ids; + PoolStringArray localized_prices; for (int i=0; i<[products count]; i++) { @@ -114,7 +114,7 @@ void InAppStore::_bind_methods() { ret["ids"] = ids; ret["localized_prices"] = localized_prices; - StringArray invalid_ids; + PoolStringArray invalid_ids; for (NSString* ipid in response.invalidProductIdentifiers) { @@ -134,7 +134,7 @@ Error InAppStore::request_product_info(Variant p_params) { Dictionary params = p_params; ERR_FAIL_COND_V(!params.has("product_ids"), ERR_INVALID_PARAMETER); - StringArray pids = params["product_ids"]; + PoolStringArray pids = params["product_ids"]; printf("************ request product info! %i\n", pids.size()); NSMutableArray* array = [[[NSMutableArray alloc] initWithCapacity:pids.size()] autorelease]; diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index 1d12501aea..e34dbae017 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -30,11 +30,9 @@ #include "os_iphone.h" -#include "drivers/gles2/rasterizer_gles2.h" - - +#include "drivers/gles3/rasterizer_gles3.h" #include "servers/visual/visual_server_raster.h" -#include "servers/visual/visual_server_wrap_mt.h" +//#include "servers/visual/visual_server_wrap_mt.h" #include "main/main.h" #include "audio_driver_iphone.h" @@ -109,16 +107,17 @@ void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_au supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical", false)?1:0) << PortraitDown); supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical_flipped", false)?1:0) << PortraitUp); - rasterizer_gles22 = memnew( RasterizerGLES2(false, false, false) ); - rasterizer = rasterizer_gles22; - rasterizer_gles22->set_base_framebuffer(gl_view_base_fb); + RasterizerGLES3::register_config(); + RasterizerGLES3::make_current(); + RasterizerStorageGLES3::system_fbo = gl_view_base_fb; - visual_server = memnew( VisualServerRaster(rasterizer) ); + visual_server = memnew( VisualServerRaster() ); + /* + FIXME: Reimplement threaded rendering? Or remove? if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { - visual_server = memnew(VisualServerWrapMT(visual_server, false)); }; - visual_server->init(); + */ visual_server->init(); visual_server->cursor_set_visible(false, 0); @@ -127,16 +126,7 @@ void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_au audio_driver->set_singleton(); audio_driver->init(); - sample_manager = memnew( SampleManagerMallocSW ); - audio_server = memnew( AudioServerSW(sample_manager) ); - audio_server->init(); - spatial_sound_server = memnew( SpatialSoundServerSW ); - spatial_sound_server->init(); - - spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); - spatial_sound_2d_server->init(); - - // + // init physics servers physics_server = memnew( PhysicsServerSW ); physics_server->init(); //physics_2d_server = memnew( Physics2DServerSW ); @@ -148,28 +138,28 @@ void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_au /* #ifdef IOS_SCORELOOP_ENABLED scoreloop = memnew(ScoreloopIOS); - Globals::get_singleton()->add_singleton(Globals::Singleton("Scoreloop", scoreloop)); + GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("Scoreloop", scoreloop)); scoreloop->connect(); #endif */ #ifdef GAME_CENTER_ENABLED game_center = memnew(GameCenter); - Globals::get_singleton()->add_singleton(Globals::Singleton("GameCenter", game_center)); + GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("GameCenter", game_center)); game_center->connect(); #endif #ifdef STOREKIT_ENABLED store_kit = memnew(InAppStore); - Globals::get_singleton()->add_singleton(Globals::Singleton("InAppStore", store_kit)); + GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("InAppStore", store_kit)); #endif #ifdef ICLOUD_ENABLED icloud = memnew(ICloud); - Globals::get_singleton()->add_singleton(Globals::Singleton("ICloud", icloud)); + GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("ICloud", icloud)); //icloud->connect(); #endif - Globals::get_singleton()->add_singleton(Globals::Singleton("iOS", memnew(iOS))); + GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("iOS", memnew(iOS))); }; MainLoop *OSIPhone::get_main_loop() const { @@ -294,8 +284,8 @@ void OSIPhone::mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_ }; input->set_mouse_pos(Point2(ev.mouse_motion.x,ev.mouse_motion.y)); - ev.mouse_motion.speed_x=input->get_mouse_speed().x; - ev.mouse_motion.speed_y=input->get_mouse_speed().y; + ev.mouse_motion.speed_x=input->get_last_mouse_speed().x; + ev.mouse_motion.speed_y=input->get_last_mouse_speed().y; ev.mouse_motion.button_mask = 1; // pressed queue_event(ev); @@ -323,9 +313,14 @@ void OSIPhone::touches_cancelled() { static const float ACCEL_RANGE = 1; +void OSIPhone::update_gravity(float p_x, float p_y, float p_z) { + input->set_gravity(Vector3(p_x, p_y, p_z)); +}; + void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) { - input->set_accelerometer(Vector3(p_x / (float)ACCEL_RANGE, p_y / (float)ACCEL_RANGE, -p_z / (float)ACCEL_RANGE)); + // Found out the Z should not be negated! Pass as is! + input->set_accelerometer(Vector3(p_x / (float)ACCEL_RANGE, p_y / (float)ACCEL_RANGE, p_z / (float)ACCEL_RANGE)); /* if (p_x != last_accel.x) { @@ -364,7 +359,13 @@ void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) { */ }; +void OSIPhone::update_magnetometer(float p_x, float p_y, float p_z) { + input->set_magnetometer(Vector3(p_x, p_y, p_z)); +}; +void OSIPhone::update_gyroscope(float p_x, float p_y, float p_z) { + input->set_gyroscope(Vector3(p_x, p_y, p_z)); +}; void OSIPhone::delete_main_loop() { @@ -383,7 +384,7 @@ void OSIPhone::finalize() { visual_server->finish(); memdelete(visual_server); - memdelete(rasterizer); +// memdelete(rasterizer); physics_server->finish(); memdelete(physics_server); @@ -391,14 +392,8 @@ void OSIPhone::finalize() { physics_2d_server->finish(); memdelete(physics_2d_server); - spatial_sound_server->finish(); - memdelete(spatial_sound_server); - memdelete(input); - spatial_sound_2d_server->finish(); - memdelete(spatial_sound_2d_server); - }; void OSIPhone::set_mouse_show(bool p_show) { }; @@ -445,9 +440,8 @@ bool OSIPhone::can_draw() const { int OSIPhone::set_base_framebuffer(int p_fb) { - if (rasterizer_gles22) { - rasterizer_gles22->set_base_framebuffer(p_fb); - }; + RasterizerStorageGLES3::system_fbo = gl_view_base_fb; + return 0; }; @@ -531,7 +525,7 @@ Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_ print("Unable to play %S using the native player as it resides in a .pck file\n", p_path.c_str()); return ERR_INVALID_PARAMETER; } else { - p_path = p_path.replace("res:/", Globals::get_singleton()->get_resource_path()); + p_path = p_path.replace("res:/", GlobalConfig::get_singleton()->get_resource_path()); } } else if (p_path.begins_with("user://")) p_path = p_path.replace("user:/", get_data_dir()); @@ -568,10 +562,8 @@ void OSIPhone::native_video_stop() { OSIPhone::OSIPhone(int width, int height) { - rasterizer_gles22 = NULL; main_loop = NULL; visual_server = NULL; - rasterizer = NULL; VideoMode vm; vm.fullscreen = true; diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index 331b20afbf..65dcc884bb 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -39,10 +39,7 @@ #include "servers/physics/physics_server_sw.h" #include "servers/physics_2d/physics_2d_server_sw.h" #include "servers/physics_2d/physics_2d_server_wrap_mt.h" -#include "servers/audio/audio_server_sw.h" -#include "servers/audio/sample_manager_sw.h" -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" +#include "servers/audio_server.h" #include "main/input_default.h" #include "game_center.h" #include "in_app_store.h" @@ -50,7 +47,7 @@ class AudioDriverIphone; -class RasterizerGLES2; +// class RasterizerGLES2; class OSIPhone : public OS_Unix { @@ -71,18 +68,13 @@ private: uint8_t supported_orientations; - Rasterizer *rasterizer; - - RasterizerGLES2* rasterizer_gles22; +// Rasterizer *rasterizer; +// RasterizerGLES2* rasterizer_gles22; VisualServer *visual_server; PhysicsServer* physics_server; Physics2DServer *physics_2d_server; - AudioServerSW *audio_server; - SampleManagerMallocSW *sample_manager; - SpatialSoundServerSW *spatial_sound_server; - SpatialSound2DServerSW *spatial_sound_2d_server; AudioDriverIphone* audio_driver; #ifdef GAME_CENTER_ENABLED @@ -152,7 +144,10 @@ public: int set_base_framebuffer(int p_fb); + void update_gravity(float p_x, float p_y, float p_z); void update_accelerometer(float p_x, float p_y, float p_z); + void update_magnetometer(float p_x, float p_y, float p_z); + void update_gyroscope(float p_x, float p_y, float p_z); static OSIPhone* get_singleton(); diff --git a/platform/iphone/platform_config.h b/platform/iphone/platform_config.h index c8468f0152..64e9388910 100644 --- a/platform/iphone/platform_config.h +++ b/platform/iphone/platform_config.h @@ -27,8 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include <alloca.h> -#define GLES2_INCLUDE_H <ES2/gl.h> - +// #define GLES2_INCLUDE_H <ES2/gl.h> +#define GLES3_INCLUDE_H <ES3/gl.h> #define PLATFORM_REFCOUNT diff --git a/platform/iphone/rasterizer_iphone.h b/platform/iphone/rasterizer_iphone.h index cec367e2fa..299a11e895 100644 --- a/platform/iphone/rasterizer_iphone.h +++ b/platform/iphone/rasterizer_iphone.h @@ -688,7 +688,7 @@ public: virtual void multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color); virtual RID multimesh_get_mesh(RID p_multimesh) const; - virtual AABB multimesh_get_aabb(RID p_multimesh) const;; + virtual AABB multimesh_get_aabb(RID p_multimesh) const; virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const; virtual Color multimesh_instance_get_color(RID p_multimesh,int p_index) const; @@ -846,7 +846,7 @@ public: virtual void canvas_begin(); virtual void canvas_set_transparency(float p_transparency); - virtual void canvas_set_rect(const Rect2& p_rect, bool p_clip);; + virtual void canvas_set_rect(const Rect2& p_rect, bool p_clip); virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width); virtual void canvas_draw_rect(const Rect2& p_rect, bool p_region, const Rect2& p_source,bool p_tile,RID p_texture,const Color& p_modulate); virtual void canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margins, bool p_draw_center=true); diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub index 5d5cd1590a..a20c0f7a70 100644 --- a/platform/javascript/SCsub +++ b/platform/javascript/SCsub @@ -22,6 +22,7 @@ env.Append(LINKFLAGS=["-s", "EXPORTED_FUNCTIONS=\"['_main','_audio_server_mix_fu env.Append(LINKFLAGS=["--shell-file", '"platform/javascript/godot_shell.html"']) build = env.Program('#bin/godot', javascript_objects, PROGSUFFIX=env["PROGSUFFIX"] + ".html") +Depends(build, "godot_shell.html") def make_html_shell(target, source, env): html_path = target[0].rstr() diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp index af9f28169b..bff01d7c37 100644 --- a/platform/javascript/audio_driver_javascript.cpp +++ b/platform/javascript/audio_driver_javascript.cpp @@ -27,20 +27,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "audio_driver_javascript.h" -#include <string.h> - - - - +#include <string.h> #define MAX_NUMBER_INTERFACES 3 #define MAX_NUMBER_OUTPUT_DEVICES 6 /* Structure for passing information to callback function */ - - //AudioDriverJavaScript* AudioDriverJavaScript::s_ad=NULL; const char* AudioDriverJavaScript::get_name() const { @@ -53,19 +47,23 @@ Error AudioDriverJavaScript::init(){ return OK; } + void AudioDriverJavaScript::start(){ } + int AudioDriverJavaScript::get_mix_rate() const { return 44100; } -AudioDriverSW::OutputFormat AudioDriverJavaScript::get_output_format() const{ - return OUTPUT_STEREO; +AudioDriver::SpeakerMode AudioDriverJavaScript::get_speaker_mode() const{ + + return SPEAKER_MODE_STEREO; } + void AudioDriverJavaScript::lock(){ /* @@ -74,6 +72,7 @@ void AudioDriverJavaScript::lock(){ */ } + void AudioDriverJavaScript::unlock() { /* @@ -82,11 +81,11 @@ void AudioDriverJavaScript::unlock() { */ } + void AudioDriverJavaScript::finish(){ } - AudioDriverJavaScript::AudioDriverJavaScript() { } diff --git a/platform/javascript/audio_driver_javascript.h b/platform/javascript/audio_driver_javascript.h index 528b45569d..4c2064663a 100644 --- a/platform/javascript/audio_driver_javascript.h +++ b/platform/javascript/audio_driver_javascript.h @@ -29,21 +29,19 @@ #ifndef AUDIO_DRIVER_JAVASCRIPT_H #define AUDIO_DRIVER_JAVASCRIPT_H +#include "servers/audio_server.h" -#include "servers/audio/audio_server_sw.h" #include "os/mutex.h" -class AudioDriverJavaScript : public AudioDriverSW { +class AudioDriverJavaScript : public AudioDriver { public: - void set_singleton(); - virtual const char* get_name() const; virtual Error init(); virtual void start(); virtual int get_mix_rate() const ; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/platform/javascript/audio_server_javascript.cpp b/platform/javascript/audio_server_javascript.cpp index 5489f179eb..d5940fb102 100644 --- a/platform/javascript/audio_server_javascript.cpp +++ b/platform/javascript/audio_server_javascript.cpp @@ -198,14 +198,15 @@ RID AudioServerJavascript::voice_create(){ voice->positional=false; voice->active=false; + /* clang-format off */ EM_ASM_( { - _as_voices[$0]=null; - _as_voice_gain[$0]=_as_audioctx.createGain(); - _as_voice_pan[$0]=_as_audioctx.createStereoPanner(); - _as_voice_gain[$0].connect(_as_voice_pan[$0]); - _as_voice_pan[$0].connect(_as_audioctx.destination); - - },voice_base); + _as_voices[$0] = null; + _as_voice_gain[$0] = _as_audioctx.createGain(); + _as_voice_pan[$0] = _as_audioctx.createStereoPanner(); + _as_voice_gain[$0].connect(_as_voice_pan[$0]); + _as_voice_pan[$0].connect(_as_audioctx.destination); + }, voice_base); + /* clang-format on */ voice_base++; @@ -227,27 +228,29 @@ void AudioServerJavascript::voice_play(RID p_voice, RID p_sample){ //create sample if not created ERR_FAIL_COND(sample->tmp_data.size()==0); sample->index=sample_base; - EM_ASM_( { - _as_samples[$0]=_as_audioctx.createBuffer($1,$2,$3); - },sample_base,sample->stereo?2:1,sample->length,sample->mix_rate); + /* clang-format off */ + EM_ASM_({ + _as_samples[$0] = _as_audioctx.createBuffer($1, $2, $3); + }, sample_base, sample->stereo ? 2 : 1, sample->length, sample->mix_rate); + /* clang-format on */ sample_base++; int chans = sample->stereo?2:1; for(int i=0;i<chans;i++) { - - + /* clang-format off */ EM_ASM_({ - _as_edited_buffer=_as_samples[$0].getChannelData($1); - },sample->index,i); - + _as_edited_buffer = _as_samples[$0].getChannelData($1); + }, sample->index, i); + /* clang-format on */ for(int j=0;j<sample->length;j++) { - + /* clang-format off */ EM_ASM_({ - _as_edited_buffer[$0]=$1; - },j,sample->tmp_data[j*chans+i]); + _as_edited_buffer[$0] = $1; + }, j, sample->tmp_data[j * chans + i]); + /* clang-format on */ } } @@ -263,26 +266,27 @@ void AudioServerJavascript::voice_play(RID p_voice, RID p_sample){ float freq_diff = Math::log(float(voice->mix_rate)/float(voice->sample_mix_rate))/Math::log(2.0); int detune = int(freq_diff*1200.0); - EM_ASM_( { - if (_as_voices[$0]!==null) { - _as_voices[$0].stop(); //stop and byebye - } - _as_voices[$0]=_as_audioctx.createBufferSource(); - _as_voices[$0].connect(_as_voice_gain[$0]); - _as_voices[$0].buffer=_as_samples[$1]; - _as_voices[$0].loopStart.value=$1; - _as_voices[$0].loopEnd.value=$2; - _as_voices[$0].loop.value=$3; - _as_voices[$0].detune.value=$6; - _as_voice_pan[$0].pan.value=$4; - _as_voice_gain[$0].gain.value=$5; - _as_voices[$0].start(); - _as_voices[$0].onended=function() { - _as_voices[$0].disconnect(_as_voice_gain[$0]); - _as_voices[$0]=null; - } - - },voice->index,sample->index,sample->mix_rate*sample->loop_begin,sample->mix_rate*sample->loop_end,sample->loop_format!=SAMPLE_LOOP_NONE,voice->pan,voice->volume*fx_volume_scale,detune); + /* clang-format off */ + EM_ASM_({ + if (_as_voices[$0] !== null) { + _as_voices[$0].stop(); //stop and byebye + } + _as_voices[$0] = _as_audioctx.createBufferSource(); + _as_voices[$0].connect(_as_voice_gain[$0]); + _as_voices[$0].buffer = _as_samples[$1]; + _as_voices[$0].loopStart.value = $1; + _as_voices[$0].loopEnd.value = $2; + _as_voices[$0].loop.value = $3; + _as_voices[$0].detune.value = $6; + _as_voice_pan[$0].pan.value = $4; + _as_voice_gain[$0].gain.value = $5; + _as_voices[$0].start(); + _as_voices[$0].onended = function() { + _as_voices[$0].disconnect(_as_voice_gain[$0]); + _as_voices[$0] = null; + } + }, voice->index, sample->index, sample->mix_rate * sample->loop_begin, sample->mix_rate * sample->loop_end, sample->loop_format != SAMPLE_LOOP_NONE, voice->pan, voice->volume * fx_volume_scale, detune); + /* clang-format on */ voice->active=true; } @@ -295,11 +299,11 @@ void AudioServerJavascript::voice_set_volume(RID p_voice, float p_volume){ voice->volume=p_volume; if (voice->active) { - EM_ASM_( { - - _as_voice_gain[$0].gain.value=$1; - - },voice->index,voice->volume*fx_volume_scale); + /* clang-format off */ + EM_ASM_({ + _as_voice_gain[$0].gain.value = $1; + }, voice->index, voice->volume * fx_volume_scale); + /* clang-format on */ } } @@ -313,11 +317,11 @@ void AudioServerJavascript::voice_set_pan(RID p_voice, float p_pan, float p_dept voice->pan_height=height; if (voice->active) { - EM_ASM_( { - - _as_voice_pan[$0].pan.value=$1; - - },voice->index,voice->pan); + /* clang-format off */ + EM_ASM_({ + _as_voice_pan[$0].pan.value = $1; + }, voice->index, voice->pan); + /* clang-format on */ } } void AudioServerJavascript::voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance, float p_gain){ @@ -340,11 +344,11 @@ void AudioServerJavascript::voice_set_mix_rate(RID p_voice, int p_mix_rate){ float freq_diff = Math::log(float(voice->mix_rate)/float(voice->sample_mix_rate))/Math::log(2.0); int detune = int(freq_diff*1200.0); - EM_ASM_( { - - _as_voices[$0].detune.value=$1; - - },voice->index,detune); + /* clang-format off */ + EM_ASM_({ + _as_voices[$0].detune.value = $1; + }, voice->index, detune); + /* clang-format on */ } } void AudioServerJavascript::voice_set_positional(RID p_voice, bool p_positional){ @@ -419,14 +423,15 @@ void AudioServerJavascript::voice_stop(RID p_voice){ ERR_FAIL_COND(!voice); if (voice->active) { - - EM_ASM_( { - if (_as_voices[$0]!==null) { - _as_voices[$0].stop(); - _as_voices[$0].disconnect(_as_voice_gain[$0]); - _as_voices[$0]=null; - } - },voice->index); + /* clang-format off */ + EM_ASM_({ + if (_as_voices[$0] !== null) { + _as_voices[$0].stop(); + _as_voices[$0].disconnect(_as_voice_gain[$0]); + _as_voices[$0] = null; + } + }, voice->index); + /* clang-format on */ voice->active=false; } @@ -524,22 +529,25 @@ void AudioServerJavascript::free(RID p_id){ ERR_FAIL_COND(!voice); if (voice->active) { - EM_ASM_( { - if (_as_voices[$0]!==null) { + /* clang-format off */ + EM_ASM_({ + if (_as_voices[$0] !== null) { _as_voices[$0].stop(); - _as_voices[$0].disconnect(_as_voice_gain[$0]); + _as_voices[$0].disconnect(_as_voice_gain[$0]); } - },voice->index); + }, voice->index); + /* clang-format on */ } - EM_ASM_( { + /* clang-format off */ + EM_ASM_({ delete _as_voices[$0]; _as_voice_gain[$0].disconnect(_as_voice_pan[$0]); delete _as_voice_gain[$0]; _as_voice_pan[$0].disconnect(_as_audioctx.destination); delete _as_voice_pan[$0]; - - },voice->index); + }, voice->index); + /* clang-format on */ voice_owner.free(p_id); memdelete(voice); @@ -549,10 +557,11 @@ void AudioServerJavascript::free(RID p_id){ Sample *sample = sample_owner.get(p_id); ERR_FAIL_COND(!sample); - EM_ASM_( { + /* clang-format off */ + EM_ASM_({ delete _as_samples[$0]; - - },sample->index); + }, sample->index); + /* clang-format on */ sample_owner.free(p_id); memdelete(sample); @@ -594,21 +603,20 @@ void AudioServerJavascript::mix_to_js(int p_frames) { int tomix=MIN(todo,INTERNAL_BUFFER_SIZE); driver_process_chunk(tomix); - + /* clang-format off */ EM_ASM_({ - - var data = HEAPF32.subarray($0/4, $0/4 + $2*2); + var data = HEAPF32.subarray($0 / 4, $0 / 4 + $2 * 2); for (var channel = 0; channel < _as_output_buffer.numberOfChannels; channel++) { var outputData = _as_output_buffer.getChannelData(channel); // Loop through samples for (var sample = 0; sample < $2; sample++) { // make output equal to the same as the input - outputData[sample+$1] = data[sample*2+channel]; + outputData[sample + $1] = data[sample * 2 + channel]; } } - - },internal_buffer,offset,tomix); + }, internal_buffer, offset, tomix); + /* clang-format on */ todo-=tomix; offset+=tomix; @@ -618,9 +626,11 @@ void AudioServerJavascript::mix_to_js(int p_frames) { void AudioServerJavascript::init(){ /* + // clang-format off EM_ASM( - console.log('server is '+audio_server); + console.log('server is ' + audio_server); ); + // clang-format on */ @@ -634,19 +644,19 @@ void AudioServerJavascript::init(){ int buffer_latency=16384; + /* clang-format off */ EM_ASM_( { - _as_script_node = _as_audioctx.createScriptProcessor($0, 0, 2); _as_script_node.connect(_as_audioctx.destination); console.log(_as_script_node.bufferSize); - _as_script_node.onaudioprocess = function(audioProcessingEvent) { // The output buffer contains the samples that will be modified and played _as_output_buffer = audioProcessingEvent.outputBuffer; audio_server_mix_function(_as_output_buffer.getChannelData(0).length); } - },buffer_latency); + }, buffer_latency); + /* clang-format on */ } @@ -813,20 +823,24 @@ AudioServerJavascript::AudioServerJavascript() { singleton=this; sample_base=1; voice_base=1; + /* clang-format off */ EM_ASM( - _as_samples={}; - _as_voices={}; - _as_voice_pan={}; - _as_voice_gain={}; + _as_samples = {}; + _as_voices = {}; + _as_voice_pan = {}; + _as_voice_gain = {}; _as_audioctx = new (window.AudioContext || window.webkitAudioContext)(); audio_server_mix_function = Module.cwrap('audio_server_mix_function', 'void', ['number']); ); + /* clang-format on */ + /* clang-format off */ webaudio_mix_rate = EM_ASM_INT_V( - return _as_audioctx.sampleRate; - ); + return _as_audioctx.sampleRate; + ); + /* clang-format on */ print_line("WEBAUDIO MIX RATE: "+itos(webaudio_mix_rate)); event_voice_scale=1.0; fx_volume_scale=1.0; diff --git a/platform/javascript/audio_server_javascript.h b/platform/javascript/audio_server_javascript.h index 8e61e94dfc..f8c8774e4c 100644 --- a/platform/javascript/audio_server_javascript.h +++ b/platform/javascript/audio_server_javascript.h @@ -29,7 +29,6 @@ #ifndef AUDIO_SERVER_JAVASCRIPT_H #define AUDIO_SERVER_JAVASCRIPT_H - #include "servers/audio_server.h" class AudioServerJavascript : public AudioServer { diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 2cb6874000..a701823b2e 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -14,9 +14,7 @@ def get_name(): def can_build(): import os - if (not os.environ.has_key("EMSCRIPTEN_ROOT")): - return False - return True + return os.environ.has_key("EMSCRIPTEN_ROOT") def get_opts(): @@ -79,10 +77,8 @@ def configure(env): # These flags help keep the file size down env.Append(CPPFLAGS=["-fno-exceptions", '-DNO_SAFE_CAST', '-fno-rtti']) env.Append(CPPFLAGS=['-DJAVASCRIPT_ENABLED', '-DUNIX_ENABLED', '-DPTHREAD_NO_RENAME', '-DNO_FCNTL', '-DMPC_FIXED_POINT', '-DTYPED_METHOD_BIND', '-DNO_THREADS']) - env.Append(CPPFLAGS=['-DGLES2_ENABLED']) + env.Append(CPPFLAGS=['-DGLES3_ENABLED']) env.Append(CPPFLAGS=['-DGLES_NO_CLIENT_ARRAYS']) - env.Append(CPPFLAGS=['-s', 'FULL_ES2=1']) -# env.Append(CPPFLAGS=['-DANDROID_ENABLED', '-DUNIX_ENABLED','-DMPC_FIXED_POINT']) if env['wasm'] == 'yes': env.Append(LINKFLAGS=['-s', 'BINARYEN=1']) @@ -102,14 +98,10 @@ def configure(env): env.Append(CPPFLAGS=['-DJAVASCRIPT_EVAL_ENABLED']) env.Append(LINKFLAGS=['-O2']) + env.Append(LINKFLAGS=['-s', 'USE_WEBGL2=1']) # env.Append(LINKFLAGS=['-g4']) # print "CCCOM is:", env.subst('$CCCOM') # print "P: ", env['p'], " Platofrm: ", env['platform'] import methods - - env.Append(BUILDERS={'GLSL120': env.Builder(action=methods.build_legacygl_headers, suffix='glsl.h', src_suffix='.glsl')}) - env.Append(BUILDERS={'GLSL': env.Builder(action=methods.build_glsl_headers, suffix='glsl.h', src_suffix='.glsl')}) - env.Append(BUILDERS={'GLSL120GLES': env.Builder(action=methods.build_gles2_headers, suffix='glsl.h', src_suffix='.glsl')}) - #env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 33776bc273..e487383ef4 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -38,6 +38,9 @@ #include "os/os.h" #include "platform/javascript/logo.h" #include "string.h" + + +#if 0 class EditorExportPlatformJavaScript : public EditorExportPlatform { GDCLASS( EditorExportPlatformJavaScript,EditorExportPlatform ); @@ -181,8 +184,8 @@ void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t>& p_html, const St String current_line = lines[i]; current_line = current_line.replace("$GODOT_TMEM",itos((1<<(max_memory+5))*1024*1024)); current_line = current_line.replace("$GODOT_BASE",p_name); - current_line = current_line.replace("$GODOT_CANVAS_WIDTH",GlobalConfig::get_singleton()->get("display/width")); - current_line = current_line.replace("$GODOT_CANVAS_HEIGHT",GlobalConfig::get_singleton()->get("display/height")); + current_line = current_line.replace("$GODOT_CANVAS_WIDTH",GlobalConfig::get_singleton()->get("display/window/width")); + current_line = current_line.replace("$GODOT_CANVAS_HEIGHT",GlobalConfig::get_singleton()->get("display/window/height")); current_line = current_line.replace("$GODOT_HEAD_TITLE",!html_title.empty()?html_title:(String) GlobalConfig::get_singleton()->get("application/name")); current_line = current_line.replace("$GODOT_HEAD_INCLUDE",html_head_include); current_line = current_line.replace("$GODOT_STYLE_FONT_FAMILY",html_font_family); @@ -377,7 +380,7 @@ EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() { logo->create_from_image(img); max_memory=3; html_title=""; - html_font_family="arial,sans-serif"; + html_font_family="'Droid Sans',arial,sans-serif"; html_controls_enabled=true; pack_mode=PACK_SINGLE_FILE; } @@ -424,3 +427,4 @@ void register_javascript_exporter() { } +#endif diff --git a/platform/javascript/godot_shell.html b/platform/javascript/godot_shell.html index 3170d2bb9e..65f3b4a340 100644 --- a/platform/javascript/godot_shell.html +++ b/platform/javascript/godot_shell.html @@ -3,14 +3,14 @@ <head> <meta charset="utf-8" /> <title>$GODOT_HEAD_TITLE</title> - $GODOT_HEAD_INCLUDE +$GODOT_HEAD_INCLUDE <style type="text/css"> body { margin: 0; border: 0 none; padding: 0; text-align: center; - background-color: black; + background-color: #222226; font-family: $GODOT_STYLE_FONT_FAMILY; } @@ -71,7 +71,7 @@ margin: 0; border: 0 none; padding: 0; - background-color: #111; + background-color: #0c0c0c; } #canvas { @@ -81,6 +81,7 @@ * calculate cursor coordinates correctly */ border: 0 none; padding: 0; + color: white; } @@ -101,6 +102,8 @@ } #status { + line-height: 1.3; + cursor: pointer; visibility: visible; padding: 4px 6px; } @@ -123,7 +126,7 @@ -ms-user-select: none; } - #container:hover > #controls { + :hover > #controls { opacity: 1.0; transition: opacity 60ms ease-in-out; } @@ -135,223 +138,289 @@ margin-right: 2px; } + #controls > label > input { + vertical-align: middle; + } + #controls > label > input[type="checkbox"] { /* override user agent style */ margin-left: 0; } - label > input { - vertical-align: middle; - } - - #display-output { display: none; } + #output-toggle { display: none; } /* Debug output * ============ */ - #output { + #output-panel { display: none; - margin: 6px auto; - border: 2px groove grey; - padding: 4px; - outline: none; + max-width: $GODOT_CANVAS_WIDTHpx; + font-size: small; + margin: 6px auto 0; + padding: 0 4px 4px; text-align: left; + line-height: 2.2; + } + + #output-header { + display: flex; + justify-content: space-between; + align-items: center; + } + + #output-container { + padding: 6px; + background-color: #2c2a32; + box-shadow: inset 0 0 1px 1px #232127; + color: #bbb; + } + + #output-scroll { + line-height: 1; + height: 12em; + overflow-y: scroll; white-space: pre-wrap; font-size: small; - color: #eee; - background-color: black; font-family: "Lucida Console", Monaco, monospace; } - /* Export style include - * ==================== */ +/* Export style include + * ==================== */ + +$GODOT_STYLE_INCLUDE - $GODOT_STYLE_INCLUDE </style> </head> <body> <div id="container"> <canvas id="canvas" width="$GODOT_CANVAS_WIDTH" height="$GODOT_CANVAS_HEIGHT" onclick="canvas.ownerDocument.defaultView.focus();" oncontextmenu="event.preventDefault();"> - HTML5 canvas appears to be unsupported in the current browser.<br />Please try updating or use a different browser. + HTML5 canvas appears to be unsupported in the current browser.<br /> + Please try updating or use a different browser. </canvas> <div id="status-container"> - <span id="status" class="godot" onclick="this.style.visibility='hidden';">Loading page...</span> + <span id="status" class="godot" onclick="this.style.visibility='hidden';">Downloading page...</span> </div> <div id="controls" class="godot"> - <label id="display-output"><input id="output-toggle" type="checkbox" autocomplete="off" onchange="Presentation.setOutputVisible(this.checked);" />display output</label> + <label id="output-toggle"><input type="checkbox" checked="checked" autocomplete="off" onchange="Presentation.setOutputVisible(this.checked);" />Display Output</label> <!-- hidden until implemented - <label><input id="lock-cursor" type="checkbox" autocomplete="off" />lock cursor</label> - <label><input id="resize-canvas" type="checkbox" autocomplete="off" />resize canvas</label> + <label><input class="postRun-enable" type="checkbox" disabled="disabled" autocomplete="off" />lock cursor</label> + <label><input class="postRun-enable" type="checkbox" disabled="disabled" autocomplete="off" onchange="Presentation.setCanvasMaximized(this.checked);" />maximize</label> --> - <button id="fullscreen" class="godot" type="button" disabled="disabled" autocomplete="off" onclick="Presentation.goFullscreen();">fullscreen</button> + <button id="fullscreen" class="godot postRun-enable" type="button" disabled="disabled" autocomplete="off" onclick="Presentation.requestFullscreen();">Fullscreen</button> </div> </div> - <!-- Firefox adds extra space to textarea, but shouldn't matter too much https://bugzilla.mozilla.org/show_bug.cgi?id=33654 --> - <textarea id="output" rows="10" cols="100" readonly="readonly" style="resize:none"></textarea> + <div id="output-panel" class="godot"> + <div id="output-header"> + Output: + <button class="godot" type="button" autocomplete="off" onclick="Presentation.clearOutput();">Clear</button> + </div> + <div id="output-container"><div id="output-scroll"></div></div> + </div> + <!-- Scripts --> <script type="text/javascript">//<![CDATA[ var Presentation = (function() { var statusElement = document.getElementById("status"); - var outputElement = document.getElementById("output"); - var doneLoading = false; - - function onLoaded() { - doneLoading = true; - var fullscreenButtonElement = document.getElementById("fullscreen"); - fullscreenButtonElement.disabled = false; - } + var canvasElement = document.getElementById("canvas"); var presentation = { - statusElement: statusElement, - outputElement: outputElement, - setOutputVisible: function setOutputVisible(visible) { - outputElement.style.display = (visible?"block":"none"); + postRun: [ + function() { + var elements = document.getElementsByClassName("postRun-enable"); + Array.prototype.slice.call(elements).forEach(function(element) { + element.disabled = false; + }); + } + ], + requestFullscreen: function requestFullscreen() { + if (typeof Module !== "undefined" && Module.requestFullscreen) { + Module.requestFullscreen(false, false); + } + }, + /* + requestPointerlock: function requestPointerlock() { + if (typeof Module !== "undefined" && Module.requestPointerlock) { + Module.requestPointerlock(false, false); + } }, + setCanvasMaximized: function setCanvasMaximized(enabled) { + if (typeof Module !== "undefined" && Module.setCanvasMaximized) { + Module.setCanvasMaximized(enabled); + } + }, + */ setStatusVisible: function setStatusVisible(visible) { statusElement.style.visibility = (visible?"visible":"hidden"); }, setStatus: function setStatus(text) { - if (!text || text.length === 0) { - Presentation.setStatusVisible(false); - onLoaded(); - } else { - Presentation.setStatusVisible(true); - statusElement.innerHTML = text; + if (text.length === 0) { + // emscripten sets empty string as status after "Running..." + // per timeout, but another status may have been set by then + if (Presentation.setStatus.lastText === "Running...") + Presentation.setStatusVisible(false); + return; } + Presentation.setStatus.lastText = text; + while (statusElement.lastChild) { + statusElement.removeChild(statusElement.lastChild); + } + var lines = text.split("\n"); + lines.forEach(function(line, index) { + statusElement.appendChild(document.createTextNode(line)); + statusElement.appendChild(document.createElement("br")); + }); + var closeNote = document.createElement("span"); + closeNote.style.fontSize = "small"; + closeNote.textContent = "click to close"; + statusElement.appendChild(closeNote); + Presentation.setStatusVisible(true); + }, + isWebGL2Available: function isWebGL2Available() { + var context; + try { + context = canvasElement.getContext("webgl2") || canvasElement.getContext("experimental-webgl2"); + } catch (e) {} + return !!context; }, - goFullscreen: function goFullscreen() { - if (doneLoading) Module.requestFullScreen(false, false); - } }; + window.onerror = function(event) { presentation.setStatus("Failure during start-up\nSee JavaScript console") }; + if ($GODOT_CONTROLS_ENABLED) { // controls enabled - (function() { - var controlsElement = document.getElementById("controls"); - controlsElement.style.visibility="visible"; - })(); + document.getElementById("controls").style.visibility="visible"; } if ($GODOT_DEBUG_ENABLED) { // debugging enabled - (function() { - var outputToggleLabel = document.getElementById("display-output"); - var outputToggle = document.getElementById("output-toggle"); - - outputElement.value = ""; // clear browser cache - outputElement.style.display = "block"; - outputToggle.checked = true; - outputToggleLabel.style.display = "inline"; - - presentation.print = function print(text) { - if (outputElement.value.length !== 0) - outputElement.value += "\n"; - outputElement.value += text; - outputElement.scrollTop = outputElement.scrollHeight; // focus on bottom - }; - })(); + var outputRoot = document.getElementById("output-panel"); + var outputElement = document.getElementById("output-scroll"); + var outputToggle = document.getElementById("output-toggle"); + const maxOutputMessages = 400; + + presentation.setOutputVisible = function setOutputVisible(visible) { + outputRoot.style.display = (visible?"block":"none"); + }; + presentation.clearOutput = function clearOutput() { + while (outputElement.firstChild) { + outputElement.firstChild.remove(); + } + }; + + presentation.setOutputVisible(true); + outputToggle.style.display = "inline"; + + presentation.print = function print(text) { + if (arguments.length > 1) { + text = Array.prototype.slice.call(arguments).join(" "); + } + if (text.length <= 0) return; + while (outputElement.childElementCount >= maxOutputMessages) { + outputElement.firstChild.remove(); + } + var msg = document.createElement("div"); + if (String.prototype.trim.call(text).startsWith("**ERROR**") + || String.prototype.trim.call(text).startsWith("**EXCEPTION**")) { + msg.style.color = "#d44"; + } else if (String.prototype.trim.call(text).startsWith("**WARNING**")) { + msg.style.color = "#ccc000"; + } else if (String.prototype.trim.call(text).startsWith("**SCRIPT ERROR**")) { + msg.style.color = "#c6d"; + } + msg.textContent = text; + var scrollToBottom = outputElement.scrollHeight - (outputElement.clientHeight + outputElement.scrollTop) < 10; + outputElement.appendChild(msg); + if (scrollToBottom) { + outputElement.scrollTop = outputElement.scrollHeight; + } + }; + + presentation.postRun.push(function() { + window.onerror = function(event) { presentation.print("**EXCEPTION**:", event) }; + }); + + } else { + presentation.postRun.push(function() { window.onerror = null; }); } return presentation; })(); // Emscripten interface - var Module = (function() { - var print = (function() { - if (typeof Presentation.print === "function") { - return function print(text) { - if (arguments.length > 1) - text = Array.prototype.slice.call(arguments).join(" "); - console.log(text); - Presentation.print(text); - }; - } else { - return function print(text) { - if (arguments.length > 1) - text = Array.prototype.slice.call(arguments).join(" "); - console.log(text); - }; + var Module = { + TOTAL_MEMORY: $GODOT_TMEM, + postRun: (function() { + if (typeof Presentation !== "undefined" && Presentation.postRun instanceof Array) { + return Presentation.postRun; } - })(); - - var canvas = (function() { - var canvasElement = document.getElementById("canvas"); - + })(), + print: function print(text) { + if (arguments.length > 1) { + text = Array.prototype.slice.call(arguments).join(" "); + } + console.log(text); + if (typeof Presentation !== "undefined" && typeof Presentation.print === "function") { + Presentation.print(text); + } + }, + printErr: function printErr(text) { + if (arguments.length > 1) { + text = Array.prototype.slice.call(arguments).join(" "); + } + console.error(text); + if (typeof Presentation !== "undefined" && typeof Presentation.print === "function") { + Presentation.print("**ERROR**:", text) + } + }, + canvas: (function() { + var canvas = document.getElementById("canvas"); // As a default initial behavior, pop up an alert when WebGL context is lost. To make your // application robust, you may want to override this behavior before shipping! // See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2 - canvasElement.addEventListener("webglcontextlost", function(e) { alert("WebGL context lost. Plase reload the page."); e.preventDefault(); }, false); - - return canvasElement; - })(); - - var setStatus = (function() { - if (typeof Presentation.setStatus === "function") - return function setStatus(text) { - if (!Module.setStatus.last) - Module.setStatus.last = { time: Date.now(), text: "" }; - if (text === Module.setStatus.text) - return; - var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); - var now = Date.now(); - if (m) { - if (now - Date.now() < 30) // if this is a progress update, skip it if too soon - return; - text = m[1]; - } - Presentation.setStatus(text); - }; - else - return function setStatus(text) { - if (!Module.setStatus.last) - Module.setStatus.last = { time: Date.now(), text: "" }; - if (text === Module.setStatus.text) - return; - var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); - var now = Date.now(); - if (m) { - if (now - Date.now() < 30) // if this is a progress update, skip it if too soon - return; - text = m[1]; - } - }; - })(); - - return { - TOTAL_MEMORY: 268435456, - preRun: [], - postRun: [], - print: print, - printErr: function printErr(text) { - if (arguments.length > 1) - text = Array.prototype.slice.call(arguments).join(" "); - if (0) { // XXX disabled for safety `if (typeof dump == "function")` - dump(text + "\n"); // fast, straight to the real console - } else { - console.error(text); - } - }, - canvas: canvas, - setStatus: setStatus, - totalDependencies: 0, - monitorRunDependencies: function monitorRunDependencies(left) { - this.totalDependencies = Math.max(this.totalDependencies, left); - Module.setStatus(left ? "Preparing... (" + (this.totalDependencies-left) + "/" + this.totalDependencies + ")" : "All downloads complete."); + canvas.addEventListener("webglcontextlost", function(e) { alert("WebGL context lost. Plase reload the page."); e.preventDefault(); }, false); + return canvas; + + })(), + setStatus: function setStatus(text) { + var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/); + var now = Date.now(); + if (m) { + if (now - Date.now() < 30) // if this is a progress update, skip it if too soon + return; + text = m[1]; } - }; - })(); + if (typeof Presentation !== "undefined" && typeof Presentation.setStatus == "function") { + Presentation.setStatus(text); + } + } + }; - Presentation.setStatus("Downloading..."); + if (!Presentation.isWebGL2Available()) { + Presentation.setStatus("WebGL2 appears to be unsupported in the current browser.\nPlease try updating or use a different browser."); + Presentation.preventLoading = true; + } else { + Presentation.setStatus("Downloading..."); + } - window.onerror = function(event) { - // TODO: do not warn on ok events like simulating an infinite loop or exitStatus - Module.setStatus("Exception thrown, see JavaScript console"); - Module.setStatus = function(text) { - if (text) Module.printErr("[post-exception status] " + text); - }; - }; + if (Presentation.preventLoading) { + // prevent *fs.js and Emscripten's SCRIPT placeholder from loading any files + Presentation._XHR_send = XMLHttpRequest.prototype.send; + XMLHttpRequest.prototype.send = function() {}; + Presentation._Node_appendChild = Node.prototype.appendChild; + Node.prototype.appendChild = function(node) { + if (!(node instanceof HTMLScriptElement)) { + return Presentation._Node_appendChild.call(this, node); + } + } + } //]]></script> <script type="text/javascript" src="$GODOT_BASEfs.js"></script> - {{{ SCRIPT }}} +{{{ SCRIPT }}} + <script type="text/javascript"> + if (Presentation.preventLoading) { + XMLHttpRequest.prototype.send = Presentation._XHR_send; + Node.prototype.appendChild = Presentation._Node_appendChild; + } + </script> </body> </html> diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp index 7bbe0ae99b..72b7ab06cd 100644 --- a/platform/javascript/javascript_eval.cpp +++ b/platform/javascript/javascript_eval.cpp @@ -41,6 +41,7 @@ JavaScript *JavaScript::get_singleton() { Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) { union { int i; double d; char* s; } js_data[4]; + /* clang-format off */ Variant::Type return_type = static_cast<Variant::Type>(EM_ASM_INT({ var eval_ret; @@ -49,8 +50,7 @@ Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) { // indirect eval call grants global execution context var global_eval = eval; eval_ret = global_eval(UTF8ToString($2)); - } - else { + } else { eval_ret = eval(UTF8ToString($2)); } } catch (e) { @@ -125,6 +125,7 @@ Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) { return 0; // NIL }, js_data, sizeof *js_data, p_code.utf8().get_data(), p_use_global_exec_context)); + /* clang-format on */ switch(return_type) { case Variant::BOOL: @@ -136,7 +137,9 @@ Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) { case Variant::STRING: { String str = String::utf8(js_data->s); + /* clang-format off */ EM_ASM_({ _free($0); }, js_data->s); + /* clang-format on */ return str; } case Variant::VECTOR2: @@ -153,7 +156,7 @@ Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) { void JavaScript::_bind_methods() { - ObjectTypeDB::bind_method(_MD("eval", "code", "use_global_execution_context"), &JavaScript::eval, false); + ClassDB::bind_method(_MD("eval", "code", "use_global_execution_context"), &JavaScript::eval, false); } JavaScript::JavaScript() { diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp index 6ec7f1ec3d..94320d53c1 100644 --- a/platform/javascript/javascript_main.cpp +++ b/platform/javascript/javascript_main.cpp @@ -140,10 +140,9 @@ static void _godot_draw(void) { extern "C" { -void main_after_fs_sync(int value) { +void main_after_fs_sync() { start_step=1; - printf("FS SYNCHED!\n"); } } @@ -178,26 +177,27 @@ int main(int argc, char *argv[]) { glutDisplayFunc(_godot_draw); //glutSpecialFunc(gears_special); - - - //mount persistent filesystem - EM_ASM( - FS.mkdir('/userfs'); - FS.mount(IDBFS, {}, '/userfs'); - - - - // sync from persisted state into memory and then - // run the 'test' function - FS.syncfs(true, function (err) { - assert(!err); - console.log("done syncinc!"); - _after_sync_cb = Module.cwrap('main_after_fs_sync', 'void',['number']); - _after_sync_cb(0); - - }); - - ); + //mount persistent file system + /* clang-format off */ + EM_ASM( + FS.mkdir('/userfs'); + FS.mount(IDBFS, {}, '/userfs'); + + // sync from persistent state into memory and then + // run the 'main_after_fs_sync' function + FS.syncfs(true, function(err) { + + if (err) { + Module.setStatus('Failed to load persistent data\nPlease allow (third-party) cookies'); + Module.printErr('Failed to populate IDB file system: ' + err.message); + Module.exit(); + } else { + Module.print('Successfully populated IDB file system'); + ccall('main_after_fs_sync', 'void', []); + } + }); + ); + /* clang-format on */ glutMainLoop(); diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 18bf8f6a86..b8c3dea3b4 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -27,27 +27,27 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "os_javascript.h" -#include "drivers/gles2/rasterizer_gles2.h" + +#include "drivers/gles3/rasterizer_gles3.h" #include "core/io/file_access_buffered_fa.h" #include "drivers/unix/file_access_unix.h" #include "drivers/unix/dir_access_unix.h" - #include "servers/visual/visual_server_raster.h" - #include "main/main.h" - #include "core/globals.h" -#include "stdlib.h" -#include "emscripten.h" #include "dom_keys.h" +#include <stdlib.h> +#include <emscripten.h> + int OS_JavaScript::get_video_driver_count() const { return 1; } + const char * OS_JavaScript::get_video_driver_name(int p_driver) const { - return "GLES2"; + return "GLES3"; } OS::VideoMode OS_JavaScript::get_default_video_mode() const { @@ -215,6 +215,7 @@ void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int // find locale, emscripten only sets "C" char locale_ptr[16]; + /* clang-format off */ EM_ASM_({ var locale = ""; if (Module.locale) { @@ -230,56 +231,26 @@ void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int locale = locale.split('.')[0]; stringToUTF8(locale, $0, 16); }, locale_ptr); + /* clang-format on */ setenv("LANG", locale_ptr, true); print_line("Init Audio"); - AudioDriverManagerSW::add_driver(&audio_driver_javascript); + AudioDriverManager::add_driver(&audio_driver_javascript); + audio_driver_javascript.set_singleton(); + if (audio_driver_javascript.init() != OK) { - if (true) { - RasterizerGLES2 *rasterizer_gles22=memnew( RasterizerGLES2(false,false,false,false) );; - rasterizer_gles22->set_use_framebuffers(false); //not supported by emscripten - if (gl_extensions) - rasterizer_gles22->set_extensions(gl_extensions); - rasterizer = rasterizer_gles22; - } else { - //rasterizer = memnew( RasterizerGLES1(true, false) ); + ERR_PRINT("Initializing audio failed."); } + RasterizerGLES3::register_config(); + RasterizerGLES3::make_current(); + print_line("Init VS"); - visual_server = memnew( VisualServerRaster(rasterizer) ); - visual_server->init(); + visual_server = memnew( VisualServerRaster() ); visual_server->cursor_set_visible(false, 0); - /*AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); - - if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { - - ERR_PRINT("Initializing audio failed."); - }*/ - - print_line("Init SM"); - - //sample_manager = memnew( SampleManagerMallocSW ); - audio_server = memnew( AudioServerJavascript ); - - print_line("Init Mixer"); - - //audio_server->set_mixer_params(AudioMixerSW::INTERPOLATION_LINEAR,false); - audio_server->init(); - - print_line("Init SoundServer"); - - spatial_sound_server = memnew( SpatialSoundServerSW ); - spatial_sound_server->init(); - - print_line("Init SpatialSoundServer"); - - spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); - spatial_sound_2d_server->init(); - - // print_line("Init Physicsserver"); physics_server = memnew( PhysicsServerSW ); @@ -332,9 +303,11 @@ void OS_JavaScript::finalize() { void OS_JavaScript::alert(const String& p_alert,const String& p_title) { + /* clang-format off */ EM_ASM_({ window.alert(UTF8ToString($0)); }, p_alert.utf8().get_data()); + /* clang-format on */ } @@ -366,9 +339,11 @@ int OS_JavaScript::get_mouse_button_state() const { void OS_JavaScript::set_window_title(const String& p_title) { + /* clang-format off */ EM_ASM_({ document.title = UTF8ToString($0); }, p_title.utf8().get_data()); + /* clang-format on */ } //interesting byt not yet @@ -424,8 +399,10 @@ void OS_JavaScript::set_window_maximized(bool p_enabled) { set_window_fullscreen(false); } else { + /* clang-format off */ video_mode.width = EM_ASM_INT_V(return window.innerWidth); video_mode.height = EM_ASM_INT_V(return window.innerHeight); + /* clang-format on */ emscripten_set_canvas_size(video_mode.width, video_mode.height); } } @@ -444,7 +421,9 @@ void OS_JavaScript::set_window_fullscreen(bool p_enable) { // _browser_resize_callback or _fullscreen_change_callback EMSCRIPTEN_RESULT result; if (p_enable) { + /* clang-format off */ EM_ASM(Module.requestFullscreen(false, false);); + /* clang-format on */ } else { result = emscripten_exit_fullscreen(); @@ -502,19 +481,15 @@ bool OS_JavaScript::main_loop_iterate() { time_to_save_sync-=elapsed; - print_line("elapsed "+itos(elapsed)+" tts "+itos(time_to_save_sync)); - if (time_to_save_sync<0) { //time to sync, for real - // run 'success' - print_line("DOING SYNCH!"); + /* clang-format off */ EM_ASM( - FS.syncfs(function (err) { - assert(!err); - console.log("Synched!"); - //ccall('success', 'v'); - }); + FS.syncfs(function(err) { + if (err) { Module.printErr('Failed to save IDB file system: ' + err.message); } + }); ); + /* clang-format on */ } @@ -782,18 +757,12 @@ void OS_JavaScript::main_loop_request_quit() { main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST); } -void OS_JavaScript::reload_gfx() { - - if (gfx_init_func) - gfx_init_func(gfx_init_ud,use_gl2,video_mode.width,video_mode.height,video_mode.fullscreen); - if (rasterizer) - rasterizer->reload_vram(); -} - Error OS_JavaScript::shell_open(String p_uri) { + /* clang-format off */ EM_ASM_({ window.open(UTF8ToString($0), '_blank'); }, p_uri.utf8().get_data()); + /* clang-format on */ return OK; } @@ -890,7 +859,6 @@ OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, Get main_loop=NULL; last_id=1; gl_extensions=NULL; - rasterizer=NULL; window_maximized=false; get_data_dir_func=p_get_data_dir_func; diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 370322e93d..582f128ce8 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -33,17 +33,16 @@ #include "drivers/unix/os_unix.h" #include "os/main_loop.h" #include "servers/physics/physics_server_sw.h" -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #include "servers/physics_2d/physics_2d_server_sw.h" #include "servers/visual/rasterizer.h" #include "audio_server_javascript.h" #include "audio_driver_javascript.h" #include "main/input_default.h" -#include "emscripten/html5.h" #include "javascript_eval.h" +#include <emscripten/html5.h> + typedef void (*GFXInitFunc)(void *ud,bool gl2,int w, int h, bool fs); typedef String (*GetDataDirFunc)(); @@ -69,12 +68,7 @@ private: int64_t time_to_save_sync; int64_t last_sync_time; - Rasterizer *rasterizer; VisualServer *visual_server; - AudioServerJavascript *audio_server; - //SampleManagerMallocSW *sample_manager; - SpatialSoundServerSW *spatial_sound_server; - SpatialSound2DServerSW *spatial_sound_2d_server; PhysicsServer *physics_server; Physics2DServer *physics_2d_server; AudioDriverJavaScript audio_driver_javascript; @@ -168,8 +162,6 @@ public: void set_opengl_extensions(const char* p_gl_extensions); - void reload_gfx(); - virtual Error shell_open(String p_uri); virtual String get_data_dir() const; String get_executable_path() const; diff --git a/platform/osx/audio_driver_osx.cpp b/platform/osx/audio_driver_osx.cpp index 87901f6ec4..4ad3a5b8fc 100644 --- a/platform/osx/audio_driver_osx.cpp +++ b/platform/osx/audio_driver_osx.cpp @@ -157,8 +157,8 @@ int AudioDriverOSX::get_mix_rate() const { return 44100; }; -AudioDriverSW::OutputFormat AudioDriverOSX::get_output_format() const { - return OUTPUT_STEREO; +AudioDriver::SpeakerMode AudioDriverOSX::get_speaker_mode() const { + return SPEAKER_MODE_STEREO; }; void AudioDriverOSX::lock() { diff --git a/platform/osx/audio_driver_osx.h b/platform/osx/audio_driver_osx.h index 19b396de57..9e9bb63726 100644 --- a/platform/osx/audio_driver_osx.h +++ b/platform/osx/audio_driver_osx.h @@ -31,11 +31,11 @@ #ifndef AUDIO_DRIVER_OSX_H #define AUDIO_DRIVER_OSX_H -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #include <AudioUnit/AudioUnit.h> -class AudioDriverOSX : public AudioDriverSW { +class AudioDriverOSX : public AudioDriver { AudioComponentInstance audio_unit; bool active; @@ -61,7 +61,7 @@ public: virtual Error init(); virtual void start(); virtual int get_mix_rate() const; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 1cb41cede2..3a97827c16 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -39,7 +39,7 @@ #include "os/os.h" #include "platform/osx/logo.h" #include "string.h" - +#if 0 class EditorExportPlatformOSX : public EditorExportPlatform { @@ -546,3 +546,4 @@ void register_osx_exporter() { } +#endif diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index f6559f1f7a..d8c35472f2 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -38,10 +38,7 @@ // #include "servers/visual/visual_server_wrap_mt.h" #include "servers/visual/rasterizer.h" #include "servers/physics_server.h" -#include "servers/audio/audio_server_sw.h" -#include "servers/audio/sample_manager_sw.h" -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" +#include "servers/audio_server.h" #include "drivers/rtaudio/audio_driver_rtaudio.h" #include "drivers/alsa/audio_driver_alsa.h" #include "servers/physics_2d/physics_2d_server_sw.h" @@ -72,10 +69,6 @@ public: IP_Unix *ip_unix; AudioDriverOSX audio_driver_osx; - AudioServerSW *audio_server; - SampleManagerMallocSW *sample_manager; - SpatialSoundServerSW *spatial_sound_server; - SpatialSound2DServerSW *spatial_sound_2d_server; InputDefault *input; JoypadOSX *joypad_osx; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 5750e19c87..854ccacbf1 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1083,7 +1083,7 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi - AudioDriverManagerSW::add_driver(&audio_driver_osx); + AudioDriverManager::add_driver(&audio_driver_osx); // only opengl support here... RasterizerGLES3::register_config(); @@ -1102,25 +1102,13 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi visual_server->init(); visual_server->cursor_set_visible(false, 0); - AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); + AudioDriverManager::get_driver(p_audio_driver)->set_singleton(); - if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { + if (AudioDriverManager::get_driver(p_audio_driver)->init()!=OK) { ERR_PRINT("Initializing audio failed."); } - sample_manager = memnew( SampleManagerMallocSW ); - audio_server = memnew( AudioServerSW(sample_manager) ); - - audio_server->set_mixer_params(AudioMixerSW::INTERPOLATION_LINEAR,false); - audio_server->init(); - - spatial_sound_server = memnew( SpatialSoundServerSW ); - spatial_sound_server->init(); - - spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); - spatial_sound_2d_server->init(); - // physics_server = memnew( PhysicsServerSW ); physics_server->init(); @@ -1167,19 +1155,9 @@ void OS_OSX::finalize() { CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL); delete_main_loop(); - spatial_sound_server->finish(); - memdelete(spatial_sound_server); - spatial_sound_2d_server->finish(); - memdelete(spatial_sound_2d_server); - memdelete(joypad_osx); memdelete(input); - memdelete(sample_manager); - - audio_server->finish(); - memdelete(audio_server); - visual_server->finish(); memdelete(visual_server); //memdelete(rasterizer); diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp index 6b91a5ce77..d691ae35bd 100644 --- a/platform/server/os_server.cpp +++ b/platform/server/os_server.cpp @@ -61,9 +61,9 @@ void OS_Server::initialize(const VideoMode& p_desired,int p_video_driver,int p_a //visual_server = memnew( VisualServerRaster(rasterizer) ); - AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); + AudioDriverManager::get_driver(p_audio_driver)->set_singleton(); - if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { + if (AudioDriverManager::get_driver(p_audio_driver)->init()!=OK) { ERR_PRINT("Initializing audio failed."); } @@ -237,7 +237,7 @@ void OS_Server::run() { OS_Server::OS_Server() { - AudioDriverManagerSW::add_driver(&driver_dummy); + AudioDriverManager::add_driver(&driver_dummy); //adriver here grab=false; diff --git a/platform/server/os_server.h b/platform/server/os_server.h index f7fe586b1b..2b6225c48d 100644 --- a/platform/server/os_server.h +++ b/platform/server/os_server.h @@ -29,17 +29,13 @@ #ifndef OS_SERVER_H #define OS_SERVER_H - #include "main/input_default.h" #include "drivers/unix/os_unix.h" #include "servers/visual_server.h" #include "servers/visual/rasterizer.h" #include "servers/audio/audio_driver_dummy.h" #include "servers/physics_server.h" -#include "servers/audio/audio_server_sw.h" -#include "servers/audio/sample_manager_sw.h" -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" +#include "servers/audio_server.h" #include "drivers/rtaudio/audio_driver_rtaudio.h" #include "servers/physics_2d/physics_2d_server_sw.h" @@ -66,11 +62,6 @@ class OS_Server : public OS_Unix { virtual void delete_main_loop(); IP_Unix *ip_unix; - AudioServerSW *audio_server; - SampleManagerMallocSW *sample_manager; - SpatialSoundServerSW *spatial_sound_server; - SpatialSound2DServerSW *spatial_sound_2d_server; - bool force_quit; InputDefault *input; diff --git a/platform/uwp/app.h b/platform/uwp/app.h index 6df9c5699e..fd6fc950a7 100644 --- a/platform/uwp/app.h +++ b/platform/uwp/app.h @@ -32,38 +32,41 @@ #include <wrl.h> -#include "os_uwp.h" #include "GLES2/gl2.h" +#include "os_uwp.h" + +/** clang-format does not play nice with this C++/CX hybrid, needs investigation. */ +/* clang-format off */ namespace GodotUWP { - ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView - { - public: - App(); - - // IFrameworkView Methods. - virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); - virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); - virtual void Load(Platform::String^ entryPoint); - virtual void Run(); - virtual void Uninitialize(); + ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView + { + public: + App(); + + // IFrameworkView Methods. + virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); + virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); + virtual void Load(Platform::String^ entryPoint); + virtual void Run(); + virtual void Uninitialize(); property Windows::Foundation::EventRegistrationToken MouseMovedToken { - Windows::Foundation::EventRegistrationToken get() { return this->mouseMovedToken; } - void set(Windows::Foundation::EventRegistrationToken p_token) { this->mouseMovedToken = p_token; } - }; + Windows::Foundation::EventRegistrationToken get() { return this->mouseMovedToken; } + void set(Windows::Foundation::EventRegistrationToken p_token) { this->mouseMovedToken = p_token; } + } - private: + private: void RecreateRenderer(); - // Application lifecycle event handlers. - void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); + // Application lifecycle event handlers. + void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); - // Window event handlers. - void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); - void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); - void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args); + // Window event handlers. + void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); + void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); + void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args); void pointer_event(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args, bool p_pressed, bool p_is_wheel = false); void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); @@ -81,20 +84,20 @@ namespace GodotUWP void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args); - void UpdateWindowSize(Windows::Foundation::Size size); - void InitializeEGL(Windows::UI::Core::CoreWindow^ window); - void CleanupEGL(); + void UpdateWindowSize(Windows::Foundation::Size size); + void InitializeEGL(Windows::UI::Core::CoreWindow^ window); + void CleanupEGL(); char** get_command_line(unsigned int* out_argc); - bool mWindowClosed; - bool mWindowVisible; - GLsizei mWindowWidth; - GLsizei mWindowHeight; + bool mWindowClosed; + bool mWindowVisible; + GLsizei mWindowWidth; + GLsizei mWindowHeight; - EGLDisplay mEglDisplay; - EGLContext mEglContext; - EGLSurface mEglSurface; + EGLDisplay mEglDisplay; + EGLContext mEglContext; + EGLSurface mEglSurface; CoreWindow^ window; OSUWP* os; @@ -103,6 +106,7 @@ namespace GodotUWP int last_touch_y[32]; int number_of_contacts; Windows::Foundation::Point last_mouse_pos; - }; - + } } + +/* clang-format on */ diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index 4648384480..167a5831cf 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -65,7 +65,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *************************************************************************/ - +#if 0 #include "version.h" #include "export.h" #include "object.h" @@ -618,9 +618,7 @@ void AppxPackager::make_content_types() { types[ext] = content_type(ext); - tmp_file->store_string("<Default Extension=\"" + ext + - "\" ContentType=\"" - + types[ext] + "\" />"); + tmp_file->store_string("<Default Extension=\"" + ext + "\" ContentType=\"" + types[ext] + "\" />"); } // Appx signature file @@ -1174,9 +1172,9 @@ Error AppxPackager::MakeIndirectDataContent(asn1::SPCIndirectDataContent &idc) { MakeSPCInfoValue(*infoValue); ASN1_TYPE* value = - EncodedASN1::FromItem<asn1::SPCInfoValue, - asn1::i2d_SPCInfoValue>(infoValue) - .ToSequenceType(); + EncodedASN1::FromItem<asn1::SPCInfoValue, + asn1::i2d_SPCInfoValue>(infoValue) + .ToSequenceType(); { Vector<uint8_t> digest; @@ -1202,8 +1200,10 @@ Error AppxPackager::add_attributes(PKCS7_SIGNER_INFO * p_signer_info) { asn1::SPCSpOpusInfo* opus = asn1::SPCSpOpusInfo_new(); if (!opus) return openssl_error(ERR_peek_last_error()); - ASN1_STRING* opus_value = EncodedASN1::FromItem<asn1::SPCSpOpusInfo, asn1::i2d_SPCSpOpusInfo>(opus) - .ToSequenceString(); + ASN1_STRING* opus_value = + EncodedASN1::FromItem<asn1::SPCSpOpusInfo, + asn1::i2d_SPCSpOpusInfo>(opus) + .ToSequenceString(); if (!PKCS7_add_signed_attribute( p_signer_info, @@ -1237,8 +1237,9 @@ Error AppxPackager::add_attributes(PKCS7_SIGNER_INFO * p_signer_info) { statement_type->type = OBJ_nid2obj(NID_ms_code_ind); ASN1_STRING* statement_type_value = - EncodedASN1::FromItem<asn1::SPCStatementType, asn1::i2d_SPCStatementType>(statement_type) - .ToSequenceString(); + EncodedASN1::FromItem<asn1::SPCStatementType, + asn1::i2d_SPCStatementType>(statement_type) + .ToSequenceString(); if (!PKCS7_add_signed_attribute( p_signer_info, @@ -2389,3 +2390,4 @@ void register_uwp_exporter() { Ref<EditorExportPlatformUWP> exporter = Ref<EditorExportPlatformUWP>(memnew(EditorExportPlatformUWP)); EditorImportExport::get_singleton()->add_export_platform(exporter); } +#endif diff --git a/platform/uwp/joypad_uwp.h b/platform/uwp/joypad_uwp.h index 90505b409a..5d81ac44c0 100644 --- a/platform/uwp/joypad_uwp.h +++ b/platform/uwp/joypad_uwp.h @@ -33,10 +33,12 @@ ref class JoypadUWP sealed { + /** clang-format breaks this, it does not understand this token. */ + /* clang-format off */ internal: - void register_events(); uint32_t process_controllers(uint32_t p_last_id); + /* clang-format on */ JoypadUWP(); JoypadUWP(InputDefault* p_input); diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 9dd745716e..90c21e11a1 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -36,16 +36,12 @@ #include "main/main.h" #include "drivers/windows/file_access_windows.h" #include "drivers/windows/dir_access_windows.h" - - #include "servers/visual/visual_server_raster.h" -#include "servers/audio/audio_server_sw.h" -#include "servers/visual/visual_server_wrap_mt.h" - +#include "servers/audio_server.h" +//#include "servers/visual/visual_server_wrap_mt.h" #include "os/memory_pool_dynamic_prealloc.h" #include "globals.h" #include "io/marshalls.h" - #include "platform/windows/packet_peer_udp_winsock.h" #include "platform/windows/stream_peer_winsock.h" #include "platform/windows/tcp_server_winsock.h" @@ -145,13 +141,14 @@ void OSUWP::set_keep_screen_on(bool p_enabled) { int OSUWP::get_audio_driver_count() const { - return AudioDriverManagerSW::get_driver_count(); + return AudioDriverManager::get_driver_count(); } + const char * OSUWP::get_audio_driver_name(int p_driver) const { - AudioDriverSW* driver = AudioDriverManagerSW::get_driver(p_driver); + AudioDriver* driver = AudioDriverManager::get_driver(p_driver); ERR_FAIL_COND_V( !driver, "" ); - return AudioDriverManagerSW::get_driver(p_driver)->get_name(); + return AudioDriverManager::get_driver(p_driver)->get_name(); } static MemoryPoolStatic *mempool_static=NULL; @@ -288,23 +285,13 @@ void OSUWP::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio joypad = ref new JoypadUWP(input); joypad->register_events(); - AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); + AudioDriverManager::get_driver(p_audio_driver)->set_singleton(); - if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { + if (AudioDriverManager::get_driver(p_audio_driver)->init()!=OK) { ERR_PRINT("Initializing audio failed."); } - sample_manager = memnew( SampleManagerMallocSW ); - audio_server = memnew( AudioServerSW(sample_manager) ); - - audio_server->init(); - - spatial_sound_server = memnew( SpatialSoundServerSW ); - spatial_sound_server->init(); - spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); - spatial_sound_2d_server->init(); - managed_object->update_clipboard(); Clipboard::ContentChanged += ref new EventHandler<Platform::Object^>(managed_object, &ManagedType::on_clipboard_changed); @@ -407,22 +394,12 @@ void OSUWP::finalize() { if (rasterizer) memdelete(rasterizer); - spatial_sound_server->finish(); - memdelete(spatial_sound_server); - spatial_sound_2d_server->finish(); - memdelete(spatial_sound_2d_server); - /* if (debugger_connection_console) { memdelete(debugger_connection_console); } */ - memdelete(sample_manager); - - audio_server->finish(); - memdelete(audio_server); - memdelete(input); physics_server->finish(); @@ -971,7 +948,7 @@ OSUWP::OSUWP() { mouse_mode_changed = CreateEvent(NULL, TRUE, FALSE, L"os_mouse_mode_changed"); - AudioDriverManagerSW::add_driver(&audio_driver); + AudioDriverManager::add_driver(&audio_driver); } diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index 82376dd2f6..f65aa2d8d9 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -34,28 +34,19 @@ #include "servers/visual_server.h" #include "servers/visual/rasterizer.h" #include "servers/physics/physics_server_sw.h" - -#include "servers/audio/audio_server_sw.h" -#include "servers/audio/sample_manager_sw.h" -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" +#include "servers/audio_server.h" #include "servers/physics_2d/physics_2d_server_sw.h" #include "drivers/xaudio2/audio_driver_xaudio2.h" - #include "gl_context_egl.h" - #include "core/math/math_2d.h" #include "core/ustring.h" +#include "main/input_default.h" +#include "joypad_uwp.h" #include <windows.h> - #include <io.h> - #include <fcntl.h> #include <stdio.h> -#include "main/input_default.h" - -#include "joypad_uwp.h" /** @author Juan Linietsky <reduzio@gmail.com> @@ -119,10 +110,6 @@ private: MainLoop *main_loop; AudioDriverXAudio2 audio_driver; - AudioServerSW *audio_server; - SampleManagerMallocSW *sample_manager; - SpatialSoundServerSW *spatial_sound_server; - SpatialSound2DServerSW *spatial_sound_2d_server; MouseMode mouse_mode; bool alt_mem; @@ -157,9 +144,12 @@ private: void on_magnetometer_reading_changed(Windows::Devices::Sensors::Magnetometer^ sender, Windows::Devices::Sensors::MagnetometerReadingChangedEventArgs^ args); void on_gyroscope_reading_changed(Windows::Devices::Sensors::Gyrometer^ sender, Windows::Devices::Sensors::GyrometerReadingChangedEventArgs^ args); + /** clang-format breaks this, it does not understand this token. */ + /* clang-format off */ internal: ManagedType() { alert_close_handle = false; } property OSUWP* os; + /* clang-format on */ }; ManagedType^ managed_object; Windows::Devices::Sensors::Accelerometer^ accelerometer; diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp index 1ad61844d0..88d534887b 100644 --- a/platform/windows/export/export.cpp +++ b/platform/windows/export/export.cpp @@ -29,7 +29,7 @@ #include "export.h" #include "platform/windows/logo.h" #include "tools/editor/editor_import_export.h" - +#if 0 void register_windows_exporter() { Image img(_windows_logo); @@ -50,3 +50,4 @@ void register_windows_exporter() { } +#endif diff --git a/platform/windows/joypad.cpp b/platform/windows/joypad.cpp index 6ea23ebb28..f2848268fc 100644 --- a/platform/windows/joypad.cpp +++ b/platform/windows/joypad.cpp @@ -249,7 +249,7 @@ BOOL CALLBACK JoypadWindows::enumCallback(const DIDEVICEINSTANCE* instance, void JoypadWindows* self = (JoypadWindows*)pContext; - if (self->is_xinput_device(&instance->guidProduct)) {; + if (self->is_xinput_device(&instance->guidProduct)) { return DIENUM_CONTINUE; } self->setup_dinput_joypad(instance); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 8910b23a2e..1e51c18b63 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -30,30 +30,25 @@ #include "os_windows.h" #include "drivers/gles3/rasterizer_gles3.h" - #include "drivers/windows/thread_windows.h" #include "drivers/windows/semaphore_windows.h" #include "drivers/windows/mutex_windows.h" #include "drivers/windows/rw_lock_windows.h" -#include "main/main.h" #include "drivers/windows/file_access_windows.h" #include "drivers/windows/dir_access_windows.h" - - #include "servers/visual/visual_server_raster.h" -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" //#include "servers/visual/visual_server_wrap_mt.h" - +#include "main/main.h" #include "tcp_server_winsock.h" #include "packet_peer_udp_winsock.h" #include "stream_peer_winsock.h" #include "lang_table.h" - #include "globals.h" #include "io/marshalls.h" #include "joypad.h" -#include "shlobj.h" +#include <shlobj.h> #include <regstr.h> #include <process.h> @@ -158,13 +153,13 @@ OS::VideoMode OS_Windows::get_default_video_mode() const { int OS_Windows::get_audio_driver_count() const { - return AudioDriverManagerSW::get_driver_count(); + return AudioDriverManager::get_driver_count(); } const char * OS_Windows::get_audio_driver_name(int p_driver) const { - AudioDriverSW* driver = AudioDriverManagerSW::get_driver(p_driver); + AudioDriver* driver = AudioDriverManager::get_driver(p_driver); ERR_FAIL_COND_V( !driver, "" ); - return AudioDriverManagerSW::get_driver(p_driver)->get_name(); + return AudioDriverManager::get_driver(p_driver)->get_name(); } @@ -259,6 +254,25 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) // Check For Windows Messages { + case WM_SETFOCUS: + { + window_has_focus = true; + // Re-capture cursor if we're in one of the capture modes + if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED) { + SetCapture(hWnd); + } + break; + } + case WM_KILLFOCUS: + { + window_has_focus = false; + + // Release capture if we're in one of the capture modes + if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED) { + ReleaseCapture(); + } + break; + } case WM_ACTIVATE: // Watch For Window Activate Message { minimized = HIWORD(wParam) != 0; @@ -271,19 +285,17 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { alt_mem=false; control_mem=false; shift_mem=false; - if (mouse_mode==MOUSE_MODE_CAPTURED) { + if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED) { RECT clipRect; GetClientRect(hWnd, &clipRect); ClientToScreen(hWnd, (POINT*) &clipRect.left); ClientToScreen(hWnd, (POINT*) &clipRect.right); ClipCursor(&clipRect); SetCapture(hWnd); - } } else { main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); alt_mem=false; - }; return 0; // Return To The Message Loop @@ -350,6 +362,9 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { } + // Don't calculate relative mouse movement if we don't have focus in CAPTURED mode. + if (!window_has_focus && mouse_mode==MOUSE_MODE_CAPTURED) + break; /* LPARAM extra = GetMessageExtraInfo(); if (IsPenEvent(extra)) { @@ -381,18 +396,19 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { mm.button_mask|=(wParam&MK_XBUTTON2)?(1<<6):0;*/ mm.x=GET_X_LPARAM(lParam); mm.y=GET_Y_LPARAM(lParam); - + if (mouse_mode==MOUSE_MODE_CAPTURED) { Point2i c(video_mode.width/2,video_mode.height/2); + old_x = c.x; + old_y = c.y; + if (Point2i(mm.x,mm.y)==c) { center=c; return 0; } Point2i ncenter(mm.x,mm.y); - mm.x = old_x + (mm.x-center.x); - mm.y = old_y + (mm.y-center.y); center=ncenter; POINT pos = { (int) c.x, (int) c.y }; ClientToScreen(hWnd, &pos); @@ -415,7 +431,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { mm.relative_y=mm.y-old_y; old_x=mm.x; old_y=mm.y; - if (main_loop) + if (window_has_focus && main_loop) input->parse_input_event(event); @@ -719,9 +735,8 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { joypad->probe_joypads(); } break; case WM_SETCURSOR: { - if(LOWORD(lParam) == HTCLIENT) { - if(mouse_mode == MOUSE_MODE_HIDDEN || mouse_mode == MOUSE_MODE_CAPTURED) { + if(window_has_focus && (mouse_mode == MOUSE_MODE_HIDDEN || mouse_mode == MOUSE_MODE_CAPTURED)) { //Hide the cursor if(hCursor == NULL) hCursor = SetCursor(NULL); @@ -953,7 +968,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ main_loop=NULL; outside=true; - + window_has_focus=true; WNDCLASSEXW wc; video_mode=p_desired; @@ -1078,11 +1093,6 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ RasterizerGLES3::register_config(); RasterizerGLES3::make_current(); -#else - // FIXME: Does DX support still work now that rasterizer is no longer used? -#ifdef DX9_ENABLED - rasterizer = memnew( RasterizerDX9(hWnd) ); -#endif #endif visual_server = memnew( VisualServerRaster ); @@ -1124,23 +1134,13 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ input = memnew( InputDefault ); joypad = memnew (JoypadWindows(input, &hWnd)); - AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); + AudioDriverManager::get_driver(p_audio_driver)->set_singleton(); - if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { + if (AudioDriverManager::get_driver(p_audio_driver)->init()!=OK) { ERR_PRINT("Initializing audio failed."); } - sample_manager = memnew( SampleManagerMallocSW ); - audio_server = memnew( AudioServerSW(sample_manager) ); - - audio_server->init(); - - spatial_sound_server = memnew( SpatialSoundServerSW ); - spatial_sound_server->init(); - spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); - spatial_sound_2d_server->init(); - TRACKMOUSEEVENT tme; tme.cbSize=sizeof(TRACKMOUSEEVENT); tme.dwFlags=TME_LEAVE; @@ -1264,29 +1264,17 @@ void OS_Windows::finalize() { if (gl_context) memdelete(gl_context); #endif - if (rasterizer) - memdelete(rasterizer); if (user_proc) { SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)user_proc); }; - spatial_sound_server->finish(); - memdelete(spatial_sound_server); - spatial_sound_2d_server->finish(); - memdelete(spatial_sound_2d_server); - /* if (debugger_connection_console) { memdelete(debugger_connection_console); } */ - memdelete(sample_manager); - - audio_server->finish(); - memdelete(audio_server); - physics_server->finish(); memdelete(physics_server); @@ -1295,6 +1283,11 @@ void OS_Windows::finalize() { monitor_info.clear(); + for (int i = 0; i < get_audio_driver_count(); i++) + { + AudioDriverManager::get_driver(i)->finish(); + } + } void OS_Windows::finalize_core() { @@ -1325,18 +1318,10 @@ void OS_Windows::vprint(const char* p_format, va_list p_list, bool p_stderr) { MultiByteToWideChar(CP_UTF8,0,buf,len,wbuf,wlen); wbuf[wlen]=0; -// Recent MinGW and MSVC compilers seem to disagree on the case here -#ifdef __MINGW32__ - if (p_stderr) - fwprintf(stderr, L"%S", wbuf); - else - wprintf(L"%S", wbuf); -#else // MSVC if (p_stderr) - fwprintf(stderr, L"%s", wbuf); + fwprintf(stderr, L"%ls", wbuf); else - wprintf(L"%s", wbuf); -#endif + wprintf(L"%ls", wbuf); #ifdef STDOUT_FILE //vwfprintf(stdo,p_format,p_list); @@ -1359,17 +1344,17 @@ void OS_Windows::set_mouse_mode(MouseMode p_mode) { if (mouse_mode==p_mode) return; mouse_mode=p_mode; - if (p_mode==MOUSE_MODE_CAPTURED) { + if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED) { RECT clipRect; GetClientRect(hWnd, &clipRect); ClientToScreen(hWnd, (POINT*) &clipRect.left); ClientToScreen(hWnd, (POINT*) &clipRect.right); ClipCursor(&clipRect); - SetCapture(hWnd); center=Point2i(video_mode.width/2,video_mode.height/2); POINT pos = { (int) center.x, (int) center.y }; ClientToScreen(hWnd, &pos); - SetCursorPos(pos.x, pos.y); + if (mouse_mode==MOUSE_MODE_CAPTURED) + SetCursorPos(pos.x, pos.y); } else { ReleaseCapture(); ClipCursor(NULL); @@ -2409,6 +2394,11 @@ bool OS_Windows::is_vsync_enabled() const{ return true; } +bool OS_Windows::check_feature_support(const String& p_feature) { + + return VisualServer::get_singleton()->has_os_feature(p_feature); + +} OS_Windows::OS_Windows(HINSTANCE _hInstance) { @@ -2432,10 +2422,10 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) { user_proc = NULL; #ifdef RTAUDIO_ENABLED - AudioDriverManagerSW::add_driver(&driver_rtaudio); + AudioDriverManager::add_driver(&driver_rtaudio); #endif #ifdef XAUDIO2_ENABLED - AudioDriverManagerSW::add_driver(&driver_xaudio2); + AudioDriverManager::add_driver(&driver_xaudio2); #endif } diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 7ca89e6366..73a2d5f451 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -35,29 +35,24 @@ #include "servers/visual_server.h" #include "servers/visual/rasterizer.h" #include "servers/physics/physics_server_sw.h" - -#include "servers/audio/audio_server_sw.h" -#include "servers/audio/sample_manager_sw.h" +#include "servers/audio_server.h" #include "drivers/rtaudio/audio_driver_rtaudio.h" #ifdef XAUDIO2_ENABLED #include "drivers/xaudio2/audio_driver_xaudio2.h" #endif -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" #include "drivers/unix/ip_unix.h" #include "servers/physics_2d/physics_2d_server_sw.h" #include "servers/physics_2d/physics_2d_server_wrap_mt.h" - #include "main/input_default.h" +#include "key_mapping_win.h" -#include <windows.h> -#include "key_mapping_win.h" +#include <windows.h> #include <windowsx.h> #include <io.h> - #include <fcntl.h> #include <stdio.h> + /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -97,7 +92,6 @@ class OS_Windows : public OS { ContextGL_Win *gl_context; #endif VisualServer *visual_server; - Rasterizer *rasterizer; PhysicsServer *physics_server; Physics2DServer *physics_2d_server; int pressrc; @@ -116,11 +110,6 @@ class OS_Windows : public OS { WNDPROC user_proc; - AudioServerSW *audio_server; - SampleManagerMallocSW *sample_manager; - SpatialSoundServerSW *spatial_sound_server; - SpatialSound2DServerSW *spatial_sound_2d_server; - MouseMode mouse_mode; bool alt_mem; bool gr_mem; @@ -128,6 +117,7 @@ class OS_Windows : public OS { bool control_mem; bool meta_mem; bool force_quit; + bool window_has_focus; uint32_t last_button_state; CursorShape cursor_shape; @@ -295,6 +285,8 @@ public: virtual void set_use_vsync(bool p_enable); virtual bool is_vsync_enabled() const; + virtual bool check_feature_support(const String& p_feature); + OS_Windows(HINSTANCE _hInstance); ~OS_Windows(); diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp index 6ceae0fcc7..9d3e3623da 100644 --- a/platform/windows/stream_peer_winsock.cpp +++ b/platform/windows/stream_peer_winsock.cpp @@ -88,7 +88,7 @@ Error StreamPeerWinsock::_poll_connection(bool p_block) const { }; struct sockaddr_storage their_addr; - size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, ip_type); + size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, sock_type); if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == SOCKET_ERROR) { @@ -98,7 +98,7 @@ Error StreamPeerWinsock::_poll_connection(bool p_block) const { return OK; }; - if (errno == WSAEINPROGRESS || errno == WSAEALREADY) { + if (err == WSAEINPROGRESS || err == WSAEALREADY) { return OK; } @@ -136,13 +136,11 @@ Error StreamPeerWinsock::write(const uint8_t* p_data,int p_bytes, int &r_sent, b int data_to_send = p_bytes; const uint8_t *offset = p_data; if (sockfd == -1) return FAILED; - errno = 0; int total_sent = 0; while (data_to_send) { int sent_amount = send(sockfd, (const char*)offset, data_to_send, 0); - //printf("Sent TCP data of %d bytes, errno %d\n", sent_amount, errno); if (sent_amount == -1) { @@ -195,7 +193,6 @@ Error StreamPeerWinsock::read(uint8_t* p_buffer, int p_bytes,int &r_received, bo int to_read = p_bytes; int total_read = 0; - errno = 0; while (to_read) { @@ -282,6 +279,7 @@ void StreamPeerWinsock::disconnect_from_host() { if (sockfd != INVALID_SOCKET) closesocket(sockfd); sockfd=INVALID_SOCKET; + sock_type = IP::TYPE_NONE; status = STATUS_NONE; @@ -293,6 +291,7 @@ void StreamPeerWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port, ip_type = p_ip_type; sockfd = p_sockfd; + sock_type = p_ip_type; status = STATUS_CONNECTING; peer_host = p_host; peer_port = p_port; @@ -302,7 +301,8 @@ Error StreamPeerWinsock::connect_to_host(const IP_Address& p_host, uint16_t p_po ERR_FAIL_COND_V( p_host == IP_Address(), ERR_INVALID_PARAMETER); - sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP); + sock_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + sockfd = _socket_create(sock_type, SOCK_STREAM, IPPROTO_TCP); if (sockfd == INVALID_SOCKET) { ERR_PRINT("Socket creation failed!"); disconnect_from_host(); @@ -318,7 +318,7 @@ Error StreamPeerWinsock::connect_to_host(const IP_Address& p_host, uint16_t p_po }; struct sockaddr_storage their_addr; - size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, ip_type); + size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, sock_type); if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == SOCKET_ERROR) { @@ -365,6 +365,7 @@ uint16_t StreamPeerWinsock::get_connected_port() const { StreamPeerWinsock::StreamPeerWinsock() { + sock_type = IP::TYPE_NONE; sockfd = INVALID_SOCKET; status = STATUS_NONE; peer_port = 0; diff --git a/platform/windows/stream_peer_winsock.h b/platform/windows/stream_peer_winsock.h index eff96930dd..59e4dc0d09 100644 --- a/platform/windows/stream_peer_winsock.h +++ b/platform/windows/stream_peer_winsock.h @@ -41,6 +41,7 @@ class StreamPeerWinsock : public StreamPeerTCP { protected: mutable Status status; + IP::Type sock_type; int sockfd; diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp index 39b704d2c4..caa5e4fc89 100644 --- a/platform/x11/context_gl_x11.cpp +++ b/platform/x11/context_gl_x11.cpp @@ -130,13 +130,6 @@ Error ContextGL_X11::initialize() { x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask, &swa); ERR_FAIL_COND_V(!x11_window,ERR_UNCONFIGURED); XMapWindow(x11_display, x11_window); - while(true) { - // wait for mapnotify (window created) - XEvent e; - XNextEvent(x11_display, &e); - if (e.type == MapNotify) - break; - } //}; diff --git a/platform/x11/detect.py b/platform/x11/detect.py index b5f6359d21..89cf639114 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -61,6 +61,7 @@ def get_opts(): ('use_static_cpp', 'link stdc++ statically', 'no'), ('use_sanitizer', 'Use llvm compiler sanitize address', 'no'), ('use_leak_sanitizer', 'Use llvm compiler sanitize memory leaks', 'no'), + ('use_lto', 'Use link time optimization', 'no'), ('pulseaudio', 'Detect & Use pulseaudio', 'yes'), ('udev', 'Use udev for gamepad connection callbacks', 'no'), ('debug_release', 'Add debug symbols to release version', 'no'), @@ -97,12 +98,12 @@ def configure(env): env.extra_suffix = ".llvm" if (env["use_sanitizer"] == "yes"): - env.Append(CXXFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer']) + env.Append(CCFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer']) env.Append(LINKFLAGS=['-fsanitize=address']) env.extra_suffix += "s" if (env["use_leak_sanitizer"] == "yes"): - env.Append(CXXFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer']) + env.Append(CCFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer']) env.Append(LINKFLAGS=['-fsanitize=address']) env.extra_suffix += "s" @@ -111,22 +112,28 @@ def configure(env): # env['OBJSUFFIX'] = ".nt"+env['OBJSUFFIX'] # env['LIBSUFFIX'] = ".nt"+env['LIBSUFFIX'] - if (env["target"] == "release"): + if (env["use_lto"] == "yes"): + env.Append(CCFLAGS=['-flto']) + env.Append(LINKFLAGS=['-flto']) + + + env.Append(CCFLAGS=['-pipe']) + env.Append(LINKFLAGS=['-pipe']) + if (env["target"] == "release"): + env.Prepend(CCFLAGS=['-Ofast']) if (env["debug_release"] == "yes"): - env.Append(CCFLAGS=['-g2']) - else: - env.Append(CCFLAGS=['-O3', '-ffast-math']) + env.Prepend(CCFLAGS=['-g2']) elif (env["target"] == "release_debug"): - env.Append(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED']) + env.Prepend(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED']) if (env["debug_release"] == "yes"): - env.Append(CCFLAGS=['-g2']) + env.Prepend(CCFLAGS=['-g2']) elif (env["target"] == "debug"): - env.Append(CCFLAGS=['-g2', '-Wall', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED']) + env.Prepend(CCFLAGS=['-g2', '-Wall', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED']) env.ParseConfig('pkg-config x11 --cflags --libs') env.ParseConfig('pkg-config xinerama --cflags --libs') diff --git a/platform/x11/export/export.cpp b/platform/x11/export/export.cpp index c1af323453..5a4751b387 100644 --- a/platform/x11/export/export.cpp +++ b/platform/x11/export/export.cpp @@ -30,7 +30,7 @@ #include "platform/x11/logo.h" #include "tools/editor/editor_import_export.h" #include "scene/resources/texture.h" - +#if 0 void register_x11_exporter() { Image img(_x11_logo); @@ -50,3 +50,4 @@ void register_x11_exporter() { } } +#endif diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 13e01ab6ac..e792d0465e 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -82,14 +82,14 @@ OS::VideoMode OS_X11::get_default_video_mode() const { } int OS_X11::get_audio_driver_count() const { - return AudioDriverManagerSW::get_driver_count(); + return AudioDriverManager::get_driver_count(); } const char *OS_X11::get_audio_driver_name(int p_driver) const { - AudioDriverSW* driver = AudioDriverManagerSW::get_driver(p_driver); + AudioDriver* driver = AudioDriverManager::get_driver(p_driver); ERR_FAIL_COND_V( !driver, "" ); - return AudioDriverManagerSW::get_driver(p_driver)->get_name(); + return AudioDriverManager::get_driver(p_driver)->get_name(); } void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { @@ -269,21 +269,21 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XFree(xsh); } - AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); + AudioDriverManager::get_driver(p_audio_driver)->set_singleton(); audio_driver_index=p_audio_driver; - if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { + if (AudioDriverManager::get_driver(p_audio_driver)->init()!=OK) { bool success=false; audio_driver_index=-1; - for(int i=0;i<AudioDriverManagerSW::get_driver_count();i++) { + for(int i=0;i<AudioDriverManager::get_driver_count();i++) { if (i==p_audio_driver) continue; - AudioDriverManagerSW::get_driver(i)->set_singleton(); - if (AudioDriverManagerSW::get_driver(i)->init()==OK) { + AudioDriverManager::get_driver(i)->set_singleton(); + if (AudioDriverManager::get_driver(i)->init()==OK) { success=true; - print_line("Audio Driver Failed: "+String(AudioDriverManagerSW::get_driver(p_audio_driver)->get_name())); - print_line("Using alternate audio driver: "+String(AudioDriverManagerSW::get_driver(i)->get_name())); + print_line("Audio Driver Failed: "+String(AudioDriverManager::get_driver(p_audio_driver)->get_name())); + print_line("Using alternate audio driver: "+String(AudioDriverManager::get_driver(i)->get_name())); audio_driver_index=i; break; } @@ -294,13 +294,6 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi } - sample_manager = memnew( SampleManagerMallocSW ); - audio_server = memnew( AudioServerSW(sample_manager) ); - audio_server->init(); - spatial_sound_server = memnew( SpatialSoundServerSW ); - spatial_sound_server->init(); - spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); - spatial_sound_2d_server->init(); ERR_FAIL_COND(!visual_server); @@ -457,6 +450,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi physics_2d_server->init(); input = memnew( InputDefault ); + + window_has_focus = true; // Set focus to true at init #ifdef JOYDEV_ENABLED joypad = memnew( JoypadLinux(input)); #endif @@ -469,10 +464,6 @@ void OS_X11::finalize() { memdelete(main_loop); main_loop=NULL; - spatial_sound_server->finish(); - memdelete(spatial_sound_server); - spatial_sound_2d_server->finish(); - memdelete(spatial_sound_2d_server); /* if (debugger_connection_console) { @@ -485,10 +476,6 @@ void OS_X11::finalize() { #endif memdelete(input); - memdelete(sample_manager); - - audio_server->finish(); - memdelete(audio_server); visual_server->finish(); memdelete(visual_server); @@ -533,17 +520,21 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) { if (p_mode==mouse_mode) return; - if (mouse_mode==MOUSE_MODE_CAPTURED) + if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED) XUngrabPointer(x11_display, CurrentTime); - if (mouse_mode!=MOUSE_MODE_VISIBLE && p_mode==MOUSE_MODE_VISIBLE) - XUndefineCursor(x11_display,x11_window); - if (p_mode!=MOUSE_MODE_VISIBLE && mouse_mode==MOUSE_MODE_VISIBLE) { - XDefineCursor(x11_display,x11_window,null_cursor); + + // The only modes that show a cursor are VISIBLE and CONFINED + bool showCursor = (p_mode == MOUSE_MODE_VISIBLE || p_mode == MOUSE_MODE_CONFINED); + + if (showCursor) { + XUndefineCursor(x11_display,x11_window); // show cursor + } else { + XDefineCursor(x11_display,x11_window,null_cursor); // hide cursor } mouse_mode=p_mode; - if (mouse_mode==MOUSE_MODE_CAPTURED) { + if (mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) { while(true) { //flush pending motion events @@ -561,11 +552,10 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) { } } - if (XGrabPointer(x11_display, x11_window, True, - ButtonPressMask | ButtonReleaseMask | - PointerMotionMask, GrabModeAsync, GrabModeAsync, - x11_window, None, CurrentTime) != - GrabSuccess) { + if (XGrabPointer( + x11_display, x11_window, True, + ButtonPressMask | ButtonReleaseMask | PointerMotionMask, + GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime) != GrabSuccess) { ERR_PRINT("NO GRAB"); } @@ -785,13 +775,31 @@ void OS_X11::set_window_position(const Point2& p_position) { } Size2 OS_X11::get_window_size() const { - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, x11_window, &xwa); - return Size2i(xwa.width, xwa.height); + // Use current_videomode width and height instead of XGetWindowAttributes + // since right after a XResizeWindow the attributes may not be updated yet + return Size2i(current_videomode.width, current_videomode.height); } void OS_X11::set_window_size(const Size2 p_size) { + // If window resizable is disabled we need to update the attributes first + if (is_window_resizable() == false) { + XSizeHints *xsh; + xsh = XAllocSizeHints(); + xsh->flags = PMinSize | PMaxSize; + xsh->min_width = p_size.x; + xsh->max_width = p_size.x; + xsh->min_height = p_size.y; + xsh->max_height = p_size.y; + XSetWMNormalHints(x11_display, x11_window, xsh); + XFree(xsh); + } + + // Resize the window XResizeWindow(x11_display, x11_window, p_size.x, p_size.y); + + // Update our videomode width and height + current_videomode.width = p_size.x; + current_videomode.height = p_size.y; } void OS_X11::set_window_fullscreen(bool p_enabled) { @@ -805,15 +813,15 @@ bool OS_X11::is_window_fullscreen() const { void OS_X11::set_window_resizable(bool p_enabled) { XSizeHints *xsh; + Size2 size = get_window_size(); + xsh = XAllocSizeHints(); xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize; if(!p_enabled) { - XWindowAttributes xwa; - XGetWindowAttributes(x11_display,x11_window,&xwa); - xsh->min_width = xwa.width; - xsh->max_width = xwa.width; - xsh->min_height = xwa.height; - xsh->max_height = xwa.height; + xsh->min_width = size.x; + xsh->max_width = size.x; + xsh->min_height = size.y; + xsh->max_height = size.y; } XSetWMNormalHints(x11_display, x11_window, xsh); XFree(xsh); @@ -1270,6 +1278,10 @@ void OS_X11::process_xevents() { do_mouse_warp=false; + + // Is the current mouse mode one where it needs to be grabbed. + bool mouse_mode_grab = mouse_mode==MOUSE_MODE_CAPTURED || mouse_mode==MOUSE_MODE_CONFINED; + while (XPending(x11_display) > 0) { XEvent event; XNextEvent(x11_display, &event); @@ -1288,35 +1300,45 @@ void OS_X11::process_xevents() { minimized = (visibility->state == VisibilityFullyObscured); } break; case LeaveNotify: { - - if (main_loop && mouse_mode!=MOUSE_MODE_CAPTURED) + if (main_loop && !mouse_mode_grab) main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_EXIT); if (input) input->set_mouse_in_window(false); } break; case EnterNotify: { - - if (main_loop && mouse_mode!=MOUSE_MODE_CAPTURED) + if (main_loop && !mouse_mode_grab) main_loop->notification(MainLoop::NOTIFICATION_WM_MOUSE_ENTER); if (input) input->set_mouse_in_window(true); } break; case FocusIn: minimized = false; + window_has_focus = true; main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN); - if (mouse_mode==MOUSE_MODE_CAPTURED) { - XGrabPointer(x11_display, x11_window, True, - ButtonPressMask | ButtonReleaseMask | - PointerMotionMask, GrabModeAsync, GrabModeAsync, - x11_window, None, CurrentTime); + if (mouse_mode_grab) { + // Show and update the cursor if confined and the window regained focus. + if (mouse_mode==MOUSE_MODE_CONFINED) + XUndefineCursor(x11_display, x11_window); + else if (mouse_mode==MOUSE_MODE_CAPTURED) // or re-hide it in captured mode + XDefineCursor(x11_display, x11_window, null_cursor); + + XGrabPointer( + x11_display, x11_window, True, + ButtonPressMask | ButtonReleaseMask | PointerMotionMask, + GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime); } break; case FocusOut: + window_has_focus = false; main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); - if (mouse_mode==MOUSE_MODE_CAPTURED) { + if (mouse_mode_grab) { //dear X11, I try, I really try, but you never work, you do whathever you want. + if (mouse_mode==MOUSE_MODE_CAPTURED) { + // Show the cursor if we're in captured mode so it doesn't look weird. + XUndefineCursor(x11_display, x11_window); + } XUngrabPointer(x11_display, CurrentTime); } break; @@ -1336,7 +1358,7 @@ void OS_X11::process_xevents() { /* exit in case of a mouse button press */ last_timestamp=event.xbutton.time; - if (mouse_mode==MOUSE_MODE_CAPTURED) { + if (mouse_mode == MOUSE_MODE_CAPTURED) { event.xbutton.x=last_mouse_pos.x; event.xbutton.y=last_mouse_pos.y; } @@ -1359,7 +1381,6 @@ void OS_X11::process_xevents() { mouse_event.mouse_button.pressed=(event.type==ButtonPress); - if (event.type==ButtonPress && event.xbutton.button==1) { uint64_t diff = get_ticks_usec()/1000 - last_click_ms; @@ -1393,7 +1414,6 @@ void OS_X11::process_xevents() { // PLEASE DO ME A FAVOR AND DIE DROWNED IN A FECAL // MOUNTAIN BECAUSE THAT'S WHERE YOU BELONG. - while(true) { if (mouse_mode==MOUSE_MODE_CAPTURED && event.xmotion.x==current_videomode.width/2 && event.xmotion.y==current_videomode.height/2) { //this is likely the warp event since it was warped here @@ -1435,7 +1455,7 @@ void OS_X11::process_xevents() { Point2i new_center = pos; pos = last_mouse_pos + ( pos - center ); center=new_center; - do_mouse_warp=true; + do_mouse_warp=window_has_focus; // warp the cursor if we're focused in #else //Dear X11, thanks for making my life miserable @@ -1478,8 +1498,11 @@ void OS_X11::process_xevents() { last_mouse_pos=pos; // printf("rel: %d,%d\n", rel.x, rel.y ); - - input->parse_input_event( motion_event); + // Don't propagate the motion event unless we have focus + // this is so that the relative motion doesn't get messed up + // after we regain focus. + if (window_has_focus || !mouse_mode_grab) + input->parse_input_event( motion_event); } break; case KeyPress: @@ -1984,20 +2007,20 @@ void OS_X11::set_context(int p_context) { OS_X11::OS_X11() { #ifdef RTAUDIO_ENABLED - AudioDriverManagerSW::add_driver(&driver_rtaudio); + AudioDriverManager::add_driver(&driver_rtaudio); #endif #ifdef PULSEAUDIO_ENABLED - AudioDriverManagerSW::add_driver(&driver_pulseaudio); + AudioDriverManager::add_driver(&driver_pulseaudio); #endif #ifdef ALSA_ENABLED - AudioDriverManagerSW::add_driver(&driver_alsa); + AudioDriverManager::add_driver(&driver_alsa); #endif - if(AudioDriverManagerSW::get_driver_count() == 0){ + if(AudioDriverManager::get_driver_count() == 0){ WARN_PRINT("No sound driver found... Defaulting to dummy driver"); - AudioDriverManagerSW::add_driver(&driver_dummy); + AudioDriverManager::add_driver(&driver_dummy); } minimized = false; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index bf676b5edf..3ec358f103 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -37,10 +37,7 @@ //#include "servers/visual/visual_server_wrap_mt.h" #include "servers/visual/rasterizer.h" #include "servers/physics_server.h" -#include "servers/audio/audio_server_sw.h" -#include "servers/audio/sample_manager_sw.h" -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" +#include "servers/audio_server.h" #include "drivers/rtaudio/audio_driver_rtaudio.h" #include "drivers/alsa/audio_driver_alsa.h" #include "drivers/pulseaudio/audio_driver_pulseaudio.h" @@ -135,14 +132,9 @@ class OS_X11 : public OS_Unix { virtual void delete_main_loop(); IP_Unix *ip_unix; - AudioServerSW *audio_server; - SampleManagerMallocSW *sample_manager; - SpatialSoundServerSW *spatial_sound_server; - SpatialSound2DServerSW *spatial_sound_2d_server; - bool force_quit; bool minimized; - + bool window_has_focus; bool do_mouse_warp; const char *cursor_theme; diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 67c596421f..61ed362cf0 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -675,7 +675,7 @@ void Area2D::_bind_methods() { Area2D::Area2D() : CollisionObject2D(Physics2DServer::get_singleton()->area_create(),true) { space_override=SPACE_OVERRIDE_DISABLED; - set_gravity(98);; + set_gravity(98); set_gravity_vector(Vector2(0,1)); gravity_is_point=false; gravity_distance_scale=0; diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 04f096f229..4364e5f1fc 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -243,6 +243,7 @@ void CollisionPolygon2D::set_polygon(const Vector<Point2>& p_polygon) { _update_parent(); } update(); + update_configuration_warning(); } Vector<Point2> CollisionPolygon2D::get_polygon() const { diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index a92065d6fb..45fc734aef 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -159,6 +159,7 @@ void CollisionShape2D::set_shape(const Ref<Shape2D>& p_shape) { if (shape.is_valid()) shape->connect("changed",this,"_shape_changed"); + update_configuration_warning(); } Ref<Shape2D> CollisionShape2D::get_shape() const { diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp index 03c2c698eb..ec1109b41b 100644 --- a/scene/2d/navigation2d.cpp +++ b/scene/2d/navigation2d.cpp @@ -127,7 +127,7 @@ void Navigation2D::_navpoly_link(int p_id) { C->get().B=&p; C->get().B_edge=j; C->get().A->edges[C->get().A_edge].C=&p; - C->get().A->edges[C->get().A_edge].C_edge=j;; + C->get().A->edges[C->get().A_edge].C_edge=j; p.edges[j].C=C->get().A; p.edges[j].C_edge=C->get().A_edge; //connection successful. @@ -679,7 +679,7 @@ debug path path.push_back(begin_point); - path.invert();; + path.invert(); } return path; diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp index 012120d023..88d6a90e81 100644 --- a/scene/2d/navigation_polygon.cpp +++ b/scene/2d/navigation_polygon.cpp @@ -137,7 +137,7 @@ PoolVector<Vector2> NavigationPolygon::get_outline(int p_idx) const { void NavigationPolygon::clear_outlines(){ - outlines.clear();; + outlines.clear(); } void NavigationPolygon::make_polygons_from_outlines(){ diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index cd99f30f6d..020c5942c4 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -364,7 +364,7 @@ void Particles2D::_process_particles(float p_delta) { p.rot=Math::deg2rad(param[PARAM_INITIAL_ANGLE]+param[PARAM_INITIAL_ANGLE]*randomness[PARAM_INITIAL_ANGLE]*_rand_from_seed(&rand_seed)); active_count++; - p.frame=Math::fmod(param[PARAM_ANIM_INITIAL_POS]+randomness[PARAM_ANIM_INITIAL_POS]*_rand_from_seed(&rand_seed),1.0); + p.frame=Math::fmod(param[PARAM_ANIM_INITIAL_POS]+randomness[PARAM_ANIM_INITIAL_POS]*_rand_from_seed(&rand_seed),1.0f); } else { @@ -438,7 +438,7 @@ void Particles2D::_process_particles(float p_delta) { p.pos+=p.velocity*frame_time; p.rot+=Math::lerp(param[PARAM_SPIN_VELOCITY],param[PARAM_SPIN_VELOCITY]*randomness[PARAM_SPIN_VELOCITY]*_rand_from_seed(&rand_seed),randomness[PARAM_SPIN_VELOCITY])*frame_time; float anim_spd=param[PARAM_ANIM_SPEED_SCALE]+param[PARAM_ANIM_SPEED_SCALE]*randomness[PARAM_ANIM_SPEED_SCALE]*_rand_from_seed(&rand_seed); - p.frame=Math::fposmod(p.frame+(frame_time/lifetime)*anim_spd,1.0); + p.frame=Math::fposmod(p.frame+(frame_time/lifetime)*anim_spd,1.0f); active_count++; @@ -555,7 +555,7 @@ void Particles2D::_notification(int p_what) { float a=color.a; //float preh=h; h+=huerot; - h=Math::abs(Math::fposmod(h,1.0)); + h=Math::abs(Math::fposmod(h,1.0f)); //print_line("rand: "+rtos(randomness[PARAM_HUE_VARIATION])+" rand: "+rtos(huerand)); //print_line(itos(i)+":hue: "+rtos(preh)+" + "+rtos(huerot)+" = "+rtos(h)); color.set_hsv(h,s,v); @@ -607,6 +607,10 @@ void Particles2D::_notification(int p_what) { src_rect.pos.y = size.y * (frame/h_frames); } + if (flip_h) + src_rect.size.x=-src_rect.size.x; + if (flip_v) + src_rect.size.y=-src_rect.size.y; texture->draw_rect_region(ci,Rect2(Point2(),size),src_rect,color); //VisualServer::get_singleton()->canvas_item_add_texture_rect(ci,r,texrid,false,color); diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index feecbd9e20..96d90a1de6 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -1262,7 +1262,7 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2& p_linear_velocity,const V //all is a wall move_and_slide_on_wall=true; } else { - if ( get_collision_normal().dot(p_floor_direction) > Math::cos(Math::deg2rad(45))) { //floor + if ( get_collision_normal().dot(p_floor_direction) > Math::cos(Math::deg2rad((float)45))) { //floor move_and_slide_on_floor=true; @@ -1272,7 +1272,7 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2& p_linear_velocity,const V revert_motion(); return Vector2(); } - } else if ( get_collision_normal().dot(p_floor_direction) < Math::cos(Math::deg2rad(45))) { //ceiling + } else if ( get_collision_normal().dot(p_floor_direction) < Math::cos(Math::deg2rad((float)45))) { //ceiling move_and_slide_on_ceiling=true; } else { move_and_slide_on_wall=true; diff --git a/scene/2d/sample_player_2d.cpp b/scene/2d/sample_player_2d.cpp deleted file mode 100644 index 62eabea98e..0000000000 --- a/scene/2d/sample_player_2d.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/*************************************************************************/ -/* sample_player_2d.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "sample_player_2d.h" - -#include "servers/audio_server.h" -#include "servers/audio_server.h" -#include "servers/spatial_sound_server.h" - - -bool SamplePlayer2D::_set(const StringName& p_name, const Variant& p_value) { - - String name=p_name; - - if (name=="play/play") { - if (library.is_valid()) { - - String what=p_value; - if (what=="") - stop_all(); - else - play(what); - - played_back=what; - } - } else - return false; - - return true; -} - -bool SamplePlayer2D::_get(const StringName& p_name,Variant &r_ret) const { - - - String name=p_name; - - if (name=="play/play") { - r_ret=played_back; - } else - return false; - - return true; -} - -void SamplePlayer2D::_get_property_list(List<PropertyInfo> *p_list) const { - - String en=""; - if (library.is_valid()) { - List<StringName> samples; - Ref<SampleLibrary> ncl=library; - ncl->get_sample_list(&samples); - for (List<StringName>::Element *E=samples.front();E;E=E->next()) { - - en+=","; - en+=E->get(); - } - } - - p_list->push_back( PropertyInfo( Variant::STRING, "play/play", PROPERTY_HINT_ENUM, en,PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_ANIMATE_AS_TRIGGER)); -} - -void SamplePlayer2D::_notification(int p_what) { - - - switch(p_what) { - - case NOTIFICATION_ENTER_TREE: { - - SpatialSound2DServer::get_singleton()->source_set_polyphony(get_source_rid(),polyphony); - - - } break; - } - -} - -void SamplePlayer2D::set_sample_library(const Ref<SampleLibrary>& p_library) { - - library=p_library; - _change_notify(); - update_configuration_warning(); -} - -Ref<SampleLibrary> SamplePlayer2D::get_sample_library() const { - - return library; -} - -void SamplePlayer2D::set_polyphony(int p_voice_count) { - - ERR_FAIL_COND(p_voice_count<0 || p_voice_count>64); - polyphony=p_voice_count; - if (get_source_rid().is_valid()) - SpatialSound2DServer::get_singleton()->source_set_polyphony(get_source_rid(),polyphony); - -} - -int SamplePlayer2D::get_polyphony() const { - - return polyphony; -} - -SamplePlayer2D::VoiceID SamplePlayer2D::play(const String& p_sample,int p_voice) { - - if (!get_source_rid().is_valid()) - return INVALID_VOICE; - if (library.is_null()) - return INVALID_VOICE; - if (!library->has_sample(p_sample)) - return INVALID_VOICE; - Ref<Sample> sample = library->get_sample(p_sample); - float vol_change = library->sample_get_volume_db(p_sample); - float pitch_change = library->sample_get_pitch_scale(p_sample); - - VoiceID vid = SpatialSound2DServer::get_singleton()->source_play_sample(get_source_rid(),sample->get_rid(),sample->get_mix_rate()*pitch_change,p_voice); - if (vol_change) - SpatialSound2DServer::get_singleton()->source_voice_set_volume_scale_db(get_source_rid(),vid,vol_change); - - - if (random_pitch_scale) { - float ps = Math::random(-random_pitch_scale,random_pitch_scale); - if (ps>0) - ps=1.0+ps; - else - ps=1.0/(1.0-ps); - SpatialSound2DServer::get_singleton()->source_voice_set_pitch_scale(get_source_rid(),vid,ps*pitch_change); - - } - - return vid; -} -//voices -void SamplePlayer2D::voice_set_pitch_scale(VoiceID p_voice, float p_pitch_scale) { - - if (!get_source_rid().is_valid()) - return; - - SpatialSound2DServer::get_singleton()->source_voice_set_pitch_scale(get_source_rid(),p_voice,p_pitch_scale); - -} - -void SamplePlayer2D::voice_set_volume_scale_db(VoiceID p_voice, float p_volume_db) { - - if (!get_source_rid().is_valid()) - return; - SpatialSound2DServer::get_singleton()->source_voice_set_volume_scale_db(get_source_rid(),p_voice,p_volume_db); - -} - -bool SamplePlayer2D::is_voice_active(VoiceID p_voice) const { - - if (!get_source_rid().is_valid()) - return false; - return SpatialSound2DServer::get_singleton()->source_is_voice_active(get_source_rid(),p_voice); - -} - -void SamplePlayer2D::stop_voice(VoiceID p_voice) { - - if (!get_source_rid().is_valid()) - return; - SpatialSound2DServer::get_singleton()->source_stop_voice(get_source_rid(),p_voice); - -} - -void SamplePlayer2D::stop_all() { - - if (!get_source_rid().is_valid()) - return; - - for(int i=0;i<polyphony;i++) { - - SpatialSound2DServer::get_singleton()->source_stop_voice(get_source_rid(),i); - } -} - -void SamplePlayer2D::set_random_pitch_scale(float p_scale) { - random_pitch_scale=p_scale; -} - -float SamplePlayer2D::get_random_pitch_scale() const { - - return random_pitch_scale; -} - -String SamplePlayer2D::get_configuration_warning() const { - - if (library.is_null()) { - return TTR("A SampleLibrary resource must be created or set in the 'samples' property in order for SamplePlayer to play sound."); - } - - return String(); -} - -void SamplePlayer2D::_bind_methods() { - - - ClassDB::bind_method(_MD("set_sample_library","library:SampleLibrary"),&SamplePlayer2D::set_sample_library); - ClassDB::bind_method(_MD("get_sample_library:SampleLibrary"),&SamplePlayer2D::get_sample_library); - - ClassDB::bind_method(_MD("set_polyphony","max_voices"),&SamplePlayer2D::set_polyphony); - ClassDB::bind_method(_MD("get_polyphony"),&SamplePlayer2D::get_polyphony); - - ClassDB::bind_method(_MD("play","sample","voice"),&SamplePlayer2D::play,DEFVAL(NEXT_VOICE)); - //voices,DEV - ClassDB::bind_method(_MD("voice_set_pitch_scale","voice","ratio"),&SamplePlayer2D::voice_set_pitch_scale); - ClassDB::bind_method(_MD("voice_set_volume_scale_db","voice","db"),&SamplePlayer2D::voice_set_volume_scale_db); - - ClassDB::bind_method(_MD("is_voice_active","voice"),&SamplePlayer2D::is_voice_active); - ClassDB::bind_method(_MD("stop_voice","voice"),&SamplePlayer2D::stop_voice); - ClassDB::bind_method(_MD("stop_all"),&SamplePlayer2D::stop_all); - - ClassDB::bind_method(_MD("set_random_pitch_scale","val"),&SamplePlayer2D::set_random_pitch_scale); - ClassDB::bind_method(_MD("get_random_pitch_scale"),&SamplePlayer2D::get_random_pitch_scale); - - BIND_CONSTANT( INVALID_VOICE ); - BIND_CONSTANT( NEXT_VOICE ); - - ADD_GROUP("Config",""); - ADD_PROPERTY( PropertyInfo( Variant::INT, "polyphony", PROPERTY_HINT_RANGE, "1,64,1"),_SCS("set_polyphony"),_SCS("get_polyphony")); - ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "samples", PROPERTY_HINT_RESOURCE_TYPE,"SampleLibrary"),_SCS("set_sample_library"),_SCS("get_sample_library")); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "pitch_random", PROPERTY_HINT_RESOURCE_TYPE,"SampleLibrary"),_SCS("set_random_pitch_scale"),_SCS("get_random_pitch_scale")); - - -} - - -SamplePlayer2D::SamplePlayer2D() { - - polyphony=1; - random_pitch_scale=0; - -} - -SamplePlayer2D::~SamplePlayer2D() { - - -} diff --git a/scene/2d/sample_player_2d.h b/scene/2d/sample_player_2d.h deleted file mode 100644 index 5cf598327b..0000000000 --- a/scene/2d/sample_player_2d.h +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************************/ -/* sample_player_2d.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SAMPLE_PLAYER_2D_H -#define SAMPLE_PLAYER_2D_H - -#include "scene/2d/sound_player_2d.h" -#include "scene/resources/sample_library.h" - -class SamplePlayer2D : public SoundPlayer2D { - - GDCLASS(SamplePlayer2D,SoundPlayer2D); -public: - - enum { - - INVALID_VOICE=SpatialSoundServer::SOURCE_INVALID_VOICE, - NEXT_VOICE=SpatialSoundServer::SOURCE_NEXT_VOICE - }; - - typedef int VoiceID; - - -private: - - Ref<SampleLibrary> library; - int polyphony; - String played_back; - float random_pitch_scale; - -protected: - - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list(List<PropertyInfo> *p_list) const; - - void _notification(int p_what); - - static void _bind_methods(); - -public: - - void set_sample_library(const Ref<SampleLibrary>& p_library); - Ref<SampleLibrary> get_sample_library() const; - - void set_polyphony(int p_voice_count); - int get_polyphony() const; - - VoiceID play(const String& p_sample,int p_voice=NEXT_VOICE); - //voices - void voice_set_pitch_scale(VoiceID p_voice, float p_pitch_scale); - void voice_set_volume_scale_db(VoiceID p_voice, float p_volume_db); - - bool is_voice_active(VoiceID p_voice) const; - void stop_voice(VoiceID p_voice); - void stop_all(); - - void set_random_pitch_scale(float p_scale); - float get_random_pitch_scale() const; - - String get_configuration_warning() const; - - SamplePlayer2D(); - ~SamplePlayer2D(); - - -}; - -#endif // SAMPLE_PLAYER_2D_H diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp index 20db63b66f..94678e5e94 100644 --- a/scene/2d/screen_button.cpp +++ b/scene/2d/screen_button.cpp @@ -63,6 +63,38 @@ Ref<BitMap> TouchScreenButton::get_bitmask() const{ return bitmask; } +void TouchScreenButton::set_shape(const Ref<Shape2D>& p_shape){ + + shape=p_shape; + + if (!is_inside_tree()) + return; + if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) + return; + update(); +} + +Ref<Shape2D> TouchScreenButton::get_shape() const{ + + return shape; +} + +void TouchScreenButton::set_shape_centered(bool p_shape_centered) { + + shape_centered=p_shape_centered; + + if (!is_inside_tree()) + return; + if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) + return; + update(); +} + +bool TouchScreenButton::is_shape_centered() const { + + return shape_centered; +} + void TouchScreenButton::_notification(int p_what) { switch(p_what) { @@ -86,6 +118,15 @@ void TouchScreenButton::_notification(int p_what) { draw_texture(texture,Point2()); } + if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) + return; + if (shape.is_valid()) { + Color draw_col=get_tree()->get_debug_collisions_color(); + Vector2 pos=shape_centered ? get_item_rect().size*0.5f : Vector2(); + draw_set_transform_matrix(get_canvas_transform().translated(pos)); + shape->draw(get_canvas_item(),draw_col); + } + } break; case NOTIFICATION_ENTER_TREE: { @@ -104,8 +145,12 @@ void TouchScreenButton::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { if (is_pressed()) - Input::get_singleton()->action_release(action); + _release(true); } break; + case NOTIFICATION_PAUSED: { + // So the button can be pressed again even though the release gets unhandled because of coming during pause + allow_repress=true; + } } } @@ -143,22 +188,7 @@ void TouchScreenButton::_input(const InputEvent& p_event) { if (p_event.type==InputEvent::SCREEN_TOUCH && !p_event.screen_touch.pressed && finger_pressed==p_event.screen_touch.index) { - emit_signal("released"); - - if (action_id!=-1) { - - Input::get_singleton()->action_release(action); - InputEvent ie; - ie.type=InputEvent::ACTION; - ie.ID=0; - ie.action.action=action_id; - ie.action.pressed=false; - get_tree()->input_event(ie); - } - finger_pressed=-1; - - update(); - + _release(); } if ((p_event.type==InputEvent::SCREEN_TOUCH && p_event.screen_touch.pressed)|| p_event.type==InputEvent::SCREEN_DRAG) { @@ -184,44 +214,12 @@ void TouchScreenButton::_input(const InputEvent& p_event) { if (touched) { - if (finger_pressed==-1) { - finger_pressed=p_event.screen_touch.index; - //emit change stuff - emit_signal("pressed"); - if (action_id!=-1) { - - Input::get_singleton()->action_press(action); - InputEvent ie; - ie.type=InputEvent::ACTION; - ie.ID=0; - ie.action.action=action_id; - ie.action.pressed=true; - get_tree()->input_event(ie); - } - - update(); + _press(p_event.screen_touch.index); } - } else { - if (finger_pressed!=-1) { - - emit_signal("released"); - - if (action_id!=-1) { - - Input::get_singleton()->action_release(action); - InputEvent ie; - ie.type=InputEvent::ACTION; - ie.ID=0; - ie.action.action=action_id; - ie.action.pressed=false; - get_tree()->input_event(ie); - } - finger_pressed=-1; - - update(); + _release(); } } @@ -239,67 +237,88 @@ void TouchScreenButton::_input(const InputEvent& p_event) { if (!is_visible_in_tree()) return; - if (finger_pressed!=-1) + const bool can_press=finger_pressed==-1 || allow_repress; + if (!can_press) return; //already fingering Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x,p_event.screen_touch.y)); + Rect2 item_rect = get_item_rect(); bool touched=false; + bool check_rect=true; + if (shape.is_valid()) { + + check_rect=false; + Transform2D xform=shape_centered ? Transform2D().translated(get_item_rect().size*0.5f) : Transform2D(); + touched=shape->collide(xform, unit_rect, Transform2D(0, coord + Vector2(0.5,0.5))); + } + if (bitmask.is_valid()) { - if (Rect2(Point2(),bitmask->get_size()).has_point(coord)) { + check_rect=false; + if (!touched && Rect2(Point2(),bitmask->get_size()).has_point(coord)) { if (bitmask->get_bit(coord)) touched=true; } - } else { - if (!texture.is_null()) - touched=Rect2(Point2(),texture->get_size()).has_point(coord); } + if (!touched && check_rect) { + if (!texture.is_null()) + touched=item_rect.has_point(coord); + } if (touched) { - - finger_pressed=p_event.screen_touch.index; - //emit change stuff - emit_signal("pressed"); - if (action_id!=-1) { - - Input::get_singleton()->action_press(action); - InputEvent ie; - ie.type=InputEvent::ACTION; - ie.ID=0; - ie.action.action=action_id; - ie.action.pressed=true; - get_tree()->input_event(ie); - } - update(); - + _press(p_event.screen_touch.index); } } else { + if (p_event.screen_touch.index==finger_pressed) { + _release(); + } + } + } + } +} +void TouchScreenButton::_press(int p_finger_pressed) { - if (p_event.screen_touch.index==finger_pressed) { - //untouch + finger_pressed=p_finger_pressed; + allow_repress=false; - emit_signal("released"); + if (action_id!=-1) { - if (action_id!=-1) { + Input::get_singleton()->action_press(action); + InputEvent ie; + ie.type=InputEvent::ACTION; + ie.ID=0; + ie.action.action=action_id; + ie.action.pressed=true; + get_tree()->input_event(ie); + } - Input::get_singleton()->action_release(action); - InputEvent ie; - ie.type=InputEvent::ACTION; - ie.ID=0; - ie.action.action=action_id; - ie.action.pressed=false; - get_tree()->input_event(ie); - } - finger_pressed=-1; - update(); - } - } - } + emit_signal("pressed"); + update(); +} + +void TouchScreenButton::_release(bool p_exiting_tree) { + + finger_pressed=-1; + + if (action_id!=-1) { + + Input::get_singleton()->action_release(action); + InputEvent ie; + ie.type=InputEvent::ACTION; + ie.ID=0; + ie.action.action=action_id; + ie.action.pressed=false; + get_tree()->input_event(ie); + } + + if (!p_exiting_tree) { + emit_signal("released"); + update(); } } @@ -349,6 +368,12 @@ void TouchScreenButton::_bind_methods() { ClassDB::bind_method(_MD("set_bitmask","bitmask"),&TouchScreenButton::set_bitmask); ClassDB::bind_method(_MD("get_bitmask"),&TouchScreenButton::get_bitmask); + ClassDB::bind_method(_MD("set_shape","shape"),&TouchScreenButton::set_shape); + ClassDB::bind_method(_MD("get_shape"),&TouchScreenButton::get_shape); + + ClassDB::bind_method(_MD("set_shape_centered","bool"),&TouchScreenButton::set_shape_centered); + ClassDB::bind_method(_MD("is_shape_centered"),&TouchScreenButton::is_shape_centered); + ClassDB::bind_method(_MD("set_action","action"),&TouchScreenButton::set_action); ClassDB::bind_method(_MD("get_action"),&TouchScreenButton::get_action); @@ -365,6 +390,8 @@ void TouchScreenButton::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"normal",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"pressed",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture_pressed"),_SCS("get_texture_pressed")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"bitmask",PROPERTY_HINT_RESOURCE_TYPE,"BitMap"),_SCS("set_bitmask"),_SCS("get_bitmask")); + ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"shape",PROPERTY_HINT_RESOURCE_TYPE,"Shape2D"),_SCS("set_shape"),_SCS("get_shape")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shape_centered"),_SCS("set_shape_centered"),_SCS("is_shape_centered")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"passby_press"),_SCS("set_passby_press"),_SCS("is_passby_press_enabled")); ADD_PROPERTY( PropertyInfo(Variant::STRING,"action"),_SCS("set_action"),_SCS("get_action")); ADD_PROPERTY( PropertyInfo(Variant::INT,"visibility_mode",PROPERTY_HINT_ENUM,"Always,TouchScreen Only"),_SCS("set_visibility_mode"),_SCS("get_visibility_mode")); @@ -379,7 +406,11 @@ void TouchScreenButton::_bind_methods() { TouchScreenButton::TouchScreenButton() { finger_pressed=-1; + allow_repress=false; action_id=-1; passby_press=false; visibility=VISIBILITY_ALWAYS; + shape_centered=true; + unit_rect=Ref<RectangleShape2D>(memnew(RectangleShape2D)); + unit_rect->set_extents(Vector2(0.5,0.5)); } diff --git a/scene/2d/screen_button.h b/scene/2d/screen_button.h index 34e02d644b..8ce378c660 100644 --- a/scene/2d/screen_button.h +++ b/scene/2d/screen_button.h @@ -32,6 +32,7 @@ #include "scene/2d/node_2d.h" #include "scene/resources/texture.h" #include "scene/resources/bit_mask.h" +#include "scene/resources/rectangle_shape_2d.h" class TouchScreenButton : public Node2D { @@ -47,16 +48,24 @@ private: Ref<Texture> texture; Ref<Texture> texture_pressed; Ref<BitMap> bitmask; + Ref<Shape2D> shape; + bool shape_centered; + + Ref<RectangleShape2D> unit_rect; StringName action; bool passby_press; int finger_pressed; + bool allow_repress; int action_id; VisibilityMode visibility; void _input(const InputEvent& p_Event); + void _press(int p_finger_pressed); + void _release(bool p_exiting_tree=false); + protected: void _notification(int p_what); @@ -73,6 +82,12 @@ public: void set_bitmask(const Ref<BitMap>& p_bitmask); Ref<BitMap> get_bitmask() const; + void set_shape(const Ref<Shape2D>& p_shape); + Ref<Shape2D> get_shape() const; + + void set_shape_centered(bool p_shape_centered); + bool is_shape_centered() const; + void set_action(const String& p_action); String get_action() const; diff --git a/scene/2d/sound_player_2d.cpp b/scene/2d/sound_player_2d.cpp deleted file mode 100644 index 7861fb5855..0000000000 --- a/scene/2d/sound_player_2d.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/*************************************************************************/ -/* sound_player_2d.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "sound_player_2d.h" - -#include "servers/audio_server.h" - -#include "servers/spatial_sound_2d_server.h" -#include "scene/resources/surface_tool.h" - - -void SoundPlayer2D::_notification(int p_what) { - - - switch(p_what) { - - case NOTIFICATION_ENTER_TREE: { - //find the sound space - - source_rid = SpatialSound2DServer::get_singleton()->source_create(get_world_2d()->get_sound_space()); - - for(int i=0;i<PARAM_MAX;i++) - set_param(Param(i),params[i]); - - SpatialSound2DServer::get_singleton()->source_set_transform(source_rid,get_global_transform()); - - - } break; - case NOTIFICATION_TRANSFORM_CHANGED: { - - SpatialSound2DServer::get_singleton()->source_set_transform(source_rid,get_global_transform()); - - } break; - case NOTIFICATION_EXIT_TREE: { - - if (source_rid.is_valid()) - SpatialSound2DServer::get_singleton()->free(source_rid); - - } break; - } - -} - - -void SoundPlayer2D::set_param( Param p_param, float p_value) { - - ERR_FAIL_INDEX(p_param,PARAM_MAX); - params[p_param]=p_value; - if (source_rid.is_valid()) - SpatialSound2DServer::get_singleton()->source_set_param(source_rid,(SpatialSound2DServer::SourceParam)p_param,p_value); - -} - -float SoundPlayer2D::get_param( Param p_param) const { - - ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0); - return params[p_param]; - -} - - -void SoundPlayer2D::_bind_methods() { - - - ClassDB::bind_method(_MD("set_param","param","value"),&SoundPlayer2D::set_param); - ClassDB::bind_method(_MD("get_param","param"),&SoundPlayer2D::get_param); - - BIND_CONSTANT( PARAM_VOLUME_DB ); - BIND_CONSTANT( PARAM_PITCH_SCALE ); - BIND_CONSTANT( PARAM_ATTENUATION_MIN_DISTANCE ); - BIND_CONSTANT( PARAM_ATTENUATION_MAX_DISTANCE ); - BIND_CONSTANT( PARAM_ATTENUATION_DISTANCE_EXP ); - BIND_CONSTANT( PARAM_MAX ); - - ADD_GROUP("Parameters",""); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "volume_db",PROPERTY_HINT_RANGE, "-80,24,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_VOLUME_DB); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "pitch_scale",PROPERTY_HINT_RANGE, "0.001,32,0.001"),_SCS("set_param"),_SCS("get_param"),PARAM_PITCH_SCALE); - ADD_GROUP("Attenuation","attenuation_"); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_min_distance",PROPERTY_HINT_EXP_RANGE, "16,16384,1"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_MIN_DISTANCE); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_max_distance",PROPERTY_HINT_EXP_RANGE, "16,16384,1"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_MAX_DISTANCE); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_distance_exp",PROPERTY_HINT_EXP_EASING, "attenuation"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_DISTANCE_EXP); - -} - - -SoundPlayer2D::SoundPlayer2D() { - - params[PARAM_VOLUME_DB]=0.0; - params[PARAM_PITCH_SCALE]=1.0; - params[PARAM_ATTENUATION_MIN_DISTANCE]=1; - params[PARAM_ATTENUATION_MAX_DISTANCE]=2048; - params[PARAM_ATTENUATION_DISTANCE_EXP]=1.0; //linear (and not really good) - - set_notify_transform(true); -} - -SoundPlayer2D::~SoundPlayer2D() { - - -} diff --git a/scene/2d/sound_player_2d.h b/scene/2d/sound_player_2d.h deleted file mode 100644 index bfabda4ec9..0000000000 --- a/scene/2d/sound_player_2d.h +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************/ -/* sound_player_2d.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SOUND_PLAYER_2D_H -#define SOUND_PLAYER_2D_H - - -#include "scene/2d/node_2d.h" -#include "scene/resources/sample_library.h" -#include "servers/spatial_sound_2d_server.h" -#include "scene/main/viewport.h" - -class SoundPlayer2D : public Node2D { - - GDCLASS(SoundPlayer2D,Node2D); -public: - - - enum Param { - - PARAM_VOLUME_DB=SpatialSound2DServer::SOURCE_PARAM_VOLUME_DB, - PARAM_PITCH_SCALE=SpatialSound2DServer::SOURCE_PARAM_PITCH_SCALE, - PARAM_ATTENUATION_MIN_DISTANCE=SpatialSound2DServer::SOURCE_PARAM_ATTENUATION_MIN_DISTANCE, - PARAM_ATTENUATION_MAX_DISTANCE=SpatialSound2DServer::SOURCE_PARAM_ATTENUATION_MAX_DISTANCE, - PARAM_ATTENUATION_DISTANCE_EXP=SpatialSound2DServer::SOURCE_PARAM_ATTENUATION_DISTANCE_EXP, - PARAM_MAX=SpatialSound2DServer::SOURCE_PARAM_MAX - }; - -private: - - float params[PARAM_MAX]; - RID source_rid; - - -protected: - - _FORCE_INLINE_ RID get_source_rid() const { return source_rid; } - - void _notification(int p_what); - - static void _bind_methods(); - -public: - - void set_param( Param p_param, float p_value); - float get_param( Param p_param) const; - - - SoundPlayer2D(); - ~SoundPlayer2D(); - - -}; - -VARIANT_ENUM_CAST(SoundPlayer2D::Param ); - -#endif // SOUND_PLAYER_2D_H diff --git a/scene/2d/sprite.h b/scene/2d/sprite.h index 05c0bd9eec..ab4487ef7b 100644 --- a/scene/2d/sprite.h +++ b/scene/2d/sprite.h @@ -58,7 +58,7 @@ protected: void _notification(int p_what); - static void _bind_methods();; + static void _bind_methods(); virtual void _validate_property(PropertyInfo& property) const; @@ -119,7 +119,7 @@ protected: void _notification(int p_what); - static void _bind_methods();; + static void _bind_methods(); public: diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index 99e40984c5..3301c4d754 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -664,7 +664,7 @@ void Area::_bind_methods() { Area::Area() : CollisionObject(PhysicsServer::get_singleton()->area_create(),true) { space_override=SPACE_OVERRIDE_DISABLED; - set_gravity(9.8);; + set_gravity(9.8); locked=false; set_gravity_vector(Vector3(0,-1,0)); gravity_is_point=false; diff --git a/scene/3d/baked_light_instance.cpp b/scene/3d/baked_light_instance.cpp index e42439bf3b..b67b75d48f 100644 --- a/scene/3d/baked_light_instance.cpp +++ b/scene/3d/baked_light_instance.cpp @@ -389,8 +389,8 @@ void BakedLight::_plot_face(int p_idx, int p_level, const Vector3 *p_vtx, const Vector2 uv = get_uv(intersection,p_vtx,p_uv); - int uv_x = CLAMP(Math::fposmod(uv.x,1.0)*bake_texture_size,0,bake_texture_size-1); - int uv_y = CLAMP(Math::fposmod(uv.y,1.0)*bake_texture_size,0,bake_texture_size-1); + int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1); + int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1); int ofs = uv_y*bake_texture_size+uv_x; albedo_accum.r+=p_material.albedo[ofs].r; @@ -415,8 +415,8 @@ void BakedLight::_plot_face(int p_idx, int p_level, const Vector3 *p_vtx, const Vector2 uv = get_uv(inters,p_vtx,p_uv); - int uv_x = CLAMP(Math::fposmod(uv.x,1.0)*bake_texture_size,0,bake_texture_size-1); - int uv_y = CLAMP(Math::fposmod(uv.y,1.0)*bake_texture_size,0,bake_texture_size-1); + int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1); + int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1); int ofs = uv_y*bake_texture_size+uv_x; @@ -943,7 +943,7 @@ void BakedLight::_bake_light(Light* p_light) { Vector3 light_dir = -rel_xf.basis.get_axis(2); Color color = dl->get_color(); - float nrg = dl->get_param(Light::PARAM_ENERGY);; + float nrg = dl->get_param(Light::PARAM_ENERGY); color.r*=nrg; color.g*=nrg; color.b*=nrg; @@ -1705,7 +1705,6 @@ void BakedLight::create_debug_mesh(DebugMode p_mode) { #else mmi->set_owner(get_owner()); #endif - } void BakedLight::_debug_mesh_albedo() { diff --git a/scene/3d/body_shape.cpp b/scene/3d/body_shape.cpp index f6ec8639d3..f3c839d525 100644 --- a/scene/3d/body_shape.cpp +++ b/scene/3d/body_shape.cpp @@ -506,7 +506,7 @@ void CollisionShape::_create_debug_shape() { if (debug_shape) { - debug_shape->queue_delete();; + debug_shape->queue_delete(); debug_shape=NULL; } diff --git a/scene/3d/bone_attachment.cpp b/scene/3d/bone_attachment.cpp index c3ab2df939..825cf1c535 100644 --- a/scene/3d/bone_attachment.cpp +++ b/scene/3d/bone_attachment.cpp @@ -79,7 +79,7 @@ void BoneAttachment::_check_bind() { Skeleton *sk = get_parent()->cast_to<Skeleton>(); int idx = sk->find_bone(bone_name); if (idx!=-1) { - sk->bind_child_node_to_bone(idx,this);; + sk->bind_child_node_to_bone(idx,this); set_transform(sk->get_bone_global_pose(idx)); bound=true; } @@ -94,7 +94,7 @@ void BoneAttachment::_check_unbind() { Skeleton *sk = get_parent()->cast_to<Skeleton>(); int idx = sk->find_bone(bone_name); if (idx!=-1) { - sk->unbind_child_node_from_bone(idx,this);; + sk->unbind_child_node_from_bone(idx,this); } } bound=false; diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index 3f36caf62c..5bd2c771ee 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -644,7 +644,7 @@ Vector<Plane> Camera::get_frustum() const { void Camera::set_v_offset(float p_offset) { v_offset=p_offset; - _update_camera();; + _update_camera(); } float Camera::get_v_offset() const { diff --git a/scene/3d/character_camera.cpp b/scene/3d/character_camera.cpp index b4cd46bd35..211619d0df 100644 --- a/scene/3d/character_camera.cpp +++ b/scene/3d/character_camera.cpp @@ -97,7 +97,7 @@ void CharacterCamera::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::INT, "type", PROPERTY_HINT_ENUM, "Fixed,Follow") ); p_list->push_back( PropertyInfo( Variant::VECTOR2, "orbit" ) ); p_list->push_back( PropertyInfo( Variant::REAL, "height", PROPERTY_HINT_RANGE,"-1024,1024,0.01" ) ); - p_list->push_back( PropertyInfo( Variant::REAL, "inclination", PROPERTY_HINT_RANGE,"-90,90,0.01" ) ); ; + p_list->push_back( PropertyInfo( Variant::REAL, "inclination", PROPERTY_HINT_RANGE,"-90,90,0.01" ) ); p_list->push_back( PropertyInfo( Variant::REAL, "max_orbit_x", PROPERTY_HINT_RANGE,"-90,90,0.01" ) ); p_list->push_back( PropertyInfo( Variant::REAL, "min_orbit_x", PROPERTY_HINT_RANGE,"-90,90,0.01" ) ); p_list->push_back( PropertyInfo( Variant::REAL, "min_distance", PROPERTY_HINT_RANGE,"0,100,0.01" ) ); @@ -168,7 +168,7 @@ void CharacterCamera::_compute_camera() { Vector3 vec1 = accepted.origin; Vector3 vec2 = proposed.origin; - final.origin = vec2.linear_interpolate(vec1, pos_ratio * time);; + final.origin = vec2.linear_interpolate(vec1, pos_ratio * time); Quat q1 = accepted.basis; Quat q2 = proposed.basis; diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index 54d7cb6b9e..4c33590568 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -64,6 +64,18 @@ float GIProbeData::get_energy() const{ } +void GIProbeData::set_propagation(float p_range) { + + VS::get_singleton()->gi_probe_set_propagation(probe,p_range); +} + +float GIProbeData::get_propagation() const{ + + return VS::get_singleton()->gi_probe_get_propagation(probe); + +} + + void GIProbeData::set_interior(bool p_enable) { VS::get_singleton()->gi_probe_set_interior(probe,p_enable); @@ -121,6 +133,9 @@ void GIProbeData::_bind_methods() { ClassDB::bind_method(_MD("set_energy","energy"),&GIProbeData::set_energy); ClassDB::bind_method(_MD("get_energy"),&GIProbeData::get_energy); + ClassDB::bind_method(_MD("set_propagation","propagation"),&GIProbeData::set_propagation); + ClassDB::bind_method(_MD("get_propagation"),&GIProbeData::get_propagation); + ClassDB::bind_method(_MD("set_interior","interior"),&GIProbeData::set_interior); ClassDB::bind_method(_MD("is_interior"),&GIProbeData::is_interior); @@ -134,6 +149,7 @@ void GIProbeData::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY,"dynamic_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_dynamic_data"),_SCS("get_dynamic_data")); ADD_PROPERTY(PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_dynamic_range"),_SCS("get_dynamic_range")); ADD_PROPERTY(PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_energy"),_SCS("get_energy")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"propagation",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_propagation"),_SCS("get_propagation")); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"interior",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_interior"),_SCS("is_interior")); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"compress",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_compress"),_SCS("is_compressed")); @@ -214,6 +230,18 @@ float GIProbe::get_energy() const { return energy; } +void GIProbe::set_propagation(float p_propagation) { + + propagation=p_propagation; + if (probe_data.is_valid()) { + probe_data->set_propagation(propagation); + } +} +float GIProbe::get_propagation() const { + + return propagation; +} + void GIProbe::set_interior(bool p_enable) { interior=p_enable; @@ -510,8 +538,8 @@ void GIProbe::_plot_face(int p_idx, int p_level,int p_x,int p_y,int p_z, const V Vector2 uv = get_uv(intersection,p_vtx,p_uv); - int uv_x = CLAMP(Math::fposmod(uv.x,1.0)*bake_texture_size,0,bake_texture_size-1); - int uv_y = CLAMP(Math::fposmod(uv.y,1.0)*bake_texture_size,0,bake_texture_size-1); + int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1); + int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1); int ofs = uv_y*bake_texture_size+uv_x; albedo_accum.r+=p_material.albedo[ofs].r; @@ -539,8 +567,8 @@ void GIProbe::_plot_face(int p_idx, int p_level,int p_x,int p_y,int p_z, const V Vector2 uv = get_uv(inters,p_vtx,p_uv); - int uv_x = CLAMP(Math::fposmod(uv.x,1.0)*bake_texture_size,0,bake_texture_size-1); - int uv_y = CLAMP(Math::fposmod(uv.y,1.0)*bake_texture_size,0,bake_texture_size-1); + int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1); + int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1); int ofs = uv_y*bake_texture_size+uv_x; @@ -906,7 +934,7 @@ GIProbe::Baker::MaterialCache GIProbe::_get_material_cache(Ref<Material> p_mater } -void GIProbe::_plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker) { +void GIProbe::_plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker, const Vector<Ref<Material> > &p_materials, const Ref<Material> &p_override_material) { for(int i=0;i<p_mesh->get_surface_count();i++) { @@ -914,7 +942,16 @@ void GIProbe::_plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_b if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES) continue; //only triangles - Baker::MaterialCache material = _get_material_cache(p_mesh->surface_get_material(i),p_baker); + Ref<Material> src_material; + + if (p_override_material.is_valid()) { + src_material=p_override_material; + } else if (i<p_materials.size() && p_materials[i].is_valid()) { + src_material=p_materials[i]; + } else { + src_material=p_mesh->surface_get_material(i); + } + Baker::MaterialCache material = _get_material_cache(src_material,p_baker); Array a = p_mesh->surface_get_arrays(i); @@ -1009,6 +1046,10 @@ void GIProbe::_find_meshes(Node *p_at_node,Baker *p_baker){ Baker::PlotMesh pm; pm.local_xform=xf; pm.mesh=mesh; + for(int i=0;i<mesh->get_surface_count();i++) { + pm.instance_materials.push_back(mi->get_surface_material(i)); + } + pm.override_material=mi->get_material_override(); p_baker->mesh_list.push_back(pm); } @@ -1083,7 +1124,7 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug){ print_line("plotting mesh "+itos(pmc++)+"/"+itos(baker.mesh_list.size())); - _plot_mesh(E->get().local_xform,E->get().mesh,&baker); + _plot_mesh(E->get().local_xform,E->get().mesh,&baker,E->get().instance_materials,E->get().override_material); } _fixup_plot(0,0,0,0,0,&baker); @@ -1324,7 +1365,6 @@ void GIProbe::_create_debug_mesh(Baker *p_baker) { #else mmi->set_owner(get_owner()); #endif - } void GIProbe::_debug_bake() { @@ -1359,6 +1399,9 @@ void GIProbe::_bind_methods() { ClassDB::bind_method(_MD("set_energy","max"),&GIProbe::set_energy); ClassDB::bind_method(_MD("get_energy"),&GIProbe::get_energy); + ClassDB::bind_method(_MD("set_propagation","max"),&GIProbe::set_propagation); + ClassDB::bind_method(_MD("get_propagation"),&GIProbe::get_propagation); + ClassDB::bind_method(_MD("set_interior","enable"),&GIProbe::set_interior); ClassDB::bind_method(_MD("is_interior"),&GIProbe::is_interior); @@ -1373,6 +1416,7 @@ void GIProbe::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"extents"),_SCS("set_extents"),_SCS("get_extents")); ADD_PROPERTY( PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_RANGE,"1,16,1"),_SCS("set_dynamic_range"),_SCS("get_dynamic_range")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_RANGE,"0,16,0.01"),_SCS("set_energy"),_SCS("get_energy")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"propagation",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_propagation"),_SCS("get_propagation")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"interior"),_SCS("set_interior"),_SCS("is_interior")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"compress"),_SCS("set_compress"),_SCS("is_compressed")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"data",PROPERTY_HINT_RESOURCE_TYPE,"GIProbeData"),_SCS("set_probe_data"),_SCS("get_probe_data")); @@ -1390,6 +1434,7 @@ GIProbe::GIProbe() { subdiv=SUBDIV_128; dynamic_range=4; energy=1.0; + propagation=1.0; extents=Vector3(10,10,10); color_scan_cell_width=4; bake_texture_size=128; diff --git a/scene/3d/gi_probe.h b/scene/3d/gi_probe.h index e416b28791..f03a558908 100644 --- a/scene/3d/gi_probe.h +++ b/scene/3d/gi_probe.h @@ -32,6 +32,9 @@ public: void set_dynamic_range(int p_range); int get_dynamic_range() const; + void set_propagation(float p_range); + float get_propagation() const; + void set_energy(float p_range); float get_energy() const; @@ -114,6 +117,8 @@ private: int axis_cell_size[3]; struct PlotMesh { + Ref<Material> override_material; + Vector<Ref<Material> > instance_materials; Ref<Mesh> mesh; Transform local_xform; }; @@ -132,6 +137,7 @@ private: Vector3 extents; int dynamic_range; float energy; + float propagation; bool interior; bool compress; @@ -141,7 +147,7 @@ private: Vector<Color> _get_bake_texture(Image &p_image,const Color& p_color); Baker::MaterialCache _get_material_cache(Ref<Material> p_material,Baker *p_baker); void _plot_face(int p_idx, int p_level, int p_x,int p_y,int p_z,const Vector3 *p_vtx, const Vector2* p_uv, const Baker::MaterialCache& p_material, const Rect3 &p_aabb,Baker *p_baker); - void _plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker); + void _plot_mesh(const Transform& p_xform, Ref<Mesh>& p_mesh, Baker *p_baker,const Vector<Ref<Material> >& p_materials,const Ref<Material>& p_override_material); void _find_meshes(Node *p_at_node,Baker *p_baker); void _fixup_plot(int p_idx, int p_level,int p_x,int p_y, int p_z,Baker *p_baker); @@ -170,6 +176,9 @@ public: void set_energy(float p_energy); float get_energy() const; + void set_propagation(float p_propagation); + float get_propagation() const; + void set_interior(bool p_enable); bool is_interior() const; diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index d685cd8ce7..799c00d266 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -47,7 +47,7 @@ void Light::set_param(Param p_param, float p_value) { VS::get_singleton()->light_set_param(light,VS::LightParam(p_param),p_value); if (p_param==PARAM_SPOT_ANGLE || p_param==PARAM_RANGE) { - update_gizmo();; + update_gizmo(); } @@ -253,6 +253,7 @@ void Light::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::BOOL, "shadow_enabled"), _SCS("set_shadow"), _SCS("has_shadow")); ADD_PROPERTY( PropertyInfo( Variant::COLOR, "shadow_color",PROPERTY_HINT_COLOR_NO_ALPHA), _SCS("set_shadow_color"), _SCS("get_shadow_color")); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow_bias",PROPERTY_HINT_RANGE,"-16,16,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_BIAS); + ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow_contact",PROPERTY_HINT_RANGE,"0,16,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_CONTACT_SHADOW_SIZE); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow_max_distance",PROPERTY_HINT_RANGE,"0,65536,0.1"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_MAX_DISTANCE); ADD_GROUP("Editor",""); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "editor_only"), _SCS("set_editor_only"), _SCS("is_editor_only")); @@ -264,6 +265,7 @@ void Light::_bind_methods() { BIND_CONSTANT( PARAM_ATTENUATION ); BIND_CONSTANT( PARAM_SPOT_ANGLE ); BIND_CONSTANT( PARAM_SPOT_ATTENUATION ); + BIND_CONSTANT( PARAM_CONTACT_SHADOW_SIZE ); BIND_CONSTANT( PARAM_SHADOW_MAX_DISTANCE ); BIND_CONSTANT( PARAM_SHADOW_SPLIT_1_OFFSET ); BIND_CONSTANT( PARAM_SHADOW_SPLIT_2_OFFSET ); @@ -297,6 +299,7 @@ Light::Light(VisualServer::LightType p_type) { set_param(PARAM_ATTENUATION,1); set_param(PARAM_SPOT_ANGLE,45); set_param(PARAM_SPOT_ATTENUATION,1); + set_param(PARAM_CONTACT_SHADOW_SIZE,0); set_param(PARAM_SHADOW_MAX_DISTANCE,0); set_param(PARAM_SHADOW_SPLIT_1_OFFSET,0.1); set_param(PARAM_SHADOW_SPLIT_2_OFFSET,0.2); diff --git a/scene/3d/light.h b/scene/3d/light.h index d27b9fed12..4cf0156d5c 100644 --- a/scene/3d/light.h +++ b/scene/3d/light.h @@ -55,6 +55,7 @@ public: PARAM_ATTENUATION = VS::LIGHT_PARAM_ATTENUATION, PARAM_SPOT_ANGLE = VS::LIGHT_PARAM_SPOT_ANGLE, PARAM_SPOT_ATTENUATION = VS::LIGHT_PARAM_SPOT_ATTENUATION, + PARAM_CONTACT_SHADOW_SIZE= VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE, PARAM_SHADOW_MAX_DISTANCE = VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE, PARAM_SHADOW_SPLIT_1_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET, PARAM_SHADOW_SPLIT_2_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET, diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance.cpp index 764aff1c08..2198f538b8 100644 --- a/scene/3d/mesh_instance.cpp +++ b/scene/3d/mesh_instance.cpp @@ -91,7 +91,7 @@ void MeshInstance::_get_property_list( List<PropertyInfo> *p_list) const { ls.push_back(E->key()); } - ls.sort();; + ls.sort(); for(List<String>::Element *E=ls.front();E;E=E->next()) { p_list->push_back( PropertyInfo(Variant::REAL,E->get(),PROPERTY_HINT_RANGE,"0,1,0.01")); diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index 9bb19880bf..38893598d6 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -129,7 +129,7 @@ void Navigation::_navmesh_link(int p_id) { C->get().B=&p; C->get().B_edge=j; C->get().A->edges[C->get().A_edge].C=&p; - C->get().A->edges[C->get().A_edge].C_edge=j;; + C->get().A->edges[C->get().A_edge].C_edge=j; p.edges[j].C=C->get().A; p.edges[j].C_edge=C->get().A_edge; //connection successful. @@ -550,7 +550,7 @@ Vector<Vector3> Navigation::get_simple_path(const Vector3& p_start, const Vector path.push_back(begin_point); - path.invert();; + path.invert(); } return path; diff --git a/scene/3d/room_instance.cpp b/scene/3d/room_instance.cpp index cdca54cd84..a2e1a48781 100644 --- a/scene/3d/room_instance.cpp +++ b/scene/3d/room_instance.cpp @@ -56,17 +56,11 @@ void Room::_notification(int p_what) { } - if (sound_enabled) - SpatialSoundServer::get_singleton()->room_set_space(sound_room,get_world()->get_sound_space()); - } break; case NOTIFICATION_TRANSFORM_CHANGED: { - SpatialSoundServer::get_singleton()->room_set_transform(sound_room,get_global_transform()); } break; case NOTIFICATION_EXIT_WORLD: { - if (sound_enabled) - SpatialSoundServer::get_singleton()->room_set_space(sound_room,RID()); } break; @@ -158,61 +152,27 @@ void Room::_parse_node_faces(PoolVector<Face3> &all_faces,const Node *p_node) co -void Room::set_simulate_acoustics(bool p_enable) { - - if (sound_enabled==p_enable) - return; - - sound_enabled=p_enable; - if (!is_inside_world()) - return; //nothing to do - - if (sound_enabled) - SpatialSoundServer::get_singleton()->room_set_space(sound_room,get_world()->get_sound_space()); - else - SpatialSoundServer::get_singleton()->room_set_space(sound_room,RID()); - - -} - void Room::_bounds_changed() { update_gizmo(); } -bool Room::is_simulating_acoustics() const { - - return sound_enabled; -} - -RID Room::get_sound_room() const { - - return RID(); -} - void Room::_bind_methods() { ClassDB::bind_method(_MD("set_room","room:Room"),&Room::set_room ); ClassDB::bind_method(_MD("get_room:Room"),&Room::get_room ); - - ClassDB::bind_method(_MD("set_simulate_acoustics","enable"),&Room::set_simulate_acoustics ); - ClassDB::bind_method(_MD("is_simulating_acoustics"),&Room::is_simulating_acoustics ); - - - ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "room/room", PROPERTY_HINT_RESOURCE_TYPE, "Area" ), _SCS("set_room"), _SCS("get_room") ); - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "room/simulate_acoustics"), _SCS("set_simulate_acoustics"), _SCS("is_simulating_acoustics") ); + } Room::Room() { - sound_enabled=false; - sound_room=SpatialSoundServer::get_singleton()->room_create(); +// sound_enabled=false; level=0; @@ -222,6 +182,6 @@ Room::Room() { Room::~Room() { - SpatialSoundServer::get_singleton()->free(sound_room); + } diff --git a/scene/3d/room_instance.h b/scene/3d/room_instance.h index 145589a780..cbc1b12b7e 100644 --- a/scene/3d/room_instance.h +++ b/scene/3d/room_instance.h @@ -31,7 +31,7 @@ #include "scene/3d/visual_instance.h" #include "scene/resources/room.h" -#include "servers/spatial_sound_server.h" + /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -58,9 +58,6 @@ public: private: Ref<RoomBounds> room; - RID sound_room; - - bool sound_enabled; int level; void _parse_node_faces(PoolVector<Face3> &all_faces,const Node *p_node) const; @@ -88,11 +85,6 @@ public: void set_room( const Ref<RoomBounds>& p_room ); Ref<RoomBounds> get_room() const; - void set_simulate_acoustics(bool p_enable); - bool is_simulating_acoustics() const; - - - RID get_sound_room() const; Room(); ~Room(); diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 6843a7e9b3..69706a6039 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -620,7 +620,7 @@ void Spatial::set_visible(bool p_visible) { bool Spatial::is_visible() const { - return !data.visible; + return data.visible; } void Spatial::rotate(const Vector3& p_normal,float p_radians) { diff --git a/scene/3d/spatial_player.cpp b/scene/3d/spatial_player.cpp deleted file mode 100644 index 6a368d771a..0000000000 --- a/scene/3d/spatial_player.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/*************************************************************************/ -/* spatial_player.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "spatial_player.h" - -#include "servers/audio_server.h" -#include "camera.h" -#include "servers/spatial_sound_server.h" -#include "scene/resources/surface_tool.h" - - -void SpatialPlayer::_notification(int p_what) { - - - switch(p_what) { - - case NOTIFICATION_ENTER_WORLD: { - //find the sound space - - source_rid = SpatialSoundServer::get_singleton()->source_create(get_world()->get_sound_space()); - for(int i=0;i<PARAM_MAX;i++) - set_param(Param(i),params[i]); - - - } break; - case NOTIFICATION_TRANSFORM_CHANGED: { - - SpatialSoundServer::get_singleton()->source_set_transform(source_rid,get_global_transform()); - - } break; - case NOTIFICATION_EXIT_WORLD: { - - if (source_rid.is_valid()) - SpatialSoundServer::get_singleton()->free(source_rid); - - } break; - } - -} - - -void SpatialPlayer::set_param( Param p_param, float p_value) { - - ERR_FAIL_INDEX(p_param,PARAM_MAX); - params[p_param]=p_value; - if (p_param==PARAM_EMISSION_CONE_DEGREES) { - update_gizmo(); - } - if (source_rid.is_valid()) - SpatialSoundServer::get_singleton()->source_set_param(source_rid,(SpatialSoundServer::SourceParam)p_param,p_value); - -} - -float SpatialPlayer::get_param( Param p_param) const { - - ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0); - return params[p_param]; - -} - -bool SpatialPlayer::_can_gizmo_scale() const { - - return false; -} - -void SpatialPlayer::_bind_methods() { - - - ClassDB::bind_method(_MD("set_param","param","value"),&SpatialPlayer::set_param); - ClassDB::bind_method(_MD("get_param","param"),&SpatialPlayer::get_param); - - BIND_CONSTANT( PARAM_VOLUME_DB ); - BIND_CONSTANT( PARAM_PITCH_SCALE ); - BIND_CONSTANT( PARAM_ATTENUATION_MIN_DISTANCE ); - BIND_CONSTANT( PARAM_ATTENUATION_MAX_DISTANCE ); - BIND_CONSTANT( PARAM_ATTENUATION_DISTANCE_EXP ); - BIND_CONSTANT( PARAM_EMISSION_CONE_DEGREES ); - BIND_CONSTANT( PARAM_EMISSION_CONE_ATTENUATION_DB ); - BIND_CONSTANT( PARAM_MAX ); - - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "volume_db",PROPERTY_HINT_RANGE, "-80,24,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_VOLUME_DB); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "pitch_scale",PROPERTY_HINT_RANGE, "0.001,32,0.001"),_SCS("set_param"),_SCS("get_param"),PARAM_PITCH_SCALE); - ADD_GROUP("Attenuation","attenuation_"); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_min_distance",PROPERTY_HINT_RANGE, "0.01,4096,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_MIN_DISTANCE); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_max_distance",PROPERTY_HINT_RANGE, "0.01,4096,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_MAX_DISTANCE); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "attenuation_distance_exp",PROPERTY_HINT_EXP_EASING, "attenuation"),_SCS("set_param"),_SCS("get_param"),PARAM_ATTENUATION_DISTANCE_EXP); - ADD_GROUP("Emission Cone","emission_cone_"); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "emission_cone_degrees",PROPERTY_HINT_RANGE, "0,180,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_EMISSION_CONE_DEGREES); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "emission_cone_attenuation_db",PROPERTY_HINT_RANGE, "-80,24,0.01"),_SCS("set_param"),_SCS("get_param"),PARAM_EMISSION_CONE_ATTENUATION_DB); - -} - - -SpatialPlayer::SpatialPlayer() { - - params[PARAM_VOLUME_DB]=0.0; - params[PARAM_PITCH_SCALE]=1.0; - params[PARAM_ATTENUATION_MIN_DISTANCE]=1; - params[PARAM_ATTENUATION_MAX_DISTANCE]=100; - params[PARAM_ATTENUATION_DISTANCE_EXP]=1.0; //linear (and not really good) - params[PARAM_EMISSION_CONE_DEGREES]=180.0; //cone disabled - params[PARAM_EMISSION_CONE_ATTENUATION_DB]=-6.0; //minus 6 db attenuation - set_notify_transform(true); - -} - -SpatialPlayer::~SpatialPlayer() { - - -} diff --git a/scene/3d/spatial_player.h b/scene/3d/spatial_player.h deleted file mode 100644 index 16671a0cb5..0000000000 --- a/scene/3d/spatial_player.h +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************/ -/* spatial_player.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SPATIAL_PLAYER_H -#define SPATIAL_PLAYER_H - - -#include "scene/3d/spatial.h" -#include "scene/main/node.h" -#include "scene/resources/sample_library.h" -#include "servers/spatial_sound_server.h" -#include "scene/main/viewport.h" - -class SpatialPlayer : public Spatial { - - GDCLASS(SpatialPlayer,Spatial); -public: - - - enum Param { - - PARAM_VOLUME_DB=SpatialSoundServer::SOURCE_PARAM_VOLUME_DB, - PARAM_PITCH_SCALE=SpatialSoundServer::SOURCE_PARAM_PITCH_SCALE, - PARAM_ATTENUATION_MIN_DISTANCE=SpatialSoundServer::SOURCE_PARAM_ATTENUATION_MIN_DISTANCE, - PARAM_ATTENUATION_MAX_DISTANCE=SpatialSoundServer::SOURCE_PARAM_ATTENUATION_MAX_DISTANCE, - PARAM_ATTENUATION_DISTANCE_EXP=SpatialSoundServer::SOURCE_PARAM_ATTENUATION_DISTANCE_EXP, - PARAM_EMISSION_CONE_DEGREES=SpatialSoundServer::SOURCE_PARAM_EMISSION_CONE_DEGREES, - PARAM_EMISSION_CONE_ATTENUATION_DB=SpatialSoundServer::SOURCE_PARAM_EMISSION_CONE_ATTENUATION_DB, - PARAM_MAX=SpatialSoundServer::SOURCE_PARAM_MAX - }; - -private: - - float params[PARAM_MAX]; - RID source_rid; - - virtual bool _can_gizmo_scale() const; - - - -protected: - - _FORCE_INLINE_ RID get_source_rid() const { return source_rid; } - - void _notification(int p_what); - - static void _bind_methods(); - -public: - - void set_param( Param p_param, float p_value); - float get_param( Param p_param) const; - - - SpatialPlayer(); - ~SpatialPlayer(); - - -}; - -VARIANT_ENUM_CAST( SpatialPlayer::Param ); -#endif // SPATIAL_PLAYER_H diff --git a/scene/3d/spatial_sample_player.cpp b/scene/3d/spatial_sample_player.cpp deleted file mode 100644 index 3e1c0e9947..0000000000 --- a/scene/3d/spatial_sample_player.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/*************************************************************************/ -/* spatial_sample_player.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "spatial_sample_player.h" - -#include "servers/audio_server.h" -#include "camera.h" -#include "servers/spatial_sound_server.h" -#include "scene/scene_string_names.h" - -bool SpatialSamplePlayer::_set(const StringName& p_name, const Variant& p_value) { - - String name=p_name; - - if (name==SceneStringNames::get_singleton()->play_play) { - if (library.is_valid()) { - - String what=p_value; - if (what=="") - stop_all(); - else - play(what); - - played_back=what; - } - return true; - - } - - return false; -} - -bool SpatialSamplePlayer::_get(const StringName& p_name,Variant &r_ret) const { - - - String name=p_name; - - if (name==SceneStringNames::get_singleton()->play_play) { - r_ret=played_back; - return true; - } - - return false; -} - -void SpatialSamplePlayer::_get_property_list(List<PropertyInfo> *p_list) const { - - String en=""; - if (library.is_valid()) { - List<StringName> samples; - Ref<SampleLibrary> ncl=library; - ncl->get_sample_list(&samples); - for (List<StringName>::Element *E=samples.front();E;E=E->next()) { - - en+=","; - en+=E->get(); - } - } - - p_list->push_back( PropertyInfo( Variant::STRING, "play/play", PROPERTY_HINT_ENUM, en,PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_ANIMATE_AS_TRIGGER)); - -} -void SpatialSamplePlayer::_notification(int p_what) { - - - switch(p_what) { - - case NOTIFICATION_ENTER_WORLD: { - - SpatialSoundServer::get_singleton()->source_set_polyphony(get_source_rid(),polyphony); - - - } break; - } - -} - -void SpatialSamplePlayer::set_sample_library(const Ref<SampleLibrary>& p_library) { - - library=p_library; - _change_notify(); - update_configuration_warning(); -} - -Ref<SampleLibrary> SpatialSamplePlayer::get_sample_library() const { - - return library; -} - -void SpatialSamplePlayer::set_polyphony(int p_voice_count) { - - ERR_FAIL_COND(p_voice_count<0 || p_voice_count>64); - polyphony=p_voice_count; - if (get_source_rid().is_valid()) - SpatialSoundServer::get_singleton()->source_set_polyphony(get_source_rid(),polyphony); - -} - -int SpatialSamplePlayer::get_polyphony() const { - - return polyphony; -} - -SpatialSamplePlayer::VoiceID SpatialSamplePlayer::play(const String& p_sample,int p_voice) { - - if (!get_source_rid().is_valid()) - return INVALID_VOICE; - if (library.is_null()) - return INVALID_VOICE; - if (!library->has_sample(p_sample)) - return INVALID_VOICE; - Ref<Sample> sample = library->get_sample(p_sample); - float vol_change = library->sample_get_volume_db(p_sample); - float pitch_change = library->sample_get_pitch_scale(p_sample); - - VoiceID vid = SpatialSoundServer::get_singleton()->source_play_sample(get_source_rid(),sample->get_rid(),sample->get_mix_rate()*pitch_change,p_voice); - if (vol_change) - SpatialSoundServer::get_singleton()->source_voice_set_volume_scale_db(get_source_rid(),vid,vol_change); - - return vid; - - -} -//voices -void SpatialSamplePlayer::voice_set_pitch_scale(VoiceID p_voice, float p_pitch_scale) { - - if (!get_source_rid().is_valid()) - return; - - SpatialSoundServer::get_singleton()->source_voice_set_pitch_scale(get_source_rid(),p_voice,p_pitch_scale); - -} - -void SpatialSamplePlayer::voice_set_volume_scale_db(VoiceID p_voice, float p_volume_db) { - - if (!get_source_rid().is_valid()) - return; - SpatialSoundServer::get_singleton()->source_voice_set_volume_scale_db(get_source_rid(),p_voice,p_volume_db); - -} - -bool SpatialSamplePlayer::is_voice_active(VoiceID p_voice) const { - - if (!get_source_rid().is_valid()) - return false; - return SpatialSoundServer::get_singleton()->source_is_voice_active(get_source_rid(),p_voice); - -} - -void SpatialSamplePlayer::stop_voice(VoiceID p_voice) { - - if (!get_source_rid().is_valid()) - return; - SpatialSoundServer::get_singleton()->source_stop_voice(get_source_rid(),p_voice); - -} - -void SpatialSamplePlayer::stop_all() { - - if (!get_source_rid().is_valid()) - return; - - for(int i=0;i<polyphony;i++) { - - SpatialSoundServer::get_singleton()->source_stop_voice(get_source_rid(),i); - } -} - -String SpatialSamplePlayer::get_configuration_warning() const { - - if (library.is_null()) { - return TTR("A SampleLibrary resource must be created or set in the 'samples' property in order for SpatialSamplePlayer to play sound."); - } - - return String(); -} - - -void SpatialSamplePlayer::_bind_methods() { - - - ClassDB::bind_method(_MD("set_sample_library","library:SampleLibrary"),&SpatialSamplePlayer::set_sample_library); - ClassDB::bind_method(_MD("get_sample_library:SampleLibrary"),&SpatialSamplePlayer::get_sample_library); - - ClassDB::bind_method(_MD("set_polyphony","voices"),&SpatialSamplePlayer::set_polyphony); - ClassDB::bind_method(_MD("get_polyphony"),&SpatialSamplePlayer::get_polyphony); - - ClassDB::bind_method(_MD("play","sample","voice"),&SpatialSamplePlayer::play,DEFVAL(NEXT_VOICE)); - //voices,DEV - ClassDB::bind_method(_MD("voice_set_pitch_scale","voice","ratio"),&SpatialSamplePlayer::voice_set_pitch_scale); - ClassDB::bind_method(_MD("voice_set_volume_scale_db","voice","db"),&SpatialSamplePlayer::voice_set_volume_scale_db); - - ClassDB::bind_method(_MD("is_voice_active","voice"),&SpatialSamplePlayer::is_voice_active); - ClassDB::bind_method(_MD("stop_voice","voice"),&SpatialSamplePlayer::stop_voice); - ClassDB::bind_method(_MD("stop_all"),&SpatialSamplePlayer::stop_all); - - BIND_CONSTANT( INVALID_VOICE ); - BIND_CONSTANT( NEXT_VOICE ); - - ADD_PROPERTY( PropertyInfo( Variant::INT, "polyphony", PROPERTY_HINT_RANGE, "1,64,1"),_SCS("set_polyphony"),_SCS("get_polyphony")); - ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "samples", PROPERTY_HINT_RESOURCE_TYPE,"SampleLibrary"),_SCS("set_sample_library"),_SCS("get_sample_library")); - - -} - - -SpatialSamplePlayer::SpatialSamplePlayer() { - - polyphony=1; - -} - -SpatialSamplePlayer::~SpatialSamplePlayer() { - - -} diff --git a/scene/3d/spatial_sample_player.h b/scene/3d/spatial_sample_player.h deleted file mode 100644 index d30ff6e908..0000000000 --- a/scene/3d/spatial_sample_player.h +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************/ -/* spatial_sample_player.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SPATIAL_SAMPLE_PLAYER_H -#define SPATIAL_SAMPLE_PLAYER_H - -#include "scene/3d/spatial_player.h" -#include "scene/resources/sample_library.h" -#include "servers/spatial_sound_server.h" - -class SpatialSamplePlayer : public SpatialPlayer { - - GDCLASS(SpatialSamplePlayer,SpatialPlayer); -public: - - enum { - - INVALID_VOICE=SpatialSoundServer::SOURCE_INVALID_VOICE, - NEXT_VOICE=SpatialSoundServer::SOURCE_NEXT_VOICE - }; - - typedef int VoiceID; - - -private: - - Ref<SampleLibrary> library; - int polyphony; - String played_back; -protected: - - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list(List<PropertyInfo> *p_list) const; - - void _notification(int p_what); - static void _bind_methods(); - -public: - - void set_sample_library(const Ref<SampleLibrary>& p_library); - Ref<SampleLibrary> get_sample_library() const; - - void set_polyphony(int p_voice_count); - int get_polyphony() const; - - VoiceID play(const String& p_sample,int p_voice=NEXT_VOICE); - //voices - void voice_set_pitch_scale(VoiceID p_voice, float p_pitch_scale); - void voice_set_volume_scale_db(VoiceID p_voice, float p_volume_db); - - bool is_voice_active(VoiceID p_voice) const; - void stop_voice(VoiceID p_voice); - void stop_all(); - - String get_configuration_warning() const; - - SpatialSamplePlayer(); - ~SpatialSamplePlayer(); - - -}; - - -#endif // SPATIAL_SAMPLE_PLAYER_H diff --git a/scene/3d/spatial_stream_player.cpp b/scene/3d/spatial_stream_player.cpp deleted file mode 100644 index 1f9765c1d3..0000000000 --- a/scene/3d/spatial_stream_player.cpp +++ /dev/null @@ -1,407 +0,0 @@ -/*************************************************************************/ -/* spatial_stream_player.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "spatial_stream_player.h" - - - -int SpatialStreamPlayer::InternalStream::get_channel_count() const { - - return player->sp_get_channel_count(); -} -void SpatialStreamPlayer::InternalStream::set_mix_rate(int p_rate){ - - return player->sp_set_mix_rate(p_rate); -} -bool SpatialStreamPlayer::InternalStream::mix(int32_t *p_buffer,int p_frames){ - - return player->sp_mix(p_buffer,p_frames); -} -void SpatialStreamPlayer::InternalStream::update(){ - - player->sp_update(); -} - - -int SpatialStreamPlayer::sp_get_channel_count() const { - - return playback->get_channels(); -} - -void SpatialStreamPlayer::sp_set_mix_rate(int p_rate){ - - server_mix_rate=p_rate; -} - -bool SpatialStreamPlayer::sp_mix(int32_t *p_buffer,int p_frames) { - - if (resampler.is_ready() && !paused) { - return resampler.mix(p_buffer,p_frames); - } - - return false; -} - -void SpatialStreamPlayer::sp_update() { - - _THREAD_SAFE_METHOD_ - if (!paused && resampler.is_ready() && playback.is_valid()) { - - if (!playback->is_playing()) { - //stream depleted data, but there's still audio in the ringbuffer - //check that all this audio has been flushed before stopping the stream - int to_mix = resampler.get_total() - resampler.get_todo(); - if (to_mix==0) { - stop(); - return; - } - - return; - } - - int todo =resampler.get_todo(); - int wrote = playback->mix(resampler.get_write_buffer(),todo); - resampler.write(wrote); - } -} - - - -void SpatialStreamPlayer::_notification(int p_what) { - - switch(p_what) { - - case NOTIFICATION_ENTER_TREE: { - - //set_idle_process(false); //don't annoy - if (stream.is_valid() && autoplay && !get_tree()->is_editor_hint()) - play(); - } break; - case NOTIFICATION_EXIT_TREE: { - - stop(); //wathever it may be doing, stop - } break; - } -} - - - -void SpatialStreamPlayer::set_stream(const Ref<AudioStream> &p_stream) { - - stop(); - - stream=p_stream; - - if (!stream.is_null()) { - playback=stream->instance_playback(); - playback->set_loop(loops); - playback->set_loop_restart_time(loop_point); - AudioServer::get_singleton()->lock(); - resampler.setup(playback->get_channels(),playback->get_mix_rate(),server_mix_rate,buffering_ms,playback->get_minimum_buffer_size()); - AudioServer::get_singleton()->unlock(); - } else { - AudioServer::get_singleton()->lock(); - resampler.clear(); - playback.unref(); - AudioServer::get_singleton()->unlock(); - } -} - -Ref<AudioStream> SpatialStreamPlayer::get_stream() const { - - return stream; -} - - -void SpatialStreamPlayer::play(float p_from_offset) { - - ERR_FAIL_COND(!is_inside_tree()); - if (playback.is_null()) - return; - if (playback->is_playing()) - stop(); - - _THREAD_SAFE_METHOD_ - playback->play(p_from_offset); - //feed the ringbuffer as long as no update callback is going on - sp_update(); - - SpatialSoundServer::get_singleton()->source_set_audio_stream(get_source_rid(),&internal_stream); - - /* - AudioServer::get_singleton()->stream_set_active(stream_rid,true); - AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume); - if (stream->get_update_mode()!=AudioStream::UPDATE_NONE) - set_idle_process(true); - */ - -} - -void SpatialStreamPlayer::stop() { - - if (!is_inside_tree()) - return; - if (playback.is_null()) - return; - - _THREAD_SAFE_METHOD_ - //AudioServer::get_singleton()->stream_set_active(stream_rid,false); - SpatialSoundServer::get_singleton()->source_set_audio_stream(get_source_rid(),NULL); - playback->stop(); - resampler.flush(); - //set_idle_process(false); -} - -bool SpatialStreamPlayer::is_playing() const { - - if (playback.is_null()) - return false; - - return playback->is_playing(); -} - -void SpatialStreamPlayer::set_loop(bool p_enable) { - - loops=p_enable; - if (playback.is_null()) - return; - playback->set_loop(loops); - -} -bool SpatialStreamPlayer::has_loop() const { - - return loops; -} - -void SpatialStreamPlayer::set_volume(float p_vol) { - - volume=p_vol; - if (stream_rid.is_valid()) - AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume); -} - -float SpatialStreamPlayer::get_volume() const { - - return volume; -} - -void SpatialStreamPlayer::set_loop_restart_time(float p_secs) { - - loop_point=p_secs; - if (playback.is_valid()) - playback->set_loop_restart_time(p_secs); -} - -float SpatialStreamPlayer::get_loop_restart_time() const { - - return loop_point; -} - - -void SpatialStreamPlayer::set_volume_db(float p_db) { - - if (p_db<-79) - set_volume(0); - else - set_volume(Math::db2linear(p_db)); -} - -float SpatialStreamPlayer::get_volume_db() const { - - if (volume==0) - return -80; - else - return Math::linear2db(volume); -} - - -String SpatialStreamPlayer::get_stream_name() const { - - if (stream.is_null()) - return "<No Stream>"; - return stream->get_name(); - -} - -int SpatialStreamPlayer::get_loop_count() const { - - if (playback.is_null()) - return 0; - return playback->get_loop_count(); - -} - -float SpatialStreamPlayer::get_pos() const { - - if (playback.is_null()) - return 0; - return playback->get_pos(); - -} - -float SpatialStreamPlayer::get_length() const { - - if (playback.is_null()) - return 0; - return playback->get_length(); -} -void SpatialStreamPlayer::seek_pos(float p_time) { - - if (playback.is_null()) - return; - return playback->seek_pos(p_time); - -} - -void SpatialStreamPlayer::set_autoplay(bool p_enable) { - - autoplay=p_enable; -} - -bool SpatialStreamPlayer::has_autoplay() const { - - return autoplay; -} - -void SpatialStreamPlayer::set_paused(bool p_paused) { - - paused=p_paused; - /* - if (stream.is_valid()) - stream->set_paused(p_paused); - */ -} - -bool SpatialStreamPlayer::is_paused() const { - - return paused; -} - -void SpatialStreamPlayer::_set_play(bool p_play) { - - _play=p_play; - if (is_inside_tree()) { - if(_play) - play(); - else - stop(); - } - -} - -bool SpatialStreamPlayer::_get_play() const{ - - return _play; -} - -void SpatialStreamPlayer::set_buffering_msec(int p_msec) { - - buffering_ms=p_msec; -} - -int SpatialStreamPlayer::get_buffering_msec() const{ - - return buffering_ms; -} - - - -void SpatialStreamPlayer::_bind_methods() { - - ClassDB::bind_method(_MD("set_stream","stream:AudioStream"),&SpatialStreamPlayer::set_stream); - ClassDB::bind_method(_MD("get_stream:AudioStream"),&SpatialStreamPlayer::get_stream); - - ClassDB::bind_method(_MD("play","offset"),&SpatialStreamPlayer::play,DEFVAL(0)); - ClassDB::bind_method(_MD("stop"),&SpatialStreamPlayer::stop); - - ClassDB::bind_method(_MD("is_playing"),&SpatialStreamPlayer::is_playing); - - ClassDB::bind_method(_MD("set_paused","paused"),&SpatialStreamPlayer::set_paused); - ClassDB::bind_method(_MD("is_paused"),&SpatialStreamPlayer::is_paused); - - ClassDB::bind_method(_MD("set_loop","enabled"),&SpatialStreamPlayer::set_loop); - ClassDB::bind_method(_MD("has_loop"),&SpatialStreamPlayer::has_loop); - - ClassDB::bind_method(_MD("set_volume","volume"),&SpatialStreamPlayer::set_volume); - ClassDB::bind_method(_MD("get_volume"),&SpatialStreamPlayer::get_volume); - - ClassDB::bind_method(_MD("set_volume_db","db"),&SpatialStreamPlayer::set_volume_db); - ClassDB::bind_method(_MD("get_volume_db"),&SpatialStreamPlayer::get_volume_db); - - ClassDB::bind_method(_MD("set_buffering_msec","msec"),&SpatialStreamPlayer::set_buffering_msec); - ClassDB::bind_method(_MD("get_buffering_msec"),&SpatialStreamPlayer::get_buffering_msec); - - ClassDB::bind_method(_MD("set_loop_restart_time","secs"),&SpatialStreamPlayer::set_loop_restart_time); - ClassDB::bind_method(_MD("get_loop_restart_time"),&SpatialStreamPlayer::get_loop_restart_time); - - ClassDB::bind_method(_MD("get_stream_name"),&SpatialStreamPlayer::get_stream_name); - ClassDB::bind_method(_MD("get_loop_count"),&SpatialStreamPlayer::get_loop_count); - - ClassDB::bind_method(_MD("get_pos"),&SpatialStreamPlayer::get_pos); - ClassDB::bind_method(_MD("seek_pos","time"),&SpatialStreamPlayer::seek_pos); - - ClassDB::bind_method(_MD("set_autoplay","enabled"),&SpatialStreamPlayer::set_autoplay); - ClassDB::bind_method(_MD("has_autoplay"),&SpatialStreamPlayer::has_autoplay); - - ClassDB::bind_method(_MD("get_length"),&SpatialStreamPlayer::get_length); - - ClassDB::bind_method(_MD("_set_play","play"),&SpatialStreamPlayer::_set_play); - ClassDB::bind_method(_MD("_get_play"),&SpatialStreamPlayer::_get_play); - - ADD_PROPERTY( PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE,"AudioStream"), _SCS("set_stream"), _SCS("get_stream") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "play"), _SCS("_set_play"), _SCS("_get_play") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "loop"), _SCS("set_loop"), _SCS("has_loop") ); - ADD_PROPERTY( PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE,"-80,24,0.01"), _SCS("set_volume_db"), _SCS("get_volume_db") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autoplay"), _SCS("set_autoplay"), _SCS("has_autoplay") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "paused"), _SCS("set_paused"), _SCS("is_paused") ); - ADD_PROPERTY( PropertyInfo(Variant::INT, "loop_restart_time"), _SCS("set_loop_restart_time"), _SCS("get_loop_restart_time") ); - ADD_PROPERTY( PropertyInfo(Variant::INT, "buffering_ms"), _SCS("set_buffering_msec"), _SCS("get_buffering_msec") ); -} - - -SpatialStreamPlayer::SpatialStreamPlayer() { - - volume=1; - loops=false; - paused=false; - autoplay=false; - _play=false; - server_mix_rate=1; - internal_stream.player=this; - stream_rid=AudioServer::get_singleton()->audio_stream_create(&internal_stream); - buffering_ms=500; - loop_point=0; - -} - -SpatialStreamPlayer::~SpatialStreamPlayer() { - AudioServer::get_singleton()->free(stream_rid); - resampler.clear(); - - -} diff --git a/scene/3d/spatial_stream_player.h b/scene/3d/spatial_stream_player.h deleted file mode 100644 index 27533d3f6e..0000000000 --- a/scene/3d/spatial_stream_player.h +++ /dev/null @@ -1,120 +0,0 @@ -/*************************************************************************/ -/* spatial_stream_player.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SPATIAL_STREAM_PLAYER_H -#define SPATIAL_STREAM_PLAYER_H - -#include "scene/resources/audio_stream.h" -#include "scene/3d/spatial_player.h" -#include "servers/audio/audio_rb_resampler.h" - -class SpatialStreamPlayer : public SpatialPlayer { - - GDCLASS(SpatialStreamPlayer,SpatialPlayer); - - _THREAD_SAFE_CLASS_ - - struct InternalStream : public AudioServer::AudioStream { - SpatialStreamPlayer *player; - virtual int get_channel_count() const; - virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate - virtual bool mix(int32_t *p_buffer,int p_frames); - virtual void update(); - }; - - - InternalStream internal_stream; - Ref<AudioStreamPlayback> playback; - Ref<AudioStream> stream; - - int sp_get_channel_count() const; - void sp_set_mix_rate(int p_rate); //notify the stream of the mix rate - bool sp_mix(int32_t *p_buffer,int p_frames); - void sp_update(); - - int server_mix_rate; - - RID stream_rid; - bool paused; - bool autoplay; - bool loops; - float volume; - float loop_point; - int buffering_ms; - - AudioRBResampler resampler; - - bool _play; - void _set_play(bool p_play); - bool _get_play() const; -protected: - void _notification(int p_what); - - static void _bind_methods(); -public: - - void set_stream(const Ref<AudioStream> &p_stream); - Ref<AudioStream> get_stream() const; - - void play(float p_from_offset=0); - void stop(); - bool is_playing() const; - - void set_paused(bool p_paused); - bool is_paused() const; - - void set_loop(bool p_enable); - bool has_loop() const; - - void set_volume(float p_vol); - float get_volume() const; - - void set_loop_restart_time(float p_secs); - float get_loop_restart_time() const; - - void set_volume_db(float p_db); - float get_volume_db() const; - - String get_stream_name() const; - - int get_loop_count() const; - - float get_pos() const; - void seek_pos(float p_time); - float get_length() const; - void set_autoplay(bool p_vol); - bool has_autoplay() const; - - void set_buffering_msec(int p_msec); - int get_buffering_msec() const; - - SpatialStreamPlayer(); - ~SpatialStreamPlayer(); -}; - -#endif // SPATIAL_STREAM_PLAYER_H diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 9f0c91c4b8..479fe1fed9 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -1190,7 +1190,7 @@ void AnimatedSprite3D::set_frame(int p_frame) { frame=p_frame; _reset_timeout(); - _queue_update();; + _queue_update(); _change_notify("frame"); emit_signal(SceneStringNames::get_singleton()->frame_changed); @@ -1293,7 +1293,7 @@ void AnimatedSprite3D::set_animation(const StringName& p_animation){ _reset_timeout(); set_frame(0); _change_notify(); - _queue_update();; + _queue_update(); } StringName AnimatedSprite3D::get_animation() const{ diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp index 25ca74de9f..bcbda5a781 100644 --- a/scene/animation/animation_cache.cpp +++ b/scene/animation/animation_cache.cpp @@ -62,7 +62,7 @@ void AnimationCache::_clear_cache() { connected_nodes.front()->get()->disconnect("tree_exited",this,"_node_exit_tree"); connected_nodes.erase(connected_nodes.front()); } - path_cache.clear();; + path_cache.clear(); cache_valid=false; cache_dirty=true; } diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 8b81c45597..e02b2b2b41 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -118,17 +118,20 @@ bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const { } else if (name=="blend_times") { - Array array; - - array.resize(blend_times.size()*3); - int idx=0; + Vector<BlendKey> keys; for(Map<BlendKey, float >::Element *E=blend_times.front();E;E=E->next()) { - array.set(idx*3+0,E->key().from); - array.set(idx*3+1,E->key().to); - array.set(idx*3+2,E->get()); - idx++; + keys.ordered_insert(E->key()); } + + Array array; + for(int i=0;i<keys.size();i++) { + + array.push_back(keys[i].from); + array.push_back(keys[i].to); + array.push_back(blend_times[keys[i]]); + } + r_ret=array; } else if (name=="autoplay") { r_ret=autoplay; @@ -476,7 +479,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p } #endif - static_cast<Node2D*>(pa->object)->set_rotation(Math::deg2rad(value)); + static_cast<Node2D*>(pa->object)->set_rotation(Math::deg2rad((double)value)); } break; case SP_NODE2D_SCALE: { #ifdef DEBUG_ENABLED @@ -690,7 +693,7 @@ void AnimationPlayer::_animation_update_transforms() { } #endif - static_cast<Node2D*>(pa->object)->set_rotation(Math::deg2rad(pa->value_accum)); + static_cast<Node2D*>(pa->object)->set_rotation(Math::deg2rad((double)pa->value_accum)); } break; case SP_NODE2D_SCALE: { #ifdef DEBUG_ENABLED @@ -855,7 +858,7 @@ void AnimationPlayer::rename_animation(const StringName& p_name,const StringName while(to_erase.size()) { blend_times.erase(to_erase.front()->get()); - to_erase.pop_front();; + to_erase.pop_front(); } while(to_insert.size()) { diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 41bae6c928..7fab651213 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -142,7 +142,7 @@ private: StringName from; StringName to; - bool operator<(const BlendKey& bk) const { return from==bk.from?to<bk.to:from<bk.from; } + bool operator<(const BlendKey& bk) const { return from==bk.from?String(to)<String(bk.to):String(from)<String(bk.from); } }; diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp index c3a05240bb..a3347dadcf 100644 --- a/scene/animation/animation_tree_player.cpp +++ b/scene/animation/animation_tree_player.cpp @@ -1643,7 +1643,7 @@ void AnimationTreePlayer::_recompute_caches(const StringName& p_node) { if (nb->type==NODE_ANIMATION) { AnimationNode *an = static_cast<AnimationNode*>(nb); - an->tref.clear();; + an->tref.clear(); if (!an->animation.is_null()) { diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 0916119db3..bd126beef4 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -405,9 +405,9 @@ Variant Tween::_run_equation(InterpolateData& p_data) { case Variant::TRANSFORM2D: { - Basis i = initial_val; - Basis d = delta_val; - Basis r; + Transform2D i = initial_val; + Transform2D d = delta_val; + Transform2D r; APPLY_EQUATION(elements[0][0]); APPLY_EQUATION(elements[0][1]); diff --git a/scene/audio/audio_player.cpp b/scene/audio/audio_player.cpp new file mode 100644 index 0000000000..9fd005e6fb --- /dev/null +++ b/scene/audio/audio_player.cpp @@ -0,0 +1,301 @@ +#include "audio_player.h" + + +void AudioPlayer::_mix_audio() { + + if (!stream_playback.is_valid()) { + return; + } + + if (!active) { + return; + } + + if (setseek>=0.0) { + stream_playback->start(setseek); + setseek=-1.0; //reset seek + + } + + int bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus); + + //get data + AudioFrame *buffer = mix_buffer.ptr(); + int buffer_size = mix_buffer.size(); + + //mix + stream_playback->mix(buffer,1.0,buffer_size); + + //multiply volume interpolating to avoid clicks if this changes + float vol = Math::db2linear(mix_volume_db); + float vol_inc = (Math::db2linear(volume_db) - vol)/float(buffer_size); + + for(int i=0;i<buffer_size;i++) { + buffer[i]*=vol; + vol+=vol_inc; + } + //set volume for next mix + mix_volume_db = volume_db; + + AudioFrame * targets[3]={NULL,NULL,NULL}; + + if (AudioServer::get_singleton()->get_speaker_mode()==AudioServer::SPEAKER_MODE_STEREO) { + targets[0] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,0); + } else { + switch(mix_target) { + case MIX_TARGET_STEREO: { + targets[0]=AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,1); + } break; + case MIX_TARGET_SURROUND: { + targets[0]=AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,1); + targets[1]=AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,2); + if (AudioServer::get_singleton()->get_speaker_mode()==AudioServer::SPEAKER_SURROUND_71) { + targets[2]=AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,3); + } + } break; + case MIX_TARGET_CENTER: { + targets[0]=AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus_index,0); + } break; + + } + } + + for(int c=0;c<3;c++) { + if (!targets[c]) + break; + for(int i=0;i<buffer_size;i++) { + targets[c][i]+=buffer[i]; + } + } + + +} + +void AudioPlayer::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_TREE) { + + AudioServer::get_singleton()->add_callback(_mix_audios,this); + if (autoplay && !get_tree()->is_editor_hint()) { + play(); + } + } + + if (p_what==NOTIFICATION_EXIT_TREE) { + + AudioServer::get_singleton()->remove_callback(_mix_audios,this); + + } +} + +void AudioPlayer::set_stream(Ref<AudioStream> p_stream) { + + AudioServer::get_singleton()->lock(); + + mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); + + if (stream_playback.is_valid()) { + stream_playback.unref(); + stream.unref(); + active=false; + setseek=-1; + } + + stream=p_stream; + stream_playback=p_stream->instance_playback(); + + if (stream_playback.is_null()) { + stream.unref(); + ERR_FAIL_COND(stream_playback.is_null()); + } + + AudioServer::get_singleton()->unlock(); + +} + +Ref<AudioStream> AudioPlayer::get_stream() const { + + return stream; +} + +void AudioPlayer::set_volume_db(float p_volume) { + + volume_db=p_volume; +} +float AudioPlayer::get_volume_db() const { + + return volume_db; +} + +void AudioPlayer::play(float p_from_pos) { + + if (stream_playback.is_valid()) { + mix_volume_db=volume_db; //reset volume ramp + setseek=p_from_pos; + active=true; + } +} + +void AudioPlayer::seek(float p_seconds) { + + if (stream_playback.is_valid()) { + setseek=p_seconds; + } +} + +void AudioPlayer::stop() { + + if (stream_playback.is_valid()) { + active=false; + } + + +} + +bool AudioPlayer::is_playing() const { + + if (stream_playback.is_valid()) { + return active && stream_playback->is_playing(); + } + + return false; +} + +float AudioPlayer::get_pos() { + + if (stream_playback.is_valid()) { + return stream_playback->get_pos(); + } + + return 0; +} + +void AudioPlayer::set_bus(const StringName& p_bus) { + + //if audio is active, must lock this + AudioServer::get_singleton()->lock(); + bus=p_bus; + AudioServer::get_singleton()->unlock(); + +} +StringName AudioPlayer::get_bus() const { + + for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) { + if (AudioServer::get_singleton()->get_bus_name(i)==bus) { + return bus; + } + } + return "Master"; +} + +void AudioPlayer::set_autoplay(bool p_enable) { + + autoplay=p_enable; +} +bool AudioPlayer::is_autoplay_enabled() { + + return autoplay; +} + +void AudioPlayer::set_mix_target(MixTarget p_target) { + + mix_target=p_target; +} + +AudioPlayer::MixTarget AudioPlayer::get_mix_target() const{ + + return mix_target; +} + +void AudioPlayer::_set_playing(bool p_enable) { + + if (p_enable) + play(); + else + stop(); +} +bool AudioPlayer::_is_active() const { + + return active; +} + + +void AudioPlayer::_validate_property(PropertyInfo& property) const { + + if (property.name=="bus") { + + String options; + for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) { + if (i>0) + options+=","; + String name = AudioServer::get_singleton()->get_bus_name(i); + options+=name; + } + + property.hint_string=options; + } +} + +void AudioPlayer::_bus_layout_changed() { + + _change_notify(); +} + +void AudioPlayer::_bind_methods() { + + ClassDB::bind_method(_MD("set_stream","stream:AudioStream"),&AudioPlayer::set_stream); + ClassDB::bind_method(_MD("get_stream"),&AudioPlayer::get_stream); + + ClassDB::bind_method(_MD("set_volume_db","volume_db"),&AudioPlayer::set_volume_db); + ClassDB::bind_method(_MD("get_volume_db"),&AudioPlayer::get_volume_db); + + ClassDB::bind_method(_MD("play","from_pos"),&AudioPlayer::play,DEFVAL(0.0)); + ClassDB::bind_method(_MD("seek","to_pos"),&AudioPlayer::seek); + ClassDB::bind_method(_MD("stop"),&AudioPlayer::stop); + + ClassDB::bind_method(_MD("is_playing"),&AudioPlayer::is_playing); + ClassDB::bind_method(_MD("get_pos"),&AudioPlayer::get_pos); + + ClassDB::bind_method(_MD("set_bus","bus"),&AudioPlayer::set_bus); + ClassDB::bind_method(_MD("get_bus"),&AudioPlayer::get_bus); + + ClassDB::bind_method(_MD("set_autoplay","enable"),&AudioPlayer::set_autoplay); + ClassDB::bind_method(_MD("is_autoplay_enabled"),&AudioPlayer::is_autoplay_enabled); + + ClassDB::bind_method(_MD("set_mix_target","mix_target"),&AudioPlayer::set_mix_target); + ClassDB::bind_method(_MD("get_mix_target"),&AudioPlayer::get_mix_target); + + ClassDB::bind_method(_MD("_set_playing","enable"),&AudioPlayer::_set_playing); + ClassDB::bind_method(_MD("_is_active"),&AudioPlayer::_is_active); + + ClassDB::bind_method(_MD("_bus_layout_changed"),&AudioPlayer::_bus_layout_changed); + + + ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"stream",PROPERTY_HINT_RESOURCE_TYPE,"AudioStream"),_SCS("set_stream"),_SCS("get_stream") ); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"volume_db",PROPERTY_HINT_RANGE,"-80,24"),_SCS("set_volume_db"),_SCS("get_volume_db") ); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"playing",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR),_SCS("_set_playing"),_SCS("_is_active" )); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"autoplay"),_SCS("set_autoplay"),_SCS("is_autoplay_enabled") ); + ADD_PROPERTY( PropertyInfo(Variant::INT,"mix_target",PROPERTY_HINT_ENUM,"Stereo,Surround,Center"),_SCS("set_mix_target"),_SCS("get_mix_target")); + ADD_PROPERTY( PropertyInfo(Variant::STRING,"bus",PROPERTY_HINT_ENUM,""),_SCS("set_bus"),_SCS("get_bus")); + +} + +AudioPlayer::AudioPlayer() { + + mix_volume_db=0; + volume_db=0; + autoplay=false; + setseek=-1; + active=false; + mix_target=MIX_TARGET_STEREO; + + AudioServer::get_singleton()->connect("bus_layout_changed",this,"_bus_layout_changed"); +} + + + +AudioPlayer::~AudioPlayer() { + + +} + diff --git a/scene/audio/audio_player.h b/scene/audio/audio_player.h new file mode 100644 index 0000000000..249e5d0381 --- /dev/null +++ b/scene/audio/audio_player.h @@ -0,0 +1,75 @@ +#ifndef AUDIOPLAYER_H +#define AUDIOPLAYER_H + +#include "scene/main/node.h" +#include "servers/audio/audio_stream.h" + + +class AudioPlayer : public Node { + + GDCLASS( AudioPlayer, Node ) + +public: + + enum MixTarget { + MIX_TARGET_STEREO, + MIX_TARGET_SURROUND, + MIX_TARGET_CENTER + }; +private: + Ref<AudioStreamPlayback> stream_playback; + Ref<AudioStream> stream; + Vector<AudioFrame> mix_buffer; + + volatile float setseek; + volatile bool active; + + float mix_volume_db; + float volume_db; + bool autoplay; + StringName bus; + + MixTarget mix_target; + + void _mix_audio(); + static void _mix_audios(void *self) { reinterpret_cast<AudioPlayer*>(self)->_mix_audio(); } + + void _set_playing(bool p_enable); + bool _is_active() const; + + void _bus_layout_changed(); + +protected: + + void _validate_property(PropertyInfo& property) const; + void _notification(int p_what); + static void _bind_methods(); +public: + + void set_stream(Ref<AudioStream> p_stream); + Ref<AudioStream> get_stream() const; + + void set_volume_db(float p_volume); + float get_volume_db() const; + + void play(float p_from_pos=0.0); + void seek(float p_seconds); + void stop(); + bool is_playing() const; + float get_pos(); + + void set_bus(const StringName& p_bus); + StringName get_bus() const; + + void set_autoplay(bool p_enable); + bool is_autoplay_enabled(); + + void set_mix_target(MixTarget p_target); + MixTarget get_mix_target() const; + + AudioPlayer(); + ~AudioPlayer(); +}; + +VARIANT_ENUM_CAST(AudioPlayer::MixTarget) +#endif // AUDIOPLAYER_H diff --git a/scene/audio/event_player.cpp b/scene/audio/event_player.cpp deleted file mode 100644 index c46f4e3b89..0000000000 --- a/scene/audio/event_player.cpp +++ /dev/null @@ -1,357 +0,0 @@ -/*************************************************************************/ -/* event_player.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "event_player.h" - - -void EventPlayer::_notification(int p_what) { - - switch(p_what) { - - case NOTIFICATION_ENTER_TREE: { - - //set_idle_process(false); //don't annoy - if (playback.is_valid() && autoplay && !get_tree()->is_editor_hint()) - play(); - } break; - case NOTIFICATION_EXIT_TREE: { - - stop(); //wathever it may be doing, stop - } break; - } -} - - - -void EventPlayer::set_stream(const Ref<EventStream> &p_stream) { - - stop(); - stream=p_stream; - if (stream.is_valid()) - playback=stream->instance_playback(); - else - playback.unref(); - - if (playback.is_valid()) { - - playback->set_loop(loops); - playback->set_paused(paused); - playback->set_volume(volume); - for(int i=0;i<(MIN(MAX_CHANNELS,stream->get_channel_count()));i++) - playback->set_channel_volume(i,channel_volume[i]); - } - - -} - -Ref<EventStream> EventPlayer::get_stream() const { - - return stream; -} - - -void EventPlayer::play() { - - ERR_FAIL_COND(!is_inside_tree()); - if (playback.is_null()) { - return; - } - if (playback->is_playing()) { - AudioServer::get_singleton()->lock(); - stop(); - AudioServer::get_singleton()->unlock(); - } - - AudioServer::get_singleton()->lock(); - playback->play(); - AudioServer::get_singleton()->unlock(); - -} - -void EventPlayer::stop() { - - if (!is_inside_tree()) - return; - if (playback.is_null()) - return; - - AudioServer::get_singleton()->lock(); - playback->stop(); - AudioServer::get_singleton()->unlock(); -} - -bool EventPlayer::is_playing() const { - - if (playback.is_null()) - return false; - - return playback->is_playing(); -} - -void EventPlayer::set_loop(bool p_enable) { - - loops=p_enable; - if (playback.is_null()) - return; - playback->set_loop(loops); - -} -bool EventPlayer::has_loop() const { - - return loops; -} - -void EventPlayer::set_volume(float p_volume) { - - volume=p_volume; - if (playback.is_valid()) - playback->set_volume(volume); -} - -float EventPlayer::get_volume() const { - - return volume; -} - - -void EventPlayer::set_volume_db(float p_db) { - - if (p_db<-79) - set_volume(0); - else - set_volume(Math::db2linear(p_db)); -} - -float EventPlayer::get_volume_db() const { - - if (volume==0) - return -80; - else - return Math::linear2db(volume); -} - -void EventPlayer::set_pitch_scale(float p_pitch_scale) { - - pitch_scale=p_pitch_scale; - if (playback.is_valid()) - playback->set_pitch_scale(pitch_scale); -} - -float EventPlayer::get_pitch_scale() const { - - return pitch_scale; -} - -void EventPlayer::set_tempo_scale(float p_tempo_scale) { - - tempo_scale=p_tempo_scale; - if (playback.is_valid()) - playback->set_tempo_scale(tempo_scale); -} - -float EventPlayer::get_tempo_scale() const { - - return tempo_scale; -} - - -String EventPlayer::get_stream_name() const { - - if (stream.is_null()) - return "<No Stream>"; - return stream->get_name(); - -} - -int EventPlayer::get_loop_count() const { - - if (playback.is_null()) - return 0; - return playback->get_loop_count(); - -} - -float EventPlayer::get_pos() const { - - if (playback.is_null()) - return 0; - return playback->get_pos(); - -} - -float EventPlayer::get_length() const { - - if (stream.is_null()) - return 0; - return stream->get_length(); -} -void EventPlayer::seek_pos(float p_time) { - - if (playback.is_null()) - return; - return playback->seek_pos(p_time); - -} - -void EventPlayer::set_autoplay(bool p_enable) { - - autoplay=p_enable; -} - -bool EventPlayer::has_autoplay() const { - - return autoplay; -} - -void EventPlayer::set_paused(bool p_paused) { - - paused=p_paused; - if (playback.is_valid()) - playback->set_paused(p_paused); -} - -bool EventPlayer::is_paused() const { - - return paused; -} - -void EventPlayer::_set_play(bool p_play) { - - _play=p_play; - if (is_inside_tree()) { - if(_play) - play(); - else - stop(); - } - -} - -bool EventPlayer::_get_play() const{ - - return _play; -} - -void EventPlayer::set_channel_volume(int p_channel,float p_volume) { - - ERR_FAIL_INDEX(p_channel,MAX_CHANNELS); - channel_volume[p_channel]=p_volume; - if (playback.is_valid()) - playback->set_channel_volume(p_channel,p_volume); -} - -float EventPlayer::get_channel_volume(int p_channel) const{ - - ERR_FAIL_INDEX_V(p_channel,MAX_CHANNELS,0); - return channel_volume[p_channel]; - -} - -float EventPlayer::get_channel_last_note_time(int p_channel) const { - - if (playback.is_valid()) - return playback->get_last_note_time(p_channel); - - return 0; -} - -void EventPlayer::_bind_methods() { - - ClassDB::bind_method(_MD("set_stream","stream:EventStream"),&EventPlayer::set_stream); - ClassDB::bind_method(_MD("get_stream:EventStream"),&EventPlayer::get_stream); - - ClassDB::bind_method(_MD("play"),&EventPlayer::play); - ClassDB::bind_method(_MD("stop"),&EventPlayer::stop); - - ClassDB::bind_method(_MD("is_playing"),&EventPlayer::is_playing); - - ClassDB::bind_method(_MD("set_paused","paused"),&EventPlayer::set_paused); - ClassDB::bind_method(_MD("is_paused"),&EventPlayer::is_paused); - - ClassDB::bind_method(_MD("set_loop","enabled"),&EventPlayer::set_loop); - ClassDB::bind_method(_MD("has_loop"),&EventPlayer::has_loop); - - ClassDB::bind_method(_MD("set_volume","volume"),&EventPlayer::set_volume); - ClassDB::bind_method(_MD("get_volume"),&EventPlayer::get_volume); - - ClassDB::bind_method(_MD("set_pitch_scale","pitch_scale"),&EventPlayer::set_pitch_scale); - ClassDB::bind_method(_MD("get_pitch_scale"),&EventPlayer::get_pitch_scale); - - ClassDB::bind_method(_MD("set_tempo_scale","tempo_scale"),&EventPlayer::set_tempo_scale); - ClassDB::bind_method(_MD("get_tempo_scale"),&EventPlayer::get_tempo_scale); - - ClassDB::bind_method(_MD("set_volume_db","db"),&EventPlayer::set_volume_db); - ClassDB::bind_method(_MD("get_volume_db"),&EventPlayer::get_volume_db); - - ClassDB::bind_method(_MD("get_stream_name"),&EventPlayer::get_stream_name); - ClassDB::bind_method(_MD("get_loop_count"),&EventPlayer::get_loop_count); - - ClassDB::bind_method(_MD("get_pos"),&EventPlayer::get_pos); - ClassDB::bind_method(_MD("seek_pos","time"),&EventPlayer::seek_pos); - - ClassDB::bind_method(_MD("get_length"),&EventPlayer::get_length); - - ClassDB::bind_method(_MD("set_autoplay","enabled"),&EventPlayer::set_autoplay); - ClassDB::bind_method(_MD("has_autoplay"),&EventPlayer::has_autoplay); - - ClassDB::bind_method(_MD("set_channel_volume","channel","channel_volume"),&EventPlayer::set_channel_volume); - ClassDB::bind_method(_MD("get_channel_volume","channel"),&EventPlayer::get_channel_volume); - ClassDB::bind_method(_MD("get_channel_last_note_time","channel"),&EventPlayer::get_channel_last_note_time); - - ClassDB::bind_method(_MD("_set_play","play"),&EventPlayer::_set_play); - ClassDB::bind_method(_MD("_get_play"),&EventPlayer::_get_play); - - ADD_PROPERTY( PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE,"EventStream"), _SCS("set_stream"), _SCS("get_stream") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "play"), _SCS("_set_play"), _SCS("_get_play") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "loop"), _SCS("set_loop"), _SCS("has_loop") ); - ADD_PROPERTY( PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE,"-80,24,0.01"), _SCS("set_volume_db"), _SCS("get_volume_db") ); - ADD_PROPERTY( PropertyInfo(Variant::REAL, "pitch_scale", PROPERTY_HINT_RANGE,"0.001,16,0.001"), _SCS("set_pitch_scale"), _SCS("get_pitch_scale") ); - ADD_PROPERTY( PropertyInfo(Variant::REAL, "tempo_scale", PROPERTY_HINT_RANGE,"0.001,16,0.001"), _SCS("set_tempo_scale"), _SCS("get_tempo_scale") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autoplay"), _SCS("set_autoplay"), _SCS("has_autoplay") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "paused"), _SCS("set_paused"), _SCS("is_paused") ); -} - - -EventPlayer::EventPlayer() { - - volume=1; - loops=false; - paused=false; - autoplay=false; - _play=false; - pitch_scale=1.0; - tempo_scale=1.0; - for(int i=0;i<MAX_CHANNELS;i++) - channel_volume[i]=1.0; - -} - -EventPlayer::~EventPlayer() { - - -} diff --git a/scene/audio/event_player.h b/scene/audio/event_player.h deleted file mode 100644 index 715017e0d6..0000000000 --- a/scene/audio/event_player.h +++ /dev/null @@ -1,109 +0,0 @@ -/*************************************************************************/ -/* event_player.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef EVENT_PLAYER_H -#define EVENT_PLAYER_H - - -#include "scene/main/node.h" -#include "scene/resources/event_stream.h" -class EventPlayer : public Node { - - GDCLASS(EventPlayer,Node); - - - enum { - MAX_CHANNELS=256 - }; - - Ref<EventStreamPlayback> playback; - Ref<EventStream> stream; - bool paused; - bool autoplay; - bool loops; - float volume; - - float tempo_scale; - float pitch_scale; - - float channel_volume[MAX_CHANNELS]; - bool _play; - void _set_play(bool p_play); - bool _get_play() const; -protected: - void _notification(int p_what); - - static void _bind_methods(); - -public: - - void set_stream(const Ref<EventStream> &p_stream); - Ref<EventStream> get_stream() const; - - void play(); - void stop(); - bool is_playing() const; - - void set_paused(bool p_paused); - bool is_paused() const; - - void set_loop(bool p_enable); - bool has_loop() const; - - void set_volume(float p_vol); - float get_volume() const; - - void set_volume_db(float p_db); - float get_volume_db() const; - - void set_pitch_scale(float p_scale); - float get_pitch_scale() const; - - void set_tempo_scale(float p_scale); - float get_tempo_scale() const; - - String get_stream_name() const; - - int get_loop_count() const; - - float get_pos() const; - void seek_pos(float p_time); - float get_length() const; - void set_autoplay(bool p_vol); - bool has_autoplay() const; - - void set_channel_volume(int p_channel,float p_volume); - float get_channel_volume(int p_channel) const; - - float get_channel_last_note_time(int p_channel) const; - - EventPlayer(); - ~EventPlayer(); -}; - -#endif // EVENT_PLAYER_H diff --git a/scene/audio/sample_player.cpp b/scene/audio/sample_player.cpp deleted file mode 100644 index ba2d379311..0000000000 --- a/scene/audio/sample_player.cpp +++ /dev/null @@ -1,718 +0,0 @@ -/*************************************************************************/ -/* sample_player.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "sample_player.h" - -#include "servers/audio_server.h" - - -bool SamplePlayer::_set(const StringName& p_name, const Variant& p_value) { - - String name=p_name; - - if (name=="play/play") { - if (library.is_valid()) { - - String what=p_value; - if (what=="") - stop_all(); - else - play(what); - - played_back=what; - } - } else if (name=="config/samples") - set_sample_library(p_value); - else if (name=="config/polyphony") - set_polyphony(p_value); - else if (name.begins_with("default/")) { - - String what=name.right(8); - - if (what=="volume_db") - set_default_volume_db(p_value); - else if (what=="pitch_scale") - set_default_pitch_scale(p_value); - else if (what=="pan") - _default.pan=p_value; - else if (what=="depth") - _default.depth=p_value; - else if (what=="height") - _default.height=p_value; - else if (what=="filter/type") - _default.filter_type=FilterType(p_value.operator int()); - else if (what=="filter/cutoff") - _default.filter_cutoff=p_value; - else if (what=="filter/resonance") - _default.filter_resonance=p_value; - else if (what=="filter/gain") - _default.filter_gain=p_value; - else if (what=="reverb_room") - _default.reverb_room=ReverbRoomType(p_value.operator int()); - else if (what=="reverb_send") - _default.reverb_send=p_value; - else if (what=="chorus_send") - _default.chorus_send=p_value; - else - return false; - - - } else - return false; - - return true; -} - -bool SamplePlayer::_get(const StringName& p_name,Variant &r_ret) const { - - - String name=p_name; - - if (name=="play/play") { - r_ret=played_back; - } else if (name=="config/polyphony") { - r_ret= get_polyphony(); - } else if (name=="config/samples") { - - r_ret= get_sample_library(); - } else if (name.begins_with("default/")) { - - String what=name.right(8); - - if (what=="volume_db") - r_ret= get_default_volume_db(); - else if (what=="pitch_scale") - r_ret= get_default_pitch_scale(); - else if (what=="pan") - r_ret= _default.pan; - else if (what=="depth") - r_ret= _default.depth; - else if (what=="height") - r_ret= _default.height; - else if (what=="filter/type") - r_ret= _default.filter_type; - else if (what=="filter/cutoff") - r_ret= _default.filter_cutoff; - else if (what=="filter/resonance") - r_ret= _default.filter_resonance; - else if (what=="filter/gain") - r_ret= _default.filter_gain; - else if (what=="reverb_room") - r_ret= _default.reverb_room; - else if (what=="reverb_send") - r_ret= _default.reverb_send; - else if (what=="chorus_send") - r_ret= _default.chorus_send; - else - return false; - - - } else - return false; - - return true; -} - -void SamplePlayer::_get_property_list(List<PropertyInfo> *p_list) const { - - String en=""; - if (library.is_valid()) { - List<StringName> samples; - Ref<SampleLibrary> ncl=library; - ncl->get_sample_list(&samples); - for (List<StringName>::Element *E=samples.front();E;E=E->next()) { - - en+=","; - en+=E->get(); - } - } - - p_list->push_back( PropertyInfo( Variant::STRING, "play/play", PROPERTY_HINT_ENUM, en,PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_ANIMATE_AS_TRIGGER)); - p_list->push_back( PropertyInfo( Variant::INT, "config/polyphony", PROPERTY_HINT_RANGE, "1,256,1")); - p_list->push_back( PropertyInfo( Variant::OBJECT, "config/samples", PROPERTY_HINT_RESOURCE_TYPE, "SampleLibrary")); - p_list->push_back( PropertyInfo( Variant::REAL, "default/volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01")); - p_list->push_back( PropertyInfo( Variant::REAL, "default/pitch_scale", PROPERTY_HINT_RANGE, "0.01,48,0.01")); - p_list->push_back( PropertyInfo( Variant::REAL, "default/pan", PROPERTY_HINT_RANGE, "-1,1,0.01")); - p_list->push_back( PropertyInfo( Variant::REAL, "default/depth", PROPERTY_HINT_RANGE, "-1,1,0.01")); - p_list->push_back( PropertyInfo( Variant::REAL, "default/height", PROPERTY_HINT_RANGE, "-1,1,0.01")); - p_list->push_back( PropertyInfo( Variant::INT, "default/filter/type", PROPERTY_HINT_ENUM, "Disabled,Lowpass,Bandpass,Highpass,Notch,Peak,BandLimit,LowShelf,HighShelf")); - p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/cutoff", PROPERTY_HINT_RANGE, "20,16384.0,0.01")); - p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/resonance", PROPERTY_HINT_RANGE, "0,4,0.01")); - p_list->push_back( PropertyInfo( Variant::REAL, "default/filter/gain", PROPERTY_HINT_RANGE, "0,2,0.01")); - p_list->push_back( PropertyInfo( Variant::INT, "default/reverb_room", PROPERTY_HINT_ENUM, "Small,Medium,Large,Hall")); - p_list->push_back( PropertyInfo( Variant::REAL, "default/reverb_send", PROPERTY_HINT_RANGE, "0,1,0.01")); - p_list->push_back( PropertyInfo( Variant::REAL, "default/chorus_send", PROPERTY_HINT_RANGE, "0,1,0.01")); - - -} - - -SamplePlayer::Voice::Voice() { - - voice=AudioServer::get_singleton()->voice_create(); - clear(); -} - - -void SamplePlayer::Voice::clear() { - - check=0; - - mix_rate=44100; - volume=1; - pan=0; - pan_depth=0; - pan_height=0; - filter_type=FILTER_NONE; - filter_cutoff=0; - filter_resonance=0; - chorus_send=0; - reverb_room=REVERB_HALL; - reverb_send=0; - active=false; - -} -SamplePlayer::Voice::~Voice() { - - AudioServer::get_singleton()->free(voice); -} - - -void SamplePlayer::set_polyphony(int p_voice_count) { - - ERR_FAIL_COND( p_voice_count <1 || p_voice_count >0xFFFE ); - - voices.resize(p_voice_count); -} - -int SamplePlayer::get_polyphony() const { - - return voices.size(); -} - -SamplePlayer::VoiceID SamplePlayer::play(const String& p_name,bool unique) { - - if (library.is_null()) - return INVALID_VOICE_ID; - ERR_FAIL_COND_V( !library->has_sample(p_name), INVALID_VOICE_ID ); - - Ref<Sample> sample = library->get_sample(p_name); - float vol_change = library->sample_get_volume_db(p_name); - float pitch_change = library->sample_get_pitch_scale(p_name); - - last_check++; - last_id = (last_id + 1) % voices.size(); - - Voice&v = voices[last_id]; - v.clear(); - - - v.mix_rate=sample->get_mix_rate()*(_default.pitch_scale*pitch_change); - v.sample_mix_rate=sample->get_mix_rate(); - v.check=last_check; - v.volume=Math::db2linear(_default.volume_db+vol_change); - v.pan=_default.pan; - v.pan_depth=_default.depth; - v.pan_height=_default.height; - v.filter_type=_default.filter_type; - v.filter_cutoff=_default.filter_cutoff; - v.filter_resonance=_default.filter_resonance; - v.filter_gain=_default.filter_gain; - v.chorus_send=_default.chorus_send; - v.reverb_room=_default.reverb_room; - v.reverb_send=_default.reverb_send; - - AudioServer::get_singleton()->voice_play(v.voice,sample->get_rid()); - AudioServer::get_singleton()->voice_set_mix_rate(v.voice,v.mix_rate); - AudioServer::get_singleton()->voice_set_volume(v.voice,v.volume); - AudioServer::get_singleton()->voice_set_pan(v.voice,v.pan,v.pan_depth,v.pan_height); - AudioServer::get_singleton()->voice_set_filter(v.voice,(AudioServer::FilterType)v.filter_type,v.filter_cutoff,v.filter_resonance,v.filter_gain); - AudioServer::get_singleton()->voice_set_chorus(v.voice,v.chorus_send); - AudioServer::get_singleton()->voice_set_reverb(v.voice,(AudioServer::ReverbRoomType)v.reverb_room,v.reverb_send); - - v.active=true; - - if (unique) { - - for(int i=0;i<voices.size();i++) { - - if (!voices[i].active || uint32_t(i)==last_id) - continue; - - AudioServer::get_singleton()->voice_stop(voices[i].voice); - - voices[i].clear(); - } - - } - - return last_id | (last_check<<16); -} - -void SamplePlayer::stop_all() { - - - for(int i=0;i<voices.size();i++) { - - if (!voices[i].active) - continue; - - AudioServer::get_singleton()->voice_stop(voices[i].voice); - voices[i].clear(); - } - -} - -#define _GET_VOICE\ - uint32_t voice=p_voice&0xFFFF;\ - ERR_FAIL_COND(voice >= (uint32_t)voices.size());\ - Voice &v=voices[voice];\ - if (v.check!=uint32_t(p_voice>>16))\ - return;\ - ERR_FAIL_COND(!v.active); - -void SamplePlayer::stop(VoiceID p_voice) { - - _GET_VOICE - - AudioServer::get_singleton()->voice_stop(v.voice); - v.active=false; - -} - -void SamplePlayer::set_mix_rate(VoiceID p_voice, int p_mix_rate) { - - _GET_VOICE - - v.mix_rate=p_mix_rate; - AudioServer::get_singleton()->voice_set_mix_rate(v.voice,v.mix_rate); - -} -void SamplePlayer::set_pitch_scale(VoiceID p_voice, float p_pitch_scale) { - - _GET_VOICE - - v.mix_rate=v.sample_mix_rate*p_pitch_scale; - AudioServer::get_singleton()->voice_set_mix_rate(v.voice,v.mix_rate); - -} -void SamplePlayer::set_volume(VoiceID p_voice, float p_volume) { - - - _GET_VOICE - v.volume=p_volume; - AudioServer::get_singleton()->voice_set_volume(v.voice,v.volume); - -} - -void SamplePlayer::set_volume_db(VoiceID p_voice, float p_db) { - - //@TODO handle 0 volume as -80db or something - _GET_VOICE - v.volume=Math::db2linear(p_db); - AudioServer::get_singleton()->voice_set_volume(v.voice,v.volume); - -} - -void SamplePlayer::set_pan(VoiceID p_voice, float p_pan,float p_pan_depth,float p_pan_height) { - - _GET_VOICE - v.pan=p_pan; - v.pan_depth=p_pan_depth; - v.pan_height=p_pan_height; - - AudioServer::get_singleton()->voice_set_pan(v.voice,v.pan,v.pan_depth,v.pan_height); - -} - -void SamplePlayer::set_filter(VoiceID p_voice,FilterType p_filter,float p_cutoff,float p_resonance,float p_gain) { - - _GET_VOICE - v.filter_type=p_filter; - v.filter_cutoff=p_cutoff; - v.filter_resonance=p_resonance; - v.filter_gain=p_gain; - - AudioServer::get_singleton()->voice_set_filter(v.voice,(AudioServer::FilterType)p_filter,p_cutoff,p_resonance); - -} -void SamplePlayer::set_chorus(VoiceID p_voice,float p_send) { - - _GET_VOICE - v.chorus_send=p_send; - - AudioServer::get_singleton()->voice_set_chorus(v.voice,p_send); - -} -void SamplePlayer::set_reverb(VoiceID p_voice,ReverbRoomType p_room,float p_send) { - - _GET_VOICE - v.reverb_room=p_room; - v.reverb_send=p_send; - - AudioServer::get_singleton()->voice_set_reverb(v.voice,(AudioServer::ReverbRoomType)p_room,p_send); - -} - -#define _GET_VOICE_V(m_ret)\ - uint32_t voice=p_voice&0xFFFF;\ - ERR_FAIL_COND_V(voice >= (uint32_t)voices.size(),m_ret);\ - const Voice &v=voices[voice];\ - if (v.check!=(p_voice>>16))\ - return m_ret;\ - ERR_FAIL_COND_V(!v.active,m_ret); - - -int SamplePlayer::get_mix_rate(VoiceID p_voice) const { - - _GET_VOICE_V(0); - - return v.mix_rate; -} -float SamplePlayer::get_pitch_scale(VoiceID p_voice) const { - - _GET_VOICE_V(0); - return v.sample_mix_rate/(float)v.mix_rate; -} -float SamplePlayer::get_volume(VoiceID p_voice) const { - - _GET_VOICE_V(0); - return v.volume; -} - - -float SamplePlayer::get_volume_db(VoiceID p_voice) const { - - _GET_VOICE_V(0); - return Math::linear2db(v.volume); -} - -float SamplePlayer::get_pan(VoiceID p_voice) const { - - _GET_VOICE_V(0); - return v.pan; -} -float SamplePlayer::get_pan_depth(VoiceID p_voice) const { - - - _GET_VOICE_V(0); - return v.pan_depth; -} -float SamplePlayer::get_pan_height(VoiceID p_voice) const { - - _GET_VOICE_V(0); - - return v.pan_height; -} -SamplePlayer::FilterType SamplePlayer::get_filter_type(VoiceID p_voice) const { - - _GET_VOICE_V(FILTER_NONE); - - return v.filter_type; -} -float SamplePlayer::get_filter_cutoff(VoiceID p_voice) const { - - _GET_VOICE_V(0); - - return v.filter_cutoff; -} -float SamplePlayer::get_filter_resonance(VoiceID p_voice) const { - - _GET_VOICE_V(0); - - return v.filter_resonance; -} - -float SamplePlayer::get_filter_gain(VoiceID p_voice) const { - - _GET_VOICE_V(0); - - return v.filter_gain; -} -float SamplePlayer::get_chorus(VoiceID p_voice) const { - - _GET_VOICE_V(0); - - return v.chorus_send; -} -SamplePlayer::ReverbRoomType SamplePlayer::get_reverb_room(VoiceID p_voice) const { - - _GET_VOICE_V(REVERB_SMALL); - - return v.reverb_room; -} - -float SamplePlayer::get_reverb(VoiceID p_voice) const { - - _GET_VOICE_V(0); - - return v.reverb_send; -} - -bool SamplePlayer::is_voice_active(VoiceID p_voice) const { - - _GET_VOICE_V(false); - return v.active && AudioServer::get_singleton()->voice_is_active(v.voice); - -} -bool SamplePlayer::is_active() const { - - for(int i=0;i<voices.size();i++) { - - if (voices[i].active && AudioServer::get_singleton()->voice_is_active(voices[i].voice)) - return true; - - - } - - return false; -} - - - -void SamplePlayer::set_sample_library(const Ref<SampleLibrary>& p_library) { - - library=p_library; - _change_notify(); -} - -Ref<SampleLibrary> SamplePlayer::get_sample_library() const { - - return library; -} - - - -void SamplePlayer::set_default_pitch_scale(float p_pitch_scale) { - - _default.pitch_scale=p_pitch_scale; -} -void SamplePlayer::set_default_volume(float p_volume) { - - _default.volume_db=Math::linear2db(p_volume); -} -void SamplePlayer::set_default_volume_db(float p_db) { - - _default.volume_db=p_db; -} -void SamplePlayer::set_default_pan(float p_pan,float p_pan_depth,float p_pan_height) { - - _default.pan=p_pan; - _default.depth=p_pan_depth; - _default.height=p_pan_height; - -} -void SamplePlayer::set_default_filter(FilterType p_filter,float p_cutoff,float p_resonance,float p_gain) { - - _default.filter_type=p_filter; - _default.filter_cutoff=p_cutoff; - _default.filter_resonance=p_resonance; - _default.filter_gain=p_gain; -} -void SamplePlayer::set_default_chorus(float p_send) { - - _default.chorus_send=p_send; - -} -void SamplePlayer::set_default_reverb(ReverbRoomType p_room,float p_send) { - - _default.reverb_room=p_room; - _default.reverb_send=p_send; -} - -float SamplePlayer::get_default_volume() const { - - return Math::db2linear(_default.volume_db); -} -float SamplePlayer::get_default_volume_db() const { - - return _default.volume_db; -} -float SamplePlayer::get_default_pitch_scale() const { - - return _default.pitch_scale; -} - - -float SamplePlayer::get_default_pan() const { - - return _default.pan; -} -float SamplePlayer::get_default_pan_depth() const { - - return _default.depth; -} -float SamplePlayer::get_default_pan_height() const { - - return _default.height; -} -SamplePlayer::FilterType SamplePlayer::get_default_filter_type() const { - - return _default.filter_type; -} -float SamplePlayer::get_default_filter_cutoff() const { - - return _default.filter_cutoff; -} -float SamplePlayer::get_default_filter_resonance() const { - - return _default.filter_resonance; -} -float SamplePlayer::get_default_filter_gain() const { - - return _default.filter_gain; -} -float SamplePlayer::get_default_chorus() const { - - return _default.chorus_send; -} -SamplePlayer::ReverbRoomType SamplePlayer::get_default_reverb_room() const { - - return _default.reverb_room; -} -float SamplePlayer::get_default_reverb() const { - - return _default.reverb_send; -} - -String SamplePlayer::get_configuration_warning() const { - - if (library.is_null()) { - return TTR("A SampleLibrary resource must be created or set in the 'samples' property in order for SamplePlayer to play sound."); - } - - return String(); -} - -void SamplePlayer::_bind_methods() { - - ClassDB::bind_method(_MD("set_sample_library","library:SampleLibrary"),&SamplePlayer::set_sample_library ); - ClassDB::bind_method(_MD("get_sample_library:SampleLibrary"),&SamplePlayer::get_sample_library ); - - ClassDB::bind_method(_MD("set_polyphony","max_voices"),&SamplePlayer::set_polyphony ); - ClassDB::bind_method(_MD("get_polyphony"),&SamplePlayer::get_polyphony ); - - ClassDB::bind_method(_MD("play","name","unique"),&SamplePlayer::play, DEFVAL(false) ); - ClassDB::bind_method(_MD("stop","voice"),&SamplePlayer::stop ); - ClassDB::bind_method(_MD("stop_all"),&SamplePlayer::stop_all ); - - ClassDB::bind_method(_MD("set_mix_rate","voice","hz"),&SamplePlayer::set_mix_rate ); - ClassDB::bind_method(_MD("set_pitch_scale","voice","ratio"),&SamplePlayer::set_pitch_scale ); - ClassDB::bind_method(_MD("set_volume","voice","volume"),&SamplePlayer::set_volume ); - ClassDB::bind_method(_MD("set_volume_db","voice","db"),&SamplePlayer::set_volume_db ); - ClassDB::bind_method(_MD("set_pan","voice","pan","depth","height"),&SamplePlayer::set_pan,DEFVAL(0),DEFVAL(0) ); - ClassDB::bind_method(_MD("set_filter","voice","type","cutoff_hz","resonance","gain"),&SamplePlayer::set_filter,DEFVAL(0) ); - ClassDB::bind_method(_MD("set_chorus","voice","send"),&SamplePlayer::set_chorus ); - ClassDB::bind_method(_MD("set_reverb","voice","room_type","send"),&SamplePlayer::set_reverb ); - - ClassDB::bind_method(_MD("get_mix_rate","voice"),&SamplePlayer::get_mix_rate ); - ClassDB::bind_method(_MD("get_pitch_scale","voice"),&SamplePlayer::get_pitch_scale ); - ClassDB::bind_method(_MD("get_volume","voice"),&SamplePlayer::get_volume ); - ClassDB::bind_method(_MD("get_volume_db","voice"),&SamplePlayer::get_volume_db ); - ClassDB::bind_method(_MD("get_pan","voice"),&SamplePlayer::get_pan ); - ClassDB::bind_method(_MD("get_pan_depth","voice"),&SamplePlayer::get_pan_depth ); - ClassDB::bind_method(_MD("get_pan_height","voice"),&SamplePlayer::get_pan_height ); - ClassDB::bind_method(_MD("get_filter_type","voice"),&SamplePlayer::get_filter_type ); - ClassDB::bind_method(_MD("get_filter_cutoff","voice"),&SamplePlayer::get_filter_cutoff ); - ClassDB::bind_method(_MD("get_filter_resonance","voice"),&SamplePlayer::get_filter_resonance ); - ClassDB::bind_method(_MD("get_filter_gain","voice"),&SamplePlayer::get_filter_gain ); - ClassDB::bind_method(_MD("get_chorus","voice"),&SamplePlayer::get_chorus ); - ClassDB::bind_method(_MD("get_reverb_room","voice"),&SamplePlayer::get_reverb_room ); - ClassDB::bind_method(_MD("get_reverb","voice"),&SamplePlayer::get_reverb ); - - ClassDB::bind_method(_MD("set_default_pitch_scale","ratio"),&SamplePlayer::set_default_pitch_scale ); - ClassDB::bind_method(_MD("set_default_volume","volume"),&SamplePlayer::set_default_volume ); - ClassDB::bind_method(_MD("set_default_volume_db","db"),&SamplePlayer::set_default_volume_db ); - ClassDB::bind_method(_MD("set_default_pan","pan","depth","height"),&SamplePlayer::set_default_pan,DEFVAL(0),DEFVAL(0) ); - ClassDB::bind_method(_MD("set_default_filter","type","cutoff_hz","resonance","gain"),&SamplePlayer::set_default_filter,DEFVAL(0) ); - ClassDB::bind_method(_MD("set_default_chorus","send"),&SamplePlayer::set_default_chorus ); - ClassDB::bind_method(_MD("set_default_reverb","room_type","send"),&SamplePlayer::set_default_reverb ); - - ClassDB::bind_method(_MD("get_default_pitch_scale"),&SamplePlayer::get_default_pitch_scale ); - ClassDB::bind_method(_MD("get_default_volume"),&SamplePlayer::get_default_volume ); - ClassDB::bind_method(_MD("get_default_volume_db"),&SamplePlayer::get_default_volume_db ); - ClassDB::bind_method(_MD("get_default_pan"),&SamplePlayer::get_default_pan ); - ClassDB::bind_method(_MD("get_default_pan_depth"),&SamplePlayer::get_default_pan_depth ); - ClassDB::bind_method(_MD("get_default_pan_height"),&SamplePlayer::get_default_pan_height ); - ClassDB::bind_method(_MD("get_default_filter_type"),&SamplePlayer::get_default_filter_type ); - ClassDB::bind_method(_MD("get_default_filter_cutoff"),&SamplePlayer::get_default_filter_cutoff ); - ClassDB::bind_method(_MD("get_default_filter_resonance"),&SamplePlayer::get_default_filter_resonance ); - ClassDB::bind_method(_MD("get_default_filter_gain"),&SamplePlayer::get_default_filter_gain ); - ClassDB::bind_method(_MD("get_default_chorus"),&SamplePlayer::get_default_chorus ); - ClassDB::bind_method(_MD("get_default_reverb_room"),&SamplePlayer::get_default_reverb_room ); - ClassDB::bind_method(_MD("get_default_reverb"),&SamplePlayer::get_default_reverb ); - - ClassDB::bind_method(_MD("is_active"),&SamplePlayer::is_active ); - ClassDB::bind_method(_MD("is_voice_active","voice"),&SamplePlayer::is_voice_active ); - - BIND_CONSTANT( FILTER_NONE); - BIND_CONSTANT( FILTER_LOWPASS); - BIND_CONSTANT( FILTER_BANDPASS); - BIND_CONSTANT( FILTER_HIPASS); - BIND_CONSTANT( FILTER_NOTCH); - BIND_CONSTANT( FILTER_PEAK); - BIND_CONSTANT( FILTER_BANDLIMIT); ///< cutoff is LP resonace is HP - BIND_CONSTANT( FILTER_LOW_SHELF); - BIND_CONSTANT( FILTER_HIGH_SHELF); - - BIND_CONSTANT( REVERB_SMALL ); - BIND_CONSTANT( REVERB_MEDIUM ); - BIND_CONSTANT( REVERB_LARGE ); - BIND_CONSTANT( REVERB_HALL ); - - BIND_CONSTANT( INVALID_VOICE_ID ); - -} - - -SamplePlayer::SamplePlayer() { - - voices.resize(1); - - _default.pitch_scale=1; - _default.volume_db=0; - _default.pan=0; - _default.depth=0; - _default.height=0; - _default.filter_type=FILTER_NONE; - _default.filter_cutoff=5000; - _default.filter_resonance=1; - _default.filter_gain=1; - _default.chorus_send=0; - _default.reverb_room=REVERB_LARGE; - _default.reverb_send=0; - last_id=0; - last_check=0; - - -} - -SamplePlayer::~SamplePlayer() { - - -} diff --git a/scene/audio/sample_player.h b/scene/audio/sample_player.h deleted file mode 100644 index 8c4e6418aa..0000000000 --- a/scene/audio/sample_player.h +++ /dev/null @@ -1,200 +0,0 @@ -/*************************************************************************/ -/* sample_player.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SAMPLE_PLAYER_H -#define SAMPLE_PLAYER_H - -#include "scene/main/node.h" -#include "scene/resources/sample_library.h" - -class SamplePlayer : public Node { - - GDCLASS( SamplePlayer, Node ); - OBJ_CATEGORY("Audio Nodes"); -public: - - - enum FilterType { - FILTER_NONE, - FILTER_LOWPASS, - FILTER_BANDPASS, - FILTER_HIPASS, - FILTER_NOTCH, - FILTER_PEAK, - FILTER_BANDLIMIT, ///< cutoff is LP resonace is HP - FILTER_LOW_SHELF, - FILTER_HIGH_SHELF, - }; - - enum ReverbRoomType { - - REVERB_SMALL, - REVERB_MEDIUM, - REVERB_LARGE, - REVERB_HALL - }; - - enum { - - INVALID_VOICE_ID=0xFFFFFFFF - }; - - typedef uint32_t VoiceID; - -private: - - Ref<SampleLibrary> library; - - struct Voice { - - RID voice; - uint32_t check; - bool active; - - int sample_mix_rate; - int mix_rate; - float volume; - float pan; - float pan_depth; - float pan_height; - FilterType filter_type; - float filter_cutoff; - float filter_resonance; - float filter_gain; - float chorus_send; - ReverbRoomType reverb_room; - float reverb_send; - - void clear(); - Voice(); - ~Voice(); - }; - - Vector<Voice> voices; - - struct Default { - - float reverb_send; - float pitch_scale; - float volume_db; - float pan; - float depth; - float height; - FilterType filter_type; - float filter_cutoff; - float filter_resonance; - float filter_gain; - float chorus_send; - ReverbRoomType reverb_room; - - } _default; - - uint32_t last_id; - uint16_t last_check; - String played_back; -protected: - - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list(List<PropertyInfo> *p_list) const; - - static void _bind_methods(); - -public: - - void set_sample_library(const Ref<SampleLibrary>& p_library); - Ref<SampleLibrary> get_sample_library() const; - - void set_polyphony(int p_voice_count); - int get_polyphony() const; - - VoiceID play(const String& p_name,bool unique=false); - void stop(VoiceID p_voice); - void stop_all(); - bool is_voice_active(VoiceID) const; - bool is_active() const; - - void set_mix_rate(VoiceID p_voice, int p_mix_rate); - void set_pitch_scale(VoiceID p_voice, float p_pitch_scale); - void set_volume(VoiceID p_voice, float p_volume); - void set_volume_db(VoiceID p_voice, float p_db); - void set_pan(VoiceID p_voice, float p_pan,float p_pan_depth=0,float p_pan_height=0); - void set_filter(VoiceID p_voice,FilterType p_filter,float p_cutoff,float p_resonance,float p_gain); - void set_chorus(VoiceID p_voice,float p_send); - void set_reverb(VoiceID p_voice,ReverbRoomType p_room,float p_send); - - int get_mix_rate(VoiceID p_voice) const; - float get_pitch_scale(VoiceID p_voice) const; - float get_volume(VoiceID p_voice) const; - float get_volume_db(VoiceID p_voice) const; - - float get_pan(VoiceID p_voice) const; - float get_pan_depth(VoiceID p_voice) const; - float get_pan_height(VoiceID p_voice) const; - FilterType get_filter_type(VoiceID p_voice) const; - float get_filter_cutoff(VoiceID p_voice) const; - float get_filter_resonance(VoiceID p_voice) const; - float get_filter_gain(VoiceID p_voice) const; - float get_chorus(VoiceID p_voice) const; - ReverbRoomType get_reverb_room(VoiceID p_voice) const; - float get_reverb(VoiceID p_voice) const; - - - - void set_default_pitch_scale(float p_pitch_scale); - void set_default_volume(float p_volume); - void set_default_volume_db(float p_db); - void set_default_pan(float p_pan,float p_pan_depth=0,float p_pan_height=0); - void set_default_filter(FilterType p_filter,float p_cutoff,float p_resonance,float p_gain); - void set_default_chorus(float p_send); - void set_default_reverb(ReverbRoomType p_room,float p_send); - - float get_default_volume() const; - float get_default_volume_db() const; - float get_default_pitch_scale() const; - float get_default_pan() const; - float get_default_pan_depth() const; - float get_default_pan_height() const; - FilterType get_default_filter_type() const; - float get_default_filter_cutoff() const; - float get_default_filter_resonance() const; - float get_default_filter_gain() const; - float get_default_chorus() const; - ReverbRoomType get_default_reverb_room() const; - float get_default_reverb() const; - - String get_configuration_warning() const; - - SamplePlayer(); - ~SamplePlayer(); -}; - -VARIANT_ENUM_CAST( SamplePlayer::FilterType ); -VARIANT_ENUM_CAST( SamplePlayer::ReverbRoomType ); - -#endif // SAMPLE_PLAYER_H diff --git a/scene/audio/sound_room_params.cpp b/scene/audio/sound_room_params.cpp deleted file mode 100644 index d08bc5d6b8..0000000000 --- a/scene/audio/sound_room_params.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/*************************************************************************/ -/* sound_room_params.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "sound_room_params.h" - -#include "scene/main/viewport.h" - -#ifndef _3D_DISABLED -void SoundRoomParams::_update_sound_room() { - - if (!room.is_valid()) - return; - - for(int i=0;i<PARAM_MAX;i++) { - - SpatialSoundServer::get_singleton()->room_set_param(room,SpatialSoundServer::RoomParam(i),params[i]); - - } - - SpatialSoundServer::get_singleton()->room_set_reverb(room,SpatialSoundServer::RoomReverb(reverb)); - SpatialSoundServer::get_singleton()->room_set_force_params_to_all_sources(room,force_params_for_all_sources); -} - - -void SoundRoomParams::_notification(int p_what) { - - - switch(p_what) { - - - case NOTIFICATION_ENTER_TREE: { -//#if 0 - Node *n=this; - Room *room_instance=NULL; - while(n) { - - room_instance=n->cast_to<Room>(); - if (room_instance) { - - break; - } - if (n->cast_to<Viewport>()) - break; - - n=n->get_parent(); - } - - - if (room_instance) { - room=room_instance->get_sound_room(); - } else { - room=get_viewport()->find_world()->get_sound_space(); - } - - _update_sound_room(); -//#endif - - } break; - case NOTIFICATION_EXIT_TREE: { - - room=RID(); - - } break; - } -} - - -void SoundRoomParams::set_param(Params p_param, float p_value) { - - ERR_FAIL_INDEX(p_param,PARAM_MAX); - params[p_param]=p_value; - if (room.is_valid()) - SpatialSoundServer::get_singleton()->room_set_param(room,SpatialSoundServer::RoomParam(p_param),p_value); -} - -float SoundRoomParams::get_param(Params p_param) const { - - ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0); - return params[p_param]; -} - - -void SoundRoomParams::set_reverb_mode(Reverb p_mode) { - - ERR_FAIL_INDEX(p_mode,4); - reverb=p_mode; - if (room.is_valid()) - SpatialSoundServer::get_singleton()->room_set_reverb(room,SpatialSoundServer::RoomReverb(p_mode)); -} - -SoundRoomParams::Reverb SoundRoomParams::get_reverb_mode() const { - - return reverb; -} - - -void SoundRoomParams::set_force_params_to_all_sources(bool p_force) { - - force_params_for_all_sources=p_force; - if (room.is_valid()) - SpatialSoundServer::get_singleton()->room_set_force_params_to_all_sources(room,p_force); -} - -bool SoundRoomParams::is_forcing_params_to_all_sources() { - - return force_params_for_all_sources; -} - - -void SoundRoomParams::_bind_methods() { - - ClassDB::bind_method(_MD("set_param","param","value"),&SoundRoomParams::set_param ); - ClassDB::bind_method(_MD("get_param","param"),&SoundRoomParams::get_param ); - - ClassDB::bind_method(_MD("set_reverb_mode","reverb_mode","value"),&SoundRoomParams::set_reverb_mode ); - ClassDB::bind_method(_MD("get_reverb_mode","reverb_mode"),&SoundRoomParams::get_reverb_mode ); - - ClassDB::bind_method(_MD("set_force_params_to_all_sources","enabled"),&SoundRoomParams::set_force_params_to_all_sources ); - ClassDB::bind_method(_MD("is_forcing_params_to_all_sources"),&SoundRoomParams::is_forcing_params_to_all_sources ); - - - ADD_PROPERTY( PropertyInfo( Variant::INT, "reverb/mode", PROPERTY_HINT_ENUM, "Small,Medium,Large,Hall"), _SCS("set_reverb_mode"), _SCS("get_reverb_mode") ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/speed_of_scale", PROPERTY_HINT_RANGE, "0.01,16,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_SPEED_OF_SOUND_SCALE); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/doppler_factor",PROPERTY_HINT_RANGE, "0.01,16,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_DOPPLER_FACTOR ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/pitch_scale",PROPERTY_HINT_RANGE, "0.01,32,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_PITCH_SCALE ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/volume_scale_db",PROPERTY_HINT_RANGE, "-80,24,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_VOLUME_SCALE_DB ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/reverb_send",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_REVERB_SEND ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/chorus_send",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_CHORUS_SEND ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation_scale",PROPERTY_HINT_RANGE, "0.01,32,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION_SCALE ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation_hf_cutoff",PROPERTY_HINT_RANGE, "30,16384,1"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION_HF_CUTOFF ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation_hf_floor_db",PROPERTY_HINT_RANGE, "-80,24,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION_HF_FLOOR_DB ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation_hf_ratio_exp",PROPERTY_HINT_RANGE, "0.01,32,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION_HF_RATIO_EXP ); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/attenuation_reverb_scale",PROPERTY_HINT_RANGE, "0.01,32,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION_REVERB_SCALE ); - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "force_to_all_sources"),_SCS("set_force_params_to_all_sources"),_SCS("is_forcing_params_to_all_sources") ); - -} - - -SoundRoomParams::SoundRoomParams() { - - reverb=REVERB_HALL; - params[PARAM_SPEED_OF_SOUND_SCALE]=1; - params[PARAM_DOPPLER_FACTOR]=1.0; - params[PARAM_PITCH_SCALE]=1.0; - params[PARAM_VOLUME_SCALE_DB]=0; - params[PARAM_REVERB_SEND]=0; - params[PARAM_CHORUS_SEND]=0; - params[PARAM_ATTENUATION_SCALE]=1.0; - params[PARAM_ATTENUATION_HF_CUTOFF]=5000; - params[PARAM_ATTENUATION_HF_FLOOR_DB]=-24.0; - params[PARAM_ATTENUATION_HF_RATIO_EXP]=1.0; - params[PARAM_ATTENUATION_REVERB_SCALE]=0.0; - force_params_for_all_sources=false; -} -#endif diff --git a/scene/audio/sound_room_params.h b/scene/audio/sound_room_params.h deleted file mode 100644 index 3cdffda652..0000000000 --- a/scene/audio/sound_room_params.h +++ /dev/null @@ -1,100 +0,0 @@ -/*************************************************************************/ -/* sound_room_params.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SOUND_ROOM_PARAMS_H -#define SOUND_ROOM_PARAMS_H - -#include "scene/main/node.h" -#include "servers/spatial_sound_server.h" - - -#ifndef _3D_DISABLED - -#include "scene/3d/room_instance.h" -class SoundRoomParams : public Node { - - GDCLASS( SoundRoomParams, Node ); -public: - - enum Params { - PARAM_SPEED_OF_SOUND_SCALE=SpatialSoundServer::ROOM_PARAM_SPEED_OF_SOUND_SCALE, - PARAM_DOPPLER_FACTOR=SpatialSoundServer::ROOM_PARAM_DOPPLER_FACTOR, - PARAM_PITCH_SCALE=SpatialSoundServer::ROOM_PARAM_PITCH_SCALE, - PARAM_VOLUME_SCALE_DB=SpatialSoundServer::ROOM_PARAM_VOLUME_SCALE_DB, - PARAM_REVERB_SEND=SpatialSoundServer::ROOM_PARAM_REVERB_SEND, - PARAM_CHORUS_SEND=SpatialSoundServer::ROOM_PARAM_CHORUS_SEND, - PARAM_ATTENUATION_SCALE=SpatialSoundServer::ROOM_PARAM_ATTENUATION_SCALE, - PARAM_ATTENUATION_HF_CUTOFF=SpatialSoundServer::ROOM_PARAM_ATTENUATION_HF_CUTOFF, - PARAM_ATTENUATION_HF_FLOOR_DB=SpatialSoundServer::ROOM_PARAM_ATTENUATION_HF_FLOOR_DB, - PARAM_ATTENUATION_HF_RATIO_EXP=SpatialSoundServer::ROOM_PARAM_ATTENUATION_HF_RATIO_EXP, - PARAM_ATTENUATION_REVERB_SCALE=SpatialSoundServer::ROOM_PARAM_ATTENUATION_REVERB_SCALE, - PARAM_MAX=SpatialSoundServer::ROOM_PARAM_MAX - }; - - enum Reverb { - REVERB_SMALL, - REVERB_MEDIUM, - REVERB_LARGE, - REVERB_HALL - }; -private: - - RID room; - - float params[PARAM_MAX]; - Reverb reverb; - bool force_params_for_all_sources; - void _update_sound_room(); - - -protected: - - void _notification(int p_what); - static void _bind_methods(); - -public: - - - void set_param(Params p_param, float p_value); - float get_param(Params p_param) const; - - void set_reverb_mode(Reverb p_mode); - Reverb get_reverb_mode() const; - - void set_force_params_to_all_sources(bool p_force); - bool is_forcing_params_to_all_sources(); - - SoundRoomParams(); -}; - -VARIANT_ENUM_CAST(SoundRoomParams::Params); -VARIANT_ENUM_CAST(SoundRoomParams::Reverb); - -#endif - -#endif // SOUND_ROOM_PARAMS_H diff --git a/scene/audio/stream_player.cpp b/scene/audio/stream_player.cpp deleted file mode 100644 index 9e506034a6..0000000000 --- a/scene/audio/stream_player.cpp +++ /dev/null @@ -1,428 +0,0 @@ -/*************************************************************************/ -/* stream_player.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "stream_player.h" - -int StreamPlayer::InternalStream::get_channel_count() const { - - return player->sp_get_channel_count(); -} -void StreamPlayer::InternalStream::set_mix_rate(int p_rate){ - - return player->sp_set_mix_rate(p_rate); -} -bool StreamPlayer::InternalStream::mix(int32_t *p_buffer,int p_frames){ - - return player->sp_mix(p_buffer,p_frames); -} -void StreamPlayer::InternalStream::update(){ - - player->sp_update(); -} - - -int StreamPlayer::sp_get_channel_count() const { - - return playback->get_channels(); -} - -void StreamPlayer::sp_set_mix_rate(int p_rate){ - - server_mix_rate=p_rate; -} - -bool StreamPlayer::sp_mix(int32_t *p_buffer,int p_frames) { - - if (resampler.is_ready() && !paused) { - return resampler.mix(p_buffer,p_frames); - } - - return false; -} - -void StreamPlayer::sp_update() { - - //_THREAD_SAFE_METHOD_ - if (!paused && resampler.is_ready() && playback.is_valid()) { - - if (!playback->is_playing()) { - //stream depleted data, but there's still audio in the ringbuffer - //check that all this audio has been flushed before stopping the stream - int to_mix = resampler.get_total() - resampler.get_todo(); - if (to_mix==0) { - if (!stop_request) { - stop_request=true; - call_deferred("_do_stop"); - } - return; - } - - return; - } - - int todo =resampler.get_todo(); - int wrote = playback->mix(resampler.get_write_buffer(),todo); - resampler.write(wrote); - } -} - -void StreamPlayer::_do_stop() { - stop(); - emit_signal("finished"); -} - -void StreamPlayer::_notification(int p_what) { - - switch(p_what) { - - case NOTIFICATION_ENTER_TREE: { - - //set_idle_process(false); //don't annoy - if (stream.is_valid() && !get_tree()->is_editor_hint()) { - if (resume_pos>=0) { - play(resume_pos); - resume_pos=-1; - } else if (autoplay) { - play(); - autoplay = false; //this line fix autoplay issues - } - } - - } break; - case NOTIFICATION_EXIT_TREE: { - - if (is_playing()) { - resume_pos=get_pos(); - } - stop(); //wathever it may be doing, stop - } break; - } -} - - - -void StreamPlayer::set_stream(const Ref<AudioStream> &p_stream) { - - stop(); - - stream=p_stream; - - if (!stream.is_null()) { - playback=stream->instance_playback(); - playback->set_loop(loops); - playback->set_loop_restart_time(loop_point); - AudioServer::get_singleton()->lock(); - resampler.setup(playback->get_channels(),playback->get_mix_rate(),server_mix_rate,buffering_ms,playback->get_minimum_buffer_size()); - AudioServer::get_singleton()->unlock(); - } else { - AudioServer::get_singleton()->lock(); - resampler.clear(); - playback.unref(); - AudioServer::get_singleton()->unlock(); - } -} - -Ref<AudioStream> StreamPlayer::get_stream() const { - - return stream; -} - - -void StreamPlayer::play(float p_from_offset) { - - ERR_FAIL_COND(!is_inside_tree()); - if (playback.is_null()) - return; - //if (is_playing()) - stop(); - - //_THREAD_SAFE_METHOD_ - playback->play(p_from_offset); - //feed the ringbuffer as long as no update callback is going on - sp_update(); - AudioServer::get_singleton()->stream_set_active(stream_rid,true); - AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume); - /* - if (stream->get_update_mode()!=AudioStream::UPDATE_NONE) - set_idle_process(true); - */ - -} - -void StreamPlayer::stop() { - - if (!is_inside_tree()) - return; - if (playback.is_null()) - return; - - //_THREAD_SAFE_METHOD_ - AudioServer::get_singleton()->stream_set_active(stream_rid,false); - stop_request=false; - playback->stop(); - resampler.flush(); - - - //set_idle_process(false); -} - -bool StreamPlayer::is_playing() const { - - if (playback.is_null()) - return false; - - return playback->is_playing() || resampler.has_data(); -} - -void StreamPlayer::set_loop(bool p_enable) { - - loops=p_enable; - if (playback.is_null()) - return; - playback->set_loop(loops); - -} -bool StreamPlayer::has_loop() const { - - return loops; -} - -void StreamPlayer::set_volume(float p_vol) { - - volume=p_vol; - if (stream_rid.is_valid()) - AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume); -} - -float StreamPlayer::get_volume() const { - - return volume; -} - -void StreamPlayer::set_loop_restart_time(float p_secs) { - - loop_point=p_secs; - if (playback.is_valid()) - playback->set_loop_restart_time(p_secs); -} - -float StreamPlayer::get_loop_restart_time() const { - - return loop_point; -} - - -void StreamPlayer::set_volume_db(float p_db) { - - if (p_db<-79) - set_volume(0); - else - set_volume(Math::db2linear(p_db)); -} - -float StreamPlayer::get_volume_db() const { - - if (volume==0) - return -80; - else - return Math::linear2db(volume); -} - - -String StreamPlayer::get_stream_name() const { - - if (stream.is_null()) - return "<No Stream>"; - return stream->get_name(); - -} - -int StreamPlayer::get_loop_count() const { - - if (playback.is_null()) - return 0; - return playback->get_loop_count(); - -} - -float StreamPlayer::get_pos() const { - - if (playback.is_null()) - return 0; - return playback->get_pos(); - -} - -float StreamPlayer::get_length() const { - - if (playback.is_null()) - return 0; - return playback->get_length(); -} -void StreamPlayer::seek_pos(float p_time) { - - if (playback.is_null()) - return; - //works better... - stop(); - playback->play(p_time); - -} - -void StreamPlayer::set_autoplay(bool p_enable) { - - autoplay=p_enable; -} - -bool StreamPlayer::has_autoplay() const { - - return autoplay; -} - -void StreamPlayer::set_paused(bool p_paused) { - - paused=p_paused; - /* - if (stream.is_valid()) - stream->set_paused(p_paused); - */ -} - -bool StreamPlayer::is_paused() const { - - return paused; -} - -void StreamPlayer::_set_play(bool p_play) { - - _play=p_play; - if (is_inside_tree()) { - if(_play) - play(); - else - stop(); - } - -} - -bool StreamPlayer::_get_play() const{ - - return _play; -} - -void StreamPlayer::set_buffering_msec(int p_msec) { - - buffering_ms=p_msec; -} - -int StreamPlayer::get_buffering_msec() const{ - - return buffering_ms; -} - - - -void StreamPlayer::_bind_methods() { - - ClassDB::bind_method(_MD("set_stream","stream:AudioStream"),&StreamPlayer::set_stream); - ClassDB::bind_method(_MD("get_stream:AudioStream"),&StreamPlayer::get_stream); - - ClassDB::bind_method(_MD("play","offset"),&StreamPlayer::play,DEFVAL(0)); - ClassDB::bind_method(_MD("stop"),&StreamPlayer::stop); - - ClassDB::bind_method(_MD("is_playing"),&StreamPlayer::is_playing); - - ClassDB::bind_method(_MD("set_paused","paused"),&StreamPlayer::set_paused); - ClassDB::bind_method(_MD("is_paused"),&StreamPlayer::is_paused); - - ClassDB::bind_method(_MD("set_loop","enabled"),&StreamPlayer::set_loop); - ClassDB::bind_method(_MD("has_loop"),&StreamPlayer::has_loop); - - ClassDB::bind_method(_MD("set_volume","volume"),&StreamPlayer::set_volume); - ClassDB::bind_method(_MD("get_volume"),&StreamPlayer::get_volume); - - ClassDB::bind_method(_MD("set_volume_db","db"),&StreamPlayer::set_volume_db); - ClassDB::bind_method(_MD("get_volume_db"),&StreamPlayer::get_volume_db); - - ClassDB::bind_method(_MD("set_buffering_msec","msec"),&StreamPlayer::set_buffering_msec); - ClassDB::bind_method(_MD("get_buffering_msec"),&StreamPlayer::get_buffering_msec); - - ClassDB::bind_method(_MD("set_loop_restart_time","secs"),&StreamPlayer::set_loop_restart_time); - ClassDB::bind_method(_MD("get_loop_restart_time"),&StreamPlayer::get_loop_restart_time); - - ClassDB::bind_method(_MD("get_stream_name"),&StreamPlayer::get_stream_name); - ClassDB::bind_method(_MD("get_loop_count"),&StreamPlayer::get_loop_count); - - ClassDB::bind_method(_MD("get_pos"),&StreamPlayer::get_pos); - ClassDB::bind_method(_MD("seek_pos","time"),&StreamPlayer::seek_pos); - - ClassDB::bind_method(_MD("set_autoplay","enabled"),&StreamPlayer::set_autoplay); - ClassDB::bind_method(_MD("has_autoplay"),&StreamPlayer::has_autoplay); - - ClassDB::bind_method(_MD("get_length"),&StreamPlayer::get_length); - - ClassDB::bind_method(_MD("_set_play","play"),&StreamPlayer::_set_play); - ClassDB::bind_method(_MD("_get_play"),&StreamPlayer::_get_play); - ClassDB::bind_method(_MD("_do_stop"),&StreamPlayer::_do_stop); - - ADD_PROPERTY( PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE,"AudioStream"), _SCS("set_stream"), _SCS("get_stream") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "play"), _SCS("_set_play"), _SCS("_get_play") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "loop"), _SCS("set_loop"), _SCS("has_loop") ); - ADD_PROPERTY( PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE,"-80,24,0.01"), _SCS("set_volume_db"), _SCS("get_volume_db") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autoplay"), _SCS("set_autoplay"), _SCS("has_autoplay") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "paused"), _SCS("set_paused"), _SCS("is_paused") ); - ADD_PROPERTY( PropertyInfo(Variant::REAL, "loop_restart_time"), _SCS("set_loop_restart_time"), _SCS("get_loop_restart_time") ); - ADD_PROPERTY( PropertyInfo(Variant::INT, "buffering_ms"), _SCS("set_buffering_msec"), _SCS("get_buffering_msec") ); - - ADD_SIGNAL(MethodInfo("finished")); -} - - -StreamPlayer::StreamPlayer() { - - volume=1; - loops=false; - paused=false; - autoplay=false; - _play=false; - server_mix_rate=1; - internal_stream.player=this; - stream_rid=AudioServer::get_singleton()->audio_stream_create(&internal_stream); - buffering_ms=500; - loop_point=0; - stop_request=false; - resume_pos=-1; - -} - -StreamPlayer::~StreamPlayer() { - AudioServer::get_singleton()->free(stream_rid); - resampler.clear(); - - -} diff --git a/scene/audio/stream_player.h b/scene/audio/stream_player.h deleted file mode 100644 index 6031d86aa2..0000000000 --- a/scene/audio/stream_player.h +++ /dev/null @@ -1,124 +0,0 @@ -/*************************************************************************/ -/* stream_player.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef STREAM_PLAYER_H -#define STREAM_PLAYER_H - -#include "scene/resources/audio_stream.h" -#include "scene/main/node.h" -#include "servers/audio/audio_rb_resampler.h" - -class StreamPlayer : public Node { - - GDCLASS(StreamPlayer,Node); - - //_THREAD_SAFE_CLASS_ - - struct InternalStream : public AudioServer::AudioStream { - StreamPlayer *player; - virtual int get_channel_count() const; - virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate - virtual bool mix(int32_t *p_buffer,int p_frames); - virtual void update(); - }; - - - InternalStream internal_stream; - Ref<AudioStreamPlayback> playback; - Ref<AudioStream> stream; - - int sp_get_channel_count() const; - void sp_set_mix_rate(int p_rate); //notify the stream of the mix rate - bool sp_mix(int32_t *p_buffer,int p_frames); - void sp_update(); - - int server_mix_rate; - - RID stream_rid; - bool paused; - bool autoplay; - bool loops; - float volume; - float loop_point; - int buffering_ms; - volatile bool stop_request; - float resume_pos; - - AudioRBResampler resampler; - - void _do_stop(); - - bool _play; - void _set_play(bool p_play); - bool _get_play() const; -protected: - void _notification(int p_what); - - static void _bind_methods(); -public: - - void set_stream(const Ref<AudioStream> &p_stream); - Ref<AudioStream> get_stream() const; - - void play(float p_from_offset=0); - void stop(); - bool is_playing() const; - - void set_paused(bool p_paused); - bool is_paused() const; - - void set_loop(bool p_enable); - bool has_loop() const; - - void set_volume(float p_vol); - float get_volume() const; - - void set_loop_restart_time(float p_secs); - float get_loop_restart_time() const; - - void set_volume_db(float p_db); - float get_volume_db() const; - - String get_stream_name() const; - - int get_loop_count() const; - - float get_pos() const; - void seek_pos(float p_time); - float get_length() const; - void set_autoplay(bool p_vol); - bool has_autoplay() const; - - void set_buffering_msec(int p_msec); - int get_buffering_msec() const; - - StreamPlayer(); - ~StreamPlayer(); -}; - -#endif // AUDIO_STREAM_PLAYER_H diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index 7ca44ac27b..9c5ddb3e7c 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -42,7 +42,7 @@ void BoxContainer::_resort() { /** First pass, determine minimum size AND amount of stretchable elements */ - Size2i new_size=get_size();; + Size2i new_size=get_size(); int sep=get_constant("separation");//,vertical?"VBoxContainer":"HBoxContainer"); diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index f28595b622..2d1d437668 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -74,17 +74,21 @@ void Button::_notification(int p_what) { //print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode())); + Ref<StyleBox> style = get_stylebox("normal"); + switch( get_draw_mode() ) { case DRAW_NORMAL: { + style = get_stylebox("normal"); if (!flat) - get_stylebox("normal" )->draw( ci, Rect2(Point2(0,0), size) ); + style->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color"); } break; case DRAW_PRESSED: { - get_stylebox("pressed" )->draw( ci, Rect2(Point2(0,0), size) ); + style = get_stylebox("pressed"); + style->draw( ci, Rect2(Point2(0,0), size) ); if (has_color("font_color_pressed")) color=get_color("font_color_pressed"); else @@ -93,13 +97,15 @@ void Button::_notification(int p_what) { } break; case DRAW_HOVER: { - get_stylebox("hover" )->draw( ci, Rect2(Point2(0,0), size) ); + style = get_stylebox("hover"); + style->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color_hover"); } break; case DRAW_DISABLED: { - get_stylebox("disabled" )->draw( ci, Rect2(Point2(0,0), size) ); + style = get_stylebox("disabled"); + style->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color_disabled"); } break; @@ -111,7 +117,6 @@ void Button::_notification(int p_what) { style->draw(ci,Rect2(Point2(),size)); } - Ref<StyleBox> style = get_stylebox("normal" ); Ref<Font> font=get_font("font"); Ref<Texture> _icon; if (icon.is_null() && has_icon("icon")) diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 533d24f998..e012874f5b 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1715,7 +1715,7 @@ Control *Control::find_next_valid_focus() const { if (!next_child) { - next_child=const_cast<Control*>(this);; + next_child=const_cast<Control*>(this); while(next_child) { if (next_child->data.SI || next_child->data.RI) diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index a3ed0a91cf..a42ef08bf3 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -300,7 +300,7 @@ void ItemList::move_item(int p_item,int p_to_pos) { ERR_FAIL_INDEX(p_to_pos,items.size()+1); Item it=items[p_item]; - items.remove(p_item);; + items.remove(p_item); if (p_to_pos>p_item) { p_to_pos--; @@ -905,7 +905,7 @@ void ItemList::_notification(int p_what) { Vector2 ofs; int col=0; int max_h=0; - separators.clear();; + separators.clear(); for(int i=0;i<items.size();i++) { if (current_columns>1 && items[i].rect_cache.size.width+ofs.x > fit_size) { diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index cd500a62bc..d32b4c6de4 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -204,7 +204,7 @@ void Label::_notification(int p_what) { } break; case ALIGN_CENTER: { - x_ofs=int(size.width-(taken+spaces*space_w))/2;; + x_ofs=int(size.width-(taken+spaces*space_w))/2; } break; case ALIGN_RIGHT: { diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 3a72e0e445..fe242ee708 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1320,7 +1320,7 @@ void LineEdit::_bind_methods() { ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "placeholder_text" ), _SCS("set_placeholder"),_SCS("get_placeholder") ); ADD_PROPERTYNZ( PropertyInfo( Variant::REAL, "placeholder_alpha",PROPERTY_HINT_RANGE,"0,1,0.001" ), _SCS("set_placeholder_alpha"),_SCS("get_placeholder_alpha") ); ADD_GROUP("Caret","caret_"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), _SCS("cursor_set_blink_enabled"), _SCS("cursor_get_blink_enabled"));; + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), _SCS("cursor_set_blink_enabled"), _SCS("cursor_get_blink_enabled")); ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "caret_blink_speed",PROPERTY_HINT_RANGE,"0.1,10,0.1"), _SCS("cursor_set_blink_speed"),_SCS("cursor_get_blink_speed") ); } diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index d5c1034c9c..5ecafccaca 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -141,8 +141,8 @@ void Range::set_as_ratio(double p_value) { if (shared->exp_ratio && get_min()>0) { - double exp_min = Math::log(get_min())/Math::log(2); - double exp_max = Math::log(get_max())/Math::log(2); + double exp_min = Math::log(get_min())/Math::log((double)2); + double exp_max = Math::log(get_max())/Math::log((double)2); v = Math::pow(2,exp_min+(exp_max-exp_min)*p_value); } else { @@ -160,9 +160,9 @@ double Range::get_as_ratio() const { if (shared->exp_ratio && get_min()>0) { - double exp_min = Math::log(get_min())/Math::log(2); - double exp_max = Math::log(get_max())/Math::log(2); - double v = Math::log(get_value())/Math::log(2); + double exp_min = Math::log(get_min())/Math::log((double)2); + double exp_max = Math::log(get_max())/Math::log((double)2); + double v = Math::log(get_value())/Math::log((double)2); return (v - exp_min) / (exp_max - exp_min); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 434fb36e24..5fe5f47d1b 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -103,7 +103,7 @@ void RichTextLabel::_process_line(ItemFrame *p_frame,const Vector2& p_ofs,int &y int line_ofs=0; int margin=_find_margin(it,p_base_font); - Align align=_find_align(it);; + Align align=_find_align(it); int line=0; int spaces=0; diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index b3ed9b209a..46312933a7 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -236,14 +236,14 @@ void ScrollContainer::_notification(int p_what) { child_max_size.y = MAX(child_max_size.y, minsize.y); Rect2 r = Rect2(-scroll,minsize); - if (!(scroll_h || h_scroll->is_visible_in_tree())) { + if (!scroll_h || (!h_scroll->is_visible_in_tree() && c->get_h_size_flags()&SIZE_EXPAND)) { r.pos.x=0; if (c->get_h_size_flags()&SIZE_EXPAND) r.size.width=MAX(size.width,minsize.width); else r.size.width=minsize.width; } - if (!(scroll_v || v_scroll->is_visible_in_tree())) { + if (!scroll_v || (!v_scroll->is_visible_in_tree() && c->get_v_size_flags()&SIZE_EXPAND)) { r.pos.y=0; r.size.height=size.height; if (c->get_v_size_flags()&SIZE_EXPAND) diff --git a/scene/gui/separator.h b/scene/gui/separator.h index 5fb17e1c2e..56d8a9724f 100644 --- a/scene/gui/separator.h +++ b/scene/gui/separator.h @@ -45,7 +45,7 @@ protected: void _notification(int p_what); public: - virtual Size2 get_minimum_size() const;; + virtual Size2 get_minimum_size() const; Separator(); ~Separator(); diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index ec6be0d19d..8920f8f056 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -162,7 +162,7 @@ void SpinBox::_gui_input(const InputEvent& p_event) { if (drag.enabled) { float diff_y = drag.mouse_pos.y - cpos.y; - diff_y=Math::pow(ABS(diff_y),1.8)*SGN(diff_y); + diff_y=Math::pow(ABS(diff_y),1.8f)*SGN(diff_y); diff_y*=0.1; drag.mouse_pos=cpos; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 52d26b29de..11802ab0fb 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -40,7 +40,7 @@ int TabContainer::_get_top_margin() const { int h = MAX( tab_bg->get_minimum_size().height,tab_fg->get_minimum_size().height); - int ch = font->get_height();; + int ch = font->get_height(); for(int i=0;i<get_child_count();i++) { Control *c = get_child(i)->cast_to<Control>(); @@ -99,7 +99,7 @@ void TabContainer::_gui_input(const InputEvent& p_event) { pp_pos.y+=menu->get_height(); popup->set_global_pos( pp_pos ); - popup->popup();; + popup->popup(); return; } pos.x-=tabs_ofs_cache; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 8efff21fc9..4ca95294ca 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -247,7 +247,7 @@ void TextEdit::Text::clear_caches() { void TextEdit::Text::clear() { - text.clear();; + text.clear(); insert(0,""); } @@ -482,14 +482,6 @@ void TextEdit::_notification(int p_what) { Color color = cache.font_color; int in_region=-1; - if (line_length_guideline) { - int x=xmargin_beg+cache.font->get_char_size('0').width*line_length_guideline_col-cursor.x_ofs; - if (x>xmargin_beg && x<xmargin_end) { - Color guideline_color(color.r,color.g,color.b,color.a*0.25f); - VisualServer::get_singleton()->canvas_item_add_line(ci,Point2(x,0),Point2(x,cache.size.height),guideline_color); - } - } - if (syntax_coloring) { if (cache.background_color.a>0.01) { @@ -1080,6 +1072,14 @@ void TextEdit::_notification(int p_what) { } } + if (line_length_guideline) { + int x=xmargin_beg+cache.font->get_char_size('0').width*line_length_guideline_col-cursor.x_ofs; + if (x>xmargin_beg && x<xmargin_end) { + VisualServer::get_singleton()->canvas_item_add_line(ci,Point2(x,0),Point2(x,cache.size.height),cache.line_length_guideline_color); + } + } + + bool completion_below = false; if (completion_active) { // code completion box @@ -2431,6 +2431,8 @@ void TextEdit::_gui_input(const InputEvent& p_gui_input) { if (k.mod.shift) _post_shift_selection(); + else if(k.mod.command || k.mod.control) + deselect(); } break; #else @@ -2440,25 +2442,30 @@ void TextEdit::_gui_input(const InputEvent& p_gui_input) { if (k.mod.shift) _pre_shift_selection(); - // compute whitespace symbols seq length - int current_line_whitespace_len = 0; - while(current_line_whitespace_len < text[cursor.line].length()) { - CharType c = text[cursor.line][current_line_whitespace_len]; - if(c != '\t' && c != ' ') - break; - current_line_whitespace_len++; - } - - if(cursor_get_column() == current_line_whitespace_len) + if (k.mod.command) { + cursor_set_line(0); cursor_set_column(0); - else - cursor_set_column(current_line_whitespace_len); + } + else { + // compute whitespace symbols seq length + int current_line_whitespace_len = 0; + while( current_line_whitespace_len < text[cursor.line].length() ) { + CharType c = text[cursor.line][current_line_whitespace_len]; + if( c != '\t' && c != ' ' ) + break; + current_line_whitespace_len++; + } - if (k.mod.command) - cursor_set_line(0); + if( cursor_get_column() == current_line_whitespace_len ) + cursor_set_column(0); + else + cursor_set_column(current_line_whitespace_len); + } if (k.mod.shift) _post_shift_selection(); + else if(k.mod.command || k.mod.control) + deselect(); _cancel_completion(); completion_hint=""; @@ -2481,6 +2488,8 @@ void TextEdit::_gui_input(const InputEvent& p_gui_input) { if (k.mod.shift) _post_shift_selection(); + else if(k.mod.command || k.mod.control) + deselect(); } break; #else @@ -2495,6 +2504,8 @@ void TextEdit::_gui_input(const InputEvent& p_gui_input) { if (k.mod.shift) _post_shift_selection(); + else if(k.mod.command || k.mod.control) + deselect(); _cancel_completion(); completion_hint=""; @@ -3484,6 +3495,7 @@ void TextEdit::_update_caches() { cache.selection_color=get_color("selection_color"); cache.mark_color=get_color("mark_color"); cache.current_line_color=get_color("current_line_color"); + cache.line_length_guideline_color=get_color("line_length_guideline_color"); cache.breakpoint_color=get_color("breakpoint_color"); cache.brace_mismatch_color=get_color("brace_mismatch_color"); cache.word_highlighted_color=get_color("word_highlighted_color"); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 6113fd72c2..437e22ca40 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -91,6 +91,7 @@ class TextEdit : public Control { Color mark_color; Color breakpoint_color; Color current_line_color; + Color line_length_guideline_color; Color brace_mismatch_color; Color word_highlighted_color; Color search_result_color; diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 03e37e9d9f..fb6262eff8 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -28,40 +28,35 @@ /*************************************************************************/ #include "texture_button.h" - Size2 TextureButton::get_minimum_size() const { - Size2 rscale; - if (normal.is_null()) { - if (pressed.is_null()) { - if (hover.is_null()) - if (click_mask.is_null()) - rscale= Size2(); + Size2 rscale = Control::get_minimum_size(); + + if (!expand) { + if (normal.is_null()) { + if (pressed.is_null()) { + if (hover.is_null()) + if (click_mask.is_null()) + rscale= Size2(); + else + rscale= click_mask->get_size(); else - rscale= click_mask->get_size(); - else - rscale= hover->get_size(); - } else - rscale=pressed->get_size(); + rscale= hover->get_size(); + } else + rscale=pressed->get_size(); - } else - rscale= normal->get_size(); + } else + rscale= normal->get_size(); + } - return rscale*scale.abs(); + return rscale.abs(); } - bool TextureButton::has_point(const Point2& p_point) const { - if (scale[0] == 0 || scale[1] == 0) { - return false; - } - - Point2 ppos = p_point/scale.abs(); - if (click_mask.is_valid()) { - Point2i p =ppos; + Point2i p =p_point; if (p.x<0 || p.x>=click_mask->get_size().width || p.y<0 || p.y>=click_mask->get_size().height) return false; @@ -119,17 +114,67 @@ void TextureButton::_notification(int p_what) { } if (texdraw.is_valid()) { - Rect2 drect(Point2(),texdraw->get_size()*scale); - draw_texture_rect(texdraw,drect,false); - + Point2 ofs; + Size2 size = texdraw->get_size(); + Rect2 tex_regin = Rect2(Point2(), texdraw->get_size()); + bool tile = false; + if (expand) { + switch (stretch_mode) { + case StretchMode::STRETCH_KEEP: + size = texdraw->get_size(); + break; + case StretchMode::STRETCH_SCALE_ON_EXPAND: + case StretchMode::STRETCH_SCALE: + size = get_size(); + break; + case StretchMode::STRETCH_TILE: + size = get_size(); + tile = true; + break; + case StretchMode::STRETCH_KEEP_CENTERED: + ofs = (get_size() - texdraw->get_size())/2; + size = texdraw->get_size(); + break; + case StretchMode::STRETCH_KEEP_ASPECT_CENTERED: + case StretchMode::STRETCH_KEEP_ASPECT: { + Size2 _size=get_size(); + float tex_width = texdraw->get_width() * _size.height / texdraw->get_height(); + float tex_height = _size.height; + + if (tex_width > _size.width) { + tex_width = _size.width; + tex_height = texdraw->get_height() * tex_width / texdraw->get_width(); + } + + if (stretch_mode==StretchMode::STRETCH_KEEP_ASPECT_CENTERED) { + ofs.x = (_size.width - tex_width)/2; + ofs.y = (_size.height - tex_height)/2; + } + size.width = tex_width; + size.height = tex_height; + } break; + case StretchMode::STRETCH_KEEP_ASPECT_COVERED:{ + size = get_size(); + Size2 tex_size = texdraw->get_size(); + Size2 scaleSize(size.width/tex_size.width, size.height/tex_size.height); + float scale = scaleSize.width > scaleSize.height? scaleSize.width : scaleSize.height; + Size2 scaledTexSize = tex_size * scale; + Point2 ofs = ((scaledTexSize - size) / scale).abs() / 2.0f; + tex_regin = Rect2(ofs, size/scale); + } break; + } + } + if (tile) + draw_texture_rect(texdraw,Rect2(ofs,size),tile); + else + draw_texture_rect_region(texdraw, Rect2(ofs, size), tex_regin); } if (has_focus() && focused.is_valid()) { - Rect2 drect(Point2(),focused->get_size()*scale); + Rect2 drect(Point2(), get_size()); draw_texture_rect(focused,drect,false); }; - } break; } } @@ -142,7 +187,8 @@ void TextureButton::_bind_methods() { ClassDB::bind_method(_MD("set_disabled_texture","texture:Texture"),&TextureButton::set_disabled_texture); ClassDB::bind_method(_MD("set_focused_texture","texture:Texture"),&TextureButton::set_focused_texture); ClassDB::bind_method(_MD("set_click_mask","mask:BitMap"),&TextureButton::set_click_mask); - ClassDB::bind_method(_MD("set_texture_scale","scale"),&TextureButton::set_texture_scale); + ClassDB::bind_method(_MD("set_expand","p_expand"),&TextureButton::set_expand); + ClassDB::bind_method(_MD("set_stretch_mode","p_mode"),&TextureButton::set_stretch_mode); ClassDB::bind_method(_MD("get_normal_texture:Texture"),&TextureButton::get_normal_texture); ClassDB::bind_method(_MD("get_pressed_texture:Texture"),&TextureButton::get_pressed_texture); @@ -150,7 +196,8 @@ void TextureButton::_bind_methods() { ClassDB::bind_method(_MD("get_disabled_texture:Texture"),&TextureButton::get_disabled_texture); ClassDB::bind_method(_MD("get_focused_texture:Texture"),&TextureButton::get_focused_texture); ClassDB::bind_method(_MD("get_click_mask:BitMap"),&TextureButton::get_click_mask); - ClassDB::bind_method(_MD("get_texture_scale"),&TextureButton::get_texture_scale); + ClassDB::bind_method(_MD("get_expand"),&TextureButton::get_expand); + ClassDB::bind_method(_MD("get_stretch_mode"),&TextureButton::get_stretch_mode); ADD_GROUP("Textures","texture_"); ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"texture_normal",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_normal_texture"), _SCS("get_normal_texture")); @@ -159,7 +206,25 @@ void TextureButton::_bind_methods() { ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"texture_disabled",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_disabled_texture"), _SCS("get_disabled_texture")); ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"texture_focused",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_focused_texture"), _SCS("get_focused_texture")); ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"texture_click_mask",PROPERTY_HINT_RESOURCE_TYPE,"BitMap"), _SCS("set_click_mask"), _SCS("get_click_mask")) ; - ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2,"texture_scale",PROPERTY_HINT_RANGE,"0.01,1024,0.01"), _SCS("set_texture_scale"), _SCS("get_texture_scale")); + ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL,"expand",PROPERTY_HINT_RESOURCE_TYPE,"bool"), _SCS("set_expand"), _SCS("get_expand")) ; + ADD_PROPERTYNO(PropertyInfo(Variant::INT,"stretch_mode",PROPERTY_HINT_ENUM,"Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), _SCS("set_stretch_mode"), _SCS("get_stretch_mode")); + + const int STRETCH_SCALE_ON_EXPAND = StretchMode::STRETCH_SCALE_ON_EXPAND; + const int STRETCH_SCALE = StretchMode::STRETCH_SCALE; + const int STRETCH_TILE = StretchMode::STRETCH_TILE; + const int STRETCH_KEEP = StretchMode::STRETCH_KEEP; + const int STRETCH_KEEP_CENTERED = StretchMode::STRETCH_KEEP_CENTERED; + const int STRETCH_KEEP_ASPECT = StretchMode::STRETCH_KEEP_ASPECT; + const int STRETCH_KEEP_ASPECT_CENTERED = StretchMode::STRETCH_KEEP_ASPECT_CENTERED; + const int STRETCH_KEEP_ASPECT_COVERED = StretchMode::STRETCH_KEEP_ASPECT_COVERED; + BIND_CONSTANT(STRETCH_SCALE_ON_EXPAND); + BIND_CONSTANT(STRETCH_SCALE); + BIND_CONSTANT(STRETCH_TILE); + BIND_CONSTANT(STRETCH_KEEP); + BIND_CONSTANT(STRETCH_KEEP_CENTERED); + BIND_CONSTANT(STRETCH_KEEP_ASPECT); + BIND_CONSTANT(STRETCH_KEEP_ASPECT_CENTERED); + BIND_CONSTANT(STRETCH_KEEP_ASPECT_COVERED); } @@ -227,19 +292,26 @@ void TextureButton::set_focused_texture(const Ref<Texture>& p_focused) { focused = p_focused; }; -void TextureButton::set_texture_scale(Size2 p_scale) { +bool TextureButton::get_expand() const { + return expand; +} - scale=p_scale; +void TextureButton::set_expand(bool p_expand) { + expand = p_expand; minimum_size_changed(); update(); } -Size2 TextureButton::get_texture_scale() const{ +void TextureButton::set_stretch_mode(TextureButton::StretchMode p_mode) { + stretch_mode = p_mode; + update(); +} - return scale; +TextureButton::StretchMode TextureButton::get_stretch_mode() const { + return stretch_mode; } TextureButton::TextureButton() { - scale=Size2(1.0, 1.0); - + expand = false; + stretch_mode = StretchMode::STRETCH_SCALE_ON_EXPAND; } diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h index ef4d4d5b5b..e1d1079ceb 100644 --- a/scene/gui/texture_button.h +++ b/scene/gui/texture_button.h @@ -31,22 +31,28 @@ #include "scene/gui/base_button.h" #include "scene/resources/bit_mask.h" +#include "scene/gui/texture_rect.h" class TextureButton : public BaseButton { GDCLASS( TextureButton, BaseButton ); +public: + typedef TextureRect::StretchMode StretchMode; + +private: Ref<Texture> normal; Ref<Texture> pressed; Ref<Texture> hover; Ref<Texture> disabled; Ref<Texture> focused; Ref<BitMap> click_mask; - Size2 scale; + bool expand; + StretchMode stretch_mode; protected: - virtual bool has_point(const Point2& p_point) const; virtual Size2 get_minimum_size() const; + virtual bool has_point(const Point2& p_point) const; void _notification(int p_what); static void _bind_methods(); @@ -66,8 +72,11 @@ public: Ref<Texture> get_focused_texture() const; Ref<BitMap> get_click_mask() const; - void set_texture_scale(Size2 p_scale); - Size2 get_texture_scale() const; + bool get_expand() const; + void set_expand(bool p_expand); + + void set_stretch_mode(StretchMode stretch_mode); + StretchMode get_stretch_mode() const; TextureButton(); }; diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index f6a33b5643..7d8373976b 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -46,7 +46,9 @@ void TextureProgress::set_over_texture(const Ref<Texture>& p_texture) { over=p_texture; update(); - minimum_size_changed(); + if (under.is_null()) { + minimum_size_changed(); + } } Ref<Texture> TextureProgress::get_over_texture() const{ @@ -302,4 +304,5 @@ TextureProgress::TextureProgress() rad_init_angle=0; rad_center_off=Point2(); rad_max_degrees=360; + set_mouse_filter(MOUSE_FILTER_PASS); } diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp index cbb077ef5d..74240fe98e 100644 --- a/scene/gui/texture_rect.cpp +++ b/scene/gui/texture_rect.cpp @@ -79,7 +79,15 @@ void TextureRect::_notification(int p_what) { draw_texture_rect(texture,Rect2(ofs_x,ofs_y,tex_width,tex_height)); } break; - + case STRETCH_KEEP_ASPECT_COVERED: { + Size2 size = get_size(); + Size2 tex_size = texture->get_size(); + Size2 scaleSize(size.width/tex_size.width, size.height/tex_size.height); + float scale = scaleSize.width > scaleSize.height? scaleSize.width : scaleSize.height; + Size2 scaledTexSize = tex_size * scale; + Point2 ofs = ((scaledTexSize - size) / scale).abs() / 2.0f; + draw_texture_rect_region(texture, Rect2(Point2(), size), Rect2(ofs, size/scale)); + } break; } } @@ -104,7 +112,7 @@ void TextureRect::_bind_methods() { ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"),_SCS("get_texture") ); ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "expand" ), _SCS("set_expand"),_SCS("has_expand") ); - ADD_PROPERTYNO( PropertyInfo( Variant::INT, "stretch_mode",PROPERTY_HINT_ENUM,"Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered"), _SCS("set_stretch_mode"),_SCS("get_stretch_mode") ); + ADD_PROPERTYNO( PropertyInfo( Variant::INT, "stretch_mode",PROPERTY_HINT_ENUM,"Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), _SCS("set_stretch_mode"),_SCS("get_stretch_mode") ); BIND_CONSTANT( STRETCH_SCALE_ON_EXPAND ); BIND_CONSTANT( STRETCH_SCALE ); @@ -113,7 +121,7 @@ void TextureRect::_bind_methods() { BIND_CONSTANT( STRETCH_KEEP_CENTERED ); BIND_CONSTANT( STRETCH_KEEP_ASPECT ); BIND_CONSTANT( STRETCH_KEEP_ASPECT_CENTERED ); - + BIND_CONSTANT( STRETCH_KEEP_ASPECT_COVERED ); } @@ -160,7 +168,7 @@ TextureRect::TextureRect() { expand=false; - set_mouse_filter(MOUSE_FILTER_IGNORE); + set_mouse_filter(MOUSE_FILTER_PASS); stretch_mode=STRETCH_SCALE_ON_EXPAND; } diff --git a/scene/gui/texture_rect.h b/scene/gui/texture_rect.h index e95d742759..0d72458909 100644 --- a/scene/gui/texture_rect.h +++ b/scene/gui/texture_rect.h @@ -45,7 +45,7 @@ public: STRETCH_KEEP_CENTERED, STRETCH_KEEP_ASPECT, STRETCH_KEEP_ASPECT_CENTERED, - + STRETCH_KEEP_ASPECT_COVERED, }; private: bool expand; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 58c829690f..1a7392f27e 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -611,7 +611,7 @@ void TreeItem::clear_custom_color(int p_column) { ERR_FAIL_INDEX( p_column, cells.size() ); cells[p_column].custom_color=false; - cells[p_column].color=Color();; + cells[p_column].color=Color(); _changed_notify(p_column); } @@ -642,7 +642,7 @@ void TreeItem::clear_custom_bg_color(int p_column) { ERR_FAIL_INDEX( p_column, cells.size() ); cells[p_column].custom_bg_color=false; - cells[p_column].bg_color=Color();; + cells[p_column].bg_color=Color(); _changed_notify(p_column); } @@ -943,7 +943,7 @@ void Tree::draw_item_rect(const TreeItem::Cell& p_cell,const Rect2i& p_rect,cons bmsize.width=p_cell.icon_max_w; } - p_cell.draw_icon(ci,rect.pos + Size2i(0,Math::floor((rect.size.y-bmsize.y)/2)),bmsize); + p_cell.draw_icon(ci,rect.pos + Size2i(0,Math::floor((real_t)(rect.size.y-bmsize.y)/2)),bmsize); rect.pos.x+=bmsize.x+cache.hseparation; rect.size.x-=bmsize.x+cache.hseparation; @@ -1008,7 +1008,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& /* Draw label, if height fits */ - bool skip=(p_item==root && hide_root); + bool skip=(p_item==root && hide_root); if (!skip && (p_pos.y+label_h-cache.offset.y)>0) { @@ -1173,7 +1173,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& Ref<Texture> checked = cache.checked; Ref<Texture> unchecked = cache.unchecked; Point2i check_ofs=item_rect.pos; - check_ofs.y+=Math::floor((item_rect.size.y-checked->get_height())/2); + check_ofs.y+=Math::floor((real_t)(item_rect.size.y-checked->get_height())/2); if (p_item->cells[i].checked) { @@ -1258,7 +1258,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2& icon_ofs+=item_rect.pos; - draw_texture_rect(p_item->cells[i].icon,Rect2(icon_ofs,icon_size));; + draw_texture_rect(p_item->cells[i].icon,Rect2(icon_ofs,icon_size)); //p_item->cells[i].icon->draw(ci, icon_ofs); } break; @@ -1711,8 +1711,15 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ case TreeItem::CELL_MODE_CHECK: { bring_up_editor=false; //checkboxes are not edited with editor - p_item->set_checked(col, !c.checked); - item_edited(col, p_item); + if (force_edit_checkbox_only_on_checkbox) { + if (x < cache.checked->get_width()) { + p_item->set_checked(col, !c.checked); + item_edited(col, p_item); + } + } else { + p_item->set_checked(col, !c.checked); + item_edited(col, p_item); + } click_handled = true; //p_item->edited_signal.call(col); @@ -2321,7 +2328,7 @@ void Tree::_gui_input(InputEvent p_event) { TreeItem::Cell &c=popup_edited_item->cells[popup_edited_item_col]; float diff_y = -b.relative_y; - diff_y=Math::pow(ABS(diff_y),1.8)*SGN(diff_y); + diff_y=Math::pow(ABS(diff_y),1.8f)*SGN(diff_y); diff_y*=0.1; range_drag_base=CLAMP(range_drag_base + c.step * diff_y, c.min, c.max); popup_edited_item->set_range(popup_edited_item_col,range_drag_base); @@ -2675,7 +2682,7 @@ void Tree::_notification(int p_what) { if (p_what==NOTIFICATION_ENTER_TREE) { - update_cache();; + update_cache(); } if (p_what==NOTIFICATION_DRAG_END) { @@ -3330,7 +3337,7 @@ TreeItem* Tree::_find_item_at_pos(TreeItem*p_item, const Point2& p_pos,int& r_co if (root!=p_item || ! hide_root) { - h = compute_item_height(p_item)+cache.vseparation;; + h = compute_item_height(p_item)+cache.vseparation; if (pos.y<h) { if (drop_mode_flags==DROP_MODE_ON_ITEM) { @@ -3555,6 +3562,16 @@ bool Tree::get_single_select_cell_editing_only_when_already_selected() const { return force_select_on_already_selected; } +void Tree::set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable) { + + force_edit_checkbox_only_on_checkbox=p_enable; +} + +bool Tree::get_edit_checkbox_cell_only_when_checkbox_is_pressed() const { + + return force_edit_checkbox_only_on_checkbox; +} + void Tree::set_allow_rmb_select(bool p_allow) { @@ -3733,6 +3750,7 @@ Tree::Tree() { force_select_on_already_selected=false; allow_rmb_select=false; + force_edit_checkbox_only_on_checkbox=false; set_clip_contents(true); } diff --git a/scene/gui/tree.h b/scene/gui/tree.h index d715ff4772..351cc4cb50 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -452,6 +452,7 @@ friend class TreeItem; bool scrolling; bool force_select_on_already_selected; + bool force_edit_checkbox_only_on_checkbox; bool hide_folding; @@ -531,6 +532,10 @@ public: void set_single_select_cell_editing_only_when_already_selected(bool p_enable); bool get_single_select_cell_editing_only_when_already_selected() const; + void set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable); + bool get_edit_checkbox_cell_only_when_checkbox_is_pressed() const; + + void set_allow_rmb_select(bool p_allow); bool get_allow_rmb_select() const; diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index 4c177ea53c..46c0eeca65 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -28,7 +28,8 @@ /*************************************************************************/ #include "video_player.h" #include "os/os.h" - +#include "servers/audio_server.h" +/* int VideoPlayer::InternalStream::get_channel_count() const { @@ -46,7 +47,7 @@ void VideoPlayer::InternalStream::update(){ player->sp_update(); } - +*/ int VideoPlayer::sp_get_channel_count() const { @@ -234,8 +235,8 @@ void VideoPlayer::play() { playback->stop(); playback->play(); set_process_internal(true); - AudioServer::get_singleton()->stream_set_active(stream_rid,true); - AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume); +// AudioServer::get_singleton()->stream_set_active(stream_rid,true); +// AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume); last_audio_time=0; }; @@ -247,7 +248,7 @@ void VideoPlayer::stop() { return; playback->stop(); - AudioServer::get_singleton()->stream_set_active(stream_rid,false); +// AudioServer::get_singleton()->stream_set_active(stream_rid,false); resampler.flush(); set_process_internal(false); last_audio_time=0; @@ -416,16 +417,16 @@ VideoPlayer::VideoPlayer() { buffering_ms=500; server_mix_rate=44100; - internal_stream.player=this; - stream_rid=AudioServer::get_singleton()->audio_stream_create(&internal_stream); +// internal_stream.player=this; +// stream_rid=AudioServer::get_singleton()->audio_stream_create(&internal_stream); last_audio_time=0; }; VideoPlayer::~VideoPlayer() { - if (stream_rid.is_valid()) - AudioServer::get_singleton()->free(stream_rid); +// if (stream_rid.is_valid()) +// AudioServer::get_singleton()->free(stream_rid); resampler.clear(); //Not necessary here, but make in consistent with other "stream_player" classes }; diff --git a/scene/gui/video_player.h b/scene/gui/video_player.h index 694cb253a4..168ea805b1 100644 --- a/scene/gui/video_player.h +++ b/scene/gui/video_player.h @@ -37,16 +37,16 @@ class VideoPlayer : public Control { GDCLASS(VideoPlayer,Control); - struct InternalStream : public AudioServer::AudioStream { +/* struct InternalStream : public AudioServer::AudioStream { VideoPlayer *player; virtual int get_channel_count() const; virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate virtual bool mix(int32_t *p_buffer,int p_frames); virtual void update(); }; +*/ - - InternalStream internal_stream; +// InternalStream internal_stream; Ref<VideoStreamPlayback> playback; Ref<VideoStream> stream; diff --git a/scene/io/resource_format_image.cpp b/scene/io/resource_format_image.cpp index 2d098d01f5..4d15ab86fd 100644 --- a/scene/io/resource_format_image.cpp +++ b/scene/io/resource_format_image.cpp @@ -27,6 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "resource_format_image.h" + +#if 0 #include "scene/resources/texture.h" #include "io/image_loader.h" #include "globals.h" @@ -260,3 +262,4 @@ ResourceFormatLoaderImage::ResourceFormatLoaderImage() { GLOBAL_DEF("rendering/image_loader/repeat",false); } +#endif diff --git a/scene/io/resource_format_image.h b/scene/io/resource_format_image.h index 6e4ead2a0b..0638e97787 100644 --- a/scene/io/resource_format_image.h +++ b/scene/io/resource_format_image.h @@ -29,6 +29,8 @@ #ifndef RESOURCE_FORMAT_IMAGE_H #define RESOURCE_FORMAT_IMAGE_H +#if 0 + #include "io/resource_loader.h" #include "io/resource_saver.h" /** @@ -49,3 +51,4 @@ public: }; #endif +#endif diff --git a/scene/io/resource_format_wav.cpp b/scene/io/resource_format_wav.cpp index 0a19e6f72b..1e14d01f4e 100644 --- a/scene/io/resource_format_wav.cpp +++ b/scene/io/resource_format_wav.cpp @@ -26,6 +26,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#if 0 #include "resource_format_wav.h" #include "os/file_access.h" #include "scene/resources/sample.h" @@ -272,3 +273,4 @@ String ResourceFormatLoaderWAV::get_resource_type(const String &p_path) const { return ""; } +#endif diff --git a/scene/io/resource_format_wav.h b/scene/io/resource_format_wav.h index 3a278b455b..fd274625f9 100644 --- a/scene/io/resource_format_wav.h +++ b/scene/io/resource_format_wav.h @@ -29,6 +29,7 @@ #ifndef RESOURCE_FORMAT_WAV_H #define RESOURCE_FORMAT_WAV_H +#if 0 #include "io/resource_loader.h" class ResourceFormatLoaderWAV : public ResourceFormatLoader { @@ -40,4 +41,5 @@ public: }; +#endif #endif // RESOURCE_FORMAT_WAV_H diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 86b78f60f6..039dce37de 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1385,7 +1385,7 @@ String Node::_generate_serial_child_name(Node *p_child) { name = p_child->get_class(); // Adjust casing according to project setting. The current type name is expected to be in PascalCase. - switch (GlobalConfig::get_singleton()->get("editor/node_name_casing").operator int()) { + switch (GlobalConfig::get_singleton()->get("node/name_casing").operator int()) { case NAME_CASING_PASCAL_CASE: break; case NAME_CASING_CAMEL_CASE: @@ -1631,7 +1631,7 @@ Node *Node::_get_node(const NodePath& p_path) const { current=const_cast<Node*>(this); //start from this } else { - root=const_cast<Node*>(this);; + root=const_cast<Node*>(this); while (root->data.parent) root=root->data.parent; //start from root } @@ -2899,10 +2899,10 @@ void Node::request_ready() { void Node::_bind_methods() { - GLOBAL_DEF("editor/node_name_num_separator",0); - GlobalConfig::get_singleton()->set_custom_property_info("editor/node_name_num_separator",PropertyInfo(Variant::INT,"editor/node_name_num_separator",PROPERTY_HINT_ENUM, "None,Space,Underscore,Dash")); - GLOBAL_DEF("editor/node_name_casing",NAME_CASING_PASCAL_CASE); - GlobalConfig::get_singleton()->set_custom_property_info("editor/node_name_casing",PropertyInfo(Variant::INT,"editor/node_name_casing",PROPERTY_HINT_ENUM,"PascalCase,camelCase,snake_case")); + GLOBAL_DEF("node/name_num_separator",0); + GlobalConfig::get_singleton()->set_custom_property_info("node/name_num_separator",PropertyInfo(Variant::INT,"node/name_num_separator",PROPERTY_HINT_ENUM, "None,Space,Underscore,Dash")); + GLOBAL_DEF("node/name_casing",NAME_CASING_PASCAL_CASE); + GlobalConfig::get_singleton()->set_custom_property_info("node/name_casing",PropertyInfo(Variant::INT,"node/name_casing",PROPERTY_HINT_ENUM,"PascalCase,camelCase,snake_case")); ClassDB::bind_method(_MD("_add_child_below_node","node:Node","child_node:Node","legible_unique_name"),&Node::add_child_below_node,DEFVAL(false)); diff --git a/scene/main/node.h b/scene/main/node.h index 14fd19a76f..d88db8ecb0 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -33,7 +33,7 @@ #include "object.h" #include "path_db.h" #include "map.h" -#include "object_type_db.h" +#include "class_db.h" #include "script_language.h" #include "scene/main/scene_main_loop.h" diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 147409a862..9db1d3fd77 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -35,7 +35,7 @@ #include "globals.h" #include <stdio.h> #include "os/keyboard.h" -#include "servers/spatial_sound_2d_server.h" +//#include "servers/spatial_sound_2d_server.h" #include "servers/physics_2d_server.h" #include "servers/physics_server.h" #include "scene/scene_string_names.h" diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index c3ece76b05..989c048682 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -33,8 +33,7 @@ #include "servers/physics_2d_server.h" //#include "scene/3d/camera.h" -#include "servers/spatial_sound_server.h" -#include "servers/spatial_sound_2d_server.h" + #include "scene/gui/control.h" #include "scene/3d/camera.h" #include "scene/3d/listener.h" @@ -468,7 +467,7 @@ void Viewport::_notification(int p_what) { */ VisualServer::get_singleton()->viewport_set_scenario(viewport,RID()); - SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); +// SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas); if (contact_2d_debug.is_valid()) { VisualServer::get_singleton()->free(contact_2d_debug); @@ -783,23 +782,24 @@ Size2 Viewport::get_size() const { void Viewport::_update_listener() { - +/* if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible_in_tree()))) { SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, find_world()->get_sound_space()); } else { SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); } - +*/ } void Viewport::_update_listener_2d() { + /* if (is_inside_tree() && audio_listener && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible_in_tree()))) SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, find_world_2d()->get_sound_space()); else SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, RID()); - +*/ } @@ -842,12 +842,12 @@ void Viewport::set_canvas_transform(const Transform2D& p_transform) { Transform2D xform = (global_canvas_transform * canvas_transform).affine_inverse(); Size2 ss = get_visible_rect().size; - SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Transform2D(0, xform.xform(ss*0.5))); + /*SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Transform2D(0, xform.xform(ss*0.5))); Vector2 ss2 = ss*xform.get_scale(); float panrange = MAX(ss2.x,ss2.y); SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange); - +*/ } @@ -867,12 +867,12 @@ void Viewport::_update_global_transform() { Transform2D xform = (sxform * canvas_transform).affine_inverse(); Size2 ss = get_visible_rect().size; - SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Transform2D(0, xform.xform(ss*0.5))); + /*SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Transform2D(0, xform.xform(ss*0.5))); Vector2 ss2 = ss*xform.get_scale(); float panrange = MAX(ss2.x,ss2.y); SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange); - +*/ } @@ -893,8 +893,8 @@ Transform2D Viewport::get_global_canvas_transform() const{ void Viewport::_listener_transform_changed_notify() { #ifndef _3D_DISABLED - if (listener) - SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, listener->get_listener_transform()); + //if (listener) +// SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, listener->get_listener_transform()); #endif } @@ -957,8 +957,8 @@ void Viewport::_camera_transform_changed_notify() { #ifndef _3D_DISABLED // If there is an active listener in the scene, it takes priority over the camera - if (camera && !listener) - SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, camera->get_camera_transform()); +// if (camera && !listener) +// SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, camera->get_camera_transform()); #endif } @@ -1777,7 +1777,7 @@ Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_g if (!ci || ci->is_set_as_toplevel()) continue; - Control *ret=_gui_find_control_at_pos(ci,p_global,matrix,r_inv_xform);; + Control *ret=_gui_find_control_at_pos(ci,p_global,matrix,r_inv_xform); if (ret) return ret; } @@ -1796,6 +1796,42 @@ Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_g return NULL; } +bool Viewport::_gui_drop(Control *p_at_control,Point2 p_at_pos,bool p_just_check) { + + + { //attempt grab, try parent controls too + CanvasItem *ci=p_at_control; + while(ci) { + + Control *control = ci->cast_to<Control>(); + if (control) { + + + if (control->can_drop_data(p_at_pos,gui.drag_data)) { + if (!p_just_check) { + control->drop_data(p_at_pos,gui.drag_data); + } + + return true; + } + + if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP) + break; + } + + p_at_pos = ci->get_transform().xform(p_at_pos); + + if (ci->is_set_as_toplevel()) + break; + + ci=ci->get_parent_item(); + } + } + + return false; +} + + void Viewport::_gui_input_event(InputEvent p_event) { @@ -1901,9 +1937,28 @@ void Viewport::_gui_input_event(InputEvent p_event) { }*/ #endif - if (gui.mouse_focus->get_focus_mode()!=Control::FOCUS_NONE && gui.mouse_focus!=gui.key_focus && p_event.mouse_button.button_index==BUTTON_LEFT) { - // also get keyboard focus - gui.mouse_focus->grab_focus(); + if (p_event.mouse_button.button_index==BUTTON_LEFT) { //assign focus + CanvasItem *ci=gui.mouse_focus; + while(ci) { + + Control *control = ci->cast_to<Control>(); + if (control) { + if (control->get_focus_mode()!=Control::FOCUS_NONE) { + if (control!=gui.key_focus) { + control->grab_focus(); + } + break; + } + + if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP) + break; + } + + if (ci->is_set_as_toplevel()) + break; + + ci=ci->get_parent_item(); + } } @@ -1918,8 +1973,8 @@ void Viewport::_gui_input_event(InputEvent p_event) { if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { //alternate drop use (when using force_drag(), as proposed by #5342 - if (gui.mouse_focus && gui.mouse_focus->can_drop_data(pos,gui.drag_data)) { - gui.mouse_focus->drop_data(pos,gui.drag_data); + if (gui.mouse_focus) { + _gui_drop(gui.mouse_focus,pos,false); } gui.drag_data=Variant(); @@ -1946,9 +2001,9 @@ void Viewport::_gui_input_event(InputEvent p_event) { if (gui.mouse_over) { Size2 pos = mpos; pos = gui.focus_inv_xform.xform(pos); - if (gui.mouse_over->can_drop_data(pos,gui.drag_data)) { - gui.mouse_over->drop_data(pos,gui.drag_data); - } + + _gui_drop(gui.mouse_over,pos,false); + } if (gui.drag_preview && p_event.mouse_button.button_index==BUTTON_LEFT) { @@ -2006,14 +2061,36 @@ void Viewport::_gui_input_event(InputEvent p_event) { // D&D if (!gui.drag_attempted && gui.mouse_focus && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { - gui.drag_accum+=Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y);; + gui.drag_accum+=Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y); float len = gui.drag_accum.length(); if (len>10) { - gui.drag_data=gui.mouse_focus->get_drag_data(gui.focus_inv_xform.xform(mpos)-gui.drag_accum); - if (gui.drag_data.get_type()!=Variant::NIL) { - gui.mouse_focus=NULL; + { //attempt grab, try parent controls too + CanvasItem *ci=gui.mouse_focus; + while(ci) { + + Control *control = ci->cast_to<Control>(); + if (control) { + + gui.drag_data=control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos)-gui.drag_accum); + if (gui.drag_data.get_type()!=Variant::NIL) { + + gui.mouse_focus=NULL; + } + + if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP) + break; + } + + if (ci->is_set_as_toplevel()) + break; + + ci=ci->get_parent_item(); + } } + + + gui.drag_attempted=true; if (gui.drag_data.get_type()!=Variant::NIL) { @@ -2140,7 +2217,7 @@ void Viewport::_gui_input_event(InputEvent p_event) { if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { - bool can_drop = over->can_drop_data(pos,gui.drag_data); + bool can_drop = _gui_drop(over,pos,true); if (!can_drop) { OS::get_singleton()->set_cursor_shape( OS::CURSOR_FORBIDDEN ); @@ -2861,9 +2938,9 @@ Viewport::Viewport() { default_texture->vp=const_cast<Viewport*>(this); viewport_textures.insert(default_texture.ptr()); - internal_listener = SpatialSoundServer::get_singleton()->listener_create(); + //internal_listener = SpatialSoundServer::get_singleton()->listener_create(); audio_listener=false; - internal_listener_2d = SpatialSound2DServer::get_singleton()->listener_create(); + //internal_listener_2d = SpatialSound2DServer::get_singleton()->listener_create(); audio_listener_2d=false; transparent_bg=false; parent=NULL; @@ -2930,8 +3007,8 @@ Viewport::~Viewport() { E->get()->vp=NULL; } VisualServer::get_singleton()->free( viewport ); - SpatialSoundServer::get_singleton()->free(internal_listener); - SpatialSound2DServer::get_singleton()->free(internal_listener_2d); + //SpatialSoundServer::get_singleton()->free(internal_listener); + //SpatialSound2DServer::get_singleton()->free(internal_listener_2d); } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 2831d177c9..59e34d5c62 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -306,6 +306,8 @@ friend class Control; Vector2 _get_window_offset() const; + bool _gui_drop(Control *p_at_control,Point2 p_at_pos,bool p_just_check); + friend class Listener; void _listener_transform_changed_notify(); void _listener_set(Listener* p_listener); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index d93fecffe1..c0bd86382b 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -34,7 +34,7 @@ //#include "scene/io/scene_format_script.h" #include "resources/default_theme/default_theme.h" -#include "object_type_db.h" +#include "class_db.h" #include "scene/main/canvas_layer.h" #include "scene/main/instance_placeholder.h" #include "scene/main/viewport.h" @@ -85,6 +85,7 @@ #include "scene/gui/graph_node.h" #include "scene/gui/graph_edit.h" #include "scene/gui/tool_button.h" +#include "scene/resources/audio_stream_sample.h" #include "scene/resources/video_stream.h" #include "scene/2d/particles_2d.h" #include "scene/2d/path_2d.h" @@ -109,8 +110,8 @@ #include "scene/2d/collision_polygon_2d.h" #include "scene/2d/parallax_background.h" #include "scene/2d/parallax_layer.h" -#include "scene/2d/sound_player_2d.h" -#include "scene/2d/sample_player_2d.h" +//#include "scene/2d/sound_player_2d.h" +//#include "scene/2d/sample_player_2d.h" #include "scene/2d/screen_button.h" #include "scene/2d/remote_transform_2d.h" #include "scene/2d/y_sort.h" @@ -141,9 +142,9 @@ #include "scene/main/timer.h" -#include "scene/audio/stream_player.h" -#include "scene/audio/event_player.h" -#include "scene/audio/sound_room_params.h" +#include "scene/audio/audio_player.h" +//#include "scene/audio/event_player.h" +//#include "scene/audio/sound_room_params.h" #include "scene/resources/sphere_shape.h" #include "scene/resources/ray_shape.h" #include "scene/resources/box_shape.h" @@ -165,8 +166,8 @@ #include "scene/resources/polygon_path_finder.h" -#include "scene/resources/sample.h" -#include "scene/audio/sample_player.h" +//#include "scene/resources/sample.h" +//#include "scene/audio/sample_player.h" #include "scene/resources/texture.h" #include "scene/resources/sky_box.h" #include "scene/resources/material.h" @@ -178,8 +179,8 @@ #include "scene/resources/world.h" #include "scene/resources/world_2d.h" -#include "scene/resources/sample_library.h" -#include "scene/resources/audio_stream.h" +//#include "scene/resources/sample_library.h" +//#include "scene/resources/audio_stream.h" #include "scene/resources/gibberish_stream.h" #include "scene/resources/bit_mask.h" #include "scene/resources/color_ramp.h" @@ -222,8 +223,8 @@ #include "scene/3d/ray_cast.h" #include "scene/3d/immediate_geometry.h" #include "scene/3d/sprite_3d.h" -#include "scene/3d/spatial_sample_player.h" -#include "scene/3d/spatial_stream_player.h" +//#include "scene/3d/spatial_sample_player.h" +//#include "scene/3d/spatial_stream_player.h" #include "scene/3d/proximity_group.h" #include "scene/3d/navigation_mesh.h" #include "scene/3d/navigation.h" @@ -232,8 +233,7 @@ #include "scene/resources/scene_format_text.h" -static ResourceFormatLoaderImage *resource_loader_image=NULL; -static ResourceFormatLoaderWAV *resource_loader_wav=NULL; +//static ResourceFormatLoaderWAV *resource_loader_wav=NULL; #ifdef TOOLS_ENABLED @@ -247,6 +247,8 @@ static ResourceFormatLoaderText *resource_loader_text=NULL; static ResourceFormatLoaderDynamicFont *resource_loader_dynamic_font=NULL; +static ResourceFormatLoaderStreamTexture *resource_loader_stream_texture=NULL; + //static SceneStringNames *string_names; void register_scene_types() { @@ -257,14 +259,14 @@ void register_scene_types() { Node::init_node_hrcr(); - resource_loader_image = memnew( ResourceFormatLoaderImage ); - ResourceLoader::add_resource_format_loader( resource_loader_image ); - - resource_loader_wav = memnew( ResourceFormatLoaderWAV ); - ResourceLoader::add_resource_format_loader( resource_loader_wav ); + //resource_loader_wav = memnew( ResourceFormatLoaderWAV ); + //ResourceLoader::add_resource_format_loader( resource_loader_wav ); resource_loader_dynamic_font = memnew( ResourceFormatLoaderDynamicFont ); ResourceLoader::add_resource_format_loader( resource_loader_dynamic_font ); + resource_loader_stream_texture = memnew( ResourceFormatLoaderStreamTexture); + ResourceLoader::add_resource_format_loader( resource_loader_stream_texture ); + #ifdef TOOLS_ENABLED //scene first! @@ -476,18 +478,12 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init - ClassDB::register_class<SpatialSamplePlayer>(); - ClassDB::register_class<SpatialStreamPlayer>(); - ClassDB::register_class<SoundRoomParams>(); #endif ClassDB::register_class<MeshLibrary>(); AcceptDialog::set_swap_ok_cancel( GLOBAL_DEF("gui/common/swap_ok_cancel",bool(OS::get_singleton()->get_swap_ok_cancel())) ); - ClassDB::register_class<SamplePlayer>(); - ClassDB::register_class<StreamPlayer>(); - ClassDB::register_class<EventPlayer>(); ClassDB::register_class<CanvasItemMaterial>(); @@ -530,8 +526,6 @@ void register_scene_types() { ClassDB::register_class<TileMap>(); ClassDB::register_class<ParallaxBackground>(); ClassDB::register_class<ParallaxLayer>(); - ClassDB::register_virtual_class<SoundPlayer2D>(); - ClassDB::register_class<SamplePlayer2D>(); ClassDB::register_class<TouchScreenButton>(); ClassDB::register_class<RemoteTransform2D>(); @@ -581,6 +575,7 @@ void register_scene_types() { ClassDB::register_virtual_class<Texture>(); ClassDB::register_virtual_class<SkyBox>(); ClassDB::register_class<ImageSkyBox>(); + ClassDB::register_class<StreamTexture>(); ClassDB::register_class<ImageTexture>(); ClassDB::register_class<AtlasTexture>(); ClassDB::register_class<LargeTexture>(); @@ -603,13 +598,9 @@ void register_scene_types() { OS::get_singleton()->yield(); //may take time to init - ClassDB::register_class<Sample>(); - ClassDB::register_class<SampleLibrary>(); - ClassDB::register_virtual_class<AudioStream>(); - ClassDB::register_virtual_class<AudioStreamPlayback>(); -//TODO: Adapt to the new AudioStream API or drop (GH-3307) - //ClassDB::register_type<AudioStreamGibberish>(); + ClassDB::register_class<AudioPlayer>(); ClassDB::register_virtual_class<VideoStream>(); + ClassDB::register_class<AudioStreamSample>(); OS::get_singleton()->yield(); //may take time to init @@ -659,9 +650,9 @@ void unregister_scene_types() { clear_default_theme(); - memdelete( resource_loader_image ); - memdelete( resource_loader_wav ); +// memdelete( resource_loader_wav ); memdelete( resource_loader_dynamic_font ); + memdelete( resource_loader_stream_texture ); #ifdef TOOLS_ENABLED diff --git a/scene/resources/audio_stream_resampled.h b/scene/resources/audio_stream_resampled.h index 761643b027..7ceb6cef84 100644 --- a/scene/resources/audio_stream_resampled.h +++ b/scene/resources/audio_stream_resampled.h @@ -29,7 +29,7 @@ #ifndef AUDIO_STREAM_RESAMPLED_H #define AUDIO_STREAM_RESAMPLED_H -#include "scene/resources/audio_stream.h" +//#include "scene/resources/audio_stream.h" #if 0 diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp new file mode 100644 index 0000000000..21339cb90b --- /dev/null +++ b/scene/resources/audio_stream_sample.cpp @@ -0,0 +1,557 @@ +#include "audio_stream_sample.h" + +void AudioStreamPlaybackSample::start(float p_from_pos) { + + for(int i=0;i<2;i++) { + ima_adpcm[i].step_index=0; + ima_adpcm[i].predictor=0; + ima_adpcm[i].loop_step_index=0; + ima_adpcm[i].loop_predictor=0; + ima_adpcm[i].last_nibble=-1; + ima_adpcm[i].loop_pos=0x7FFFFFFF; + ima_adpcm[i].window_ofs=0; + ima_adpcm[i].ptr=(const uint8_t*)base->data; + ima_adpcm[i].ptr+=AudioStreamSample::DATA_PAD; + } + + seek_pos(p_from_pos); + sign=1; + active=true; +} + +void AudioStreamPlaybackSample::stop() { + + active=false; +} + +bool AudioStreamPlaybackSample::is_playing() const { + + return active; +} + +int AudioStreamPlaybackSample::get_loop_count() const { + + return 0; +} + +float AudioStreamPlaybackSample::get_pos() const { + + return float(offset>>MIX_FRAC_BITS)/base->mix_rate; +} +void AudioStreamPlaybackSample::seek_pos(float p_time) { + + if (base->format==AudioStreamSample::FORMAT_IMA_ADPCM) + return; //no seeking in ima-adpcm + + float max=get_length(); + if (p_time<0) { + p_time=0; + } else if (p_time>=max) { + p_time=max-0.001; + } + + offset = uint64_t(p_time * base->mix_rate)<<MIX_FRAC_BITS; +} + + +template<class Depth,bool is_stereo,bool is_ima_adpcm> +void AudioStreamPlaybackSample::do_resample(const Depth* p_src, AudioFrame *p_dst,int64_t &offset,int32_t &increment,uint32_t amount,IMA_ADPCM_State *ima_adpcm) { + + // this function will be compiled branchless by any decent compiler + + int32_t final,final_r,next,next_r; + while (amount--) { + + int64_t pos=offset >> MIX_FRAC_BITS; + if (is_stereo && !is_ima_adpcm) + pos<<=1; + + if (is_ima_adpcm) { + + int64_t sample_pos = pos + ima_adpcm[0].window_ofs; + + while(sample_pos>ima_adpcm[0].last_nibble) { + + + static const int16_t _ima_adpcm_step_table[89] = { + 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, + 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, + 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, + 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, + 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, + 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, + 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, + 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, + 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 + }; + + static const int8_t _ima_adpcm_index_table[16] = { + -1, -1, -1, -1, 2, 4, 6, 8, + -1, -1, -1, -1, 2, 4, 6, 8 + }; + + for(int i=0;i<(is_stereo?2:1);i++) { + + + int16_t nibble,diff,step; + + ima_adpcm[i].last_nibble++; + const uint8_t *src_ptr=ima_adpcm[i].ptr; + + + uint8_t nbb = src_ptr[ (ima_adpcm[i].last_nibble>>1) * (is_stereo?2:1) + i ]; + nibble = (ima_adpcm[i].last_nibble&1)?(nbb>>4):(nbb&0xF); + step=_ima_adpcm_step_table[ima_adpcm[i].step_index]; + + + ima_adpcm[i].step_index += _ima_adpcm_index_table[nibble]; + if (ima_adpcm[i].step_index<0) + ima_adpcm[i].step_index=0; + if (ima_adpcm[i].step_index>88) + ima_adpcm[i].step_index=88; + + diff = step >> 3 ; + if (nibble & 1) + diff += step >> 2 ; + if (nibble & 2) + diff += step >> 1 ; + if (nibble & 4) + diff += step ; + if (nibble & 8) + diff = -diff ; + + ima_adpcm[i].predictor+=diff; + if (ima_adpcm[i].predictor<-0x8000) + ima_adpcm[i].predictor=-0x8000; + else if (ima_adpcm[i].predictor>0x7FFF) + ima_adpcm[i].predictor=0x7FFF; + + + /* store loop if there */ + if (ima_adpcm[i].last_nibble==ima_adpcm[i].loop_pos) { + + ima_adpcm[i].loop_step_index = ima_adpcm[i].step_index; + ima_adpcm[i].loop_predictor = ima_adpcm[i].predictor; + } + + //printf("%i - %i - pred %i\n",int(ima_adpcm[i].last_nibble),int(nibble),int(ima_adpcm[i].predictor)); + + } + + } + + final=ima_adpcm[0].predictor; + if (is_stereo) { + final_r=ima_adpcm[1].predictor; + } + + } else { + final=p_src[pos]; + if (is_stereo) + final_r=p_src[pos+1]; + + if (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 (sizeof(Depth)==1) { + next<<=8; + if (is_stereo) + next_r<<=8; + } + + int32_t frac=int64_t(offset&MIX_FRAC_MASK); + + final=final+((next-final)*frac >> MIX_FRAC_BITS); + if (is_stereo) + final_r=final_r+((next_r-final_r)*frac >> MIX_FRAC_BITS); + + } + + + if (!is_stereo) { + final_r=final; //copy to right channel if stereo + } + + p_dst->l=final/32767.0; + p_dst->r=final_r/32767.0; + p_dst++; + + offset+=increment; + } +} + +void AudioStreamPlaybackSample::mix(AudioFrame* p_buffer,float p_rate_scale,int p_frames) { + + if (!base->data || !active) { + for(int i=0;i<p_frames;i++) { + p_buffer[i]=AudioFrame(0,0); + } + return; + } + + int len = base->data_bytes; + switch(base->format) { + case AudioStreamSample::FORMAT_8_BITS: len/=1; break; + case AudioStreamSample::FORMAT_16_BITS: len/=2; break; + case AudioStreamSample::FORMAT_IMA_ADPCM: len*=2; break; + } + + if (base->stereo) { + len/=2; + } + + /* some 64-bit fixed point precaches */ + + int64_t loop_begin_fp=((int64_t)len<< 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!=AudioStreamSample::LOOP_DISABLED)?loop_begin_fp:0; + int64_t end_limit=(base->loop_mode!=AudioStreamSample::LOOP_DISABLED)?loop_end_fp:length_fp; + bool is_stereo=base->stereo; + + int32_t todo=p_frames; + + float base_rate = AudioServer::get_singleton()->get_mix_rate(); + float srate = base->mix_rate; + srate*=p_rate_scale; + float fincrement = srate / base_rate; + int32_t increment = int32_t(fincrement * MIX_FRAC_LEN); + increment*=sign; + + + //looping + + AudioStreamSample::LoopMode loop_format=base->loop_mode; + AudioStreamSample::Format format = base->format; + + + /* audio data */ + + uint8_t *dataptr=(uint8_t*)base->data; + const void *data=dataptr+AudioStreamSample::DATA_PAD; + AudioFrame *dst_buff=p_buffer; + + + if (format==AudioStreamSample::FORMAT_IMA_ADPCM) { + + if (loop_format!=AudioStreamSample::LOOP_DISABLED) { + ima_adpcm[0].loop_pos=loop_begin_fp>>MIX_FRAC_BITS; + ima_adpcm[1].loop_pos=loop_begin_fp>>MIX_FRAC_BITS; + loop_format=AudioStreamSample::LOOP_FORWARD; + } + } + + while (todo>0) { + + int64_t limit=0; + int32_t target=0,aux=0; + + /** LOOP CHECKING **/ + + if ( increment < 0 ) { + /* going backwards */ + + if ( loop_format!=AudioStreamSample::LOOP_DISABLED && offset < loop_begin_fp ) { + /* loopstart reached */ + if ( loop_format==AudioStreamSample::LOOP_PING_PONG ) { + /* bounce ping pong */ + offset= loop_begin_fp + ( loop_begin_fp-offset ); + increment=-increment; + sign*=-1; + } else { + /* go to loop-end */ + offset=loop_end_fp-(loop_begin_fp-offset); + } + } else { + /* check for sample not reaching begining */ + if(offset < 0) { + + active=false; + break; + } + } + } else { + /* going forward */ + if( loop_format!=AudioStreamSample::LOOP_DISABLED && offset >= loop_end_fp ) { + /* loopend reached */ + + if ( loop_format==AudioStreamSample::LOOP_PING_PONG ) { + /* bounce ping pong */ + offset=loop_end_fp-(offset-loop_end_fp); + increment=-increment; + sign*=-1; + } else { + /* go to loop-begin */ + + if (format==AudioStreamSample::FORMAT_IMA_ADPCM) { + 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; + } + offset=loop_begin_fp; + } else { + offset=loop_begin_fp+(offset-loop_end_fp); + } + + } + } else { + /* no loop, check for end of sample */ + if(offset >= length_fp) { + + active=false; + break; + } + } + } + + /** MIXCOUNT COMPUTING **/ + + /* next possible limit (looppoints or sample begin/end */ + limit=(increment < 0) ?begin_limit:end_limit; + + /* compute what is shorter, the todo or the limit? */ + aux=(limit-offset)/increment+1; + target=(aux<todo)?aux:todo; /* mix target is the shorter buffer */ + + /* check just in case */ + if ( target<=0 ) { + active=false; + break; + } + + todo-=target; + + switch(base->format) { + case AudioStreamSample::FORMAT_8_BITS: { + + if (is_stereo) + do_resample<int8_t,true,false>((int8_t*)data,dst_buff,offset,increment,target,ima_adpcm); + else + do_resample<int8_t,false,false>((int8_t*)data,dst_buff,offset,increment,target,ima_adpcm); + } break; + case AudioStreamSample::FORMAT_16_BITS: { + if (is_stereo) + do_resample<int16_t,true,false>((int16_t*)data,dst_buff,offset,increment,target,ima_adpcm); + else + do_resample<int16_t,false,false>((int16_t*)data,dst_buff,offset,increment,target,ima_adpcm); + + } break; + case AudioStreamSample::FORMAT_IMA_ADPCM: { + if (is_stereo) + do_resample<int8_t,true,true>((int8_t*)data,dst_buff,offset,increment,target,ima_adpcm); + else + do_resample<int8_t,false,true>((int8_t*)data,dst_buff,offset,increment,target,ima_adpcm); + + } break; + } + + dst_buff+=target; + + } + + +} + +float AudioStreamPlaybackSample::get_length() const { + + int len = base->data_bytes; + switch(base->format) { + case AudioStreamSample::FORMAT_8_BITS: len/=1; break; + case AudioStreamSample::FORMAT_16_BITS: len/=2; break; + case AudioStreamSample::FORMAT_IMA_ADPCM: len*=2; break; + } + + if (base->stereo) { + len/=2; + } + + + return float(len)/base->mix_rate; +} + + +AudioStreamPlaybackSample::AudioStreamPlaybackSample() { + + active=false; + offset=0; + sign=1; +} + + +///////////////////// + + +void AudioStreamSample::set_format(Format p_format) { + + format=p_format; +} + +AudioStreamSample::Format AudioStreamSample::get_format() const{ + + return format; +} + +void AudioStreamSample::set_loop_mode(LoopMode p_loop_mode){ + + loop_mode=p_loop_mode; +} +AudioStreamSample::LoopMode AudioStreamSample::get_loop_mode() const{ + + return loop_mode; +} + +void AudioStreamSample::set_loop_begin(int p_frame){ + + loop_begin=p_frame; +} +int AudioStreamSample::get_loop_begin() const{ + + return loop_begin; +} + +void AudioStreamSample::set_loop_end(int p_frame){ + + loop_end=p_frame; +} +int AudioStreamSample::get_loop_end() const{ + + return loop_end; +} + + +void AudioStreamSample::set_mix_rate(int p_hz){ + + mix_rate=p_hz; +} +int AudioStreamSample::get_mix_rate() const{ + + return mix_rate; +} +void AudioStreamSample::set_stereo(bool p_enable){ + + stereo=p_enable; +} +bool AudioStreamSample::is_stereo() const{ + + return stereo; +} + +void AudioStreamSample::set_data(const PoolVector<uint8_t>& p_data) { + + AudioServer::get_singleton()->lock(); + if (data) { + AudioServer::get_singleton()->audio_data_free(data); + data=NULL; + data_bytes=0; + } + + int datalen = p_data.size(); + if (datalen) { + + PoolVector<uint8_t>::Read r = p_data.read(); + int alloc_len = datalen+DATA_PAD*2; + data = AudioServer::get_singleton()->audio_data_alloc(alloc_len); //alloc with some padding for interpolation + zeromem(data,alloc_len); + uint8_t *dataptr=(uint8_t*)data; + copymem(dataptr+DATA_PAD,r.ptr(),datalen); + data_bytes=datalen; + } + + AudioServer::get_singleton()->unlock(); + +} +PoolVector<uint8_t> AudioStreamSample::get_data() const{ + + PoolVector<uint8_t> pv; + + if (data) { + pv.resize(data_bytes); + { + + PoolVector<uint8_t>::Write w =pv.write(); + copymem(w.ptr(),data,data_bytes); + } + } + + return pv; +} + + +Ref<AudioStreamPlayback> AudioStreamSample::instance_playback() { + + Ref<AudioStreamPlaybackSample> sample; + sample.instance(); + sample->base=Ref<AudioStreamSample>(this); + return sample; +} + +String AudioStreamSample::get_stream_name() const { + + return ""; +} + +void AudioStreamSample::_bind_methods() { + + ClassDB::bind_method(_MD("set_format","format"),&AudioStreamSample::set_format); + ClassDB::bind_method(_MD("get_format"),&AudioStreamSample::get_format); + + ClassDB::bind_method(_MD("set_loop_mode","loop_mode"),&AudioStreamSample::set_loop_mode); + ClassDB::bind_method(_MD("get_loop_mode"),&AudioStreamSample::get_loop_mode); + + ClassDB::bind_method(_MD("set_loop_begin","loop_begin"),&AudioStreamSample::set_loop_begin); + ClassDB::bind_method(_MD("get_loop_begin"),&AudioStreamSample::get_loop_begin); + + ClassDB::bind_method(_MD("set_loop_end","loop_end"),&AudioStreamSample::set_loop_end); + ClassDB::bind_method(_MD("get_loop_end"),&AudioStreamSample::get_loop_end); + + ClassDB::bind_method(_MD("set_mix_rate","mix_rate"),&AudioStreamSample::set_mix_rate); + ClassDB::bind_method(_MD("get_mix_rate"),&AudioStreamSample::get_mix_rate); + + ClassDB::bind_method(_MD("set_stereo","stereo"),&AudioStreamSample::set_stereo); + ClassDB::bind_method(_MD("is_stereo"),&AudioStreamSample::is_stereo); + + ClassDB::bind_method(_MD("set_data","data"),&AudioStreamSample::set_data); + ClassDB::bind_method(_MD("get_data"),&AudioStreamSample::get_data); + + ADD_PROPERTY(PropertyInfo(Variant::INT,"format",PROPERTY_HINT_ENUM,"8-Bit,16-Bit,IMA-ADPCM"),_SCS("set_format"),_SCS("get_format")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"loop_mode",PROPERTY_HINT_ENUM,"Disabled,Forward,Ping-Pong"),_SCS("set_loop_mode"),_SCS("get_loop_mode")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"loop_begin"),_SCS("set_loop_begin"),_SCS("get_loop_begin")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"loop_end"),_SCS("set_loop_end"),_SCS("get_loop_end")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"mix_rate"),_SCS("set_mix_rate"),_SCS("get_mix_rate")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"stereo"),_SCS("set_stereo"),_SCS("is_stereo")); + ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_data"),_SCS("get_data")); + +} + +AudioStreamSample::AudioStreamSample() +{ + format=FORMAT_8_BITS; + loop_mode=LOOP_DISABLED; + stereo=false; + loop_begin=0; + loop_end=0; + mix_rate=44100; + data=NULL; + data_bytes=0; +} +AudioStreamSample::~AudioStreamSample() { + + + if (data) { + AudioServer::get_singleton()->audio_data_free(data); + data=NULL; + data_bytes=0; + } +} diff --git a/scene/resources/audio_stream_sample.h b/scene/resources/audio_stream_sample.h new file mode 100644 index 0000000000..8c1e74608b --- /dev/null +++ b/scene/resources/audio_stream_sample.h @@ -0,0 +1,128 @@ +#ifndef AUDIOSTREAMSAMPLE_H +#define AUDIOSTREAMSAMPLE_H + +#include "servers/audio/audio_stream.h" + + +class AudioStreamSample; + +class AudioStreamPlaybackSample : public AudioStreamPlayback { + + GDCLASS( AudioStreamPlaybackSample, AudioStreamPlayback ) + enum { + MIX_FRAC_BITS=13, + MIX_FRAC_LEN=(1<<MIX_FRAC_BITS), + MIX_FRAC_MASK=MIX_FRAC_LEN-1, + }; + + struct IMA_ADPCM_State { + + int16_t step_index; + int32_t predictor; + /* values at loop point */ + int16_t loop_step_index; + int32_t loop_predictor; + int32_t last_nibble; + int32_t loop_pos; + int32_t window_ofs; + const uint8_t *ptr; + } ima_adpcm[2]; + + int64_t offset; + int sign; + bool active; +friend class AudioStreamSample; + Ref<AudioStreamSample> base; + + template<class Depth,bool is_stereo,bool is_ima_adpcm> + void do_resample(const Depth* p_src, AudioFrame *p_dst,int64_t &offset,int32_t &increment,uint32_t amount,IMA_ADPCM_State *ima_adpcm); +public: + + virtual void start(float p_from_pos=0.0); + virtual void stop(); + virtual bool is_playing() const; + + virtual int get_loop_count() const; //times it looped + + virtual float get_pos() const; + virtual void seek_pos(float p_time); + + virtual void mix(AudioFrame* p_buffer,float p_rate_scale,int p_frames); + + virtual float get_length() const; //if supported, otherwise return 0 + + + AudioStreamPlaybackSample(); +}; + +class AudioStreamSample : public AudioStream { + GDCLASS(AudioStreamSample,AudioStream) + RES_BASE_EXTENSION("smp") + +public: + + enum Format { + FORMAT_8_BITS, + FORMAT_16_BITS, + FORMAT_IMA_ADPCM + }; + + enum LoopMode { + LOOP_DISABLED, + LOOP_FORWARD, + LOOP_PING_PONG + }; + + +private: +friend class AudioStreamPlaybackSample; + + enum { + DATA_PAD=16 //padding for interpolation + }; + + Format format; + LoopMode loop_mode; + bool stereo; + int loop_begin; + int loop_end; + int mix_rate; + void *data; + uint32_t data_bytes; +protected: + + static void _bind_methods(); +public: + void set_format(Format p_format); + Format get_format() const; + + void set_loop_mode(LoopMode p_loop_mode); + LoopMode get_loop_mode() const; + + void set_loop_begin(int p_frame); + int get_loop_begin() const; + + void set_loop_end(int p_frame); + int get_loop_end() const; + + void set_mix_rate(int p_hz); + int get_mix_rate() const; + + void set_stereo(bool p_enable); + bool is_stereo() const; + + void set_data(const PoolVector<uint8_t>& p_data); + PoolVector<uint8_t> get_data() const; + + + virtual Ref<AudioStreamPlayback> instance_playback(); + virtual String get_stream_name() const; + + AudioStreamSample(); + ~AudioStreamSample(); +}; + +VARIANT_ENUM_CAST(AudioStreamSample::Format) +VARIANT_ENUM_CAST(AudioStreamSample::LoopMode) + +#endif // AUDIOSTREAMSample_H diff --git a/scene/resources/capsule_shape.cpp b/scene/resources/capsule_shape.cpp index db83a20f38..23538c1957 100644 --- a/scene/resources/capsule_shape.cpp +++ b/scene/resources/capsule_shape.cpp @@ -42,8 +42,8 @@ Vector<Vector3> CapsuleShape::_gen_debug_mesh_lines() { Vector3 d(0,0,height*0.5); for(int i=0;i<360;i++) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+1); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+1); Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*radius; Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*radius; diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index e201cb16ac..3392c68e75 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -498,7 +498,7 @@ Vector2 Curve2D::interpolatef(real_t p_findex) const { else if (p_findex>=points.size()) p_findex=points.size(); - return interpolate((int)p_findex,Math::fmod(p_findex,1.0)); + return interpolate((int)p_findex,Math::fmod(p_findex,(real_t)1.0)); } @@ -653,7 +653,7 @@ Vector2 Curve2D::interpolate_baked(float p_offset,bool p_cubic) const{ return r[bpc-1]; int idx = Math::floor((double)p_offset/(double)bake_interval); - float frac = Math::fmod(p_offset,bake_interval); + float frac = Math::fmod(p_offset,(float)bake_interval); if (idx>=bpc-1) { return r[bpc-1]; @@ -974,7 +974,7 @@ Vector3 Curve3D::interpolatef(real_t p_findex) const { else if (p_findex>=points.size()) p_findex=points.size(); - return interpolate((int)p_findex,Math::fmod(p_findex,1.0)); + return interpolate((int)p_findex,Math::fmod(p_findex,(real_t)1.0)); } diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h index 46fd770a27..5b5868ba14 100644 --- a/scene/resources/default_theme/theme_data.h +++ b/scene/resources/default_theme/theme_data.h @@ -45,7 +45,7 @@ static const unsigned char button_normal_png[]={ static const unsigned char button_pressed_png[]={ -0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x3,0x0,0x0,0x0,0x28,0x2d,0xf,0x53,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x20,0x63,0x48,0x52,0x4d,0x0,0x0,0x7a,0x26,0x0,0x0,0x80,0x84,0x0,0x0,0xfa,0x0,0x0,0x0,0x80,0xe8,0x0,0x0,0x75,0x30,0x0,0x0,0xea,0x60,0x0,0x0,0x3a,0x98,0x0,0x0,0x17,0x70,0x9c,0xba,0x51,0x3c,0x0,0x0,0x0,0x93,0x50,0x4c,0x54,0x45,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0x2f,0x37,0x46,0x43,0x4f,0x47,0x44,0x50,0x55,0x52,0x5f,0x55,0x52,0x60,0x3d,0x3a,0x45,0x56,0x52,0x60,0x56,0x52,0x60,0x43,0x40,0x4c,0x42,0x40,0x4b,0x3a,0x38,0x41,0x36,0x34,0x3d,0x44,0x42,0x4e,0x36,0x34,0x3e,0x46,0x42,0x4f,0x38,0x35,0x3f,0x47,0x45,0x50,0x39,0x37,0x40,0x49,0x46,0x53,0x3a,0x38,0x42,0x4a,0x47,0x54,0x3b,0x39,0x43,0x4b,0x49,0x55,0x3c,0x3a,0x44,0x4e,0x4a,0x58,0x3e,0x3b,0x46,0x50,0x4d,0x5a,0x3f,0x3d,0x48,0x3f,0x3d,0x47,0x45,0x42,0x4d,0x41,0x3e,0x49,0x40,0x3e,0x48,0x52,0x4e,0x5c,0x51,0x4e,0x5b,0xff,0xff,0xff,0x32,0xd2,0xb4,0xc,0x0,0x0,0x0,0x16,0x74,0x52,0x4e,0x53,0x4,0xa,0x11,0x19,0x1f,0x22,0x24,0x15,0x25,0x34,0x3f,0x46,0x47,0x48,0x77,0xef,0xef,0xef,0xef,0x77,0xef,0xed,0x6b,0x28,0x52,0x7a,0x0,0x0,0x0,0x1,0x62,0x4b,0x47,0x44,0x30,0xae,0xdc,0x2d,0xe4,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x6,0x16,0x12,0x2b,0x5,0x39,0x1a,0x32,0x39,0x0,0x0,0x0,0x95,0x49,0x44,0x41,0x54,0x18,0xd3,0x65,0xcf,0xdb,0x12,0x42,0x50,0x14,0x6,0xe0,0xb5,0x8f,0xf6,0x11,0xa5,0x24,0x9,0x49,0x22,0xd2,0xfb,0xbf,0x5d,0x9b,0x31,0xfb,0xa2,0xbe,0xcb,0x7f,0x66,0x1d,0x7e,0x0,0x84,0x9,0x65,0xdc,0x61,0x94,0x60,0x4,0x80,0x2,0x21,0x95,0x36,0xd6,0x1a,0xad,0xa4,0x8,0x10,0x60,0x11,0x46,0xe9,0x69,0x95,0x46,0xa1,0xc0,0x40,0x64,0x9c,0x9d,0x37,0x59,0x2c,0x9,0x50,0x95,0x5f,0xbc,0x5c,0x51,0x60,0xba,0xb8,0x7a,0x85,0x66,0xc0,0x4d,0x59,0x79,0xa5,0xe1,0xc0,0x6d,0x7d,0xf3,0x6a,0xbb,0x4,0xcd,0xdd,0x6b,0x96,0xc0,0xb4,0xf,0xaf,0x75,0x23,0x4c,0x77,0x4f,0xaf,0x73,0x4b,0xa9,0xea,0x87,0xd7,0x66,0xe8,0xdd,0x59,0x22,0x77,0xe3,0xf4,0x5e,0x4d,0xe3,0xde,0x3d,0x86,0x45,0x72,0x98,0x3f,0xab,0xf9,0x98,0xb8,0xd7,0xff,0xca,0xfd,0xd6,0xff,0x2,0x86,0xd,0x15,0x51,0x39,0x7d,0xa8,0x8e,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x63,0x72,0x65,0x61,0x74,0x65,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xc9,0xad,0xc8,0x52,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x6d,0x6f,0x64,0x69,0x66,0x79,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xb8,0xf0,0x70,0xee,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x7,0x1c,0xc,0x14,0x2b,0xf9,0x77,0x52,0x64,0x0,0x0,0x1,0x92,0x49,0x44,0x41,0x54,0x38,0xcb,0x8d,0x93,0x4d,0x4e,0x1b,0x41,0x10,0x85,0xbf,0xea,0xaa,0x1e,0x20,0x83,0xf9,0x9,0x36,0xb2,0x85,0x72,0x84,0x8,0x65,0x11,0xe5,0xc,0x9c,0x80,0x73,0x10,0xee,0xc1,0x41,0x38,0x1,0xab,0xec,0xa3,0x2c,0x2,0x8a,0xe0,0x2,0x51,0xc2,0x48,0x46,0x42,0x64,0xc6,0x91,0x21,0xf4,0x74,0x16,0x2e,0xb0,0x71,0x2,0xf2,0x93,0x9e,0xba,0x16,0xdd,0xaf,0x5e,0xa9,0x5f,0x9,0x60,0x40,0x1,0x2c,0x1,0xcb,0x5e,0x2b,0x10,0x78,0x8a,0x16,0x48,0xc0,0x1d,0x30,0x6,0x6e,0x81,0x3b,0xf3,0x87,0x25,0xb0,0x9,0xac,0x7b,0xbd,0xc,0x88,0x13,0x20,0x3b,0xc7,0xc0,0x8,0xb8,0x1,0xae,0x81,0x91,0xf9,0xe5,0xad,0x77,0xbb,0x1f,0xf6,0x7b,0xdd,0xfe,0x41,0x4a,0x69,0x2d,0x93,0xf9,0x1f,0x4,0x41,0x55,0x7f,0xd,0xaf,0xaa,0xa3,0xaf,0x67,0x9f,0x8f,0x81,0x64,0xde,0xb1,0xbb,0xdd,0x1b,0x7c,0xac,0x9b,0x9b,0xce,0xd9,0xb7,0x2f,0xfc,0xf3,0x5e,0xa6,0xe5,0xee,0xdb,0xf7,0x6b,0xdb,0xbd,0xc1,0x21,0xf0,0x9,0x18,0x5,0x60,0x5,0xd8,0x48,0x6d,0xdb,0x39,0xbf,0x38,0xc5,0x34,0x62,0x36,0x47,0x9d,0xf2,0xfc,0xe2,0x94,0xd4,0xb6,0x1d,0x60,0x3,0x58,0x31,0x20,0x2,0x65,0x40,0x88,0x31,0x92,0xbd,0xbb,0x8,0xe4,0x3c,0x39,0x67,0x91,0x33,0x84,0x89,0xa5,0x12,0x88,0xf,0x3f,0x10,0x45,0x5,0xb3,0xc8,0x73,0x10,0x11,0xb2,0xab,0x8b,0xa,0xde,0xb8,0x30,0x9f,0xb0,0x8,0xa2,0xc4,0x58,0xb0,0x8,0x82,0x28,0xde,0x58,0xcc,0xff,0x5c,0x45,0x64,0x61,0x1,0x99,0xcc,0xa5,0x80,0x4e,0x5,0xc2,0xcb,0x2,0xe2,0x41,0x10,0x40,0xc2,0x53,0x81,0xc,0xa8,0x8a,0x52,0x2c,0xe8,0x40,0x27,0x23,0x28,0x90,0xcd,0xe3,0x79,0x1b,0x34,0x50,0x14,0x4b,0xf0,0x4c,0x88,0x66,0xbd,0x4,0xd,0x78,0x94,0x93,0x79,0x3c,0x9b,0x18,0x63,0x7a,0xbd,0xb9,0xa5,0xcd,0xa8,0x7e,0xb4,0x3a,0x2f,0x15,0x10,0xca,0x72,0x95,0x18,0x8b,0x4,0x34,0xc0,0xd8,0x80,0x1a,0x18,0x56,0xd5,0xcf,0x93,0x41,0x7f,0x67,0xaf,0xb3,0xba,0x1e,0x5e,0x8a,0xb2,0x99,0xb5,0x97,0xd5,0x8f,0x13,0x60,0x8,0xd4,0x2,0x74,0x9d,0x6f,0x80,0xbe,0x2f,0x55,0xe9,0x26,0xc2,0xcc,0x26,0x66,0x5f,0xa4,0x6b,0xa0,0x2,0xbe,0x3,0x57,0xe6,0x56,0x1e,0x66,0x1a,0x2,0xaf,0x3c,0x24,0x36,0x67,0xe0,0x1e,0xf8,0x3,0xfc,0xf6,0x6d,0xac,0x81,0xe6,0x2f,0x7c,0x22,0x6d,0x74,0x25,0xb,0xb3,0xa2,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; @@ -540,12 +540,12 @@ static const unsigned char vslider_bg_png[]={ static const unsigned char vslider_grabber_png[]={ -0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x4,0x0,0x0,0x0,0xb5,0xfa,0x37,0xea,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x20,0x63,0x48,0x52,0x4d,0x0,0x0,0x7a,0x26,0x0,0x0,0x80,0x84,0x0,0x0,0xfa,0x0,0x0,0x0,0x80,0xe8,0x0,0x0,0x75,0x30,0x0,0x0,0xea,0x60,0x0,0x0,0x3a,0x98,0x0,0x0,0x17,0x70,0x9c,0xba,0x51,0x3c,0x0,0x0,0x0,0x2,0x62,0x4b,0x47,0x44,0x0,0xff,0x87,0x8f,0xcc,0xbf,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x6,0x16,0x12,0x2b,0x5,0x39,0x1a,0x32,0x39,0x0,0x0,0x0,0xf8,0x49,0x44,0x41,0x54,0x28,0xcf,0xbd,0x90,0xaf,0x4b,0x43,0x51,0x18,0x86,0x9f,0xf3,0x43,0xcf,0x76,0xae,0xde,0xb9,0xc9,0x1c,0x82,0x86,0xa1,0x16,0x15,0x87,0xc3,0x20,0x68,0x30,0x58,0xb4,0x5a,0x6c,0x62,0x37,0x88,0xff,0x81,0xc5,0xe4,0x5f,0x70,0x8b,0x75,0x45,0xb3,0xc1,0xa6,0x41,0x4,0x19,0xc,0x19,0x18,0x4,0x8d,0xb,0x82,0xdb,0xd8,0x81,0x29,0xf7,0x1e,0x8b,0x6e,0x43,0x30,0xea,0x93,0x5e,0xf8,0x5e,0x5e,0x78,0x3e,0xf8,0x73,0xc4,0x40,0x92,0x18,0x46,0x9,0x18,0xc6,0xd3,0xa1,0x89,0x23,0xee,0x17,0x86,0xc8,0x14,0xa7,0x97,0x57,0x4a,0xdb,0xe1,0xa2,0xc9,0x4b,0xdf,0xac,0x3d,0x9d,0x47,0x15,0x5e,0x89,0x5,0x20,0xb0,0x23,0xc5,0x83,0xc3,0xc2,0xa6,0x99,0xea,0xaa,0xf,0x62,0xc0,0xa0,0x1b,0xf,0x27,0xd1,0x19,0x6d,0x8d,0x66,0x6c,0x75,0x6d,0xf7,0x54,0xcd,0x3a,0x1c,0xc9,0xd7,0x60,0x8c,0x2d,0xcc,0xec,0x70,0x41,0x5b,0x63,0x8e,0xf6,0xe6,0x8f,0xdf,0x82,0x4e,0xef,0x8,0xe0,0xe9,0x92,0x5d,0x22,0x0,0x89,0x48,0x59,0xd4,0xef,0x16,0x8a,0xe4,0xba,0xde,0xaa,0x2e,0x94,0x53,0xb9,0x4,0x8f,0xef,0x29,0xa5,0x71,0x77,0x57,0x15,0x5a,0x8a,0x4,0xf7,0xfc,0x72,0x73,0x39,0xc7,0xf8,0x44,0x90,0x11,0x2,0x24,0x92,0x34,0xba,0xf1,0x18,0xdd,0xdf,0xf2,0xde,0xd7,0xc,0x75,0x7e,0x6b,0x7d,0x63,0x5f,0x4c,0x9a,0x9c,0xfa,0xa1,0xf9,0x8d,0xc4,0x12,0x62,0xd1,0x83,0x8f,0xfa,0x7,0x3e,0x1,0x87,0xd0,0x4a,0x12,0xcf,0xee,0xfb,0xd8,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x63,0x72,0x65,0x61,0x74,0x65,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xc9,0xad,0xc8,0x52,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x6d,0x6f,0x64,0x69,0x66,0x79,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xb8,0xf0,0x70,0xee,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x4,0x0,0x0,0x0,0xb5,0xfa,0x37,0xea,0x0,0x0,0x0,0x2,0x62,0x4b,0x47,0x44,0x0,0xb7,0xff,0x88,0x5,0x1d,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe1,0x1,0x12,0x1,0x36,0x8,0x50,0xb9,0xa7,0x53,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0xf6,0x49,0x44,0x41,0x54,0x28,0xcf,0xbd,0x90,0xb1,0x4a,0x42,0x51,0x0,0x86,0xbf,0x73,0x8e,0x71,0xe5,0x9a,0x5c,0x41,0xd0,0x66,0x6b,0x33,0x1c,0x7c,0x80,0xa0,0xa5,0x17,0x8,0xa2,0x2d,0x84,0xf0,0x1,0xa2,0x25,0xf1,0x9,0x9a,0x1c,0xda,0x5b,0xb2,0x47,0xa8,0xa5,0xc1,0xa0,0x51,0x88,0xa2,0x29,0xa,0xc1,0x84,0x8,0x43,0xf4,0x96,0x17,0xcf,0xed,0xde,0x73,0x9c,0xcc,0x5c,0xda,0xea,0x9f,0x3f,0xfe,0x9f,0xef,0x87,0x3f,0x8f,0x0,0x40,0xe1,0xe2,0x91,0x42,0x10,0x32,0xe6,0x3,0x8d,0xc1,0xce,0x1,0x45,0xb6,0xba,0xbb,0xba,0xed,0x95,0x8c,0xd0,0x7d,0xff,0xe1,0xee,0xe2,0xb6,0xdd,0x79,0x61,0xc4,0xd7,0xc,0x48,0x57,0x2b,0xeb,0xb5,0x28,0xaf,0x1,0xc5,0x12,0x4e,0xac,0x7b,0x6f,0x57,0x27,0x8d,0xcf,0xe,0x1,0x56,0x1,0xb9,0x9d,0xba,0x28,0x6,0x18,0xc,0x31,0x21,0x5a,0xda,0x4c,0xb6,0xbc,0xb9,0x35,0x7c,0xea,0xbd,0x13,0x4a,0x20,0xe5,0x95,0xf4,0x6c,0x12,0x30,0x84,0xf8,0x44,0x6b,0xfb,0xcd,0x83,0x3d,0x1c,0xf9,0x8b,0x80,0x4a,0xba,0x88,0x4,0x30,0x1e,0xdd,0x3b,0x1b,0xf1,0x77,0x87,0x24,0x81,0x8b,0x79,0x3e,0x3b,0x6a,0x5d,0x33,0x51,0x80,0x2d,0x38,0x2b,0x65,0xb5,0x6c,0x91,0x28,0x92,0xa4,0xad,0xec,0x76,0xcf,0x8f,0xf,0x1f,0xdb,0xc,0x31,0xb,0x9a,0xb1,0xd0,0x3,0xfb,0xda,0x3a,0xbd,0xbc,0x89,0xfa,0xf8,0x73,0xcd,0x9f,0x47,0x45,0x4,0xf8,0x4,0x18,0xfe,0x2f,0x53,0x8,0x62,0x5c,0xcf,0x1f,0x5f,0xcb,0x2c,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; static const unsigned char vslider_grabber_hl_png[]={ -0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x3,0x0,0x0,0x0,0x28,0x2d,0xf,0x53,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x20,0x63,0x48,0x52,0x4d,0x0,0x0,0x7a,0x26,0x0,0x0,0x80,0x84,0x0,0x0,0xfa,0x0,0x0,0x0,0x80,0xe8,0x0,0x0,0x75,0x30,0x0,0x0,0xea,0x60,0x0,0x0,0x3a,0x98,0x0,0x0,0x17,0x70,0x9c,0xba,0x51,0x3c,0x0,0x0,0x0,0xc6,0x50,0x4c,0x54,0x45,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x17,0x2a,0x29,0x3a,0x69,0x69,0x5b,0xa6,0xa5,0x61,0xb3,0xbc,0x63,0xb7,0xc8,0x65,0xbb,0xca,0x60,0xaf,0xb1,0x48,0x83,0x83,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0xf,0xf,0x55,0x9b,0x9a,0x60,0xb2,0xbd,0x5e,0xb1,0xcd,0x61,0xb3,0xc2,0x0,0x0,0x0,0x27,0x48,0x47,0x62,0xb4,0xbd,0x51,0x93,0x92,0x68,0xc0,0xcf,0x0,0x0,0x0,0x56,0x9d,0x9c,0x68,0xc1,0xcf,0x2d,0x52,0x52,0x63,0xb7,0xbf,0x52,0x96,0x95,0x62,0xb3,0xbf,0x5e,0xb0,0xcd,0x0,0x0,0x0,0x3,0x5,0x5,0x36,0x63,0x63,0x63,0xb4,0xb6,0x60,0xb1,0xbc,0x63,0xb7,0xc7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x55,0xa3,0xc8,0x4f,0x98,0xc4,0x4b,0x93,0xc2,0x4c,0x94,0xc2,0x54,0xa2,0xc8,0x5a,0xab,0xcb,0x4e,0x97,0xc4,0x49,0x8f,0xc0,0x47,0x8c,0xbf,0x48,0x8e,0xc0,0x52,0x9e,0xc6,0x51,0x9d,0xc6,0x5a,0xac,0xcc,0x53,0x9f,0xc7,0x4d,0x96,0xc3,0x4b,0x92,0xc2,0xff,0xff,0xff,0xec,0x37,0x7,0xf6,0x0,0x0,0x0,0x31,0x74,0x52,0x4e,0x53,0x0,0x1,0x3,0xa,0x17,0x22,0x28,0x27,0x1c,0xd,0x5,0x14,0x31,0x65,0xaf,0xdb,0xf0,0xef,0xc1,0x6e,0x16,0xb,0x2c,0x9c,0xe0,0xfc,0xe8,0x4,0x4f,0xdb,0x73,0xf4,0xc,0x7d,0xf7,0x55,0xdc,0x95,0xe0,0xfe,0x13,0x28,0x64,0xc5,0xde,0xf0,0x2,0x1a,0x24,0x77,0x58,0x79,0x88,0x0,0x0,0x0,0x1,0x62,0x4b,0x47,0x44,0x41,0x89,0xde,0x6c,0x4e,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x6,0x16,0x12,0x2b,0x5,0x39,0x1a,0x32,0x39,0x0,0x0,0x0,0x7d,0x49,0x44,0x41,0x54,0x18,0xd3,0x63,0x60,0x20,0xf,0x30,0x32,0x31,0xb3,0xb0,0xb2,0xb1,0x73,0x70,0x32,0x41,0xf8,0x5c,0xdc,0x3c,0xbc,0x7c,0xfc,0x2,0x82,0x42,0xc2,0x22,0x20,0x11,0x46,0x51,0x31,0x71,0x9,0x49,0x43,0x23,0x63,0x13,0x53,0x29,0x61,0x4e,0x6,0x6,0x69,0x6e,0x19,0x59,0x33,0x73,0xb,0x4b,0x20,0xb0,0x32,0x15,0xe2,0x60,0x60,0x10,0x95,0x93,0xb7,0x6,0x73,0x81,0xc0,0x44,0x90,0x9d,0x81,0x41,0x41,0x51,0xc9,0x6,0x45,0x40,0x5a,0x44,0x59,0xc5,0x16,0x59,0xb,0x3,0xa3,0x82,0x98,0xaa,0x9a,0xba,0x9d,0xbd,0x3,0xd4,0x50,0x90,0xb5,0x1a,0x9a,0x5a,0xda,0x3a,0xba,0x30,0x6b,0x41,0x40,0x4f,0x41,0xdf,0x0,0xc9,0x61,0x24,0x2,0x0,0x9d,0x96,0x10,0xf9,0x6,0xb2,0x58,0x28,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x63,0x72,0x65,0x61,0x74,0x65,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xc9,0xad,0xc8,0x52,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x6d,0x6f,0x64,0x69,0x66,0x79,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xb8,0xf0,0x70,0xee,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x3,0x0,0x0,0x0,0x28,0x2d,0xf,0x53,0x0,0x0,0x0,0xc3,0x50,0x4c,0x54,0x45,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x17,0x2a,0x29,0x3a,0x69,0x69,0x5b,0xa6,0xa5,0x61,0xb3,0xbc,0x63,0xb7,0xc8,0x65,0xbb,0xca,0x60,0xaf,0xb1,0x48,0x83,0x83,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0xf,0xf,0x55,0x9b,0x9a,0x60,0xb2,0xbd,0x5e,0xb1,0xcd,0x61,0xb3,0xc2,0x0,0x0,0x0,0x27,0x48,0x47,0x62,0xb4,0xbd,0x51,0x93,0x92,0x68,0xc0,0xcf,0x0,0x0,0x0,0x56,0x9d,0x9c,0x68,0xc1,0xcf,0x2d,0x52,0x52,0x63,0xb7,0xbf,0x52,0x96,0x95,0x62,0xb3,0xbf,0x5e,0xb0,0xcd,0x0,0x0,0x0,0x3,0x5,0x5,0x36,0x63,0x63,0x63,0xb4,0xb6,0x60,0xb1,0xbc,0x63,0xb7,0xc7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x55,0xa3,0xc8,0x4f,0x98,0xc4,0x4b,0x93,0xc2,0x4c,0x94,0xc2,0x54,0xa2,0xc8,0x5a,0xab,0xcb,0x4e,0x97,0xc4,0x49,0x8f,0xc0,0x47,0x8c,0xbf,0x48,0x8e,0xc0,0x52,0x9e,0xc6,0x51,0x9d,0xc6,0x5a,0xac,0xcc,0x53,0x9f,0xc7,0x4d,0x96,0xc3,0x4b,0x92,0xc2,0xff,0xff,0xff,0x76,0xbd,0x27,0x7a,0x0,0x0,0x0,0x1,0x74,0x52,0x4e,0x53,0x0,0x40,0xe6,0xd8,0x66,0x0,0x0,0x0,0x1,0x62,0x4b,0x47,0x44,0x0,0x88,0x5,0x1d,0x48,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe1,0x1,0x12,0x1,0x36,0x11,0x34,0xd2,0xf,0x93,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0x48,0x49,0x44,0x41,0x54,0x18,0xd3,0x63,0x60,0xa0,0x12,0x10,0x14,0xe0,0xe7,0xe3,0x45,0xe2,0x4b,0x9a,0x18,0x1b,0x19,0x1a,0x48,0x88,0x8b,0xc1,0xe4,0x4d,0x2c,0x2d,0x80,0xc0,0xdc,0xcc,0x54,0x6,0x22,0x20,0x60,0x6c,0x1,0x1,0xe6,0x56,0x72,0x68,0x2,0xd6,0x8a,0xa8,0x5a,0x6c,0x94,0x11,0x86,0xda,0xdb,0xd9,0xaa,0xa9,0xaa,0x20,0x59,0xab,0xa3,0xad,0xc5,0x40,0x3d,0x0,0x0,0xbf,0x8e,0xc,0xed,0xed,0xc7,0x67,0x72,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; diff --git a/scene/resources/default_theme/vslider_grabber.png b/scene/resources/default_theme/vslider_grabber.png Binary files differindex a61a6a57c9..afc490be45 100644 --- a/scene/resources/default_theme/vslider_grabber.png +++ b/scene/resources/default_theme/vslider_grabber.png diff --git a/scene/resources/default_theme/vslider_grabber_hl.png b/scene/resources/default_theme/vslider_grabber_hl.png Binary files differindex 548dbbbff8..548972e115 100644 --- a/scene/resources/default_theme/vslider_grabber_hl.png +++ b/scene/resources/default_theme/vslider_grabber_hl.png diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 63a7829d26..ba4b12900f 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -938,7 +938,7 @@ RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String& p_ *r_error=ERR_FILE_CANT_OPEN; Ref<DynamicFontData> dfont; - dfont.instance();; + dfont.instance(); dfont->set_font_path(p_path); diff --git a/scene/resources/event_stream.cpp b/scene/resources/event_stream.cpp deleted file mode 100644 index 521f305327..0000000000 --- a/scene/resources/event_stream.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************/ -/* event_stream.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "event_stream.h" - - -Error EventStreamPlayback::play() { - if (stream.is_valid()) - stop(); - - Error err = _play(); - if (err) - return err; - - - playing=true; - AudioServer::get_singleton()->stream_set_active(stream,true); - - return OK; -} - -void EventStreamPlayback::stop(){ - - if (!playing) - return; - - AudioServer::get_singleton()->stream_set_active(stream,false); - _stop(); - playing=false; - - -} -bool EventStreamPlayback::is_playing() const{ - - return playing; -} - - -EventStreamPlayback::EventStreamPlayback() { - - playing=false; - estream.playback=this; - stream=AudioServer::get_singleton()->event_stream_create(&estream); - -} - -EventStreamPlayback::~EventStreamPlayback() { - - AudioServer::get_singleton()->free(stream); - -} - - - -EventStream::EventStream() -{ - - -} - diff --git a/scene/resources/event_stream.h b/scene/resources/event_stream.h deleted file mode 100644 index 40af78fcce..0000000000 --- a/scene/resources/event_stream.h +++ /dev/null @@ -1,118 +0,0 @@ -/*************************************************************************/ -/* event_stream.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef EVENT_STREAM_H -#define EVENT_STREAM_H - -#include "resource.h" -#include "servers/audio_server.h" - -class EventStreamPlayback : public Reference { - - GDCLASS(EventStreamPlayback,Reference); - - class InternalEventStream : public AudioServer::EventStream { - public: - AudioMixer *_get_mixer(){ return get_mixer(); } - EventStreamPlayback *playback; - virtual void update(uint64_t p_usec) { - - playback->_update(get_mixer(),p_usec); - } - - - virtual ~InternalEventStream() {} - }; - - - InternalEventStream estream; - - RID stream; - bool playing; - - -protected: - - virtual AudioMixer* _get_mixer() { return estream._get_mixer(); } - virtual Error _play()=0; - virtual bool _update(AudioMixer* p_mixer, uint64_t p_usec)=0; - virtual void _stop()=0; -public: - - virtual Error play(); - virtual void stop(); - virtual bool is_playing() const; - - virtual void set_paused(bool p_paused)=0; - virtual bool is_paused() const=0; - - virtual void set_loop(bool p_loop)=0; - virtual bool is_loop_enabled() const=0; - - virtual int get_loop_count() const=0; - - virtual float get_pos() const=0; - virtual void seek_pos(float p_time)=0; - - virtual void set_volume(float p_vol)=0; - virtual float get_volume() const=0; - - virtual void set_pitch_scale(float p_pitch_scale)=0; - virtual float get_pitch_scale() const=0; - - virtual void set_tempo_scale(float p_tempo_scale)=0; - virtual float get_tempo_scale() const=0; - - virtual void set_channel_volume(int p_channel,float p_volume)=0; - virtual float get_channel_volume(int p_channel) const=0; - - virtual float get_last_note_time(int p_channel) const=0; - EventStreamPlayback(); - ~EventStreamPlayback(); - -}; - -class EventStream : public Resource { - - GDCLASS(EventStream,Resource); - OBJ_SAVE_TYPE( EventStream ); //children are all saved as EventStream, so they can be exchanged - -public: - - virtual Ref<EventStreamPlayback> instance_playback()=0; - - virtual String get_stream_name() const=0; - virtual float get_length() const=0; - virtual int get_channel_count() const=0; - - - - EventStream(); -}; - -#endif // EVENT_STREAM_H diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 112ecaae2f..e2e79970f9 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -732,7 +732,7 @@ Ref<Texture> FixedSpatialMaterial::get_texture(TextureParam p_param) const { void FixedSpatialMaterial::_validate_feature(const String& text, Feature feature,PropertyInfo& property) const { - if (property.name.begins_with(text) && property.name!=text+"/enabled" && !features[feature]) { + if (property.name.begins_with(text) && property.name!=text+"_enabled" && !features[feature]) { property.usage=0; } diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 5cefca348b..2707dd6198 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -332,7 +332,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { //remove nodes that could not be added, likely as a result that while(stray_instances.size()) { memdelete(stray_instances.front()->get()); - stray_instances.pop_front();; + stray_instances.pop_front(); } for(int i=0;i<editable_instances.size();i++) { diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index 2156487407..568f086d34 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -419,7 +419,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector path.push_back(points[at].pos); } while (at!=aidx); - path.invert();; + path.invert(); } for(int i=0;i<points.size()-2;i++) { diff --git a/scene/resources/sample.cpp b/scene/resources/sample.cpp deleted file mode 100644 index e07e4d3767..0000000000 --- a/scene/resources/sample.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/*************************************************************************/ -/* sample.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "sample.h" - - -void Sample::_set_data(const Dictionary& p_data) { - - ERR_FAIL_COND(!p_data.has("packing")); - String packing = p_data["packing"]; - - if (packing=="raw") { - - ERR_FAIL_COND( !p_data.has("stereo")); - ERR_FAIL_COND( !p_data.has("format")); - ERR_FAIL_COND( !p_data.has("length")); - bool stereo=p_data["stereo"]; - int length=p_data["length"]; - Format fmt; - String fmtstr=p_data["format"]; - if (fmtstr=="pcm8") - fmt=FORMAT_PCM8; - else if (fmtstr=="pcm16") - fmt=FORMAT_PCM16; - else if (fmtstr=="ima_adpcm") - fmt=FORMAT_IMA_ADPCM; - else { - ERR_EXPLAIN("Invalid format for sample: "+fmtstr); - ERR_FAIL(); - } - - ERR_FAIL_COND(!p_data.has("data")); - - create(fmt,stereo,length); - set_data(p_data["data"]); - } else { - - ERR_EXPLAIN("Invalid packing for sample data: "+packing); - ERR_FAIL(); - } -} - -Dictionary Sample::_get_data() const { - - Dictionary d; - switch(get_format()) { - - case FORMAT_PCM8: d["format"]="pcm8"; break; - case FORMAT_PCM16: d["format"]="pcm16"; break; - case FORMAT_IMA_ADPCM: d["format"]="ima_adpcm"; break; - } - - d["stereo"]=is_stereo(); - d["length"]=get_length(); - d["packing"]="raw"; - d["data"]=get_data(); - return d; - -} - -void Sample::create(Format p_format, bool p_stereo, int p_length) { - - if (p_length<1) - return; - - if (sample.is_valid()) - AudioServer::get_singleton()->free(sample); - - - mix_rate=44100; - stereo=p_stereo; - length=p_length; - format=p_format; - loop_format=LOOP_NONE; - loop_begin=0; - loop_end=0; - - sample=AudioServer::get_singleton()->sample_create((AudioServer::SampleFormat)p_format,p_stereo,p_length); -} - - -Sample::Format Sample::get_format() const { - - return format; -} -bool Sample::is_stereo() const { - - - return stereo; -} -int Sample::get_length() const { - - - return length; -} - -void Sample::set_data(const PoolVector<uint8_t>& p_buffer) { - - if (sample.is_valid()) - AudioServer::get_singleton()->sample_set_data(sample,p_buffer); - -} -PoolVector<uint8_t> Sample::get_data() const { - - if (sample.is_valid()) - return AudioServer::get_singleton()->sample_get_data(sample); - - return PoolVector<uint8_t>(); - -} - -void Sample::set_mix_rate(int p_rate) { - - mix_rate=p_rate; - if (sample.is_valid()) - return AudioServer::get_singleton()->sample_set_mix_rate(sample,mix_rate); - -} -int Sample::get_mix_rate() const { - - return mix_rate; -} - -void Sample::set_loop_format(LoopFormat p_format) { - - if (sample.is_valid()) - AudioServer::get_singleton()->sample_set_loop_format(sample,(AudioServer::SampleLoopFormat)p_format); - loop_format=p_format; -} - -Sample::LoopFormat Sample::get_loop_format() const { - - return loop_format; -} - -void Sample::set_loop_begin(int p_pos) { - - if (sample.is_valid()) - AudioServer::get_singleton()->sample_set_loop_begin(sample,p_pos); - loop_begin=p_pos; - -} -int Sample::get_loop_begin() const { - - return loop_begin; -} - -void Sample::set_loop_end(int p_pos) { - - if (sample.is_valid()) - AudioServer::get_singleton()->sample_set_loop_end(sample,p_pos); - loop_end=p_pos; -} - -int Sample::get_loop_end() const { - - return loop_end; -} - -RID Sample::get_rid() const { - - return sample; -} - - - -void Sample::_bind_methods(){ - - - ClassDB::bind_method(_MD("create","format","stereo","length"),&Sample::create); - ClassDB::bind_method(_MD("get_format"),&Sample::get_format); - ClassDB::bind_method(_MD("is_stereo"),&Sample::is_stereo); - ClassDB::bind_method(_MD("get_length"),&Sample::get_length); - ClassDB::bind_method(_MD("set_data","data"),&Sample::set_data); - ClassDB::bind_method(_MD("get_data"),&Sample::get_data); - ClassDB::bind_method(_MD("set_mix_rate","hz"),&Sample::set_mix_rate); - ClassDB::bind_method(_MD("get_mix_rate"),&Sample::get_mix_rate); - ClassDB::bind_method(_MD("set_loop_format","format"),&Sample::set_loop_format); - ClassDB::bind_method(_MD("get_loop_format"),&Sample::get_loop_format); - ClassDB::bind_method(_MD("set_loop_begin","pos"),&Sample::set_loop_begin); - ClassDB::bind_method(_MD("get_loop_begin"),&Sample::get_loop_begin); - ClassDB::bind_method(_MD("set_loop_end","pos"),&Sample::set_loop_end); - ClassDB::bind_method(_MD("get_loop_end"),&Sample::get_loop_end); - - ClassDB::bind_method(_MD("_set_data"),&Sample::_set_data); - ClassDB::bind_method(_MD("_get_data"),&Sample::_get_data); - - ADD_PROPERTY( PropertyInfo( Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("_set_data"), _SCS("_get_data") ); - ADD_PROPERTY( PropertyInfo( Variant::BOOL, "stereo"), _SCS(""), _SCS("is_stereo") ); - ADD_PROPERTY( PropertyInfo( Variant::INT, "length",PROPERTY_HINT_RANGE,"0,999999999"), _SCS(""), _SCS("get_length") ); - ADD_PROPERTY( PropertyInfo( Variant::INT, "mix_rate", PROPERTY_HINT_RANGE,"1,192000,1" ), _SCS("set_mix_rate"), _SCS("get_mix_rate") ); - ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_format", PROPERTY_HINT_ENUM,"None,Forward,PingPong" ), _SCS("set_loop_format"), _SCS("get_loop_format") ); - ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_begin", PROPERTY_HINT_RANGE,"0,"+itos(999999999)+",1"), _SCS("set_loop_begin"), _SCS("get_loop_begin") ); - ADD_PROPERTY( PropertyInfo( Variant::INT, "loop_end", PROPERTY_HINT_RANGE,"0,"+itos(999999999)+",1"), _SCS("set_loop_end"), _SCS("get_loop_end") ); - - BIND_CONSTANT( FORMAT_PCM8 ); - BIND_CONSTANT( FORMAT_PCM16 ); - BIND_CONSTANT( FORMAT_IMA_ADPCM ); - - BIND_CONSTANT( LOOP_NONE ); - BIND_CONSTANT( LOOP_FORWARD ); - BIND_CONSTANT( LOOP_PING_PONG ); - -} - -Sample::Sample() { - - format=FORMAT_PCM8; - length=0; - stereo=false; - - loop_format=LOOP_NONE; - loop_begin=0; - loop_end=0; - mix_rate=44100; - -} - -Sample::~Sample() { - - if (sample.is_valid()) - AudioServer::get_singleton()->free(sample); -} diff --git a/scene/resources/sample.h b/scene/resources/sample.h deleted file mode 100644 index be2cf67954..0000000000 --- a/scene/resources/sample.h +++ /dev/null @@ -1,108 +0,0 @@ -/*************************************************************************/ -/* sample.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SAMPLE_H -#define SAMPLE_H - -#include "servers/audio_server.h" -#include "resource.h" - -class Sample : public Resource { - - GDCLASS(Sample, Resource ); - RES_BASE_EXTENSION("smp"); -public: - - enum Format { - - FORMAT_PCM8, - FORMAT_PCM16, - FORMAT_IMA_ADPCM - }; - - enum LoopFormat { - LOOP_NONE, - LOOP_FORWARD, - LOOP_PING_PONG // not supported in every platform - - }; - -private: - - Format format; - int length; - bool stereo; - - LoopFormat loop_format; - int loop_begin; - int loop_end; - int mix_rate; - - RID sample; - - - void _set_data(const Dictionary& p_data); - Dictionary _get_data() const; - -protected: - - static void _bind_methods(); - -public: - - - void create(Format p_format, bool p_stereo, int p_length); - - Format get_format() const; - bool is_stereo() const; - int get_length() const; - - void set_data(const PoolVector<uint8_t>& p_buffer); - PoolVector<uint8_t> get_data() const; - - void set_mix_rate(int p_rate); - int get_mix_rate() const; - - void set_loop_format(LoopFormat p_format); - LoopFormat get_loop_format() const; - - void set_loop_begin(int p_pos); - int get_loop_begin() const; - - void set_loop_end(int p_pos); - int get_loop_end() const; - - virtual RID get_rid() const; - Sample(); - ~Sample(); -}; - -VARIANT_ENUM_CAST( Sample::Format ); -VARIANT_ENUM_CAST( Sample::LoopFormat ); - -#endif // SAMPLE_H diff --git a/scene/resources/sample_library.cpp b/scene/resources/sample_library.cpp deleted file mode 100644 index 44895df8fa..0000000000 --- a/scene/resources/sample_library.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/*************************************************************************/ -/* sample_library.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "sample_library.h" - - -bool SampleLibrary::_set(const StringName& p_name, const Variant& p_value) { - - - if (String(p_name).begins_with("samples/")) { - - String name=String(p_name).get_slicec('/',1); - if (p_value.get_type()==Variant::NIL) - sample_map.erase(name); - else { - SampleData sd; - - if (p_value.get_type()==Variant::OBJECT) - sd.sample=p_value; - else if (p_value.get_type()==Variant::DICTIONARY) { - - Dictionary d = p_value; - ERR_FAIL_COND_V(!d.has("sample"),false); - ERR_FAIL_COND_V(!d.has("pitch"),false); - ERR_FAIL_COND_V(!d.has("db"),false); - sd.sample=d["sample"]; - sd.pitch_scale=d["pitch"]; - sd.db=d["db"]; - } - - sample_map[name]=sd; - } - - return true; - } - - return false; -} - -bool SampleLibrary::_get(const StringName& p_name,Variant &r_ret) const { - - if (String(p_name).begins_with("samples/")) { - - String name=String(p_name).get_slicec('/',1); - if(sample_map.has(name)) { - Dictionary d; - d["sample"]=sample_map[name].sample; - d["pitch"]=sample_map[name].pitch_scale; - d["db"]=sample_map[name].db; - r_ret=d; - } else { - return false; - } - - return true; - } - - return false; - - -} - -void SampleLibrary::add_sample(const StringName& p_name, const Ref<Sample>& p_sample) { - - ERR_FAIL_COND(p_sample.is_null()); - - SampleData sd; - sd.sample=p_sample; - sample_map[p_name]=sd; -} - -Ref<Sample> SampleLibrary::get_sample(const StringName& p_name) const { - - ERR_FAIL_COND_V(!sample_map.has(p_name),Ref<Sample>()); - - return sample_map[p_name].sample; -} - -void SampleLibrary::remove_sample(const StringName& p_name) { - - sample_map.erase(p_name); -} - -void SampleLibrary::get_sample_list(List<StringName> *p_samples) const { - - for(const Map<StringName,SampleData >::Element *E=sample_map.front();E;E=E->next()) { - - p_samples->push_back(E->key()); - } - -} - -bool SampleLibrary::has_sample(const StringName& p_name) const { - - return sample_map.has(p_name); -} - -void SampleLibrary::_get_property_list(List<PropertyInfo> *p_list) const { - - - List<PropertyInfo> tpl; - for(Map<StringName,SampleData>::Element *E=sample_map.front();E;E=E->next()) { - - tpl.push_back( PropertyInfo( Variant::DICTIONARY, "samples/"+E->key(),PROPERTY_HINT_RESOURCE_TYPE,"Sample",PROPERTY_USAGE_NOEDITOR ) ); - } - - tpl.sort(); - //sort so order is kept - for(List<PropertyInfo>::Element *E=tpl.front();E;E=E->next()) { - p_list->push_back(E->get()); - } -} - -StringName SampleLibrary::get_sample_idx(int p_idx) const { - - int idx=0; - for (Map<StringName, SampleData >::Element *E=sample_map.front();E;E=E->next()) { - - if (p_idx==idx) - return E->key(); - idx++; - } - - return ""; -} - -void SampleLibrary::sample_set_volume_db(const StringName& p_name, float p_db) { - - ERR_FAIL_COND( !sample_map.has(p_name) ); - sample_map[p_name].db=p_db; - -} - -float SampleLibrary::sample_get_volume_db(const StringName& p_name) const{ - - ERR_FAIL_COND_V( !sample_map.has(p_name),0 ); - - return sample_map[p_name].db; -} - -void SampleLibrary::sample_set_pitch_scale(const StringName& p_name, float p_pitch){ - - ERR_FAIL_COND( !sample_map.has(p_name) ); - - sample_map[p_name].pitch_scale=p_pitch; -} - -float SampleLibrary::sample_get_pitch_scale(const StringName& p_name) const{ - - ERR_FAIL_COND_V( !sample_map.has(p_name),0 ); - - return sample_map[p_name].pitch_scale; -} - -Array SampleLibrary::_get_sample_list() const { - - List<StringName> snames; - get_sample_list(&snames); - - snames.sort_custom<StringName::AlphCompare>(); - - Array ret; - for (List<StringName>::Element *E=snames.front();E;E=E->next()) { - ret.push_back(E->get()); - } - - return ret; -} - -void SampleLibrary::_bind_methods() { - - ClassDB::bind_method(_MD("add_sample","name","sample:Sample"),&SampleLibrary::add_sample ); - ClassDB::bind_method(_MD("get_sample:Sample","name"),&SampleLibrary::get_sample ); - ClassDB::bind_method(_MD("has_sample","name"),&SampleLibrary::has_sample ); - ClassDB::bind_method(_MD("remove_sample","name"),&SampleLibrary::remove_sample ); - - ClassDB::bind_method(_MD("get_sample_list"),&SampleLibrary::_get_sample_list ); - - ClassDB::bind_method(_MD("sample_set_volume_db","name","db"),&SampleLibrary::sample_set_volume_db ); - ClassDB::bind_method(_MD("sample_get_volume_db","name"),&SampleLibrary::sample_get_volume_db ); - - ClassDB::bind_method(_MD("sample_set_pitch_scale","name","pitch"),&SampleLibrary::sample_set_pitch_scale ); - ClassDB::bind_method(_MD("sample_get_pitch_scale","name"),&SampleLibrary::sample_get_pitch_scale ); - - -} - -SampleLibrary::SampleLibrary() -{ -} diff --git a/scene/resources/sample_library.h b/scene/resources/sample_library.h deleted file mode 100644 index d09eea64c5..0000000000 --- a/scene/resources/sample_library.h +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************/ -/* sample_library.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SAMPLE_LIBRARY_H -#define SAMPLE_LIBRARY_H - -#include "resource.h" -#include "scene/resources/sample.h" -#include "map.h" - -class SampleLibrary : public Resource { - - GDCLASS(SampleLibrary,Resource); - - struct SampleData { - - Ref<Sample> sample; - float db; - float pitch_scale; - - SampleData() { db=0; pitch_scale=1; } - }; - - Map<StringName,SampleData > sample_map; - - Array _get_sample_list() const; -protected: - - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list(List<PropertyInfo> *p_list) const; - - static void _bind_methods(); - -public: - - - - void add_sample(const StringName& p_name, const Ref<Sample>& p_sample); - bool has_sample(const StringName& p_name) const; - void sample_set_volume_db(const StringName& p_name, float p_db); - float sample_get_volume_db(const StringName& p_name) const; - void sample_set_pitch_scale(const StringName& p_name, float p_pitch); - float sample_get_pitch_scale(const StringName& p_name) const; - Ref<Sample> get_sample(const StringName& p_name) const; - void get_sample_list(List<StringName> *p_samples) const; - void remove_sample(const StringName& p_name); - StringName get_sample_idx(int p_idx) const; - - SampleLibrary(); -}; - -#endif // SAMPLE_LIBRARY_H diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index a913687e7f..9719f321d6 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -32,7 +32,8 @@ #include "version.h" #include "os/dir_access.h" -#define FORMAT_VERSION 1 +//version 2: changed names for basis, rect3, poolvectors, etc. +#define FORMAT_VERSION 2 #include "version.h" #include "os/dir_access.h" @@ -1158,7 +1159,7 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant& p_variant,b static String _valprop(const String& p_name) { if (p_name.find("\"")!=-1 || p_name.find("=")!=-1 || p_name.find(" ")!=-1) - return "\""+p_name.c_escape()+"\""; + return "\""+p_name.c_escape_multiline()+"\""; return p_name; } @@ -1360,13 +1361,11 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re } if (groups.size()) { - String sgroups=" groups=[ "; + String sgroups=" groups=[\n"; for(int j=0;j<groups.size();j++) { - if (j>0) - sgroups+=", "; - sgroups+="\""+groups[j].operator String().c_escape()+"\""; + sgroups+="\""+String(groups[j]).c_escape()+"\",\n"; } - sgroups+=" ]"; + sgroups+="]"; header+=sgroups; } diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index 10f852f17c..22ee253b1a 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -1993,8 +1993,7 @@ void ShaderGraph::_plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector /* compose the basis and geometry matrices */ - static const float CR_basis[4][4] = - { + static const float CR_basis[4][4] = { { -0.5, 1.5, -1.5, 0.5 }, { 1.0, -2.5, 2.0, -0.5 }, { -0.5, 0.0, 0.5, 0.0 }, @@ -2161,7 +2160,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str case SCALAR_OP_ATAN2: optxt = "atan2("+p_inputs[0]+","+p_inputs[1]+");"; break; } - code+=OUTNAME(p_node->id,0)+"="+optxt+"\n";; + code+=OUTNAME(p_node->id,0)+"="+optxt+"\n"; }break; case NODE_VEC_OP: { @@ -2364,7 +2363,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str code+="\t"+OUTVAR(p_node->id,0)+"=vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n"; code+="}\n"; } else if (func==VEC_FUNC_HSV2RGB) { - code += OUTNAME(p_node->id,0)+";\n";; + code += OUTNAME(p_node->id,0)+";\n"; code+="{\n"; code+="\tvec3 c = "+p_inputs[0]+";\n"; code+="\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n"; diff --git a/scene/resources/sphere_shape.cpp b/scene/resources/sphere_shape.cpp index bcfb164b4c..c7c4d94aad 100644 --- a/scene/resources/sphere_shape.cpp +++ b/scene/resources/sphere_shape.cpp @@ -37,8 +37,8 @@ Vector<Vector3> SphereShape::_gen_debug_mesh_lines() { for(int i=0;i<=360;i++) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+1); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+1); Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*r; Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*r; diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index 27cc7e131b..1d0d323546 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -852,7 +852,7 @@ void SurfaceTool::clear() { begun=false; primitive=Mesh::PRIMITIVE_LINES; format=0; - last_bones.clear();; + last_bones.clear(); last_weights.clear(); index_array.clear(); vertex_array.clear(); diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index a1ad5d8237..fa89b7ba00 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -453,6 +453,379 @@ ImageTexture::~ImageTexture() { VisualServer::get_singleton()->free( texture ); } +////////////////////////////////////////// + + +void StreamTexture::_requested_3d(void* p_ud) { + + StreamTexture *st = (StreamTexture *)p_ud; + Ref<StreamTexture> stex(st); + ERR_FAIL_COND(!request_3d_callback); + request_3d_callback(stex); +} + +void StreamTexture::_requested_srgb(void* p_ud) { + + StreamTexture *st = (StreamTexture *)p_ud; + Ref<StreamTexture> stex(st); + ERR_FAIL_COND(!request_srgb_callback); + request_srgb_callback(stex); + +} + +StreamTexture::TextureFormatRequestCallback StreamTexture::request_3d_callback=NULL; +StreamTexture::TextureFormatRequestCallback StreamTexture::request_srgb_callback=NULL; + + +uint32_t StreamTexture::get_flags() const { + + return flags; +} +Image::Format StreamTexture::get_format() const { + + return format; +} + + +Error StreamTexture::_load_data(const String& p_path,int &tw,int &th,int& flags,Image& image,int p_size_limit) { + + + FileAccess *f = FileAccess::open(p_path,FileAccess::READ); + ERR_FAIL_COND_V(!f,ERR_CANT_OPEN); + + uint8_t header[4]; + f->get_buffer(header,4); + if (header[0]!='G' || header[1]!='D' || header[2]!='S' || header[3]!='T') { + memdelete(f); + ERR_FAIL_COND_V(header[0]!='G' || header[1]!='D' || header[2]!='S' || header[3]!='T',ERR_FILE_CORRUPT); + } + + tw = f->get_32(); + th = f->get_32(); + flags= f->get_32(); //texture flags! + uint32_t df = f->get_32(); //data format + + print_line("width: "+itos(tw)); + print_line("height: "+itos(th)); + print_line("flags: "+itos(flags)); + print_line("df: "+itos(df)); + + + if (request_3d_callback && df&FORMAT_BIT_DETECT_3D) { + print_line("request detect 3D at "+p_path); + VS::get_singleton()->texture_set_detect_3d_callback(texture,_requested_3d,this); + } else { + print_line("not requesting detect 3D at "+p_path); + VS::get_singleton()->texture_set_detect_3d_callback(texture,NULL,NULL); + } + + if (request_srgb_callback && df&FORMAT_BIT_DETECT_SRGB) { + print_line("request detect srgb at "+p_path); + VS::get_singleton()->texture_set_detect_srgb_callback(texture,_requested_srgb,this); + } else { + VS::get_singleton()->texture_set_detect_srgb_callback(texture,NULL,NULL); + print_line("not requesting detect srgb at "+p_path); + } + + if (!(df&FORMAT_BIT_STREAM)) { + p_size_limit=0; + } + + + if (df&FORMAT_BIT_LOSSLESS || df&FORMAT_BIT_LOSSY) { + //look for a PNG or WEBP file inside + + int sw=tw; + int sh=th; + + uint32_t mipmaps = f->get_32(); + uint32_t size = f->get_32(); + + print_line("mipmaps: "+itos(mipmaps)); + + while(mipmaps>1 && p_size_limit>0 && (sw>p_size_limit || sh>p_size_limit)) { + + f->seek(f->get_pos()+size); + mipmaps = f->get_32(); + size = f->get_32(); + + sw=MAX(sw>>1,1); + sh=MAX(sh>>1,1); + mipmaps--; + } + + //mipmaps need to be read independently, they will be later combined + Vector<Image> mipmap_images; + int total_size=0; + + for(int i=0;i<mipmaps;i++) { + PoolVector<uint8_t> pv; + pv.resize(size); + { + PoolVector<uint8_t>::Write w = pv.write(); + f->get_buffer(w.ptr(),size); + } + + Image img; + if (df&FORMAT_BIT_LOSSLESS) { + img = Image::lossless_unpacker(pv); + } else { + img = Image::lossy_unpacker(pv); + } + + if (img.empty()) { + memdelete(f); + ERR_FAIL_COND_V(img.empty(),ERR_FILE_CORRUPT); + } + total_size+=img.get_data().size(); + + mipmap_images.push_back(img); + } + + print_line("mipmap read total: "+itos(mipmap_images.size())); + + + memdelete(f); //no longer needed + + if (mipmap_images.size()==1) { + + image=mipmap_images[0]; + return OK; + + } else { + PoolVector<uint8_t> img_data; + img_data.resize(total_size); + + { + PoolVector<uint8_t>::Write w=img_data.write(); + + int ofs=0; + for(int i=0;i<mipmap_images.size();i++) { + + PoolVector<uint8_t> id = mipmap_images[i].get_data(); + int len = id.size(); + PoolVector<uint8_t>::Read r = id.read(); + copymem(&w[ofs],r.ptr(),len); + ofs+=len; + } + } + + image = Image(sw,sh,true,mipmap_images[0].get_format(),img_data); + return OK; + } + + } else { + + //look for regular format + Image::Format format = (Image::Format)(df&FORMAT_MASK_IMAGE_FORMAT); + bool mipmaps = df&FORMAT_BIT_HAS_MIPMAPS; + + if (!mipmaps) { + int size = Image::get_image_data_size(tw,th,format,0); + + PoolVector<uint8_t> img_data; + img_data.resize(size); + + { + PoolVector<uint8_t>::Write w=img_data.write(); + f->get_buffer(w.ptr(),size); + } + + memdelete(f); + + image = Image(tw,th,false,format,img_data); + return OK; + } else { + + int sw=tw; + int sh=th; + + int mipmaps = Image::get_image_required_mipmaps(tw,th,format); + int total_size = Image::get_image_data_size(tw,th,format,mipmaps); + int idx=0; + int ofs=0; + + + while(mipmaps>1 && p_size_limit>0 && (sw>p_size_limit || sh>p_size_limit)) { + + sw=MAX(sw>>1,1); + sh=MAX(sh>>1,1); + mipmaps--; + idx++; + } + + if (idx>0) { + ofs=Image::get_image_data_size(tw,th,format,idx-1); + } + + if (total_size - ofs <=0) { + memdelete(f); + ERR_FAIL_V(ERR_FILE_CORRUPT); + } + + f->seek(f->get_pos()+ofs); + + + PoolVector<uint8_t> img_data; + img_data.resize(total_size - ofs); + + { + PoolVector<uint8_t>::Write w=img_data.write(); + int bytes = f->get_buffer(w.ptr(),total_size - ofs); + print_line("requested read: "+itos(total_size - ofs)+" but got: "+itos(bytes)); + + memdelete(f); + + if (bytes != total_size - ofs) { + ERR_FAIL_V(ERR_FILE_CORRUPT); + } + } + + image = Image(sw,sh,true,format,img_data); + + return OK; + } + } + + return ERR_BUG; //unreachable +} + +Error StreamTexture::load(const String& p_path) { + + + int lw,lh,lflags; + Image image; + Error err = _load_data(p_path,lw,lh,lflags,image); + if (err) + return err; + + VS::get_singleton()->texture_allocate(texture,image.get_width(),image.get_height(),image.get_format(),lflags); + VS::get_singleton()->texture_set_data(texture,image); + + w=lw; + h=lh; + flags=lflags; + path_to_file=p_path; + format=image.get_format(); + + return OK; +} +String StreamTexture::get_load_path() const { + + return path_to_file; +} + +int StreamTexture::get_width() const { + + return w; +} +int StreamTexture::get_height() const { + + return h; +} +RID StreamTexture::get_rid() const { + + return texture; +} + + +void StreamTexture::draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate, bool p_transpose) const { + + if ((w|h)==0) + return; + VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item,Rect2( p_pos, Size2(w,h)),texture,false,p_modulate,p_transpose); + +} +void StreamTexture::draw_rect(RID p_canvas_item,const Rect2& p_rect, bool p_tile,const Color& p_modulate, bool p_transpose) const { + + if ((w|h)==0) + return; + VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item,p_rect,texture,p_tile,p_modulate,p_transpose); + +} +void StreamTexture::draw_rect_region(RID p_canvas_item,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate, bool p_transpose) const{ + + if ((w|h)==0) + return; + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item,p_rect,texture,p_src_rect,p_modulate,p_transpose); +} + +bool StreamTexture::has_alpha() const { + + return false; +} +void StreamTexture::set_flags(uint32_t p_flags){ + +} + +void StreamTexture::reload_from_file() { + +#ifdef TOOLS_ENABLED + String ipath = get_import_path(); + if (ipath.is_resource_file() && ipath!=path_to_file) { + path_to_file=ipath; + } +#endif + load(path_to_file); +} + +void StreamTexture::_bind_methods() { + + ClassDB::bind_method(_MD("load","path"),&StreamTexture::load); + ClassDB::bind_method(_MD("get_load_path"),&StreamTexture::get_load_path); + + ADD_PROPERTY( PropertyInfo(Variant::STRING,"load_path",PROPERTY_HINT_FILE,"*.stex"),_SCS("load"),_SCS("get_load_path")); +} + + +StreamTexture::StreamTexture() { + + format=Image::FORMAT_MAX; + flags=0; + w=0; + h=0; + + texture = VS::get_singleton()->texture_create(); +} + +StreamTexture::~StreamTexture() { + + VS::get_singleton()->free(texture); +} + + + +RES ResourceFormatLoaderStreamTexture::load(const String &p_path,const String& p_original_path,Error *r_error) { + + Ref<StreamTexture> st; + st.instance(); + Error err = st->load(p_path); + if (r_error) + *r_error=err; + if (err!=OK) + return RES(); + + return st; +} + +void ResourceFormatLoaderStreamTexture::get_recognized_extensions(List<String> *p_extensions) const{ + + p_extensions->push_back("stex"); +} +bool ResourceFormatLoaderStreamTexture::handles_type(const String& p_type) const{ + return p_type=="StreamTexture"; + +} +String ResourceFormatLoaderStreamTexture::get_resource_type(const String &p_path) const{ + + if (p_path.get_extension().to_lower()=="stex") + return "StreamTexture"; + return ""; +} + + + + ////////////////////////////////////////// diff --git a/scene/resources/texture.h b/scene/resources/texture.h index aac3514af3..f684aeb658 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -31,6 +31,7 @@ #include "resource.h" #include "servers/visual_server.h" +#include "io/resource_loader.h" #include "math_2d.h" /** @@ -160,6 +161,86 @@ public: }; + +class StreamTexture : public Texture { + + GDCLASS( StreamTexture, Texture ); +public: + enum DataFormat { + DATA_FORMAT_IMAGE, + DATA_FORMAT_LOSSLESS, + DATA_FORMAT_LOSSY + }; + + enum FormatBits { + FORMAT_MASK_IMAGE_FORMAT=(1<<20)-1, + FORMAT_BIT_LOSSLESS=1<<20, + FORMAT_BIT_LOSSY=1<<21, + FORMAT_BIT_STREAM=1<<22, + FORMAT_BIT_HAS_MIPMAPS=1<<23, + FORMAT_BIT_DETECT_3D=1<<24, + FORMAT_BIT_DETECT_SRGB=1<<25, + }; + +private: + + Error _load_data(const String &p_path, int &tw, int &th, int& flags, Image& image, int p_size_limit=0); + String path_to_file; + RID texture; + Image::Format format; + uint32_t flags; + int w,h; + + virtual void reload_from_file(); + + static void _requested_3d(void* p_ud); + static void _requested_srgb(void* p_ud); + +protected: + + static void _bind_methods(); + +public: + + + typedef void (*TextureFormatRequestCallback)(const Ref<StreamTexture>&); + + static TextureFormatRequestCallback request_3d_callback; + static TextureFormatRequestCallback request_srgb_callback; + + uint32_t get_flags() const; + Image::Format get_format() const; + Error load(const String& p_path); + String get_load_path() const; + + int get_width() const; + int get_height() const; + virtual RID get_rid() const; + + virtual void draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const; + virtual void draw_rect(RID p_canvas_item,const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const; + virtual void draw_rect_region(RID p_canvas_item,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const; + + virtual bool has_alpha() const; + virtual void set_flags(uint32_t p_flags); + + StreamTexture(); + ~StreamTexture(); + +}; + + +class ResourceFormatLoaderStreamTexture : public ResourceFormatLoader { +public: + virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual bool handles_type(const String& p_type) const; + virtual String get_resource_type(const String &p_path) const; + +}; + + + VARIANT_ENUM_CAST( ImageTexture::Storage ); class AtlasTexture : public Texture { diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index d950407f54..4793f8143b 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -233,7 +233,7 @@ void Theme::set_default_theme_font( const Ref<Font>& p_default_font ) { } _change_notify(); - emit_changed();; + emit_changed(); } @@ -275,7 +275,7 @@ void Theme::set_icon(const StringName& p_name,const StringName& p_type,const Ref if (new_value) { _change_notify(); - emit_changed();; + emit_changed(); } } Ref<Texture> Theme::get_icon(const StringName& p_name,const StringName& p_type) const { @@ -301,7 +301,7 @@ void Theme::clear_icon(const StringName& p_name,const StringName& p_type) { icon_map[p_type].erase(p_name); _change_notify(); - emit_changed();; + emit_changed(); } @@ -326,7 +326,7 @@ void Theme::set_shader(const StringName &p_name,const StringName &p_type,const R if (new_value) { _change_notify(); - emit_changed();; + emit_changed(); } } @@ -348,7 +348,7 @@ void Theme::clear_shader(const StringName &p_name, const StringName &p_type) { shader_map[p_type].erase(p_name); _change_notify(); - emit_changed();; + emit_changed(); } void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) const { @@ -375,7 +375,7 @@ void Theme::set_stylebox(const StringName& p_name,const StringName& p_type,const if (new_value) _change_notify(); - emit_changed();; + emit_changed(); } @@ -403,7 +403,7 @@ void Theme::clear_stylebox(const StringName& p_name,const StringName& p_type) { style_map[p_type].erase(p_name); _change_notify(); - emit_changed();; + emit_changed(); } @@ -447,7 +447,7 @@ void Theme::set_font(const StringName& p_name,const StringName& p_type,const Ref if (new_value) { _change_notify(); - emit_changed();; + emit_changed(); } } Ref<Font> Theme::get_font(const StringName& p_name,const StringName& p_type) const { @@ -477,7 +477,7 @@ void Theme::clear_font(const StringName& p_name,const StringName& p_type) { font_map[p_type].erase(p_name); _change_notify(); - emit_changed();; + emit_changed(); } @@ -503,7 +503,7 @@ void Theme::set_color(const StringName& p_name,const StringName& p_type,const Co if (new_value) { _change_notify(); - emit_changed();; + emit_changed(); } } @@ -531,7 +531,7 @@ void Theme::clear_color(const StringName& p_name,const StringName& p_type) { color_map[p_type].erase(p_name); _change_notify(); - emit_changed();; + emit_changed(); } @@ -556,7 +556,7 @@ void Theme::set_constant(const StringName& p_name,const StringName& p_type,int p if (new_value) { _change_notify(); - emit_changed();; + emit_changed(); } } @@ -582,7 +582,7 @@ void Theme::clear_constant(const StringName& p_name,const StringName& p_type) { constant_map[p_type].erase(p_name); _change_notify(); - emit_changed();; + emit_changed(); } @@ -611,7 +611,7 @@ void Theme::copy_default_theme() { color_map=default_theme->color_map; constant_map=default_theme->constant_map; _change_notify(); - emit_changed();; + emit_changed(); } diff --git a/scene/resources/world.cpp b/scene/resources/world.cpp index 3f7261c312..72cb8cc906 100644 --- a/scene/resources/world.cpp +++ b/scene/resources/world.cpp @@ -287,10 +287,6 @@ RID World::get_scenario() const{ return scenario; } -RID World::get_sound_space() const{ - - return sound_space; -} void World::set_environment(const Ref<Environment>& p_environment) { @@ -316,7 +312,6 @@ void World::_bind_methods() { ClassDB::bind_method(_MD("get_space"),&World::get_space); ClassDB::bind_method(_MD("get_scenario"),&World::get_scenario); - ClassDB::bind_method(_MD("get_sound_space"),&World::get_sound_space); ClassDB::bind_method(_MD("set_environment","env:Environment"),&World::set_environment); ClassDB::bind_method(_MD("get_environment:Environment"),&World::get_environment); ClassDB::bind_method(_MD("get_direct_space_state:PhysicsDirectSpaceState"),&World::get_direct_space_state); @@ -329,7 +324,6 @@ World::World() { space = PhysicsServer::get_singleton()->space_create(); scenario = VisualServer::get_singleton()->scenario_create(); - sound_space = SpatialSoundServer::get_singleton()->space_create(); PhysicsServer::get_singleton()->space_set_active(space,true); PhysicsServer::get_singleton()->area_set_param(space,PhysicsServer::AREA_PARAM_GRAVITY,GLOBAL_DEF("physics/3d/default_gravity",9.8)); @@ -348,7 +342,6 @@ World::~World() { PhysicsServer::get_singleton()->free(space); VisualServer::get_singleton()->free(scenario); - SpatialSoundServer::get_singleton()->free(sound_space); #ifndef _3D_DISABLED memdelete( indexer ); diff --git a/scene/resources/world.h b/scene/resources/world.h index bea07882d7..1ad60f3405 100644 --- a/scene/resources/world.h +++ b/scene/resources/world.h @@ -32,7 +32,6 @@ #include "resource.h" #include "servers/physics_server.h" #include "servers/visual_server.h" -#include "servers/spatial_sound_server.h" #include "scene/resources/environment.h" class SpatialIndexer; @@ -45,7 +44,6 @@ class World : public Resource { private: RID space; RID scenario; - RID sound_space; SpatialIndexer* indexer; Ref<Environment> environment; @@ -71,7 +69,6 @@ public: RID get_space() const; RID get_scenario() const; - RID get_sound_space() const; void set_environment(const Ref<Environment>& p_environment); Ref<Environment> get_environment() const; diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 98c5ae3bb9..d4eff8d2b3 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -29,7 +29,7 @@ #include "world_2d.h" #include "servers/visual_server.h" #include "servers/physics_2d_server.h" -#include "servers/spatial_sound_2d_server.h" +//#include "servers/spatial_sound_2d_server.h" #include "globals.h" #include "scene/2d/visibility_notifier_2d.h" #include "scene/main/viewport.h" @@ -400,18 +400,11 @@ World2D::World2D() { canvas = VisualServer::get_singleton()->canvas_create(); space = Physics2DServer::get_singleton()->space_create(); - sound_space = SpatialSound2DServer::get_singleton()->space_create(); //set space2D to be more friendly with pixels than meters, by adjusting some constants Physics2DServer::get_singleton()->space_set_active(space,true); Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY,GLOBAL_DEF("physics/2d/default_gravity",98)); Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY_VECTOR,GLOBAL_DEF("physics/2d/default_gravity_vector",Vector2(0,1))); - // TODO: Remove this deprecation warning and compatibility code for 2.2 or 3.0 - if (GlobalConfig::get_singleton()->get("physics/2d/default_density") && !GlobalConfig::get_singleton()->get("physics/2d/default_linear_damp")) { - WARN_PRINT("Deprecated parameter 'physics/2d/default_density'. It was renamed to 'physics/2d/default_linear_damp', adjusting your project settings accordingly (make sure to adjust scripts that potentially rely on 'physics/2d/default_density'."); - GlobalConfig::get_singleton()->set("physics/2d/default_linear_damp", GlobalConfig::get_singleton()->get("physics/2d/default_density")); - GlobalConfig::get_singleton()->save(); - } Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_LINEAR_DAMP,GLOBAL_DEF("physics/2d/default_linear_damp",0.1)); Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_ANGULAR_DAMP,GLOBAL_DEF("physics/2d/default_angular_damp",1)); indexer = memnew( SpatialIndexer2D ); @@ -423,6 +416,5 @@ World2D::~World2D() { VisualServer::get_singleton()->free(canvas); Physics2DServer::get_singleton()->free(space); - SpatialSound2DServer::get_singleton()->free(sound_space); memdelete(indexer); } diff --git a/servers/audio/SCsub b/servers/audio/SCsub index ccc76e823f..afaffcfe93 100644 --- a/servers/audio/SCsub +++ b/servers/audio/SCsub @@ -5,3 +5,5 @@ Import('env') env.add_source_files(env.servers_sources, "*.cpp") Export('env') + +SConscript("effects/SCsub") diff --git a/servers/audio/audio_driver_dummy.cpp b/servers/audio/audio_driver_dummy.cpp index 6fe14b0fcb..6e0c0089ca 100644 --- a/servers/audio/audio_driver_dummy.cpp +++ b/servers/audio/audio_driver_dummy.cpp @@ -43,7 +43,7 @@ Error AudioDriverDummy::init() { mix_rate = 44100; - output_format = OUTPUT_STEREO; + speaker_mode = SPEAKER_MODE_STEREO; channels = 2; int latency = GLOBAL_DEF("audio/output_latency",25); @@ -97,16 +97,18 @@ int AudioDriverDummy::get_mix_rate() const { return mix_rate; }; -AudioDriverSW::OutputFormat AudioDriverDummy::get_output_format() const { +AudioDriver::SpeakerMode AudioDriverDummy::get_speaker_mode() const { - return output_format; + return speaker_mode; }; + void AudioDriverDummy::lock() { if (!thread || !mutex) return; mutex->lock(); }; + void AudioDriverDummy::unlock() { if (!thread || !mutex) diff --git a/servers/audio/audio_driver_dummy.h b/servers/audio/audio_driver_dummy.h index c91a0db43a..78ec41ea09 100644 --- a/servers/audio/audio_driver_dummy.h +++ b/servers/audio/audio_driver_dummy.h @@ -29,13 +29,13 @@ #ifndef AUDIO_DRIVER_DUMMY_H #define AUDIO_DRIVER_DUMMY_H -#include "servers/audio/audio_server_sw.h" +#include "servers/audio_server.h" #include "core/os/thread.h" #include "core/os/mutex.h" -class AudioDriverDummy : public AudioDriverSW { +class AudioDriverDummy : public AudioDriver { Thread* thread; Mutex* mutex; @@ -46,7 +46,7 @@ class AudioDriverDummy : public AudioDriverSW { int buffer_size; unsigned int mix_rate; - OutputFormat output_format; + SpeakerMode speaker_mode; int channels; @@ -64,7 +64,7 @@ public: virtual Error init(); virtual void start(); virtual int get_mix_rate() const; - virtual OutputFormat get_output_format() const; + virtual SpeakerMode get_speaker_mode() const; virtual void lock(); virtual void unlock(); virtual void finish(); diff --git a/servers/audio/audio_effect.cpp b/servers/audio/audio_effect.cpp new file mode 100644 index 0000000000..372c0cbc13 --- /dev/null +++ b/servers/audio/audio_effect.cpp @@ -0,0 +1,6 @@ +#include "audio_effect.h" + +AudioEffect::AudioEffect() +{ + +} diff --git a/servers/audio/audio_effect.h b/servers/audio/audio_effect.h new file mode 100644 index 0000000000..02eb258f99 --- /dev/null +++ b/servers/audio/audio_effect.h @@ -0,0 +1,26 @@ +#ifndef AUDIOEFFECT_H +#define AUDIOEFFECT_H + +#include "audio_frame.h" +#include "resource.h" + + +class AudioEffectInstance : public Reference { + GDCLASS(AudioEffectInstance,Reference) + +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count)=0; + +}; + + +class AudioEffect : public Resource { + GDCLASS(AudioEffect,Resource) +public: + + virtual Ref<AudioEffectInstance> instance()=0; + AudioEffect(); +}; + +#endif // AUDIOEFFECT_H diff --git a/servers/audio/audio_filter_sw.cpp b/servers/audio/audio_filter_sw.cpp index cdfe1a29f0..e97eb75d04 100644 --- a/servers/audio/audio_filter_sw.cpp +++ b/servers/audio/audio_filter_sw.cpp @@ -142,9 +142,9 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) { //this one is extra tricky double hicutoff=resonance; double centercutoff = (cutoff+resonance)/2.0; - double bandwidth=(Math::log(centercutoff)-Math::log(hicutoff))/Math::log(2); + double bandwidth=(Math::log(centercutoff)-Math::log(hicutoff))/Math::log((double)2); omega=2.0*Math_PI*centercutoff/sampling_rate; - alpha = Math::sin(omega)*Math::sinh( Math::log(2)/2 * bandwidth * omega/Math::sin(omega) ); + alpha = Math::sin(omega)*Math::sinh( Math::log((double)2)/2 * bandwidth * omega/Math::sin(omega) ); a0=1+alpha; p_coeffs->b0 = alpha; diff --git a/servers/audio/audio_filter_sw.h b/servers/audio/audio_filter_sw.h index 0f3e2410fd..b711944ca8 100644 --- a/servers/audio/audio_filter_sw.h +++ b/servers/audio/audio_filter_sw.h @@ -65,7 +65,7 @@ public: void set_filter(AudioFilterSW * p_filter); void process(float *p_samples,int p_amount, int p_stride=1); void update_coeffs(); - inline void process_one(float& p_sample); + _ALWAYS_INLINE_ void process_one(float& p_sample); Processor(); }; diff --git a/servers/audio/audio_mixer_sw.cpp b/servers/audio/audio_mixer_sw.cpp deleted file mode 100644 index 0123b66430..0000000000 --- a/servers/audio/audio_mixer_sw.cpp +++ /dev/null @@ -1,1222 +0,0 @@ -/*************************************************************************/ -/* audio_mixer_sw.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "audio_mixer_sw.h" -#include "print_string.h" -#include "os/os.h" -//TODO implement FAST_AUDIO macro - -#ifdef FAST_AUDIO -#define NO_REVERB -#endif - -template<class Depth,bool is_stereo,bool is_ima_adpcm,bool use_filter,bool use_fx,AudioMixerSW::InterpolationType type,AudioMixerSW::MixChannels mix_mode> -void AudioMixerSW::do_resample(const Depth* p_src, int32_t *p_dst, ResamplerState *p_state) { - - // this function will be compiled branchless by any decent compiler - - int32_t final,final_r,next,next_r; - int32_t *reverb_dst = p_state->reverb_buffer; - while (p_state->amount--) { - - int32_t pos=p_state->pos >> MIX_FRAC_BITS; - if (is_stereo && !is_ima_adpcm) - pos<<=1; - - if (is_ima_adpcm) { - - int sample_pos = pos + p_state->ima_adpcm[0].window_ofs; - - while(sample_pos>p_state->ima_adpcm[0].last_nibble) { - - - static const int16_t _ima_adpcm_step_table[89] = { - 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, - 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, - 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, - 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, - 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, - 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, - 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, - 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, - 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 - }; - - static const int8_t _ima_adpcm_index_table[16] = { - -1, -1, -1, -1, 2, 4, 6, 8, - -1, -1, -1, -1, 2, 4, 6, 8 - }; - - for(int i=0;i<(is_stereo?2:1);i++) { - - - int16_t nibble,diff,step; - - p_state->ima_adpcm[i].last_nibble++; - const uint8_t *src_ptr=p_state->ima_adpcm[i].ptr; - - - uint8_t nbb = src_ptr[ (p_state->ima_adpcm[i].last_nibble>>1) * (is_stereo?2:1) + i ]; - nibble = (p_state->ima_adpcm[i].last_nibble&1)?(nbb>>4):(nbb&0xF); - step=_ima_adpcm_step_table[p_state->ima_adpcm[i].step_index]; - - - p_state->ima_adpcm[i].step_index += _ima_adpcm_index_table[nibble]; - if (p_state->ima_adpcm[i].step_index<0) - p_state->ima_adpcm[i].step_index=0; - if (p_state->ima_adpcm[i].step_index>88) - p_state->ima_adpcm[i].step_index=88; - - diff = step >> 3 ; - if (nibble & 1) - diff += step >> 2 ; - if (nibble & 2) - diff += step >> 1 ; - if (nibble & 4) - diff += step ; - if (nibble & 8) - diff = -diff ; - - p_state->ima_adpcm[i].predictor+=diff; - if (p_state->ima_adpcm[i].predictor<-0x8000) - p_state->ima_adpcm[i].predictor=-0x8000; - else if (p_state->ima_adpcm[i].predictor>0x7FFF) - p_state->ima_adpcm[i].predictor=0x7FFF; - - - /* store loop if there */ - if (p_state->ima_adpcm[i].last_nibble==p_state->ima_adpcm[i].loop_pos) { - - p_state->ima_adpcm[i].loop_step_index = p_state->ima_adpcm[i].step_index; - p_state->ima_adpcm[i].loop_predictor = p_state->ima_adpcm[i].predictor; - } - - //printf("%i - %i - pred %i\n",int(p_state->ima_adpcm[i].last_nibble),int(nibble),int(p_state->ima_adpcm[i].predictor)); - - } - - } - - final=p_state->ima_adpcm[0].predictor; - if (is_stereo) { - final_r=p_state->ima_adpcm[1].predictor; - } - - } else { - final=p_src[pos]; - if (is_stereo) - final_r=p_src[pos+1]; - - if (sizeof(Depth)==1) { /* conditions will not exist anymore when compiled! */ - final<<=8; - if (is_stereo) - final_r<<=8; - } - - if (type==INTERPOLATION_LINEAR) { - - if (is_stereo) { - - next=p_src[pos+2]; - next_r=p_src[pos+3]; - } else { - next=p_src[pos+1]; - } - - if (sizeof(Depth)==1) { - next<<=8; - if (is_stereo) - next_r<<=8; - } - - int32_t frac=int32_t(p_state->pos&MIX_FRAC_MASK); - - final=final+((next-final)*frac >> MIX_FRAC_BITS); - if (is_stereo) - final_r=final_r+((next_r-final_r)*frac >> MIX_FRAC_BITS); - } - } - - if (use_filter) { - - Channel::Mix::Filter *f = p_state->filter_l; - float finalf=final; - float pre = finalf; - finalf = ((finalf*p_state->coefs.b0) + (f->hb[0]*p_state->coefs.b1) + (f->hb[1]*p_state->coefs.b2) + (f->ha[0]*p_state->coefs.a1) + (f->ha[1]*p_state->coefs.a2) - ); - - f->ha[1]=f->ha[0]; - f->hb[1]=f->hb[0]; - f->hb[0]=pre; - f->ha[0]=finalf; - - final=Math::fast_ftoi(finalf); - - if (is_stereo) { - - f = p_state->filter_r; - finalf=final_r; - pre = finalf; - finalf = ((finalf*p_state->coefs.b0) + (f->hb[0]*p_state->coefs.b1) + (f->hb[1]*p_state->coefs.b2) + (f->ha[0]*p_state->coefs.a1) + (f->ha[1]*p_state->coefs.a2) - ); - f->ha[1]=f->ha[0]; - f->hb[1]=f->hb[0]; - f->hb[0]=pre; - f->ha[0]=finalf; - - final_r=Math::fast_ftoi(finalf); - - } - - p_state->coefs.b0+=p_state->coefs_inc.b0; - p_state->coefs.b1+=p_state->coefs_inc.b1; - p_state->coefs.b2+=p_state->coefs_inc.b2; - p_state->coefs.a1+=p_state->coefs_inc.a1; - p_state->coefs.a2+=p_state->coefs_inc.a2; - } - - if (!is_stereo) { - final_r=final; //copy to right channel if stereo - } - - //convert back to 24 bits and mix to buffers - - if (mix_mode==MIX_STEREO) { - *p_dst++ +=(final*(p_state->vol[0]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - *p_dst++ +=(final_r*(p_state->vol[1]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - - p_state->vol[0]+=p_state->vol_inc[0]; - p_state->vol[1]+=p_state->vol_inc[1]; - - if (use_fx) { - *reverb_dst++ +=(final*(p_state->reverb_vol[0]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - *reverb_dst++ +=(final_r*(p_state->reverb_vol[1]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - p_state->reverb_vol[0]+=p_state->reverb_vol_inc[0]; - p_state->reverb_vol[1]+=p_state->reverb_vol_inc[1]; - } - - - } else if (mix_mode==MIX_QUAD) { - - *p_dst++ +=(final*(p_state->vol[0]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - *p_dst++ +=(final_r*(p_state->vol[1]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - - *p_dst++ +=(final*(p_state->vol[2]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - *p_dst++ +=(final_r*(p_state->vol[3]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - - p_state->vol[0]+=p_state->vol_inc[0]; - p_state->vol[1]+=p_state->vol_inc[1]; - p_state->vol[2]+=p_state->vol_inc[2]; - p_state->vol[3]+=p_state->vol_inc[3]; - - if (use_fx) { - *reverb_dst++ +=(final*(p_state->reverb_vol[0]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - *reverb_dst++ +=(final_r*(p_state->reverb_vol[1]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - *reverb_dst++ +=(final*(p_state->reverb_vol[2]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - *reverb_dst++ +=(final_r*(p_state->reverb_vol[3]>>MIX_VOLRAMP_FRAC_BITS))>>MIX_VOL_MOVE_TO_24; - p_state->reverb_vol[0]+=p_state->reverb_vol_inc[0]; - p_state->reverb_vol[1]+=p_state->reverb_vol_inc[1]; - p_state->reverb_vol[2]+=p_state->reverb_vol_inc[2]; - p_state->reverb_vol[3]+=p_state->reverb_vol_inc[3]; - } - } - - p_state->pos+=p_state->increment; - } -} - - -void AudioMixerSW::mix_channel(Channel& c) { - - - if (!sample_manager->is_sample(c.sample)) { - // sample is gone! - c.active=false; - return; - } - - - /* some 64-bit fixed point precaches */ - - int64_t loop_begin_fp=((int64_t)sample_manager->sample_get_loop_begin(c.sample) << MIX_FRAC_BITS); - int64_t loop_end_fp=((int64_t)sample_manager->sample_get_loop_end(c.sample) << MIX_FRAC_BITS); - int64_t length_fp=((int64_t)sample_manager->sample_get_length(c.sample) << MIX_FRAC_BITS); - int64_t begin_limit=(sample_manager->sample_get_loop_format(c.sample)!=AS::SAMPLE_LOOP_NONE)?loop_begin_fp:0; - int64_t end_limit=(sample_manager->sample_get_loop_format(c.sample)!=AS::SAMPLE_LOOP_NONE)?loop_end_fp:length_fp; - bool is_stereo=sample_manager->sample_is_stereo(c.sample); - - int32_t todo=mix_chunk_size; - //int mixed=0; - bool use_filter=false; - - ResamplerState rstate; - - /* compute voume ramps, increment, etc */ - - - - for(int i=0;i<mix_channels;i++) { - c.mix.old_vol[i]=c.mix.vol[i]; - c.mix.old_reverb_vol[i]=c.mix.reverb_vol[i]; - c.mix.old_chorus_vol[i]=c.mix.chorus_vol[i]; - } - - float vol = c.vol*channel_nrg; - - float reverb_vol = c.reverb_send*channel_nrg; - float chorus_vol = c.chorus_send*channel_nrg; - - if (mix_channels==2) { - //stereo pan - float pan = c.pan * 0.5 + 0.5; - float panv[2]={ - (1.0 - pan)*(1<<MIX_VOL_FRAC_BITS), - (pan)*(1<<MIX_VOL_FRAC_BITS) - }; - - for(int i=0;i<2;i++) { - - c.mix.vol[i]=Math::fast_ftoi(vol*panv[i]); - c.mix.reverb_vol[i]=Math::fast_ftoi(reverb_vol*panv[i]); - c.mix.chorus_vol[i]=Math::fast_ftoi(chorus_vol*panv[i]); - } - - } else { - //qudra pan - float panx = c.pan * 0.5 + 0.5; - float pany = c.depth * 0.5 + 0.5; - // with this model every speaker plays at 0.25 energy at the center.. i'm not sure if it's correct but it seems to be balanced - float panv[4]={ - (1.0-pany)*(1.0-panx)*(1<<MIX_VOL_FRAC_BITS), - (1.0-pany)*( panx)*(1<<MIX_VOL_FRAC_BITS), - ( pany)*(1.0-panx)*(1<<MIX_VOL_FRAC_BITS), - ( pany)*( panx)*(1<<MIX_VOL_FRAC_BITS) - }; - - for(int i=0;i<4;i++) { - - c.mix.vol[i]=Math::fast_ftoi(vol*panv[i]); - c.mix.reverb_vol[i]=Math::fast_ftoi(reverb_vol*panv[i]); - c.mix.chorus_vol[i]=Math::fast_ftoi(chorus_vol*panv[i]); - } - - } - - if (c.first_mix) { // avoid ramp up - - for(int i=0;i<mix_channels;i++) { - c.mix.old_vol[i]=c.mix.vol[i]; - c.mix.old_reverb_vol[i]=c.mix.reverb_vol[i]; - c.mix.old_chorus_vol[i]=c.mix.chorus_vol[i]; - } - - c.first_mix=false; - } - - - - Channel::Filter::Coefs filter_coefs; - Channel::Filter::Coefs filter_inc; - - if (c.filter.type!=AudioMixer::FILTER_NONE) { - - filter_coefs=c.filter.old_coefs; - filter_inc.b0=(c.filter.coefs.b0-filter_coefs.b0)/(1<<mix_chunk_bits); - filter_inc.b1=(c.filter.coefs.b1-filter_coefs.b1)/(1<<mix_chunk_bits); - filter_inc.b2=(c.filter.coefs.b2-filter_coefs.b2)/(1<<mix_chunk_bits); - filter_inc.a1=(c.filter.coefs.a1-filter_coefs.a1)/(1<<mix_chunk_bits); - filter_inc.a2=(c.filter.coefs.a2-filter_coefs.a2)/(1<<mix_chunk_bits); - use_filter=true; - } - - if (c.mix.increment>0) - c.mix.increment=((int64_t)c.speed<<MIX_FRAC_BITS)/mix_rate; - else - c.mix.increment=-((int64_t)c.speed<<MIX_FRAC_BITS)/mix_rate; - - //volume ramp - - - for(int i=0;i<mix_channels;i++) { - rstate.vol_inc[i]=((c.mix.vol[i]-c.mix.old_vol[i])<<MIX_VOLRAMP_FRAC_BITS)>>mix_chunk_bits; - rstate.vol[i]=c.mix.old_vol[i]<<MIX_VOLRAMP_FRAC_BITS; - rstate.reverb_vol_inc[i]=((c.mix.reverb_vol[i]-c.mix.old_reverb_vol[i])<<MIX_VOLRAMP_FRAC_BITS)>>mix_chunk_bits; - rstate.reverb_vol[i]=c.mix.old_reverb_vol[i]<<MIX_VOLRAMP_FRAC_BITS; - rstate.chorus_vol_inc[i]=((c.mix.chorus_vol[i]-c.mix.old_chorus_vol[i])<<MIX_VOLRAMP_FRAC_BITS)>>mix_chunk_bits; - rstate.chorus_vol[i]=c.mix.old_chorus_vol[i]<<MIX_VOLRAMP_FRAC_BITS; - } - - - //looping - - AS::SampleLoopFormat loop_format=sample_manager->sample_get_loop_format(c.sample); - AS::SampleFormat format=sample_manager->sample_get_format(c.sample); - - bool use_fx=false; - - if (fx_enabled) { - - for(int i=0;i<mix_channels;i++) { - if (c.mix.old_reverb_vol[i] || c.mix.reverb_vol[i] || c.mix.old_chorus_vol[i] || c.mix.chorus_vol[i] ) { - use_fx=true; - break; - } - } - } - - /* audio data */ - - const void *data=sample_manager->sample_get_data_ptr(c.sample); - int32_t *dst_buff=mix_buffer; - -#ifndef NO_REVERB - rstate.reverb_buffer=reverb_state[c.reverb_room].buffer; -#endif - - /* @TODO validar loops al registrar? */ - - rstate.coefs=filter_coefs; - rstate.coefs_inc=filter_inc; - rstate.filter_l=&c.mix.filter_l; - rstate.filter_r=&c.mix.filter_r; - - if (format==AS::SAMPLE_FORMAT_IMA_ADPCM) { - - rstate.ima_adpcm=c.mix.ima_adpcm; - if (loop_format!=AS::SAMPLE_LOOP_NONE) { - c.mix.ima_adpcm[0].loop_pos=loop_begin_fp>>MIX_FRAC_BITS; - c.mix.ima_adpcm[1].loop_pos=loop_begin_fp>>MIX_FRAC_BITS; - loop_format=AS::SAMPLE_LOOP_FORWARD; - } - } - - while (todo>0) { - - int64_t limit=0; - int32_t target=0,aux=0; - - /** LOOP CHECKING **/ - - if ( c.mix.increment < 0 ) { - /* going backwards */ - - if ( loop_format!=AS::SAMPLE_LOOP_NONE && c.mix.offset < loop_begin_fp ) { - /* loopstart reached */ - if ( loop_format==AS::SAMPLE_LOOP_PING_PONG ) { - /* bounce ping pong */ - c.mix.offset= loop_begin_fp + ( loop_begin_fp-c.mix.offset ); - c.mix.increment=-c.mix.increment; - } else { - /* go to loop-end */ - c.mix.offset=loop_end_fp-(loop_begin_fp-c.mix.offset); - } - } else { - /* check for sample not reaching begining */ - if(c.mix.offset < 0) { - - c.active=false; - break; - } - } - } else { - /* going forward */ - if( loop_format!=AS::SAMPLE_LOOP_NONE && c.mix.offset >= loop_end_fp ) { - /* loopend reached */ - - if ( loop_format==AS::SAMPLE_LOOP_PING_PONG ) { - /* bounce ping pong */ - c.mix.offset=loop_end_fp-(c.mix.offset-loop_end_fp); - c.mix.increment=-c.mix.increment; - } else { - /* go to loop-begin */ - - if (format==AS::SAMPLE_FORMAT_IMA_ADPCM) { - for(int i=0;i<2;i++) { - c.mix.ima_adpcm[i].step_index=c.mix.ima_adpcm[i].loop_step_index; - c.mix.ima_adpcm[i].predictor=c.mix.ima_adpcm[i].loop_predictor; - c.mix.ima_adpcm[i].last_nibble=loop_begin_fp>>MIX_FRAC_BITS; - } - c.mix.offset=loop_begin_fp; - } else { - c.mix.offset=loop_begin_fp+(c.mix.offset-loop_end_fp); - } - - } - } else { - /* no loop, check for end of sample */ - if(c.mix.offset >= length_fp) { - - c.active=false; - break; - } - } - } - - /** MIXCOUNT COMPUTING **/ - - /* next possible limit (looppoints or sample begin/end */ - limit=(c.mix.increment < 0) ?begin_limit:end_limit; - - /* compute what is shorter, the todo or the limit? */ - aux=(limit-c.mix.offset)/c.mix.increment+1; - target=(aux<todo)?aux:todo; /* mix target is the shorter buffer */ - - /* check just in case */ - if ( target<=0 ) { - c.active=false; - break; - } - - todo-=target; - - int32_t offset=c.mix.offset&mix_chunk_mask; /* strip integer */ - c.mix.offset-=offset; - - rstate.increment=c.mix.increment; - rstate.amount=target; - rstate.pos=offset; - -/* Macros to call the resample function for all possibilities, creating a dedicated-non branchy function call for each thanks to template magic*/ - -#define CALL_RESAMPLE_FUNC( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ - do_resample<m_depth,m_stereo,m_ima_adpcm, m_use_filter,m_use_fx,m_interp, m_mode>(\ - src_ptr,\ - dst_buff,&rstate); - - -#define CALL_RESAMPLE_INTERP( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ - if(m_interp==INTERPOLATION_RAW) {\ - CALL_RESAMPLE_FUNC(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,INTERPOLATION_RAW,m_mode);\ - } else if(m_interp==INTERPOLATION_LINEAR) {\ - CALL_RESAMPLE_FUNC(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,INTERPOLATION_LINEAR,m_mode);\ - } else if(m_interp==INTERPOLATION_CUBIC) {\ - CALL_RESAMPLE_FUNC(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,INTERPOLATION_CUBIC,m_mode);\ - }\ - -#define CALL_RESAMPLE_FX( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ - if(m_use_fx) {\ - CALL_RESAMPLE_INTERP(m_depth,m_stereo, m_ima_adpcm,m_use_filter,true,m_interp, m_mode);\ - } else {\ - CALL_RESAMPLE_INTERP(m_depth,m_stereo, m_ima_adpcm,m_use_filter,false,m_interp, m_mode);\ - }\ - - -#define CALL_RESAMPLE_FILTER( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ - if(m_use_filter) {\ - CALL_RESAMPLE_FX(m_depth,m_stereo, m_ima_adpcm,true,m_use_fx,m_interp, m_mode);\ - } else {\ - CALL_RESAMPLE_FX(m_depth,m_stereo, m_ima_adpcm,false,m_use_fx,m_interp, m_mode);\ - }\ - -#define CALL_RESAMPLE_STEREO( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ - if(m_stereo) {\ - CALL_RESAMPLE_FILTER(m_depth,true,m_ima_adpcm, m_use_filter,m_use_fx,m_interp, m_mode);\ - } else {\ - CALL_RESAMPLE_FILTER(m_depth,false,m_ima_adpcm,m_use_filter,m_use_fx,m_interp, m_mode);\ - }\ - -#define CALL_RESAMPLE_MODE( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ - if(m_mode==MIX_STEREO) {\ - CALL_RESAMPLE_STEREO(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,m_interp, MIX_STEREO);\ - } else {\ - CALL_RESAMPLE_STEREO(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,m_interp, MIX_QUAD);\ - }\ - - - - - if (format==AS::SAMPLE_FORMAT_PCM8) { - - int8_t *src_ptr = &((int8_t*)data)[(c.mix.offset >> MIX_FRAC_BITS)<<(is_stereo?1:0) ]; - CALL_RESAMPLE_MODE(int8_t,is_stereo,false,use_filter,use_fx,interpolation_type,mix_channels); - - } else if (format==AS::SAMPLE_FORMAT_PCM16) { - int16_t *src_ptr = &((int16_t*)data)[(c.mix.offset >> MIX_FRAC_BITS)<<(is_stereo?1:0) ]; - CALL_RESAMPLE_MODE(int16_t,is_stereo,false,use_filter,use_fx,interpolation_type,mix_channels); - - } else if (format==AS::SAMPLE_FORMAT_IMA_ADPCM) { - for(int i=0;i<2;i++) { - c.mix.ima_adpcm[i].window_ofs=c.mix.offset>>MIX_FRAC_BITS; - c.mix.ima_adpcm[i].ptr=(const uint8_t*)data; - } - int8_t *src_ptr = NULL; - CALL_RESAMPLE_MODE(int8_t,is_stereo,true,use_filter,use_fx,interpolation_type,mix_channels); - - } - - c.mix.offset+=rstate.pos; - dst_buff+=target*mix_channels; - rstate.reverb_buffer+=target*mix_channels; - } - - c.filter.old_coefs=c.filter.coefs; -} - -void AudioMixerSW::mix_chunk() { - - ERR_FAIL_COND(mix_chunk_left); - - inside_mix=true; - - // emit tick in usecs - for (int i=0;i<mix_chunk_size*mix_channels;i++) { - - mix_buffer[i]=0; - } -#ifndef NO_REVERB - for(int i=0;i<max_reverbs;i++) - reverb_state[i].used_in_chunk=false; -#endif - - - audio_mixer_chunk_call(mix_chunk_size); - - int ac=0; - for (int i=0;i<MAX_CHANNELS;i++) { - - if (!channels[i].active) - continue; - ac++; - - /* process volume */ - Channel&c=channels[i]; -#ifndef NO_REVERB - bool has_reverb = c.reverb_send>CMP_EPSILON && fx_enabled; - if (has_reverb || c.had_prev_reverb) { - - if (!reverb_state[c.reverb_room].used_in_chunk) { - //zero the room - int32_t *buff = reverb_state[c.reverb_room].buffer; - int len = mix_chunk_size*mix_channels; - for (int j=0;j<len;j++) { - - buff[j]=0; // buffer in use, clear it for appending - } - reverb_state[c.reverb_room].used_in_chunk=true; - } - } -#else - bool has_reverb = false; -#endif - bool has_chorus = c.chorus_send>CMP_EPSILON && fx_enabled; - - - mix_channel(c); - - c.had_prev_reverb=has_reverb; - c.had_prev_chorus=has_chorus; - - } - - //process reverb -#ifndef NO_REVERB - if (fx_enabled) { - - - for(int i=0;i<max_reverbs;i++) { - - if (!reverb_state[i].enabled && !reverb_state[i].used_in_chunk) - continue; //this reverb is not in use - - int32_t *src=NULL; - - if (reverb_state[i].used_in_chunk) - src=reverb_state[i].buffer; - else - src=zero_buffer; - - bool in_use=false; - - int passes=mix_channels/2; - - for(int j=0;j<passes;j++) { - - if (reverb_state[i].reverb[j].process((int*)&src[j*2],(int*)&mix_buffer[j*2],mix_chunk_size,passes)) - in_use=true; - } - - if (in_use) { - reverb_state[i].enabled=true; - reverb_state[i].frames_idle=0; - //copy data over - - } else { - reverb_state[i].frames_idle+=mix_chunk_size; - if (false) { // go idle because too many frames passed - //disable this reverb, as nothing important happened on it - reverb_state[i].enabled=false; - reverb_state[i].frames_idle=0; - } - } - - } - } -#endif - mix_chunk_left=mix_chunk_size; - inside_mix=false; -} - -int AudioMixerSW::mix(int32_t *p_buffer,int p_frames) { - - int todo=p_frames; - int mixes=0; - - while(todo) { - - - if (!mix_chunk_left) { - - if (step_callback) - step_callback(step_udata); - mix_chunk(); - mixes++; - } - - int to_mix=MIN(mix_chunk_left,todo); - int from=mix_chunk_size-mix_chunk_left; - - for (int i=0;i<to_mix*2;i++) { - - (*p_buffer++)=mix_buffer[from*2+i]; - } - - mix_chunk_left-=to_mix; - todo-=to_mix; - } - - return mixes; -} - -uint64_t AudioMixerSW::get_step_usecs() const { - - double mct = (1<<mix_chunk_bits)/double(mix_rate); - return mct*1000000.0; -} - -int AudioMixerSW::_get_channel(ChannelID p_channel) const { - - if (p_channel<0) { - return -1; - } - - int idx=p_channel%MAX_CHANNELS; - int check=p_channel/MAX_CHANNELS; - ERR_FAIL_INDEX_V(idx,MAX_CHANNELS,-1); - if (channels[idx].check!=check) { - return -1; - } - if (!channels[idx].active) { - return -1; - } - - return idx; -} - -AudioMixer::ChannelID AudioMixerSW::channel_alloc(RID p_sample) { - - ERR_FAIL_COND_V( !sample_manager->is_sample(p_sample), INVALID_CHANNEL ); - - - int index=-1; - for (int i=0;i<MAX_CHANNELS;i++) { - - if (!channels[i].active) { - index=i; - break; - } - } - - if (index==-1) - return INVALID_CHANNEL; - - Channel &c=channels[index]; - - // init variables - c.sample=p_sample; - c.vol=1; - c.pan=0; - c.depth=0; - c.height=0; - c.chorus_send=0; - c.reverb_send=0; - c.reverb_room=REVERB_HALL; - c.positional=false; - c.filter.type=FILTER_NONE; - c.speed=sample_manager->sample_get_mix_rate(p_sample); - c.active=true; - c.check=channel_id_count++; - c.first_mix=true; - - // init mix variables - - c.mix.offset=0; - c.mix.increment=1; - //zero everything when this errors - for(int i=0;i<4;i++) { - c.mix.vol[i]=0; - c.mix.reverb_vol[i]=0; - c.mix.chorus_vol[i]=0; - - c.mix.old_vol[i]=0; - c.mix.old_reverb_vol[i]=0; - c.mix.old_chorus_vol[i]=0; - } - - c.had_prev_chorus=false; - c.had_prev_reverb=false; - c.had_prev_vol=false; - - - if (sample_manager->sample_get_format(c.sample)==AudioServer::SAMPLE_FORMAT_IMA_ADPCM) { - - for(int i=0;i<2;i++) { - c.mix.ima_adpcm[i].step_index=0; - c.mix.ima_adpcm[i].predictor=0; - c.mix.ima_adpcm[i].loop_step_index=0; - c.mix.ima_adpcm[i].loop_predictor=0; - c.mix.ima_adpcm[i].last_nibble=-1; - c.mix.ima_adpcm[i].loop_pos=0x7FFFFFFF; - c.mix.ima_adpcm[i].window_ofs=0; - c.mix.ima_adpcm[i].ptr=NULL; - } - } - - ChannelID ret_id = index+c.check*MAX_CHANNELS; - - return ret_id; - -} - -void AudioMixerSW::channel_set_volume(ChannelID p_channel, float p_gain) { - - if (p_gain>3) // avoid gain going too high - p_gain=3; - if (p_gain<0) - p_gain=0; - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return; - Channel &c = channels[chan]; - - //Math::exp( p_db * 0.11512925464970228420089957273422 ); - c.vol=p_gain; - -} - -void AudioMixerSW::channel_set_pan(ChannelID p_channel, float p_pan, float p_depth,float p_height) { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return; - Channel &c = channels[chan]; - - c.pan=p_pan; - c.depth=p_depth; - c.height=p_height; - -} -void AudioMixerSW::channel_set_filter(ChannelID p_channel, FilterType p_type, float p_cutoff, float p_resonance, float p_gain) { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return; - - Channel &c = channels[chan]; - - if (c.filter.type==p_type && c.filter.cutoff==p_cutoff && c.filter.resonance==p_resonance && c.filter.gain==p_gain) - return; //bye - - - bool type_changed = p_type!=c.filter.type; - - c.filter.type=p_type; - c.filter.cutoff=p_cutoff; - c.filter.resonance=p_resonance; - c.filter.gain=p_gain; - - - AudioFilterSW filter; - switch(p_type) { - case FILTER_NONE: { - - return; //do nothing else - } break; - case FILTER_LOWPASS: { - filter.set_mode(AudioFilterSW::LOWPASS); - } break; - case FILTER_BANDPASS: { - filter.set_mode(AudioFilterSW::BANDPASS); - } break; - case FILTER_HIPASS: { - filter.set_mode(AudioFilterSW::HIGHPASS); - } break; - case FILTER_NOTCH: { - filter.set_mode(AudioFilterSW::NOTCH); - } break; - case FILTER_PEAK: { - filter.set_mode(AudioFilterSW::PEAK); - } break; - case FILTER_BANDLIMIT: { - filter.set_mode(AudioFilterSW::BANDLIMIT); - } break; - case FILTER_LOW_SHELF: { - filter.set_mode(AudioFilterSW::LOWSHELF); - } break; - case FILTER_HIGH_SHELF: { - filter.set_mode(AudioFilterSW::HIGHSHELF); - } break; - } - - filter.set_cutoff(p_cutoff); - filter.set_resonance(p_resonance); - filter.set_gain(p_gain); - filter.set_sampling_rate(mix_rate); - filter.set_stages(1); - - AudioFilterSW::Coeffs coefs; - filter.prepare_coefficients(&coefs); - - if (!type_changed) - c.filter.old_coefs=c.filter.coefs; - - c.filter.coefs.b0=coefs.b0; - c.filter.coefs.b1=coefs.b1; - c.filter.coefs.b2=coefs.b2; - c.filter.coefs.a1=coefs.a1; - c.filter.coefs.a2=coefs.a2; - - - if (type_changed) { - //type changed reset filter - c.filter.old_coefs=c.filter.coefs; - c.mix.filter_l.ha[0]=0; - c.mix.filter_l.ha[1]=0; - c.mix.filter_l.hb[0]=0; - c.mix.filter_l.hb[1]=0; - c.mix.filter_r.ha[0]=0; - c.mix.filter_r.ha[1]=0; - c.mix.filter_r.hb[0]=0; - c.mix.filter_r.hb[1]=0; - } - - -} -void AudioMixerSW::channel_set_chorus(ChannelID p_channel, float p_chorus ) { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return; - - Channel &c = channels[chan]; - c.chorus_send=p_chorus; - -} -void AudioMixerSW::channel_set_reverb(ChannelID p_channel, ReverbRoomType p_room_type, float p_reverb) { - - ERR_FAIL_INDEX(p_room_type,MAX_REVERBS); - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return; - - Channel &c = channels[chan]; - c.reverb_room=p_room_type; - c.reverb_send=p_reverb; - -} - -void AudioMixerSW::channel_set_mix_rate(ChannelID p_channel, int p_mix_rate) { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return; - - Channel &c = channels[chan]; - c.speed=p_mix_rate; - -} -void AudioMixerSW::channel_set_positional(ChannelID p_channel, bool p_positional) { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return; - - Channel &c = channels[chan]; - c.positional=p_positional; -} - -float AudioMixerSW::channel_get_volume(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return 0; - - const Channel &c = channels[chan]; - //Math::log( c.vol ) * 8.6858896380650365530225783783321; - return c.vol; -} - -float AudioMixerSW::channel_get_pan(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return 0; - - const Channel &c = channels[chan]; - return c.pan; -} -float AudioMixerSW::channel_get_pan_depth(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return 0; - - const Channel &c = channels[chan]; - return c.depth; -} -float AudioMixerSW::channel_get_pan_height(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return 0; - - const Channel &c = channels[chan]; - return c.height; - -} -AudioMixer::FilterType AudioMixerSW::channel_get_filter_type(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return FILTER_NONE; - - const Channel &c = channels[chan]; - return c.filter.type; -} -float AudioMixerSW::channel_get_filter_cutoff(ChannelID p_channel) const { - - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return 0; - - const Channel &c = channels[chan]; - return c.filter.cutoff; - -} -float AudioMixerSW::channel_get_filter_resonance(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return 0; - - const Channel &c = channels[chan]; - return c.filter.resonance; - -} - -float AudioMixerSW::channel_get_filter_gain(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return 0; - - const Channel &c = channels[chan]; - return c.filter.gain; -} - - -float AudioMixerSW::channel_get_chorus(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return 0; - - const Channel &c = channels[chan]; - return c.chorus_send; - -} -AudioMixer::ReverbRoomType AudioMixerSW::channel_get_reverb_type(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return REVERB_HALL; - - const Channel &c = channels[chan]; - return c.reverb_room; - -} -float AudioMixerSW::channel_get_reverb(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return 0; - - const Channel &c = channels[chan]; - return c.reverb_send; -} - -int AudioMixerSW::channel_get_mix_rate(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return 0; - - const Channel &c = channels[chan]; - return c.speed; -} -bool AudioMixerSW::channel_is_positional(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return false; - - const Channel &c = channels[chan]; - return c.positional; -} - -bool AudioMixerSW::channel_is_valid(ChannelID p_channel) const { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return false; - return channels[chan].active; -} - - -void AudioMixerSW::channel_free(ChannelID p_channel) { - - int chan = _get_channel(p_channel); - if (chan<0 || chan >=MAX_CHANNELS) - return; - - Channel &c=channels[chan]; - - if (!c.active) - return; - - bool has_vol=false; - - for(int i=0;i<mix_channels;i++) { - - if (c.mix.vol[i]) - has_vol=true; - if (c.mix.reverb_vol[i]) - has_vol=true; - if (c.mix.chorus_vol[i]) - has_vol=true; - } - if (c.active && has_vol && inside_mix) { - // drive voice to zero, and run a chunk, the VRAMP will fade it good - c.vol=0; - c.reverb_send=0; - c.chorus_send=0; - mix_channel(c); - } - /* @TODO RAMP DOWN ON STOP */ - c.active=false; -} - - - -AudioMixerSW::AudioMixerSW(SampleManagerSW *p_sample_manager,int p_desired_latency_ms,int p_mix_rate,MixChannels p_mix_channels,bool p_use_fx,InterpolationType p_interp,MixStepCallback p_step_callback,void *p_step_udata) { - - if (OS::get_singleton()->is_stdout_verbose()) { - print_line("AudioServerSW Params: "); - print_line(" -mix chans: "+itos(p_mix_channels)); - print_line(" -mix rate: "+itos(p_mix_rate)); - print_line(" -latency: "+itos(p_desired_latency_ms)); - print_line(" -fx: "+itos(p_use_fx)); - print_line(" -interp: "+itos(p_interp)); - } - sample_manager=p_sample_manager; - mix_channels=p_mix_channels; - mix_rate=p_mix_rate; - step_callback=p_step_callback; - step_udata=p_step_udata; - - - mix_chunk_bits=nearest_shift( p_desired_latency_ms * p_mix_rate / 1000 ); - - mix_chunk_size=(1<<mix_chunk_bits); - mix_chunk_mask=mix_chunk_size-1; - mix_buffer = memnew_arr(int32_t,mix_chunk_size*mix_channels); -#ifndef NO_REVERB - zero_buffer = memnew_arr(int32_t,mix_chunk_size*mix_channels); - for(int i=0;i<mix_chunk_size*mix_channels;i++) - zero_buffer[i]=0; //zero buffer is zero... - - max_reverbs=MAX_REVERBS; - int reverberators=mix_channels/2; - - reverb_state = memnew_arr(ReverbState,max_reverbs); - for(int i=0;i<max_reverbs;i++) { - reverb_state[i].enabled=false; - reverb_state[i].reverb = memnew_arr(ReverbSW,reverberators); - reverb_state[i].buffer = memnew_arr(int32_t,mix_chunk_size*mix_channels); - reverb_state[i].frames_idle=0; - for(int j=0;j<reverberators;j++) { - static ReverbSW::ReverbMode modes[MAX_REVERBS]={ReverbSW::REVERB_MODE_STUDIO_SMALL,ReverbSW::REVERB_MODE_STUDIO_MEDIUM,ReverbSW::REVERB_MODE_STUDIO_LARGE,ReverbSW::REVERB_MODE_HALL}; - reverb_state[i].reverb[j].set_mix_rate(p_mix_rate); - reverb_state[i].reverb[j].set_mode(modes[i]); - } - - } - fx_enabled=p_use_fx; -#else - fx_enabled=false; -#endif - mix_chunk_left=0; - - interpolation_type=p_interp; - channel_id_count=1; - inside_mix=false; - channel_nrg=1.0; - -} - -void AudioMixerSW::set_mixer_volume(float p_volume) { - - channel_nrg=p_volume; -} - -AudioMixerSW::~AudioMixerSW() { - - memdelete_arr(mix_buffer); - -#ifndef NO_REVERB - memdelete_arr(zero_buffer); - for(int i=0;i<max_reverbs;i++) { - memdelete_arr(reverb_state[i].reverb); - memdelete_arr(reverb_state[i].buffer); - } - memdelete_arr(reverb_state); -#endif - - -} diff --git a/servers/audio/audio_mixer_sw.h b/servers/audio/audio_mixer_sw.h deleted file mode 100644 index 952cad4cfa..0000000000 --- a/servers/audio/audio_mixer_sw.h +++ /dev/null @@ -1,264 +0,0 @@ -/*************************************************************************/ -/* audio_mixer_sw.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef AUDIO_MIXER_SW_H -#define AUDIO_MIXER_SW_H - -#include "servers/audio_server.h" -#include "servers/audio/sample_manager_sw.h" -#include "servers/audio/audio_filter_sw.h" -#include "servers/audio/reverb_sw.h" - -class AudioMixerSW : public AudioMixer { -public: - - enum InterpolationType { - - INTERPOLATION_RAW, - INTERPOLATION_LINEAR, - INTERPOLATION_CUBIC - }; - - enum MixChannels { - - MIX_STEREO=2, - MIX_QUAD=4 - }; - - typedef void (*MixStepCallback)(void*); - -private: - SampleManagerSW *sample_manager; - - enum { - - MAX_CHANNELS=64, - // fixed point defs - - MIX_FRAC_BITS=13, - MIX_FRAC_LEN=(1<<MIX_FRAC_BITS), - MIX_FRAC_MASK=MIX_FRAC_LEN-1, - MIX_VOL_FRAC_BITS=12, - MIX_VOLRAMP_FRAC_BITS=16, - MIX_VOLRAMP_FRAC_LEN=(1<<MIX_VOLRAMP_FRAC_BITS), - MIX_VOLRAMP_FRAC_MASK=MIX_VOLRAMP_FRAC_LEN-1, - MIX_FILTER_FRAC_BITS=16, - MIX_FILTER_RAMP_FRAC_BITS=8, - MIX_VOL_MOVE_TO_24=4 - }; - - - struct Channel { - - RID sample; - struct Mix { - int64_t offset; - int32_t increment; - - int32_t vol[4]; - int32_t reverb_vol[4]; - int32_t chorus_vol[4]; - - int32_t old_vol[4]; - int32_t old_reverb_vol[4]; - int32_t old_chorus_vol[4]; - - - struct Filter { //history (stereo) - float ha[2],hb[2]; - } filter_l,filter_r; - - struct IMA_ADPCM_State { - - int16_t step_index; - int32_t predictor; - /* values at loop point */ - int16_t loop_step_index; - int32_t loop_predictor; - int32_t last_nibble; - int32_t loop_pos; - int32_t window_ofs; - const uint8_t *ptr; - } ima_adpcm[2]; - - } mix; - - float vol; - float pan; - float depth; - float height; - - float chorus_send; - ReverbRoomType reverb_room; - float reverb_send; - int speed; - int check; - bool positional; - - bool had_prev_reverb; - bool had_prev_chorus; - bool had_prev_vol; - - struct Filter { - - bool dirty; - - FilterType type; - float cutoff; - float resonance; - float gain; - - struct Coefs { - - float a1,a2,b0,b1,b2; // fixed point coefficients - } coefs,old_coefs; - - } filter; - - bool first_mix; - bool active; - Channel() { active=false; check=-1; first_mix=false; filter.dirty=true; filter.type=FILTER_NONE; filter.cutoff=8000; filter.resonance=0; filter.gain=0; } - }; - - Channel channels[MAX_CHANNELS]; - - uint32_t mix_rate; - bool fx_enabled; - InterpolationType interpolation_type; - - int mix_chunk_bits; - int mix_chunk_size; - int mix_chunk_mask; - - int32_t *mix_buffer; - int32_t *zero_buffer; // fx feed when no input was mixed - - struct ResamplerState { - - uint32_t amount; - int32_t increment; - - - int32_t pos; - - - int32_t vol[4]; - int32_t reverb_vol[4]; - int32_t chorus_vol[4]; - - int32_t vol_inc[4]; - int32_t reverb_vol_inc[4]; - int32_t chorus_vol_inc[4]; - - - - Channel::Mix::Filter *filter_l; - Channel::Mix::Filter *filter_r; - Channel::Filter::Coefs coefs; - Channel::Filter::Coefs coefs_inc; - - Channel::Mix::IMA_ADPCM_State *ima_adpcm; - - int32_t *reverb_buffer; - }; - - - - template<class Depth,bool is_stereo,bool use_filter,bool is_ima_adpcm,bool use_fx,InterpolationType type,MixChannels> - _FORCE_INLINE_ void do_resample(const Depth* p_src, int32_t *p_dst, ResamplerState *p_state); - - MixChannels mix_channels; - - void mix_channel(Channel& p_channel); - int mix_chunk_left; - void mix_chunk(); - - float channel_nrg; - int channel_id_count; - bool inside_mix; - MixStepCallback step_callback; - void *step_udata; - _FORCE_INLINE_ int _get_channel(ChannelID p_channel) const; - - int max_reverbs; - struct ReverbState { - - bool used_in_chunk; - bool enabled; - ReverbSW *reverb; - int frames_idle; - int32_t *buffer; //reverb is sent here - ReverbState() { enabled=false; frames_idle=0; used_in_chunk=false; } - }; - - ReverbState *reverb_state; - - -public: - - - virtual ChannelID channel_alloc(RID p_sample); - - virtual void channel_set_volume(ChannelID p_channel, float p_gain); - virtual void channel_set_pan(ChannelID p_channel, float p_pan, float p_depth=0,float height=0); //pan and depth go from -1 to 1 - virtual void channel_set_filter(ChannelID p_channel, FilterType p_type, float p_cutoff, float p_resonance, float p_gain=1.0); - virtual void channel_set_chorus(ChannelID p_channel, float p_chorus ); - virtual void channel_set_reverb(ChannelID p_channel, ReverbRoomType p_room_type, float p_reverb); - virtual void channel_set_mix_rate(ChannelID p_channel, int p_mix_rate); - virtual void channel_set_positional(ChannelID p_channel, bool p_positional); - - virtual float channel_get_volume(ChannelID p_channel) const; - virtual float channel_get_pan(ChannelID p_channel) const; //pan and depth go from -1 to 1 - virtual float channel_get_pan_depth(ChannelID p_channel) const; //pan and depth go from -1 to 1 - virtual float channel_get_pan_height(ChannelID p_channel) const; //pan and depth go from -1 to 1 - virtual FilterType channel_get_filter_type(ChannelID p_channel) const; - virtual float channel_get_filter_cutoff(ChannelID p_channel) const; - virtual float channel_get_filter_resonance(ChannelID p_channel) const; - virtual float channel_get_filter_gain(ChannelID p_channel) const; - - virtual float channel_get_chorus(ChannelID p_channel) const; - virtual ReverbRoomType channel_get_reverb_type(ChannelID p_channel) const; - virtual float channel_get_reverb(ChannelID p_channel) const; - - virtual int channel_get_mix_rate(ChannelID p_channel) const; - virtual bool channel_is_positional(ChannelID p_channel) const; - - virtual bool channel_is_valid(ChannelID p_channel) const; - - virtual void channel_free(ChannelID p_channel); - - int mix(int32_t *p_buffer,int p_frames); //return amount of mixsteps - uint64_t get_step_usecs() const; - - virtual void set_mixer_volume(float p_volume); - - AudioMixerSW(SampleManagerSW *p_sample_manager,int p_desired_latency_ms,int p_mix_rate,MixChannels p_mix_channels,bool p_use_fx=true,InterpolationType p_interp=INTERPOLATION_LINEAR,MixStepCallback p_step_callback=NULL,void *p_callback_udata=NULL); - ~AudioMixerSW(); -}; - -#endif // AUDIO_MIXER_SW_H diff --git a/servers/audio/audio_server_sw.cpp b/servers/audio/audio_server_sw.cpp deleted file mode 100644 index f508a130b4..0000000000 --- a/servers/audio/audio_server_sw.cpp +++ /dev/null @@ -1,1028 +0,0 @@ -/*************************************************************************/ -/* audio_server_sw.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "audio_server_sw.h" -#include "globals.h" -#include "os/os.h" - -struct _AudioDriverLock { - - _AudioDriverLock() { if (AudioDriverSW::get_singleton()) AudioDriverSW::get_singleton()->lock(); } - ~_AudioDriverLock() { if (AudioDriverSW::get_singleton()) AudioDriverSW::get_singleton()->unlock(); } - -}; - -#define AUDIO_LOCK _AudioDriverLock _adlock; - -AudioMixer *AudioServerSW::get_mixer() { - - return mixer; -} - -/* CALLBACKS */ - -void AudioServerSW::audio_mixer_chunk_callback(int p_frames) { -/* - for(List<Stream*>::Element *E=event_streams.front();E;E=E->next()) { - - if (E->get()->active) - E->get()->audio_stream->mix(NULL,p_frames); - } -*/ -} - -void AudioServerSW::_mixer_callback(void *p_udata) { - - AudioServerSW *self = (AudioServerSW*)p_udata; - for(List<Stream*>::Element *E=self->active_audio_streams.front();E;E=E->next()) { - - if (!E->get()->active) - continue; - - EventStream *es=E->get()->event_stream; - if (!es) - continue; - - es->update(self->mixer_step_usecs); - } - -} - -void AudioServerSW::driver_process_chunk(int p_frames,int32_t *p_buffer) { - - - - int samples=p_frames*internal_buffer_channels; - - for(int i=0;i<samples;i++) { - internal_buffer[i]=0; - } - - while(voice_rb.commands_left()) { - - VoiceRBSW::Command cmd = voice_rb.pop_command(); - - if (cmd.type==VoiceRBSW::Command::CMD_CHANGE_ALL_FX_VOLUMES) { - - SelfList<Voice>*al = active_list.first(); - while(al) { - - Voice *v=al->self(); - if (v->channel!=AudioMixer::INVALID_CHANNEL) { - mixer->channel_set_volume(v->channel,v->volume*fx_volume_scale); - } - al=al->next(); - } - - continue; - } - if (!voice_owner.owns(cmd.voice)) - continue; - - - Voice *v = voice_owner.get(cmd.voice); - - switch(cmd.type) { - case VoiceRBSW::Command::CMD_NONE: { - - - } break; - case VoiceRBSW::Command::CMD_PLAY: { - - if (v->channel!=AudioMixer::INVALID_CHANNEL) - mixer->channel_free(v->channel); - - RID sample = cmd.play.sample; - if (!sample_manager->is_sample(sample)) - continue; - - v->channel=mixer->channel_alloc(sample); - v->volume=1.0; - mixer->channel_set_volume(v->channel,fx_volume_scale); - if (v->channel==AudioMixer::INVALID_CHANNEL) { -#ifdef AUDIO_DEBUG - WARN_PRINT("AUDIO: all channels used, failed to allocate voice"); -#endif - v->active=false; - break; // no voices left? - } - - v->active=true; // this kind of ensures it works - if (!v->active_item.in_list()) - active_list.add(&v->active_item); - - } break; - case VoiceRBSW::Command::CMD_STOP: { - - if (v->channel!=AudioMixer::INVALID_CHANNEL) { - mixer->channel_free(v->channel); - if (v->active_item.in_list()) { - active_list.remove(&v->active_item); - } - } - v->active=false; - } break; - case VoiceRBSW::Command::CMD_SET_VOLUME: { - - - if (v->channel!=AudioMixer::INVALID_CHANNEL) { - v->volume=cmd.volume.volume; - mixer->channel_set_volume(v->channel,cmd.volume.volume*fx_volume_scale); - } - - } break; - case VoiceRBSW::Command::CMD_SET_PAN: { - - if (v->channel!=AudioMixer::INVALID_CHANNEL) - mixer->channel_set_pan(v->channel,cmd.pan.pan,cmd.pan.depth,cmd.pan.height); - - } break; - case VoiceRBSW::Command::CMD_SET_FILTER: { - - - if (v->channel!=AudioMixer::INVALID_CHANNEL) - mixer->channel_set_filter(v->channel,(AudioMixer::FilterType)cmd.filter.type,cmd.filter.cutoff,cmd.filter.resonance,cmd.filter.gain); - } break; - case VoiceRBSW::Command::CMD_SET_CHORUS: { - - if (v->channel!=AudioMixer::INVALID_CHANNEL) - mixer->channel_set_chorus(v->channel,cmd.chorus.send); - - } break; - case VoiceRBSW::Command::CMD_SET_REVERB: { - - if (v->channel!=AudioMixer::INVALID_CHANNEL) - mixer->channel_set_reverb(v->channel,(AudioMixer::ReverbRoomType)cmd.reverb.room,cmd.reverb.send); - - } break; - case VoiceRBSW::Command::CMD_SET_MIX_RATE: { - - if (v->channel!=AudioMixer::INVALID_CHANNEL) - mixer->channel_set_mix_rate(v->channel,cmd.mix_rate.mix_rate); - - } break; - case VoiceRBSW::Command::CMD_SET_POSITIONAL: { - - if (v->channel!=AudioMixer::INVALID_CHANNEL) - mixer->channel_set_positional(v->channel,cmd.positional.positional); - - } break; - default: {} - - } - } - - mixer->mix(internal_buffer,p_frames); - //uint64_t stepsize=mixer->get_step_usecs(); - - - for(List<Stream*>::Element *E=active_audio_streams.front();E;E=E->next()) { - - ERR_CONTINUE(!E->get()->active); // bug? - - - AudioStream *as=E->get()->audio_stream; - if (!as) - continue; - - int channels=as->get_channel_count(); - if (channels==0) - continue; // does not want mix - if (!as->mix(stream_buffer,p_frames)) - continue; //nothing was mixed!! - - int32_t stream_vol_scale=(stream_volume*stream_volume_scale*E->get()->volume_scale)*(1<<STREAM_SCALE_BITS); - -#define STRSCALE(m_val) (((m_val>>STREAM_SCALE_BITS)*stream_vol_scale)>>8) - switch(internal_buffer_channels) { - - case 2: { - - switch(channels) { - case 1: { - - for(int i=0;i<p_frames;i++) { - - internal_buffer[(i<<1)+0]+=STRSCALE(stream_buffer[i]); - internal_buffer[(i<<1)+1]+=STRSCALE(stream_buffer[i]); - } - } break; - case 2: { - - for(int i=0;i<p_frames*2;i++) { - - internal_buffer[i]+=STRSCALE(stream_buffer[i]); - } - } break; - case 4: { - - for(int i=0;i<p_frames;i++) { - - internal_buffer[(i<<2)+0]+=STRSCALE((stream_buffer[(i<<2)+0]+stream_buffer[(i<<2)+2])>>1); - internal_buffer[(i<<2)+1]+=STRSCALE((stream_buffer[(i<<2)+1]+stream_buffer[(i<<2)+3])>>1); - } - } break; - - } break; - - } break; - case 4: { - - switch(channels) { - case 1: { - - for(int i=0;i<p_frames;i++) { - - internal_buffer[(i<<2)+0]+=STRSCALE(stream_buffer[i]); - internal_buffer[(i<<2)+1]+=STRSCALE(stream_buffer[i]); - internal_buffer[(i<<2)+2]+=STRSCALE(stream_buffer[i]); - internal_buffer[(i<<2)+3]+=STRSCALE(stream_buffer[i]); - } - } break; - case 2: { - - for(int i=0;i<p_frames*2;i++) { - - internal_buffer[(i<<2)+0]+=STRSCALE(stream_buffer[(i<<1)+0]); - internal_buffer[(i<<2)+1]+=STRSCALE(stream_buffer[(i<<1)+1]); - internal_buffer[(i<<2)+2]+=STRSCALE(stream_buffer[(i<<1)+0]); - internal_buffer[(i<<2)+3]+=STRSCALE(stream_buffer[(i<<1)+1]); - } - } break; - case 4: { - - for(int i=0;i<p_frames*4;i++) { - internal_buffer[i]+=STRSCALE(stream_buffer[i]); - } - } break; - - } break; - - } break; - case 6: { - - - } break; - } - -#undef STRSCALE - } - - SelfList<Voice> *activeE=active_list.first(); - while(activeE) { - - SelfList<Voice> *activeN=activeE->next(); - if (activeE->self()->channel==AudioMixer::INVALID_CHANNEL || !mixer->channel_is_valid(activeE->self()->channel)) { - - active_list.remove(activeE); - activeE->self()->active=false; - - } - activeE=activeN; - } - - uint32_t peak=0; - for(int i=0;i<samples;i++) { - //clamp to (1<<24) using branchless code - int32_t in = internal_buffer[i]; -#ifdef DEBUG_ENABLED - { - int mask = (in >> (32 - 1)); - uint32_t p = (in + mask) ^ mask; - if (p>peak) - peak=p; - } -#endif - int32_t lo = -0x800000, hi=0x7FFFFF; - lo-=in; - hi-=in; - in += (lo & ((lo < 0) - 1)) + (hi & ((hi > 0) - 1)); - p_buffer[i]=in<<8; - } - - if (peak>max_peak) - max_peak=peak; -} - -void AudioServerSW::driver_process(int p_frames,int32_t *p_buffer) { - - - _output_delay=p_frames/double(AudioDriverSW::get_singleton()->get_mix_rate()); - //process in chunks to make sure to never process more than INTERNAL_BUFFER_SIZE - int todo=p_frames; - while(todo) { - - int tomix=MIN(todo,INTERNAL_BUFFER_SIZE); - driver_process_chunk(tomix,p_buffer); - p_buffer+=tomix; - todo-=tomix; - } - - -} - -/* SAMPLE API */ - -RID AudioServerSW::sample_create(SampleFormat p_format, bool p_stereo, int p_length) { - - AUDIO_LOCK - - return sample_manager->sample_create(p_format,p_stereo,p_length); -} - -void AudioServerSW::sample_set_description(RID p_sample, const String& p_description) { - - AUDIO_LOCK - sample_manager->sample_set_description(p_sample,p_description); -} -String AudioServerSW::sample_get_description(RID p_sample) const { - - AUDIO_LOCK - return sample_manager->sample_get_description(p_sample); -} - -AS::SampleFormat AudioServerSW::sample_get_format(RID p_sample) const { - //AUDIO_LOCK - return sample_manager->sample_get_format(p_sample); -} -bool AudioServerSW::sample_is_stereo(RID p_sample) const { - //AUDIO_LOCK - return sample_manager->sample_is_stereo(p_sample); -} -int AudioServerSW::sample_get_length(RID p_sample) const { - ///AUDIO_LOCK - return sample_manager->sample_get_length(p_sample); -} - -const void* AudioServerSW::sample_get_data_ptr(RID p_sample) const { - ///AUDIO_LOCK - return sample_manager->sample_get_data_ptr(p_sample); -} - -void AudioServerSW::sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer) { - AUDIO_LOCK - sample_manager->sample_set_data(p_sample,p_buffer); -} -PoolVector<uint8_t> AudioServerSW::sample_get_data(RID p_sample) const { - AUDIO_LOCK - return sample_manager->sample_get_data(p_sample); -} - -void AudioServerSW::sample_set_mix_rate(RID p_sample,int p_rate) { - AUDIO_LOCK - sample_manager->sample_set_mix_rate(p_sample,p_rate); -} -int AudioServerSW::sample_get_mix_rate(RID p_sample) const { - AUDIO_LOCK - return sample_manager->sample_get_mix_rate(p_sample); -} - -void AudioServerSW::sample_set_loop_format(RID p_sample,SampleLoopFormat p_format) { - AUDIO_LOCK - sample_manager->sample_set_loop_format(p_sample,p_format); -} -AS::SampleLoopFormat AudioServerSW::sample_get_loop_format(RID p_sample) const { - AUDIO_LOCK - return sample_manager->sample_get_loop_format(p_sample); -} - -void AudioServerSW::sample_set_loop_begin(RID p_sample,int p_pos) { - AUDIO_LOCK - sample_manager->sample_set_loop_begin(p_sample,p_pos); -} -int AudioServerSW::sample_get_loop_begin(RID p_sample) const { - AUDIO_LOCK - return sample_manager->sample_get_loop_begin(p_sample); -} - -void AudioServerSW::sample_set_loop_end(RID p_sample,int p_pos) { - AUDIO_LOCK - sample_manager->sample_set_loop_end(p_sample,p_pos); -} -int AudioServerSW::sample_get_loop_end(RID p_sample) const { - AUDIO_LOCK - return sample_manager->sample_get_loop_end(p_sample); -} - -/* VOICE API */ - -RID AudioServerSW::voice_create() { - - Voice * v = memnew( Voice ); - v->channel=AudioMixer::INVALID_CHANNEL; - - AUDIO_LOCK - return voice_owner.make_rid(v); - -} -void AudioServerSW::voice_play(RID p_voice, RID p_sample) { - - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND(!v); - v->active=true; // force actvive (will be disabled later i gues..) - - //stop old, start new - VoiceRBSW::Command cmd; - cmd.type=VoiceRBSW::Command::CMD_PLAY; - cmd.voice=p_voice; - cmd.play.sample=p_sample; - voice_rb.push_command(cmd); - -} - -void AudioServerSW::voice_set_volume(RID p_voice, float p_volume) { - - VoiceRBSW::Command cmd; - cmd.type=VoiceRBSW::Command::CMD_SET_VOLUME; - cmd.voice=p_voice; - cmd.volume.volume=p_volume; - voice_rb.push_command(cmd); - -} -void AudioServerSW::voice_set_pan(RID p_voice, float p_pan, float p_depth,float p_height) { - - VoiceRBSW::Command cmd; - cmd.type=VoiceRBSW::Command::CMD_SET_PAN; - cmd.voice=p_voice; - cmd.pan.pan=p_pan; - cmd.pan.depth=p_depth; - cmd.pan.height=p_height; - voice_rb.push_command(cmd); - -} -void AudioServerSW::voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance,float p_gain) { - - VoiceRBSW::Command cmd; - cmd.type=VoiceRBSW::Command::CMD_SET_FILTER; - cmd.voice=p_voice; - cmd.filter.type=p_type; - cmd.filter.cutoff=p_cutoff; - cmd.filter.resonance=p_resonance; - cmd.filter.gain=p_gain; - voice_rb.push_command(cmd); - -} -void AudioServerSW::voice_set_chorus(RID p_voice, float p_chorus ) { - - VoiceRBSW::Command cmd; - cmd.type=VoiceRBSW::Command::CMD_SET_CHORUS; - cmd.voice=p_voice; - cmd.chorus.send=p_chorus; - voice_rb.push_command(cmd); - -} -void AudioServerSW::voice_set_reverb(RID p_voice, ReverbRoomType p_room_type, float p_reverb) { - - VoiceRBSW::Command cmd; - cmd.type=VoiceRBSW::Command::CMD_SET_REVERB; - cmd.voice=p_voice; - cmd.reverb.room=p_room_type; - cmd.reverb.send=p_reverb; - - voice_rb.push_command(cmd); - -} -void AudioServerSW::voice_set_mix_rate(RID p_voice, int p_mix_rate) { - - VoiceRBSW::Command cmd; - cmd.type=VoiceRBSW::Command::CMD_SET_MIX_RATE; - cmd.voice=p_voice; - cmd.mix_rate.mix_rate=p_mix_rate; - voice_rb.push_command(cmd); - -} -void AudioServerSW::voice_set_positional(RID p_voice, bool p_positional) { - - VoiceRBSW::Command cmd; - cmd.type=VoiceRBSW::Command::CMD_SET_POSITIONAL; - cmd.voice=p_voice; - cmd.positional.positional=p_positional; - voice_rb.push_command(cmd); - -} - -float AudioServerSW::voice_get_volume(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, 0); - - return mixer->channel_get_volume( v->channel ); - -} -float AudioServerSW::voice_get_pan(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, 0); - - return mixer->channel_get_pan( v->channel ); - -} -float AudioServerSW::voice_get_pan_depth(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, 0); - - return mixer->channel_get_pan_depth( v->channel ); - -} -float AudioServerSW::voice_get_pan_height(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, 0); - - return mixer->channel_get_pan_height( v->channel ); - -} -AS::FilterType AudioServerSW::voice_get_filter_type(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, AS::FILTER_NONE); - - return (AS::FilterType)mixer->channel_get_filter_type(v->channel); - -} -float AudioServerSW::voice_get_filter_cutoff(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, 0); - - return mixer->channel_get_filter_cutoff( v->channel ); - -} -float AudioServerSW::voice_get_filter_resonance(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, 0); - - return mixer->channel_get_filter_resonance( v->channel ); - -} -float AudioServerSW::voice_get_chorus(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, 0); - - return mixer->channel_get_chorus( v->channel ); - -} -AS::ReverbRoomType AudioServerSW::voice_get_reverb_type(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, REVERB_SMALL); - - return (AS::ReverbRoomType)mixer->channel_get_reverb_type( v->channel ); - -} -float AudioServerSW::voice_get_reverb(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, 0); - - return mixer->channel_get_reverb( v->channel ); - -} - -int AudioServerSW::voice_get_mix_rate(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, 0); - - return mixer->channel_get_mix_rate( v->channel ); - -} -bool AudioServerSW::voice_is_positional(RID p_voice) const { - - AUDIO_LOCK - Voice *v = voice_owner.get( p_voice ); - ERR_FAIL_COND_V(!v, 0); - - return mixer->channel_is_positional( v->channel ); - -} - -void AudioServerSW::voice_stop(RID p_voice) { - - VoiceRBSW::Command cmd; - cmd.type=VoiceRBSW::Command::CMD_STOP; - cmd.voice=p_voice; - voice_rb.push_command(cmd); - - //return mixer->channel_free( v->channel ); - -} - -bool AudioServerSW::voice_is_active(RID p_voice) const { - - Voice *v = voice_owner.get(p_voice); - ERR_FAIL_COND_V(!v,false); - return v->active; - -} - -/* STREAM API */ - -RID AudioServerSW::audio_stream_create(AudioStream *p_stream) { - - AUDIO_LOCK - Stream *s = memnew(Stream); - s->audio_stream=p_stream; - s->event_stream=NULL; - s->active=false; - s->E=NULL; - s->volume_scale=1.0; - p_stream->set_mix_rate(AudioDriverSW::get_singleton()->get_mix_rate()); - - return stream_owner.make_rid(s); -} - -RID AudioServerSW::event_stream_create(EventStream *p_stream) { - - AUDIO_LOCK - Stream *s = memnew(Stream); - s->audio_stream=NULL; - s->event_stream=p_stream; - s->active=false; - s->E=NULL; - s->volume_scale=1.0; - //p_stream->set_mix_rate(AudioDriverSW::get_singleton()->get_mix_rate()); - - return stream_owner.make_rid(s); - - -} - - -void AudioServerSW::stream_set_active(RID p_stream, bool p_active) { - - - Stream *s = stream_owner.get(p_stream); - ERR_FAIL_COND(!s); - _THREAD_SAFE_METHOD_ - - if (s->active==p_active) - return; - AUDIO_LOCK; - s->active=p_active; - if (p_active) - s->E=active_audio_streams.push_back(s); - else { - active_audio_streams.erase(s->E); - s->E=NULL; - } - - -} - -bool AudioServerSW::stream_is_active(RID p_stream) const { - - Stream *s = stream_owner.get(p_stream); - ERR_FAIL_COND_V(!s,false); - return s->active; -} - -void AudioServerSW::stream_set_volume_scale(RID p_stream, float p_scale) { - - Stream *s = stream_owner.get(p_stream); - ERR_FAIL_COND(!s); - s->volume_scale=p_scale; - -} - -float AudioServerSW::stream_set_volume_scale(RID p_stream) const { - - Stream *s = stream_owner.get(p_stream); - ERR_FAIL_COND_V(!s,0); - return s->volume_scale; - -} - - -void AudioServerSW::free(RID p_id) { - - if(voice_owner.owns(p_id)) { - - Voice *v = voice_owner.get(p_id); - AUDIO_LOCK - mixer->channel_free( v->channel ); - voice_owner.free(p_id); - memdelete(v); - - } else if (stream_owner.owns(p_id)) { - - - Stream *s=stream_owner.get(p_id); - - if (s->active) { - stream_set_active(p_id,false); - } - - memdelete(s); - stream_owner.free(p_id); - - } else if (sample_manager->is_sample(p_id)) { - - AUDIO_LOCK - sample_manager->free(p_id); - } - -} - -void AudioServerSW::_thread_func(void *self) { - - Thread::set_name("AudioServerSW"); - - AudioServerSW *as=(AudioServerSW *)self; - - while (!as->exit_update_thread) { - as->_update_streams(true); - OS::get_singleton()->delay_usec(5000); - } - -} - -void AudioServerSW::init() { - - int latency = GLOBAL_DEF("audio/mixer_latency",10); - internal_buffer_channels=2; // read from driver - internal_buffer = memnew_arr(int32_t,INTERNAL_BUFFER_SIZE*internal_buffer_channels); - stream_buffer = memnew_arr(int32_t,INTERNAL_BUFFER_SIZE*4); //max 4 channels - AudioMixerSW::MixChannels mix_chans = AudioMixerSW::MIX_STEREO; - - switch(AudioDriverSW::get_singleton()->get_output_format()) { - - case AudioDriverSW::OUTPUT_MONO: - case AudioDriverSW::OUTPUT_STEREO: - mix_chans=AudioMixerSW::MIX_STEREO; - break; - case AudioDriverSW::OUTPUT_QUAD: - case AudioDriverSW::OUTPUT_5_1: - mix_chans=AudioMixerSW::MIX_QUAD; - break; - } - - mixer = memnew( AudioMixerSW( sample_manager, latency, AudioDriverSW::get_singleton()->get_mix_rate(),mix_chans,mixer_use_fx,mixer_interp,_mixer_callback,this ) ); - mixer_step_usecs=mixer->get_step_usecs(); - - _output_delay=0; - - stream_volume=0.3; - // start the audio driver - if (AudioDriverSW::get_singleton()) - AudioDriverSW::get_singleton()->start(); - -#ifndef NO_THREADS - exit_update_thread=false; - thread = Thread::create(_thread_func,this); -#endif - -} - -void AudioServerSW::finish() { - -#ifndef NO_THREADS - exit_update_thread=true; - Thread::wait_to_finish(thread); - memdelete(thread); -#endif - - if (AudioDriverSW::get_singleton()) - AudioDriverSW::get_singleton()->finish(); - - memdelete_arr(internal_buffer); - memdelete_arr(stream_buffer); - memdelete(mixer); - -} - -void AudioServerSW::_update_streams(bool p_thread) { - - _THREAD_SAFE_METHOD_ - for(List<Stream*>::Element *E=active_audio_streams.front();E;) { //stream might be removed durnig this callback - - List<Stream*>::Element *N=E->next(); - - if (E->get()->audio_stream && p_thread == E->get()->audio_stream->can_update_mt()) - E->get()->audio_stream->update(); - - E=N; - } - -} - -void AudioServerSW::update() { - - _update_streams(false); -#ifdef NO_THREADS - - _update_streams(true); -#endif -} - - -void AudioServerSW::lock() { - - AudioDriverSW::get_singleton()->lock(); -} - -void AudioServerSW::unlock() { - AudioDriverSW::get_singleton()->unlock(); - -} - -int AudioServerSW::get_default_mix_rate() const { - - return AudioDriverSW::get_singleton()->get_mix_rate(); -} -int AudioServerSW::get_default_channel_count() const { - return internal_buffer_channels; -} - -void AudioServerSW::set_mixer_params(AudioMixerSW::InterpolationType p_interp, bool p_use_fx) { - - mixer_interp=p_interp; - mixer_use_fx=p_use_fx; -} - -void AudioServerSW::set_stream_global_volume_scale(float p_volume) { - - stream_volume_scale=p_volume; -} - -float AudioServerSW::get_stream_global_volume_scale() const { - - return stream_volume_scale; - - -} - -void AudioServerSW::set_fx_global_volume_scale(float p_volume) { - - fx_volume_scale=p_volume; - //mixer->set_mixer_volume(fx_volume_scale); - VoiceRBSW::Command cmd; - cmd.type=VoiceRBSW::Command::CMD_CHANGE_ALL_FX_VOLUMES; - cmd.voice=RID(); - cmd.volume.volume=p_volume; - voice_rb.push_command(cmd); - -} - - -float AudioServerSW::get_fx_global_volume_scale() const { - - return fx_volume_scale; -} - -void AudioServerSW::set_event_voice_global_volume_scale(float p_volume) { - - event_voice_volume_scale=p_volume; - //mixer->set_mixer_volume(event_voice_volume_scale); -} - - -float AudioServerSW::get_event_voice_global_volume_scale() const { - - return event_voice_volume_scale; -} - -double AudioServerSW::get_output_delay() const { - - return _output_delay+AudioDriverSW::get_singleton()->get_latency(); -} - -double AudioServerSW::get_mix_time() const { - - return AudioDriverSW::get_singleton()->get_mix_time(); -} - -uint32_t AudioServerSW::read_output_peak() const { - - uint32_t val = max_peak; - uint32_t *p = (uint32_t*)&max_peak; - *p=0; - return val; -} - -AudioServerSW::AudioServerSW(SampleManagerSW *p_sample_manager) { - - sample_manager=p_sample_manager; - String interp = GLOBAL_DEF("audio/mixer_interp","linear"); - GlobalConfig::get_singleton()->set_custom_property_info("audio/mixer_interp",PropertyInfo(Variant::STRING,"audio/mixer_interp",PROPERTY_HINT_ENUM,"raw,linear,cubic")); - if (interp=="raw") - mixer_interp=AudioMixerSW::INTERPOLATION_RAW; - else if (interp=="cubic") - mixer_interp=AudioMixerSW::INTERPOLATION_CUBIC; - else - mixer_interp=AudioMixerSW::INTERPOLATION_LINEAR; - mixer_use_fx = GLOBAL_DEF("audio/use_chorus_reverb",true); - stream_volume_scale=GLOBAL_DEF("audio/stream_volume_scale",1.0); - fx_volume_scale=GLOBAL_DEF("audio/fx_volume_scale",1.0); - event_voice_volume_scale=GLOBAL_DEF("audio/event_voice_volume_scale",0.5); - max_peak=0; - - -} - -AudioServerSW::~AudioServerSW() { - -} - - -AudioDriverSW *AudioDriverSW::singleton=NULL; -AudioDriverSW *AudioDriverSW::get_singleton() { - - return singleton; -} - -void AudioDriverSW::set_singleton() { - - singleton=this; -} - -void AudioDriverSW::audio_server_process(int p_frames,int32_t *p_buffer,bool p_update_mix_time) { - - AudioServerSW * audio_server = static_cast<AudioServerSW*>(AudioServer::get_singleton()); - if (p_update_mix_time) - update_mix_time(p_frames); - audio_server->driver_process(p_frames,p_buffer); -} - -void AudioDriverSW::update_mix_time(int p_frames) { - - _mix_amount+=p_frames; - _last_mix_time=OS::get_singleton()->get_ticks_usec(); -} - -double AudioDriverSW::get_mix_time() const { - - double total = (OS::get_singleton()->get_ticks_usec() - _last_mix_time) / 1000000.0; - total+=_mix_amount/(double)get_mix_rate(); - return total; - -} - - -AudioDriverSW::AudioDriverSW() { - - _last_mix_time=0; - _mix_amount=0; -} - - -AudioDriverSW *AudioDriverManagerSW::drivers[MAX_DRIVERS]; -int AudioDriverManagerSW::driver_count=0; - - - -void AudioDriverManagerSW::add_driver(AudioDriverSW *p_driver) { - - ERR_FAIL_COND(driver_count>=MAX_DRIVERS); - drivers[driver_count++]=p_driver; -} - -int AudioDriverManagerSW::get_driver_count() { - - return driver_count; -} -AudioDriverSW *AudioDriverManagerSW::get_driver(int p_driver) { - - ERR_FAIL_INDEX_V(p_driver,driver_count,NULL); - return drivers[p_driver]; -} - diff --git a/servers/audio/audio_server_sw.h b/servers/audio/audio_server_sw.h deleted file mode 100644 index 52b45351c3..0000000000 --- a/servers/audio/audio_server_sw.h +++ /dev/null @@ -1,286 +0,0 @@ -/*************************************************************************/ -/* audio_server_sw.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef AUDIO_SERVER_SW_H -#define AUDIO_SERVER_SW_H - -#include "servers/audio_server.h" -#include "servers/audio/audio_mixer_sw.h" -#include "servers/audio/voice_rb_sw.h" -#include "self_list.h" -#include "os/thread_safe.h" -#include "os/thread.h" -class AudioServerSW : public AudioServer { - - GDCLASS( AudioServerSW, AudioServer ); - - _THREAD_SAFE_CLASS_ - - enum { - INTERNAL_BUFFER_SIZE=4096, - STREAM_SCALE_BITS=12 - - }; - - SampleManagerSW *sample_manager; - AudioMixerSW *mixer; - - virtual AudioMixer *get_mixer(); - virtual void audio_mixer_chunk_callback(int p_frames); - - struct Voice : public RID_Data { - - float volume; - volatile bool active; - SelfList<Voice> active_item; - AudioMixer::ChannelID channel; - - - Voice () : active_item(this) { channel=AudioMixer::INVALID_CHANNEL; active=false;} - }; - - mutable RID_Owner<Voice> voice_owner; - SelfList<Voice>::List active_list; - - struct Stream : public RID_Data { - bool active; - List<Stream*>::Element *E; - AudioStream *audio_stream; - EventStream *event_stream; - float volume_scale; - }; - - List<Stream*> active_audio_streams; - - //List<Stream*> event_streams; - - int32_t * internal_buffer; - int internal_buffer_channels; - int32_t * stream_buffer; - - mutable RID_Owner<Stream> stream_owner; - - float stream_volume; - float stream_volume_scale; - float fx_volume_scale; - float event_voice_volume_scale; - float peak_left,peak_right; - uint32_t max_peak; - - double _output_delay; - - VoiceRBSW voice_rb; - - bool exit_update_thread; - Thread *thread; - static void _thread_func(void *self); - - void _update_streams(bool p_thread); - void driver_process_chunk(int p_frames,int32_t *p_buffer); - - AudioMixerSW::InterpolationType mixer_interp; - bool mixer_use_fx; - uint64_t mixer_step_usecs; - - static void _mixer_callback(void *p_udata); -friend class AudioDriverSW; - void driver_process(int p_frames,int32_t *p_buffer); -public: - - - /* SAMPLE API */ - - virtual RID sample_create(SampleFormat p_format, bool p_stereo, int p_length); - - virtual void sample_set_description(RID p_sample, const String& p_description); - virtual String sample_get_description(RID p_sample) const; - - virtual SampleFormat sample_get_format(RID p_sample) const; - virtual bool sample_is_stereo(RID p_sample) const; - virtual int sample_get_length(RID p_sample) const; - const void* sample_get_data_ptr(RID p_sample) const; - - virtual void sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer); - virtual PoolVector<uint8_t> sample_get_data(RID p_sample) const; - - virtual void sample_set_mix_rate(RID p_sample,int p_rate); - virtual int sample_get_mix_rate(RID p_sample) const; - - virtual void sample_set_loop_format(RID p_sample,SampleLoopFormat p_format); - virtual SampleLoopFormat sample_get_loop_format(RID p_sample) const; - - virtual void sample_set_loop_begin(RID p_sample,int p_pos); - virtual int sample_get_loop_begin(RID p_sample) const; - - virtual void sample_set_loop_end(RID p_sample,int p_pos); - virtual int sample_get_loop_end(RID p_sample) const; - - /* VOICE API */ - - virtual RID voice_create(); - - virtual void voice_play(RID p_voice, RID p_sample); - - virtual void voice_set_volume(RID p_voice, float p_volume); - virtual void voice_set_pan(RID p_voice, float p_pan, float p_depth=0,float height=0); //pan and depth go from -1 to 1 - virtual void voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance,float p_gain=0); - virtual void voice_set_chorus(RID p_voice, float p_chorus ); - virtual void voice_set_reverb(RID p_voice, ReverbRoomType p_room_type, float p_reverb); - virtual void voice_set_mix_rate(RID p_voice, int p_mix_rate); - virtual void voice_set_positional(RID p_voice, bool p_positional); - - virtual float voice_get_volume(RID p_voice) const; - virtual float voice_get_pan(RID p_voice) const; //pan and depth go from -1 to 1 - virtual float voice_get_pan_depth(RID p_voice) const; //pan and depth go from -1 to 1 - virtual float voice_get_pan_height(RID p_voice) const; //pan and depth go from -1 to 1 - virtual FilterType voice_get_filter_type(RID p_voice) const; - virtual float voice_get_filter_cutoff(RID p_voice) const; - virtual float voice_get_filter_resonance(RID p_voice) const; - virtual float voice_get_chorus(RID p_voice) const; - virtual ReverbRoomType voice_get_reverb_type(RID p_voice) const; - virtual float voice_get_reverb(RID p_voice) const; - - virtual int voice_get_mix_rate(RID p_voice) const; - virtual bool voice_is_positional(RID p_voice) const; - - virtual void voice_stop(RID p_voice); - virtual bool voice_is_active(RID p_voice) const; - - /* STREAM API */ - - virtual RID audio_stream_create(AudioStream *p_stream); - virtual RID event_stream_create(EventStream *p_stream); - - virtual void stream_set_active(RID p_stream, bool p_active); - virtual bool stream_is_active(RID p_stream) const; - - virtual void stream_set_volume_scale(RID p_stream, float p_scale); - virtual float stream_set_volume_scale(RID p_stream) const; - - virtual void free(RID p_id); - - virtual void init(); - virtual void finish(); - virtual void update(); - - virtual void lock(); - virtual void unlock(); - virtual int get_default_channel_count() const; - virtual int get_default_mix_rate() const; - - void set_mixer_params(AudioMixerSW::InterpolationType p_interp, bool p_use_fx); - - virtual void set_stream_global_volume_scale(float p_volume); - virtual void set_fx_global_volume_scale(float p_volume); - virtual void set_event_voice_global_volume_scale(float p_volume); - - - virtual float get_stream_global_volume_scale() const; - virtual float get_fx_global_volume_scale() const; - virtual float get_event_voice_global_volume_scale() const; - - virtual uint32_t read_output_peak() const; - - virtual double get_mix_time() const; //useful for video -> audio sync - - virtual double get_output_delay() const; - - - AudioServerSW(SampleManagerSW *p_sample_manager); - ~AudioServerSW(); - -}; - - -class AudioDriverSW { - - - static AudioDriverSW *singleton; - uint64_t _last_mix_time; - uint64_t _mix_amount; - - -protected: - - void audio_server_process(int p_frames,int32_t *p_buffer,bool p_update_mix_time=true); - void update_mix_time(int p_frames); - -public: - - - double get_mix_time() const; //useful for video -> audio sync - - enum OutputFormat { - - OUTPUT_MONO, - OUTPUT_STEREO, - OUTPUT_QUAD, - OUTPUT_5_1 - }; - - static AudioDriverSW *get_singleton(); - void set_singleton(); - - virtual const char* get_name() const=0; - - virtual Error init()=0; - virtual void start()=0; - virtual int get_mix_rate() const =0; - virtual OutputFormat get_output_format() const=0; - virtual void lock()=0; - virtual void unlock()=0; - virtual void finish()=0; - - virtual float get_latency() { return 0; } - - - - - AudioDriverSW(); - virtual ~AudioDriverSW() {}; -}; - - - -class AudioDriverManagerSW { - - enum { - - MAX_DRIVERS=10 - }; - - static AudioDriverSW *drivers[MAX_DRIVERS]; - static int driver_count; -public: - - static void add_driver(AudioDriverSW *p_driver); - static int get_driver_count(); - static AudioDriverSW *get_driver(int p_driver); -}; - -#endif // AUDIO_SERVER_SW_H diff --git a/scene/resources/audio_stream.cpp b/servers/audio/audio_stream.cpp index 7c269de007..f4214838a1 100644 --- a/scene/resources/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -31,31 +31,56 @@ ////////////////////////////// -void AudioStreamPlayback::_bind_methods() { - ClassDB::bind_method(_MD("play","from_pos_sec"),&AudioStreamPlayback::play,DEFVAL(0)); - ClassDB::bind_method(_MD("stop"),&AudioStreamPlayback::stop); - ClassDB::bind_method(_MD("is_playing"),&AudioStreamPlayback::is_playing); +void AudioStreamPlaybackResampled::_begin_resample() { - ClassDB::bind_method(_MD("set_loop","enabled"),&AudioStreamPlayback::set_loop); - ClassDB::bind_method(_MD("has_loop"),&AudioStreamPlayback::has_loop); + //clear cubic interpolation history + internal_buffer[0]=AudioFrame(0.0,0.0); + internal_buffer[1]=AudioFrame(0.0,0.0); + internal_buffer[2]=AudioFrame(0.0,0.0); + internal_buffer[3]=AudioFrame(0.0,0.0); + //mix buffer + _mix_internal(internal_buffer+4,INTERNAL_BUFFER_LEN); + mix_offset=0; +} - ClassDB::bind_method(_MD("get_loop_count"),&AudioStreamPlayback::get_loop_count); +void AudioStreamPlaybackResampled::mix(AudioFrame* p_buffer,float p_rate_scale,int p_frames) { - ClassDB::bind_method(_MD("seek_pos","pos"),&AudioStreamPlayback::seek_pos); - ClassDB::bind_method(_MD("get_pos"),&AudioStreamPlayback::get_pos); + float target_rate = AudioServer::get_singleton()->get_mix_rate() * p_rate_scale; - ClassDB::bind_method(_MD("get_length"),&AudioStreamPlayback::get_length); - ClassDB::bind_method(_MD("get_channels"),&AudioStreamPlayback::get_channels); - ClassDB::bind_method(_MD("get_mix_rate"),&AudioStreamPlayback::get_mix_rate); - ClassDB::bind_method(_MD("get_minimum_buffer_size"),&AudioStreamPlayback::get_minimum_buffer_size); + uint64_t mix_increment = uint64_t((get_stream_sampling_rate() / double(target_rate)) * double( FP_LEN )); + for(int i=0;i<p_frames;i++) { -} -void AudioStream::_bind_methods() { + uint32_t idx = CUBIC_INTERP_HISTORY + uint32_t(mix_offset >> FP_BITS); + //standard cubic interpolation (great quality/performance ratio) + //this used to be moved to a LUT for greater performance, but nowadays CPU speed is generally faster than memory. + float mu = (mix_offset&FP_MASK)/float(FP_LEN); + AudioFrame y0 = internal_buffer[idx-3]; + AudioFrame y1 = internal_buffer[idx-2]; + AudioFrame y2 = internal_buffer[idx-1]; + AudioFrame y3 = internal_buffer[idx-0]; + float mu2 = mu*mu; + AudioFrame a0 = y3 - y2 - y0 + y1; + AudioFrame a1 = y0 - y1 - a0; + AudioFrame a2 = y2 - y0; + AudioFrame a3 = y1; -} + p_buffer[i] = (a0*mu*mu2 + a1*mu2 + a2*mu + a3); + mix_offset+=mix_increment; + + while ( (mix_offset >> FP_BITS) >= INTERNAL_BUFFER_LEN ) { + + internal_buffer[0]=internal_buffer[INTERNAL_BUFFER_LEN+0]; + internal_buffer[1]=internal_buffer[INTERNAL_BUFFER_LEN+1]; + internal_buffer[2]=internal_buffer[INTERNAL_BUFFER_LEN+2]; + internal_buffer[3]=internal_buffer[INTERNAL_BUFFER_LEN+3]; + _mix_internal(internal_buffer+4,INTERNAL_BUFFER_LEN); + mix_offset-=(INTERNAL_BUFFER_LEN<<FP_BITS); + } + } +} diff --git a/scene/resources/audio_stream.h b/servers/audio/audio_stream.h index b79707cd32..d08fedb084 100644 --- a/scene/resources/audio_stream.h +++ b/servers/audio/audio_stream.h @@ -34,47 +34,65 @@ class AudioStreamPlayback : public Reference { - GDCLASS( AudioStreamPlayback, Reference ); -protected: - static void _bind_methods(); -public: + GDCLASS( AudioStreamPlayback, Reference ) +public: - virtual void play(float p_from_pos=0)=0; + virtual void start(float p_from_pos=0.0)=0; virtual void stop()=0; virtual bool is_playing() const=0; - virtual void set_loop(bool p_enable)=0; - virtual bool has_loop() const=0; - - virtual void set_loop_restart_time(float p_time)=0; - - virtual int get_loop_count() const=0; + virtual int get_loop_count() const=0; //times it looped virtual float get_pos() const=0; virtual void seek_pos(float p_time)=0; - virtual int mix(int16_t* p_bufer,int p_frames)=0; + virtual void mix(AudioFrame* p_bufer,float p_rate_scale,int p_frames)=0; - virtual float get_length() const=0; - virtual String get_stream_name() const=0; + virtual float get_length() const=0; //if supported, otherwise return 0 - virtual int get_channels() const=0; - virtual int get_mix_rate() const=0; - virtual int get_minimum_buffer_size() const=0; }; -class AudioStream : public Resource { +class AudioStreamPlaybackResampled : public AudioStreamPlayback { + + GDCLASS( AudioStreamPlaybackResampled, AudioStreamPlayback ) + + + + enum { + FP_BITS=16, //fixed point used for resampling + FP_LEN=(1<<FP_BITS), + FP_MASK=FP_LEN-1, + INTERNAL_BUFFER_LEN=256, + CUBIC_INTERP_HISTORY=4 + }; - GDCLASS( AudioStream, Resource ); - OBJ_SAVE_TYPE( AudioStream ); //children are all saved as AudioStream, so they can be exchanged + AudioFrame internal_buffer[INTERNAL_BUFFER_LEN+CUBIC_INTERP_HISTORY]; + uint64_t mix_offset; protected: - static void _bind_methods(); + void _begin_resample(); + virtual void _mix_internal(AudioFrame* p_bufer,int p_frames)=0; + virtual float get_stream_sampling_rate()=0; + +public: + + virtual void mix(AudioFrame* p_bufer,float p_rate_scale,int p_frames); + + AudioStreamPlaybackResampled() { mix_offset=0; } +}; + +class AudioStream : public Resource { + + GDCLASS( AudioStream, Resource ) + OBJ_SAVE_TYPE( AudioStream ) //children are all saved as AudioStream, so they can be exchanged + + public: virtual Ref<AudioStreamPlayback> instance_playback()=0; + virtual String get_stream_name() const=0; }; diff --git a/servers/spatial_sound/SCsub b/servers/audio/effects/SCsub index ccc76e823f..ccc76e823f 100644 --- a/servers/spatial_sound/SCsub +++ b/servers/audio/effects/SCsub diff --git a/servers/audio/effects/audio_effect_amplify.cpp b/servers/audio/effects/audio_effect_amplify.cpp new file mode 100644 index 0000000000..d723f8d2fe --- /dev/null +++ b/servers/audio/effects/audio_effect_amplify.cpp @@ -0,0 +1,50 @@ +#include "audio_effect_amplify.h" + + +void AudioEffectAmplifyInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + + //multiply volume interpolating to avoid clicks if this changes + float volume_db = base->volume_db; + float vol = Math::db2linear(mix_volume_db); + float vol_inc = (Math::db2linear(volume_db) - vol)/float(p_frame_count); + + for(int i=0;i<p_frame_count;i++) { + p_dst_frames[i]=p_src_frames[i]*vol; + vol+=vol_inc; + } + //set volume for next mix + mix_volume_db = volume_db; + +} + + +Ref<AudioEffectInstance> AudioEffectAmplify::instance() { + Ref<AudioEffectAmplifyInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectAmplify>(this); + ins->mix_volume_db=volume_db; + return ins; +} + +void AudioEffectAmplify::set_volume_db(float p_volume) { + volume_db=p_volume; +} + +float AudioEffectAmplify::get_volume_db() const { + + return volume_db; +} + +void AudioEffectAmplify::_bind_methods() { + + ClassDB::bind_method(_MD("set_volume_db","volume"),&AudioEffectAmplify::set_volume_db); + ClassDB::bind_method(_MD("get_volume_db"),&AudioEffectAmplify::get_volume_db); + + ADD_PROPERTY(PropertyInfo(Variant::REAL,"volume_db",PROPERTY_HINT_RANGE,"-80,24,0.01"),_SCS("set_volume_db"),_SCS("get_volume_db")); +} + +AudioEffectAmplify::AudioEffectAmplify() +{ + volume_db=0; +} diff --git a/servers/audio/effects/audio_effect_amplify.h b/servers/audio/effects/audio_effect_amplify.h new file mode 100644 index 0000000000..921054e2cd --- /dev/null +++ b/servers/audio/effects/audio_effect_amplify.h @@ -0,0 +1,40 @@ +#ifndef AUDIOEFFECTAMPLIFY_H +#define AUDIOEFFECTAMPLIFY_H + +#include "servers/audio/audio_effect.h" + +class AudioEffectAmplify; + +class AudioEffectAmplifyInstance : public AudioEffectInstance { + GDCLASS(AudioEffectAmplifyInstance,AudioEffectInstance) +friend class AudioEffectAmplify; + Ref<AudioEffectAmplify> base; + + float mix_volume_db; +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +}; + + +class AudioEffectAmplify : public AudioEffect { + GDCLASS(AudioEffectAmplify,AudioEffect) + +friend class AudioEffectAmplifyInstance; + float volume_db; + +protected: + + static void _bind_methods(); +public: + + + Ref<AudioEffectInstance> instance(); + void set_volume_db(float p_volume); + float get_volume_db() const; + + AudioEffectAmplify(); +}; + +#endif // AUDIOEFFECTAMPLIFY_H diff --git a/servers/audio/effects/audio_effect_chorus.cpp b/servers/audio/effects/audio_effect_chorus.cpp new file mode 100644 index 0000000000..d3105343ae --- /dev/null +++ b/servers/audio/effects/audio_effect_chorus.cpp @@ -0,0 +1,365 @@ +#include "audio_effect_chorus.h" +#include "servers/audio_server.h" +#include "math_funcs.h" + +void AudioEffectChorusInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + int todo = p_frame_count; + + while(todo) { + + int to_mix = MIN(todo,256); //can't mix too much + + _process_chunk(p_src_frames,p_dst_frames,to_mix); + + p_src_frames+=to_mix; + p_dst_frames+=to_mix; + + todo-=to_mix; + } +} + +void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + + //fill ringbuffer + for(int i=0;i<p_frame_count;i++) { + audio_buffer[(buffer_pos+i)&buffer_mask]=p_src_frames[i]; + p_dst_frames[i]=p_src_frames[i]*base->dry; + } + + float mix_rate = AudioServer::get_singleton()->get_mix_rate(); + + /* process voices */ + for (int vc=0;vc<base->voice_count;vc++) { + + AudioEffectChorus::Voice &v=base->voice[vc]; + + + double time_to_mix=(float)p_frame_count/mix_rate; + double cycles_to_mix=time_to_mix*v.rate; + + unsigned int local_rb_pos=buffer_pos; + AudioFrame *dst_buff=p_dst_frames; + AudioFrame *rb_buff=audio_buffer.ptr(); + + double delay_msec=v.delay; + unsigned int delay_frames=Math::fast_ftoi((delay_msec/1000.0)*mix_rate); + float max_depth_frames=(v.depth/1000.0)*mix_rate; + + uint64_t local_cycles=cycles[vc]; + uint64_t increment=llrint(cycles_to_mix/(double)p_frame_count*(double)(1<<AudioEffectChorus::CYCLES_FRAC)); + + //check the LFO doesnt read ahead of the write pos + if ((((int)max_depth_frames)+10)>delay_frames) { //10 as some threshold to avoid precision stuff + delay_frames+=(int)max_depth_frames-delay_frames; + delay_frames+=10; //threshold to avoid precision stuff + + } + + + + //low pass filter + if (v.cutoff==0) + continue; + float auxlp=expf(-2.0*Math_PI*v.cutoff/mix_rate); + float c1=1.0-auxlp; + float c2=auxlp; + AudioFrame h=filter_h[vc]; + if (v.cutoff>=AudioEffectChorus::MS_CUTOFF_MAX) { + c1=1.0; c2=0.0; + } + + //vol modifier + + AudioFrame vol_modifier=AudioFrame(base->wet,base->wet) * Math::db2linear(v.level); + vol_modifier.l*=CLAMP( 1.0 - v.pan, 0, 1); + vol_modifier.r*=CLAMP( 1.0 + v.pan, 0, 1); + + + + for (int i=0;i<p_frame_count;i++) { + + /** COMPUTE WAVEFORM **/ + + float phase=(float)(local_cycles&AudioEffectChorus::CYCLES_MASK)/(float)(1<<AudioEffectChorus::CYCLES_FRAC); + + float wave_delay=sinf(phase*2.0*Math_PI)*max_depth_frames; + + int wave_delay_frames=lrint(floor(wave_delay)); + float wave_delay_frac=wave_delay-(float)wave_delay_frames; + + /** COMPUTE RINGBUFFER POS**/ + + unsigned int rb_source=local_rb_pos; + rb_source-=delay_frames; + + rb_source-=wave_delay_frames; + + /** READ FROM RINGBUFFER, LINEARLY INTERPOLATE */ + + AudioFrame val=rb_buff[rb_source&buffer_mask]; + AudioFrame val_next=rb_buff[(rb_source-1)&buffer_mask]; + + val+=(val_next-val)*wave_delay_frac; + + val=val*c1+h*c2; + h=val; + + /** MIX VALUE TO OUTPUT **/ + + dst_buff[i]+=val*vol_modifier; + + local_cycles+=increment; + local_rb_pos++; + + } + + filter_h[vc]=h; + cycles[vc]+=Math::fast_ftoi(cycles_to_mix*(double)(1<<AudioEffectChorus::CYCLES_FRAC)); + } + + buffer_pos+=p_frame_count; +} + + +Ref<AudioEffectInstance> AudioEffectChorus::instance() { + + Ref<AudioEffectChorusInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectChorus>(this); + for(int i=0;i<4;i++) { + ins->filter_h[i]=AudioFrame(0,0); + ins->cycles[i]=0; + } + + float ring_buffer_max_size=AudioEffectChorus::MAX_DELAY_MS+AudioEffectChorus::MAX_DEPTH_MS+AudioEffectChorus::MAX_WIDTH_MS; + + ring_buffer_max_size*=2; //just to avoid complications + ring_buffer_max_size/=1000.0;//convert to seconds + ring_buffer_max_size*=AudioServer::get_singleton()->get_mix_rate(); + + int ringbuff_size=ring_buffer_max_size; + + int bits=0; + + while(ringbuff_size>0) { + bits++; + ringbuff_size/=2; + } + + ringbuff_size=1<<bits; + ins->buffer_mask=ringbuff_size-1; + ins->buffer_pos=0; + ins->audio_buffer.resize(ringbuff_size); + for(int i=0;i<ringbuff_size;i++) { + ins->audio_buffer[i]=AudioFrame(0,0); + } + + return ins; +} + +void AudioEffectChorus::set_voice_count(int p_voices) { + + ERR_FAIL_COND(p_voices<1 || p_voices>=MAX_VOICES); + voice_count=p_voices; + _change_notify(); +} + + +int AudioEffectChorus::get_voice_count() const{ + + return voice_count; +} + +void AudioEffectChorus::set_voice_delay_ms(int p_voice,float p_delay_ms){ + + ERR_FAIL_INDEX(p_voice,MAX_VOICES); + + voice[p_voice].delay=p_delay_ms; + +} +float AudioEffectChorus::get_voice_delay_ms(int p_voice) const{ + + ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0); + return voice[p_voice].delay; +} + +void AudioEffectChorus::set_voice_rate_hz(int p_voice,float p_rate_hz){ + ERR_FAIL_INDEX(p_voice,MAX_VOICES); + + voice[p_voice].rate=p_rate_hz; +} +float AudioEffectChorus::get_voice_rate_hz(int p_voice) const{ + + ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0); + + return voice[p_voice].rate; +} + +void AudioEffectChorus::set_voice_depth_ms(int p_voice,float p_depth_ms){ + + ERR_FAIL_INDEX(p_voice,MAX_VOICES); + + voice[p_voice].depth=p_depth_ms; +} +float AudioEffectChorus::get_voice_depth_ms(int p_voice) const{ + + ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0); + + return voice[p_voice].depth; +} + +void AudioEffectChorus::set_voice_level_db(int p_voice,float p_level_db){ + + ERR_FAIL_INDEX(p_voice,MAX_VOICES); + + voice[p_voice].level=p_level_db; +} +float AudioEffectChorus::get_voice_level_db(int p_voice) const{ + + ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0); + + return voice[p_voice].level; +} + + +void AudioEffectChorus::set_voice_cutoff_hz(int p_voice,float p_cutoff_hz){ + + ERR_FAIL_INDEX(p_voice,MAX_VOICES); + + voice[p_voice].cutoff=p_cutoff_hz; +} +float AudioEffectChorus::get_voice_cutoff_hz(int p_voice) const{ + + ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0); + + return voice[p_voice].cutoff; +} + +void AudioEffectChorus::set_voice_pan(int p_voice,float p_pan){ + + ERR_FAIL_INDEX(p_voice,MAX_VOICES); + + voice[p_voice].pan=p_pan; +} +float AudioEffectChorus::get_voice_pan(int p_voice) const{ + + ERR_FAIL_INDEX_V(p_voice,MAX_VOICES,0); + + return voice[p_voice].pan; +} + + +void AudioEffectChorus::set_wet(float amount){ + + + wet=amount; +} +float AudioEffectChorus::get_wet() const{ + + return wet; +} + +void AudioEffectChorus::set_dry(float amount){ + + dry=amount; + +} +float AudioEffectChorus::get_dry() const{ + + return dry; +} + +void AudioEffectChorus::_validate_property(PropertyInfo& property) const { + + if (property.name.begins_with("voice/")) { + int voice_idx = property.name.get_slice("/",1).to_int(); + if (voice_idx>voice_count) { + property.usage=0; + } + } +} + + +void AudioEffectChorus::_bind_methods() { + + ClassDB::bind_method(_MD("set_voice_count","voices"),&AudioEffectChorus::set_voice_count); + ClassDB::bind_method(_MD("get_voice_count"),&AudioEffectChorus::get_voice_count); + + + ClassDB::bind_method(_MD("set_voice_delay_ms","voice_idx","delay_ms"),&AudioEffectChorus::set_voice_delay_ms); + ClassDB::bind_method(_MD("get_voice_delay_ms","voice_idx"),&AudioEffectChorus::get_voice_delay_ms); + + ClassDB::bind_method(_MD("set_voice_rate_hz","voice_idx","rate_hz"),&AudioEffectChorus::set_voice_rate_hz); + ClassDB::bind_method(_MD("get_voice_rate_hz","voice_idx"),&AudioEffectChorus::get_voice_rate_hz); + + ClassDB::bind_method(_MD("set_voice_depth_ms","voice_idx","depth_ms"),&AudioEffectChorus::set_voice_depth_ms); + ClassDB::bind_method(_MD("get_voice_depth_ms","voice_idx"),&AudioEffectChorus::get_voice_depth_ms); + + ClassDB::bind_method(_MD("set_voice_level_db","voice_idx","level_db"),&AudioEffectChorus::set_voice_level_db); + ClassDB::bind_method(_MD("get_voice_level_db","voice_idx"),&AudioEffectChorus::get_voice_level_db); + + ClassDB::bind_method(_MD("set_voice_cutoff_hz","voice_idx","cutoff_hz"),&AudioEffectChorus::set_voice_cutoff_hz); + ClassDB::bind_method(_MD("get_voice_cutoff_hz","voice_idx"),&AudioEffectChorus::get_voice_cutoff_hz); + + ClassDB::bind_method(_MD("set_voice_pan","voice_idx","pan"),&AudioEffectChorus::set_voice_pan); + ClassDB::bind_method(_MD("get_voice_pan","voice_idx"),&AudioEffectChorus::get_voice_pan); + + ClassDB::bind_method(_MD("set_wet","amount"),&AudioEffectChorus::set_wet); + ClassDB::bind_method(_MD("get_wet"),&AudioEffectChorus::get_wet); + + ClassDB::bind_method(_MD("set_dry","amount"),&AudioEffectChorus::set_dry); + ClassDB::bind_method(_MD("get_dry"),&AudioEffectChorus::get_dry); + + ADD_PROPERTY(PropertyInfo(Variant::INT,"voice_count",PROPERTY_HINT_RANGE,"1,4,1"),_SCS("set_voice_count"),_SCS("get_voice_count")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"dry",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_dry"),_SCS("get_dry")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"wet",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_wet"),_SCS("get_wet")); + + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/delay_ms",PROPERTY_HINT_RANGE,"0,50,0.01"),_SCS("set_voice_delay_ms"),_SCS("get_voice_delay_ms"),0); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/rate_hz",PROPERTY_HINT_RANGE,"0.1,20,0.1"),_SCS("set_voice_rate_hz"),_SCS("get_voice_rate_hz"),0); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/depth_ms",PROPERTY_HINT_RANGE,"0,20,0.01"),_SCS("set_voice_depth_ms"),_SCS("get_voice_depth_ms"),0); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/level_db",PROPERTY_HINT_RANGE,"-60,24,0.1"),_SCS("set_voice_level_db"),_SCS("get_voice_level_db"),0); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/cutoff_hz",PROPERTY_HINT_RANGE,"1,16000,1"),_SCS("set_voice_cutoff_hz"),_SCS("get_voice_cutoff_hz"),0); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/1/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_voice_pan"),_SCS("get_voice_pan"),0); + + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/delay_ms",PROPERTY_HINT_RANGE,"0,50,0.01"),_SCS("set_voice_delay_ms"),_SCS("get_voice_delay_ms"),1); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/rate_hz",PROPERTY_HINT_RANGE,"0.1,20,0.1"),_SCS("set_voice_rate_hz"),_SCS("get_voice_rate_hz"),1); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/depth_ms",PROPERTY_HINT_RANGE,"0,20,0.01"),_SCS("set_voice_depth_ms"),_SCS("get_voice_depth_ms"),1); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/level_db",PROPERTY_HINT_RANGE,"-60,24,0.1"),_SCS("set_voice_level_db"),_SCS("get_voice_level_db"),1); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/cutoff_hz",PROPERTY_HINT_RANGE,"1,16000,1"),_SCS("set_voice_cutoff_hz"),_SCS("get_voice_cutoff_hz"),1); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/2/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_voice_pan"),_SCS("get_voice_pan"),1); + + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/delay_ms",PROPERTY_HINT_RANGE,"0,50,0.01"),_SCS("set_voice_delay_ms"),_SCS("get_voice_delay_ms"),2); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/rate_hz",PROPERTY_HINT_RANGE,"0.1,20,0.1"),_SCS("set_voice_rate_hz"),_SCS("get_voice_rate_hz"),2); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/depth_ms",PROPERTY_HINT_RANGE,"0,20,0.01"),_SCS("set_voice_depth_ms"),_SCS("get_voice_depth_ms"),2); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/level_db",PROPERTY_HINT_RANGE,"-60,24,0.1"),_SCS("set_voice_level_db"),_SCS("get_voice_level_db"),2); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/cutoff_hz",PROPERTY_HINT_RANGE,"1,16000,1"),_SCS("set_voice_cutoff_hz"),_SCS("get_voice_cutoff_hz"),2); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/3/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_voice_pan"),_SCS("get_voice_pan"),2); + + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/delay_ms",PROPERTY_HINT_RANGE,"0,50,0.01"),_SCS("set_voice_delay_ms"),_SCS("get_voice_delay_ms"),3); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/rate_hz",PROPERTY_HINT_RANGE,"0.1,20,0.1"),_SCS("set_voice_rate_hz"),_SCS("get_voice_rate_hz"),3); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/depth_ms",PROPERTY_HINT_RANGE,"0,20,0.01"),_SCS("set_voice_depth_ms"),_SCS("get_voice_depth_ms"),3); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/level_db",PROPERTY_HINT_RANGE,"-60,24,0.1"),_SCS("set_voice_level_db"),_SCS("get_voice_level_db"),3); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/cutoff_hz",PROPERTY_HINT_RANGE,"1,16000,1"),_SCS("set_voice_cutoff_hz"),_SCS("get_voice_cutoff_hz"),3); + ADD_PROPERTYI(PropertyInfo(Variant::REAL,"voice/4/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_voice_pan"),_SCS("get_voice_pan"),3); + +} + +AudioEffectChorus::AudioEffectChorus() +{ + voice_count=2; + voice[0].delay=15; + voice[1].delay=20; + voice[0].rate=0.8; + voice[1].rate=1.2; + voice[0].depth=2; + voice[1].depth=3; + voice[0].cutoff=8000; + voice[1].cutoff=8000; + voice[0].pan=-0.5; + voice[1].pan=0.5; + + wet=0.5; + dry=1.0; +} diff --git a/servers/audio/effects/audio_effect_chorus.h b/servers/audio/effects/audio_effect_chorus.h new file mode 100644 index 0000000000..4cfba5d61a --- /dev/null +++ b/servers/audio/effects/audio_effect_chorus.h @@ -0,0 +1,115 @@ +#ifndef AUDIOEFFECTCHORUS_H +#define AUDIOEFFECTCHORUS_H + + +#include "servers/audio/audio_effect.h" + +class AudioEffectChorus; + +class AudioEffectChorusInstance : public AudioEffectInstance { + GDCLASS(AudioEffectChorusInstance,AudioEffectInstance) +friend class AudioEffectChorus; + Ref<AudioEffectChorus> base; + + Vector<AudioFrame> audio_buffer; + unsigned int buffer_pos; + unsigned int buffer_mask; + + AudioFrame filter_h[4]; + uint64_t cycles[4]; + + void _process_chunk(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +}; + + +class AudioEffectChorus : public AudioEffect { + GDCLASS(AudioEffectChorus,AudioEffect) + +friend class AudioEffectChorusInstance; +public: + enum { + + MAX_DELAY_MS=50, + MAX_DEPTH_MS=20, + MAX_WIDTH_MS=50, + MAX_VOICES=4, + CYCLES_FRAC=16, + CYCLES_MASK=(1<<CYCLES_FRAC)-1, + MAX_CHANNELS=4, + MS_CUTOFF_MAX=16000 + }; + +private: + + struct Voice { + + float delay; + float rate; + float depth; + float level; + float cutoff; + float pan; + + Voice() { + + delay=12.0; + rate=1; + depth=0; + level=0; + cutoff=MS_CUTOFF_MAX; + pan=0; + + } + + } voice[MAX_VOICES]; + + int voice_count; + + float wet; + float dry; + + +protected: + void _validate_property(PropertyInfo& property) const; + + static void _bind_methods(); +public: + + void set_voice_count(int p_voices); + int get_voice_count() const; + + void set_voice_delay_ms(int p_voice,float p_delay_ms); + float get_voice_delay_ms(int p_voice) const; + + void set_voice_rate_hz(int p_voice,float p_rate_hz); + float get_voice_rate_hz(int p_voice) const; + + void set_voice_depth_ms(int p_voice,float p_depth_ms); + float get_voice_depth_ms(int p_voice) const; + + void set_voice_level_db(int p_voice,float p_level_db); + float get_voice_level_db(int p_voice) const; + + void set_voice_cutoff_hz(int p_voice,float p_cutoff_hz); + float get_voice_cutoff_hz(int p_voice) const; + + void set_voice_pan(int p_voice,float p_pan); + float get_voice_pan(int p_voice) const; + + void set_wet(float amount); + float get_wet() const; + + void set_dry(float amount); + float get_dry() const; + + Ref<AudioEffectInstance> instance(); + + AudioEffectChorus(); +}; + +#endif // AUDIOEFFECTCHORUS_H diff --git a/servers/audio/effects/audio_effect_compressor.cpp b/servers/audio/effects/audio_effect_compressor.cpp new file mode 100644 index 0000000000..5d116a9543 --- /dev/null +++ b/servers/audio/effects/audio_effect_compressor.cpp @@ -0,0 +1,227 @@ +#include "audio_effect_compressor.h" +#include "servers/audio_server.h" + +void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + + float treshold = Math::db2linear(base->treshold); + float sample_rate=AudioServer::get_singleton()->get_mix_rate(); + + float ratatcoef = exp(-1 / (0.00001f * sample_rate)); + float ratrelcoef = exp(-1 / (0.5f * sample_rate)); + float attime = base->attack_us / 1000000.0; + float reltime = base->release_ms / 1000.0; + float atcoef = exp(-1 / (attime * sample_rate)); + float relcoef = exp(-1 / (reltime * sample_rate)); + + float makeup = Math::db2linear(base->gain); + + float mix = base->mix; + float gr_meter_decay = exp(1 / (1 * sample_rate)); + + const AudioFrame *src = p_src_frames; + + if (base->sidechain!=StringName() && current_channel!=-1) { + + int bus = AudioServer::get_singleton()->thread_find_bus_index(base->sidechain); + if (bus>=0) { + src = AudioServer::get_singleton()->thread_get_channel_mix_buffer(bus,current_channel); + } + } + + for(int i=0;i<p_frame_count;i++) { + + AudioFrame s = src[i]; + //convert to positive + s.l = Math::abs(s.l); + s.r = Math::abs(s.r); + + float peak = MAX(s.l,s.r); + + float overdb = 2.08136898f * Math::linear2db(peak/treshold); + + if (overdb<0.0) //we only care about what goes over to compress + overdb=0.0; + + if(overdb-rundb>5) // diffeence is too large + averatio = 4; + + if(overdb > rundb) { + rundb = overdb + atcoef * (rundb - overdb); + runratio = averatio + ratatcoef * (runratio - averatio); + } else { + rundb = overdb + relcoef * (rundb - overdb); + runratio = averatio + ratrelcoef * (runratio - averatio); + } + + overdb = rundb; + averatio = runratio; + + float cratio; + + if(false) { //rato all-in + cratio = 12 + averatio; + } else { + cratio = base->ratio; + } + + float gr = -overdb * (cratio-1)/cratio; + float grv = Math::db2linear(gr); + + runmax = maxover + relcoef * (runmax - maxover); // highest peak for setting att/rel decays in reltime + maxover = runmax; + + if (grv < gr_meter) { + gr_meter=grv; + } else { + gr_meter*=gr_meter_decay; + if(gr_meter>1) + gr_meter=1; + } + + + p_dst_frames[i] = p_src_frames[i] * grv * makeup * mix + p_src_frames[i] * (1.0-mix); + + } + +} + + +Ref<AudioEffectInstance> AudioEffectCompressor::instance() { + Ref<AudioEffectCompressorInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectCompressor>(this); + ins->rundb=0; + ins->runratio=0; + ins->averatio=0; + ins->runmax=0; + ins->maxover=0; + ins->gr_meter=1.0; + ins->current_channel=-1; + return ins; +} + + +void AudioEffectCompressor::set_treshold(float p_treshold) { + + treshold=p_treshold; +} + +float AudioEffectCompressor::get_treshold() const { + + return treshold; +} + +void AudioEffectCompressor::set_ratio(float p_ratio) { + + ratio=p_ratio; +} +float AudioEffectCompressor::get_ratio() const { + + return ratio; +} + +void AudioEffectCompressor::set_gain(float p_gain) { + + gain=p_gain; +} +float AudioEffectCompressor::get_gain() const { + + return gain; +} + +void AudioEffectCompressor::set_attack_us(float p_attack_us) { + + attack_us=p_attack_us; +} +float AudioEffectCompressor::get_attack_us() const { + + return attack_us; +} + +void AudioEffectCompressor::set_release_ms(float p_release_ms) { + + release_ms=p_release_ms; +} +float AudioEffectCompressor::get_release_ms() const { + + return release_ms; +} + +void AudioEffectCompressor::set_mix(float p_mix) { + + mix=p_mix; +} +float AudioEffectCompressor::get_mix() const { + + return mix; +} + +void AudioEffectCompressor::set_sidechain(const StringName& p_sidechain) { + + AudioServer::get_singleton()->lock(); + sidechain=p_sidechain; + AudioServer::get_singleton()->unlock(); +} + +StringName AudioEffectCompressor::get_sidechain() const { + + return sidechain; +} + +void AudioEffectCompressor::_validate_property(PropertyInfo& property) const { + + if (property.name=="sidechain") { + + String buses=""; + for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) { + buses+=","; + buses+=AudioServer::get_singleton()->get_bus_name(i); + } + + property.hint_string=buses; + } +} + +void AudioEffectCompressor::_bind_methods() { + + ClassDB::bind_method(_MD("set_treshold","treshold"),&AudioEffectCompressor::set_treshold); + ClassDB::bind_method(_MD("get_treshold"),&AudioEffectCompressor::get_treshold); + + ClassDB::bind_method(_MD("set_ratio","ratio"),&AudioEffectCompressor::set_ratio); + ClassDB::bind_method(_MD("get_ratio"),&AudioEffectCompressor::get_ratio); + + ClassDB::bind_method(_MD("set_gain","gain"),&AudioEffectCompressor::set_gain); + ClassDB::bind_method(_MD("get_gain"),&AudioEffectCompressor::get_gain); + + ClassDB::bind_method(_MD("set_attack_us","attack_us"),&AudioEffectCompressor::set_attack_us); + ClassDB::bind_method(_MD("get_attack_us"),&AudioEffectCompressor::get_attack_us); + + ClassDB::bind_method(_MD("set_release_ms","release_ms"),&AudioEffectCompressor::set_release_ms); + ClassDB::bind_method(_MD("get_release_ms"),&AudioEffectCompressor::get_release_ms); + + ClassDB::bind_method(_MD("set_mix","mix"),&AudioEffectCompressor::set_mix); + ClassDB::bind_method(_MD("get_mix"),&AudioEffectCompressor::get_mix); + + ClassDB::bind_method(_MD("set_sidechain","sidechain"),&AudioEffectCompressor::set_sidechain); + ClassDB::bind_method(_MD("get_sidechain"),&AudioEffectCompressor::get_sidechain); + + ADD_PROPERTY(PropertyInfo(Variant::REAL,"treshold",PROPERTY_HINT_RANGE,"-60,0,0.1"),_SCS("set_treshold"),_SCS("get_treshold")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"ratio",PROPERTY_HINT_RANGE,"1,48,0.1"),_SCS("set_ratio"),_SCS("get_ratio")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"gain",PROPERTY_HINT_RANGE,"-20,20,0.1"),_SCS("set_gain"),_SCS("get_gain")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"attack_us",PROPERTY_HINT_RANGE,"20,2000,1"),_SCS("set_attack_us"),_SCS("get_attack_us")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"release_ms",PROPERTY_HINT_RANGE,"20,2000,1"),_SCS("set_release_ms"),_SCS("get_release_ms")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"mix",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_mix"),_SCS("get_mix")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"sidechain",PROPERTY_HINT_ENUM),_SCS("set_sidechain"),_SCS("get_sidechain")); + +} + +AudioEffectCompressor::AudioEffectCompressor() +{ + treshold=0; + ratio=4; + gain=0; + attack_us=20; + release_ms=250; + mix=1; +} diff --git a/servers/audio/effects/audio_effect_compressor.h b/servers/audio/effects/audio_effect_compressor.h new file mode 100644 index 0000000000..eb06b3db77 --- /dev/null +++ b/servers/audio/effects/audio_effect_compressor.h @@ -0,0 +1,70 @@ +#ifndef AUDIOEFFECTCOMPRESSOR_H +#define AUDIOEFFECTCOMPRESSOR_H + + +#include "servers/audio/audio_effect.h" + +class AudioEffectCompressor; + +class AudioEffectCompressorInstance : public AudioEffectInstance { + GDCLASS(AudioEffectCompressorInstance,AudioEffectInstance) +friend class AudioEffectCompressor; + Ref<AudioEffectCompressor> base; + + float rundb,averatio,runratio,runmax,maxover,gr_meter; + int current_channel; +public: + + void set_current_channel(int p_channel) { current_channel=p_channel; } + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +}; + + +class AudioEffectCompressor : public AudioEffect { + GDCLASS(AudioEffectCompressor,AudioEffect) + +friend class AudioEffectCompressorInstance; + float treshold; + float ratio; + float gain; + float attack_us; + float release_ms; + float mix; + StringName sidechain; + + +protected: + void _validate_property(PropertyInfo& property) const; + static void _bind_methods(); +public: + + + Ref<AudioEffectInstance> instance(); + + + void set_treshold(float p_treshold); + float get_treshold() const; + + void set_ratio(float p_ratio); + float get_ratio() const; + + void set_gain(float p_gain); + float get_gain() const; + + void set_attack_us(float p_attack_us); + float get_attack_us() const; + + void set_release_ms(float p_release_ms); + float get_release_ms() const; + + void set_mix(float p_mix); + float get_mix() const; + + void set_sidechain(const StringName& p_sidechain); + StringName get_sidechain() const; + + AudioEffectCompressor(); +}; + +#endif // AUDIOEFFECTCOMPRESSOR_H diff --git a/servers/audio/effects/audio_effect_delay.cpp b/servers/audio/effects/audio_effect_delay.cpp new file mode 100644 index 0000000000..aae2657a63 --- /dev/null +++ b/servers/audio/effects/audio_effect_delay.cpp @@ -0,0 +1,326 @@ +#include "audio_effect_delay.h" +#include "servers/audio_server.h" +#include "math_funcs.h" + +void AudioEffectDelayInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + int todo = p_frame_count; + + while(todo) { + + int to_mix = MIN(todo,256); //can't mix too much + + _process_chunk(p_src_frames,p_dst_frames,to_mix); + + p_src_frames+=to_mix; + p_dst_frames+=to_mix; + + todo-=to_mix; + } +} + +void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + + + float main_level_f=base->dry; + + + float mix_rate = AudioServer::get_singleton()->get_mix_rate(); + + float tap_1_level_f=base->tap_1_active?Math::db2linear(base->tap_1_level):0.0; + int tap_1_delay_frames=int((base->tap_1_delay_ms/1000.0)*mix_rate);; + + float tap_2_level_f=base->tap_2_active?Math::db2linear(base->tap_2_level):0.0; + int tap_2_delay_frames=int((base->tap_2_delay_ms/1000.0)*mix_rate);; + + float feedback_level_f=base->feedback_active?Math::db2linear(base->feedback_level):0.0; + unsigned int feedback_delay_frames=int((base->feedback_delay_ms/1000.0)*mix_rate);; + + + AudioFrame tap1_vol=AudioFrame(tap_1_level_f,tap_1_level_f); + + tap1_vol.l*=CLAMP( 1.0 - base->tap_1_pan, 0, 1); + tap1_vol.r*=CLAMP( 1.0 + base->tap_1_pan, 0, 1); + + AudioFrame tap2_vol=AudioFrame(tap_2_level_f,tap_2_level_f); + + tap2_vol.l*=CLAMP( 1.0 - base->tap_2_pan, 0, 1); + tap2_vol.r*=CLAMP( 1.0 + base->tap_2_pan, 0, 1); + + // feedback lowpass here + float lpf_c=expf(-2.0*Math_PI*base->feedback_lowpass/mix_rate); // 0 .. 10khz + float lpf_ic=1.0-lpf_c; + + const AudioFrame *src=p_src_frames; + AudioFrame *dst=p_dst_frames; + AudioFrame *rb_buf=ring_buffer.ptr(); + AudioFrame *fb_buf=feedback_buffer.ptr(); + + + for (int i=0;i<p_frame_count;i++) { + + + rb_buf[ring_buffer_pos&ring_buffer_mask]=src[i]; + + AudioFrame main_val=src[i]*main_level_f; + AudioFrame tap_1_val=rb_buf[(ring_buffer_pos-tap_1_delay_frames)&ring_buffer_mask]*tap1_vol; + AudioFrame tap_2_val=rb_buf[(ring_buffer_pos-tap_2_delay_frames)&ring_buffer_mask]*tap2_vol; + + AudioFrame out=main_val+tap_1_val+tap_2_val; + + out+=fb_buf[ feedback_buffer_pos ]; + + //apply lowpass and feedback gain + AudioFrame fb_in=out*feedback_level_f*lpf_ic+h*lpf_c; + fb_in.undenormalise(); //avoid denormals + + h=fb_in; + fb_buf[ feedback_buffer_pos ]=fb_in; + + dst[i]=out; + + ring_buffer_pos++; + + if ( (++feedback_buffer_pos) >= feedback_delay_frames ) + feedback_buffer_pos=0; + } +} + + + +Ref<AudioEffectInstance> AudioEffectDelay::instance() { + Ref<AudioEffectDelayInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectDelay>(this); + + float ring_buffer_max_size=MAX_DELAY_MS+100; //add 100ms of extra room, just in case + ring_buffer_max_size/=1000.0;//convert to seconds + ring_buffer_max_size*=AudioServer::get_singleton()->get_mix_rate(); + + int ringbuff_size=ring_buffer_max_size; + + int bits=0; + + while(ringbuff_size>0) { + bits++; + ringbuff_size/=2; + } + + ringbuff_size=1<<bits; + ins->ring_buffer_mask=ringbuff_size-1; + ins->ring_buffer_pos=0; + + ins->ring_buffer.resize( ringbuff_size ); + ins->feedback_buffer.resize( ringbuff_size ); + + ins->feedback_buffer_pos=0; + + ins->h=AudioFrame(0,0); + + return ins; +} + + +void AudioEffectDelay::set_dry(float p_dry) { + + dry=p_dry; +} + +float AudioEffectDelay::get_dry(){ + + return dry; +} + +void AudioEffectDelay::set_tap1_active(bool p_active){ + + tap_1_active=p_active; +} +bool AudioEffectDelay::is_tap1_active() const{ + + return tap_1_active; +} + +void AudioEffectDelay::set_tap1_delay_ms(float p_delay_ms){ + + tap_1_delay_ms=p_delay_ms; +} +float AudioEffectDelay::get_tap1_delay_ms() const{ + + return tap_1_delay_ms; +} + +void AudioEffectDelay::set_tap1_level_db(float p_level_db){ + + tap_1_level=p_level_db; +} +float AudioEffectDelay::get_tap1_level_db() const{ + + return tap_1_level; +} + +void AudioEffectDelay::set_tap1_pan(float p_pan){ + + tap_1_pan=p_pan; +} +float AudioEffectDelay::get_tap1_pan() const{ + + return tap_1_pan; +} + + +void AudioEffectDelay::set_tap2_active(bool p_active){ + + tap_2_active=p_active; +} +bool AudioEffectDelay::is_tap2_active() const{ + + return tap_2_active; +} + +void AudioEffectDelay::set_tap2_delay_ms(float p_delay_ms){ + + tap_2_delay_ms=p_delay_ms; +} +float AudioEffectDelay::get_tap2_delay_ms() const{ + + return tap_2_delay_ms; +} + +void AudioEffectDelay::set_tap2_level_db(float p_level_db){ + + tap_2_level=p_level_db; +} +float AudioEffectDelay::get_tap2_level_db() const{ + + return tap_2_level; +} + +void AudioEffectDelay::set_tap2_pan(float p_pan){ + + tap_2_pan=p_pan; +} +float AudioEffectDelay::get_tap2_pan() const{ + + return tap_2_pan; +} + +void AudioEffectDelay::set_feedback_active(bool p_active){ + + feedback_active=p_active; +} +bool AudioEffectDelay::is_feedback_active() const{ + + return feedback_active; +} + +void AudioEffectDelay::set_feedback_delay_ms(float p_delay_ms){ + + feedback_delay_ms=p_delay_ms; +} +float AudioEffectDelay::get_feedback_delay_ms() const{ + + return feedback_delay_ms; +} + +void AudioEffectDelay::set_feedback_level_db(float p_level_db){ + + feedback_level=p_level_db; +} +float AudioEffectDelay::get_feedback_level_db() const{ + + return feedback_level; +} + +void AudioEffectDelay::set_feedback_lowpass(float p_lowpass){ + + feedback_lowpass=p_lowpass; +} +float AudioEffectDelay::get_feedback_lowpass() const{ + + return feedback_lowpass; +} + + +void AudioEffectDelay::_bind_methods() { + + ClassDB::bind_method(_MD("set_dry","amount"),&AudioEffectDelay::set_dry); + ClassDB::bind_method(_MD("get_dry"),&AudioEffectDelay::get_dry); + + ClassDB::bind_method(_MD("set_tap1_active","amount"),&AudioEffectDelay::set_tap1_active); + ClassDB::bind_method(_MD("is_tap1_active"),&AudioEffectDelay::is_tap1_active); + + ClassDB::bind_method(_MD("set_tap1_delay_ms","amount"),&AudioEffectDelay::set_tap1_delay_ms); + ClassDB::bind_method(_MD("get_tap1_delay_ms"),&AudioEffectDelay::get_tap1_delay_ms); + + ClassDB::bind_method(_MD("set_tap1_level_db","amount"),&AudioEffectDelay::set_tap1_level_db); + ClassDB::bind_method(_MD("get_tap1_level_db"),&AudioEffectDelay::get_tap1_level_db); + + ClassDB::bind_method(_MD("set_tap1_pan","amount"),&AudioEffectDelay::set_tap1_pan); + ClassDB::bind_method(_MD("get_tap1_pan"),&AudioEffectDelay::get_tap1_pan); + + ClassDB::bind_method(_MD("set_tap2_active","amount"),&AudioEffectDelay::set_tap2_active); + ClassDB::bind_method(_MD("is_tap2_active"),&AudioEffectDelay::is_tap2_active); + + ClassDB::bind_method(_MD("set_tap2_delay_ms","amount"),&AudioEffectDelay::set_tap2_delay_ms); + ClassDB::bind_method(_MD("get_tap2_delay_ms"),&AudioEffectDelay::get_tap2_delay_ms); + + ClassDB::bind_method(_MD("set_tap2_level_db","amount"),&AudioEffectDelay::set_tap2_level_db); + ClassDB::bind_method(_MD("get_tap2_level_db"),&AudioEffectDelay::get_tap2_level_db); + + ClassDB::bind_method(_MD("set_tap2_pan","amount"),&AudioEffectDelay::set_tap2_pan); + ClassDB::bind_method(_MD("get_tap2_pan"),&AudioEffectDelay::get_tap2_pan); + + + ClassDB::bind_method(_MD("set_feedback_active","amount"),&AudioEffectDelay::set_feedback_active); + ClassDB::bind_method(_MD("is_feedback_active"),&AudioEffectDelay::is_feedback_active); + + ClassDB::bind_method(_MD("set_feedback_delay_ms","amount"),&AudioEffectDelay::set_feedback_delay_ms); + ClassDB::bind_method(_MD("get_feedback_delay_ms"),&AudioEffectDelay::get_feedback_delay_ms); + + ClassDB::bind_method(_MD("set_feedback_level_db","amount"),&AudioEffectDelay::set_feedback_level_db); + ClassDB::bind_method(_MD("get_feedback_level_db"),&AudioEffectDelay::get_feedback_level_db); + + ClassDB::bind_method(_MD("set_feedback_lowpass","amount"),&AudioEffectDelay::set_feedback_lowpass); + ClassDB::bind_method(_MD("get_feedback_lowpass"),&AudioEffectDelay::get_feedback_lowpass); + + ADD_PROPERTY(PropertyInfo(Variant::REAL,"dry",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_dry"),_SCS("get_dry")); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"tap1/active"),_SCS("set_tap1_active"),_SCS("is_tap1_active")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap1/delay_ms",PROPERTY_HINT_RANGE,"0,1500,1"),_SCS("set_tap1_delay_ms"),_SCS("get_tap1_delay_ms")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap1/level_db",PROPERTY_HINT_RANGE,"-60,0,0.01"),_SCS("set_tap1_level_db"),_SCS("get_tap1_level_db")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap1/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_tap1_pan"),_SCS("get_tap1_pan")); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"tap2/active"),_SCS("set_tap2_active"),_SCS("is_tap2_active")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap2/delay_ms",PROPERTY_HINT_RANGE,"0,1500,1"),_SCS("set_tap2_delay_ms"),_SCS("get_tap2_delay_ms")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap2/level_db",PROPERTY_HINT_RANGE,"-60,0,0.01"),_SCS("set_tap2_level_db"),_SCS("get_tap2_level_db")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"tap2/pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_tap2_pan"),_SCS("get_tap2_pan")); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"feedback/active"),_SCS("set_feedback_active"),_SCS("is_feedback_active")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"feedback/delay_ms",PROPERTY_HINT_RANGE,"0,1500,1"),_SCS("set_feedback_delay_ms"),_SCS("get_feedback_delay_ms")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"feedback/level_db",PROPERTY_HINT_RANGE,"-60,0,0.01"),_SCS("set_feedback_level_db"),_SCS("get_feedback_level_db")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"feedback/lowpass",PROPERTY_HINT_RANGE,"1,16000,1"),_SCS("set_feedback_lowpass"),_SCS("get_feedback_lowpass")); + + +} + +AudioEffectDelay::AudioEffectDelay() +{ + tap_1_active=true; + tap_1_delay_ms=250; + tap_1_level=-6; + tap_1_pan=0.2; + + tap_2_active=true; + tap_2_delay_ms=500; + tap_2_level=-12; + tap_2_pan=-0.4; + + feedback_active=false; + feedback_delay_ms=340; + feedback_level=-6; + feedback_lowpass=16000; + + dry=1.0; + +} diff --git a/servers/audio/effects/audio_effect_delay.h b/servers/audio/effects/audio_effect_delay.h new file mode 100644 index 0000000000..645561138b --- /dev/null +++ b/servers/audio/effects/audio_effect_delay.h @@ -0,0 +1,112 @@ +#ifndef AUDIOEFFECTECHO_H +#define AUDIOEFFECTECHO_H + +#include "servers/audio/audio_effect.h" + +class AudioEffectDelay; + +class AudioEffectDelayInstance : public AudioEffectInstance { + GDCLASS(AudioEffectDelayInstance,AudioEffectInstance) +friend class AudioEffectDelay; + Ref<AudioEffectDelay> base; + + Vector<AudioFrame> ring_buffer; + + unsigned int ring_buffer_pos; + unsigned int ring_buffer_mask; + + /* feedback buffer */ + Vector<AudioFrame> feedback_buffer; + + unsigned int feedback_buffer_pos; + + AudioFrame h; + void _process_chunk(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +}; + + +class AudioEffectDelay : public AudioEffect { + GDCLASS(AudioEffectDelay,AudioEffect) + +friend class AudioEffectDelayInstance; + enum { + + MAX_DELAY_MS=3000, + MAX_TAPS=2 + }; + + float dry; + + bool tap_1_active; + float tap_1_delay_ms; + float tap_1_level; + float tap_1_pan; + + bool tap_2_active; + float tap_2_delay_ms; + float tap_2_level; + float tap_2_pan; + + bool feedback_active; + float feedback_delay_ms; + float feedback_level; + float feedback_lowpass; + + + +protected: + + static void _bind_methods(); +public: + + void set_dry(float p_dry); + float get_dry(); + + void set_tap1_active(bool p_active); + bool is_tap1_active() const; + + void set_tap1_delay_ms(float p_delay_ms); + float get_tap1_delay_ms() const; + + void set_tap1_level_db(float p_level_db); + float get_tap1_level_db() const; + + void set_tap1_pan(float p_pan); + float get_tap1_pan() const; + + void set_tap2_active(bool p_active); + bool is_tap2_active() const; + + void set_tap2_delay_ms(float p_delay_ms); + float get_tap2_delay_ms() const; + + void set_tap2_level_db(float p_level_db); + float get_tap2_level_db() const; + + void set_tap2_pan(float p_pan); + float get_tap2_pan() const; + + void set_feedback_active(bool p_active); + bool is_feedback_active() const; + + void set_feedback_delay_ms(float p_delay_ms); + float get_feedback_delay_ms() const; + + void set_feedback_level_db(float p_level_db); + float get_feedback_level_db() const; + + void set_feedback_lowpass(float p_lowpass); + float get_feedback_lowpass() const; + + Ref<AudioEffectInstance> instance(); + + AudioEffectDelay(); +}; + + +#endif // AUDIOEFFECTECHO_H diff --git a/servers/audio/effects/audio_effect_distortion.cpp b/servers/audio/effects/audio_effect_distortion.cpp new file mode 100644 index 0000000000..3ba409b0a5 --- /dev/null +++ b/servers/audio/effects/audio_effect_distortion.cpp @@ -0,0 +1,171 @@ +#include "audio_effect_distortion.h" +#include "servers/audio_server.h" +#include "math_funcs.h" + + + +void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + const float *src = (const float*)p_src_frames; + float *dst = (float*)p_dst_frames; + + //float lpf_c=expf(-2.0*Math_PI*keep_hf_hz.get()/(mix_rate*(float)OVERSAMPLE)); + float lpf_c=expf(-2.0*Math_PI*base->keep_hf_hz/(AudioServer::get_singleton()->get_mix_rate())); + float lpf_ic=1.0-lpf_c; + + float drive_f=base->drive; + float pregain_f=Math::db2linear(base->pre_gain); + float postgain_f=Math::db2linear(base->post_gain); + + float atan_mult=pow(10,drive_f*drive_f*3.0)-1.0+0.001; + float atan_div=1.0/(atanf(atan_mult)*(1.0+drive_f*8)); + + float lofi_mult=powf(2.0,2.0+(1.0-drive_f)*14); //goes from 16 to 2 bits + + for (int i=0;i<p_frame_count*2;i++) { + + float out=undenormalise(src[i]*lpf_ic+lpf_c*h[i&1]); + h[i&1]=out; + float a=out; + float ha=src[i]-out; //high freqs + a*=pregain_f; + + switch (base->mode) { + + case AudioEffectDistortion::MODE_CLIP: { + + a=powf(a,1.0001-drive_f); + if (a>1.0) + a=1.0; + else if (a<(-1.0)) + a=-1.0; + + } break; + case AudioEffectDistortion::MODE_ATAN: { + + + a=atanf(a*atan_mult)*atan_div; + + } break; + case AudioEffectDistortion::MODE_LOFI: { + + a = floorf(a*lofi_mult+0.5)/lofi_mult; + + } break; + case AudioEffectDistortion::MODE_OVERDRIVE: { + + + const double x = a * 0.686306; + const double z = 1 + exp (sqrt (fabs (x)) * -0.75); + a = (expf(x) - expf(-x * z)) / (expf(x) + expf(-x)); + } break; + case AudioEffectDistortion::MODE_WAVESHAPE: { + float x = a; + float k= 2*drive_f/(1.00001-drive_f); + + a = (1.0+k)*x/(1.0+k*fabsf(x)); + + + } break; + } + + dst[i]=a*postgain_f+ha; + + } + + +} + + +Ref<AudioEffectInstance> AudioEffectDistortion::instance() { + Ref<AudioEffectDistortionInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectDistortion>(this); + ins->h[0]=0; + ins->h[1]=0; + + return ins; +} + + +void AudioEffectDistortion::set_mode(Mode p_mode) { + + mode=p_mode; +} + +AudioEffectDistortion::Mode AudioEffectDistortion::get_mode() const{ + + return mode; +} + +void AudioEffectDistortion::set_pre_gain(float p_pre_gain){ + + pre_gain=p_pre_gain; +} +float AudioEffectDistortion::get_pre_gain() const{ + + return pre_gain; +} + +void AudioEffectDistortion::set_keep_hf_hz(float p_keep_hf_hz){ + + keep_hf_hz=p_keep_hf_hz; +} +float AudioEffectDistortion::get_keep_hf_hz() const{ + + return keep_hf_hz; +} + +void AudioEffectDistortion::set_drive(float p_drive){ + + drive=p_drive; +} +float AudioEffectDistortion::get_drive() const{ + + return drive; +} + +void AudioEffectDistortion::set_post_gain(float p_post_gain){ + + post_gain=p_post_gain; +} +float AudioEffectDistortion::get_post_gain() const{ + + return post_gain; +} + + +void AudioEffectDistortion::_bind_methods() { + + ClassDB::bind_method(_MD("set_mode","mode"),&AudioEffectDistortion::set_mode); + ClassDB::bind_method(_MD("get_mode"),&AudioEffectDistortion::get_mode); + + ClassDB::bind_method(_MD("set_pre_gain","pre_gain"),&AudioEffectDistortion::set_pre_gain); + ClassDB::bind_method(_MD("get_pre_gain"),&AudioEffectDistortion::get_pre_gain); + + ClassDB::bind_method(_MD("set_keep_hf_hz","keep_hf_hz"),&AudioEffectDistortion::set_keep_hf_hz); + ClassDB::bind_method(_MD("get_keep_hf_hz"),&AudioEffectDistortion::get_keep_hf_hz); + + ClassDB::bind_method(_MD("set_drive","drive"),&AudioEffectDistortion::set_drive); + ClassDB::bind_method(_MD("get_drive"),&AudioEffectDistortion::get_drive); + + + ClassDB::bind_method(_MD("set_post_gain","post_gain"),&AudioEffectDistortion::set_post_gain); + ClassDB::bind_method(_MD("get_post_gain"),&AudioEffectDistortion::get_post_gain); + + ADD_PROPERTY(PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Clip,ATan,LoFi,Overdrive,WaveShape"),_SCS("set_mode"),_SCS("get_mode")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"pre_gain",PROPERTY_HINT_RANGE,"-60,60,0.01"),_SCS("set_pre_gain"),_SCS("get_pre_gain")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"keep_hf_hz",PROPERTY_HINT_RANGE,"1,20000,1"),_SCS("set_keep_hf_hz"),_SCS("get_keep_hf_hz")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"drive",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_drive"),_SCS("get_drive")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"post_gain",PROPERTY_HINT_RANGE,"-80,24,0.01"),_SCS("set_post_gain"),_SCS("get_post_gain")); +} + +AudioEffectDistortion::AudioEffectDistortion() +{ + mode=MODE_CLIP; + pre_gain=0; + post_gain=0; + keep_hf_hz=16000; + drive=0; +} + diff --git a/servers/audio/effects/audio_effect_distortion.h b/servers/audio/effects/audio_effect_distortion.h new file mode 100644 index 0000000000..1d2433faeb --- /dev/null +++ b/servers/audio/effects/audio_effect_distortion.h @@ -0,0 +1,69 @@ +#ifndef AUDIOEFFECTDISTORTION_H +#define AUDIOEFFECTDISTORTION_H + +#include "servers/audio/audio_effect.h" + +class AudioEffectDistortion; + +class AudioEffectDistortionInstance : public AudioEffectInstance { + GDCLASS(AudioEffectDistortionInstance,AudioEffectInstance) +friend class AudioEffectDistortion; + Ref<AudioEffectDistortion> base; + float h[2]; +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +}; + + +class AudioEffectDistortion : public AudioEffect { + GDCLASS(AudioEffectDistortion,AudioEffect) +public: + enum Mode { + MODE_CLIP, + MODE_ATAN, + MODE_LOFI, + MODE_OVERDRIVE, + MODE_WAVESHAPE, + }; + +friend class AudioEffectDistortionInstance; + Mode mode; + float pre_gain; + float post_gain; + float keep_hf_hz; + float drive; + +protected: + + static void _bind_methods(); +public: + + + Ref<AudioEffectInstance> instance(); + + + void set_mode(Mode p_mode); + Mode get_mode() const; + + void set_pre_gain(float pre_gain); + float get_pre_gain() const; + + void set_keep_hf_hz(float keep_hf_hz); + float get_keep_hf_hz() const; + + void set_drive(float drive); + float get_drive() const; + + void set_post_gain(float post_gain); + float get_post_gain() const; + + + + AudioEffectDistortion(); +}; + +VARIANT_ENUM_CAST( AudioEffectDistortion::Mode ) + +#endif // AUDIOEFFECTDISTORTION_H diff --git a/servers/audio/effects/audio_effect_eq.cpp b/servers/audio/effects/audio_effect_eq.cpp new file mode 100644 index 0000000000..3c6a684224 --- /dev/null +++ b/servers/audio/effects/audio_effect_eq.cpp @@ -0,0 +1,122 @@ +#include "audio_effect_eq.h" +#include "servers/audio_server.h" + + +void AudioEffectEQInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + int band_count = bands[0].size(); + EQ::BandProcess *proc_l = bands[0].ptr(); + EQ::BandProcess *proc_r = bands[1].ptr(); + float *bgain = gains.ptr(); + for(int i=0;i<band_count;i++) { + bgain[i]=Math::db2linear(base->gain[i]); + } + + + for(int i=0;i<p_frame_count;i++) { + + AudioFrame src = p_src_frames[i]; + AudioFrame dst = AudioFrame(0,0); + + for(int j=0;j<band_count;j++) { + + float l = src.l; + float r = src.r; + + proc_l[j].process_one(l); + proc_r[j].process_one(r); + + dst.l+=l * bgain[j]; + dst.r+=r * bgain[j]; + } + + p_dst_frames[i]=dst; + } + +} + + +Ref<AudioEffectInstance> AudioEffectEQ::instance() { + Ref<AudioEffectEQInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectEQ>(this); + ins->gains.resize(eq.get_band_count()); + for(int i=0;i<2;i++) { + ins->bands[i].resize(eq.get_band_count()); + for(int j=0;j<ins->bands[i].size();j++) { + ins->bands[i][j]=eq.get_band_processor(j); + } + } + + return ins; +} + +void AudioEffectEQ::set_band_gain_db(int p_band,float p_volume) { + ERR_FAIL_INDEX(p_band,gain.size()); + gain[p_band]=p_volume; +} + +float AudioEffectEQ::get_band_gain_db(int p_band) const { + ERR_FAIL_INDEX_V(p_band,gain.size(),0); + + return gain[p_band]; +} +int AudioEffectEQ::get_band_count() const { + return gain.size(); +} + +bool AudioEffectEQ::_set(const StringName& p_name, const Variant& p_value) { + + const Map<StringName,int>::Element *E=prop_band_map.find(p_name); + if (E) { + set_band_gain_db(E->get(),p_value); + return true; + } + + return false; +} + +bool AudioEffectEQ::_get(const StringName& p_name,Variant &r_ret) const{ + + const Map<StringName,int>::Element *E=prop_band_map.find(p_name); + if (E) { + r_ret=get_band_gain_db(E->get()); + return true; + } + + return false; + +} + +void AudioEffectEQ::_get_property_list( List<PropertyInfo> *p_list) const{ + + for(int i=0;i<band_names.size();i++) { + + p_list->push_back(PropertyInfo(Variant::REAL,band_names[i],PROPERTY_HINT_RANGE,"-60,24,0.1")); + } +} + + + +void AudioEffectEQ::_bind_methods() { + + ClassDB::bind_method(_MD("set_band_gain_db","band_idx","volume_db"),&AudioEffectEQ::set_band_gain_db); + ClassDB::bind_method(_MD("get_band_gain_db","band_idx"),&AudioEffectEQ::get_band_gain_db); + ClassDB::bind_method(_MD("get_band_count"),&AudioEffectEQ::get_band_count); + +} + +AudioEffectEQ::AudioEffectEQ(EQ::Preset p_preset) +{ + + + eq.set_mix_rate(AudioServer::get_singleton()->get_mix_rate()); + eq.set_preset_band_mode(p_preset); + gain.resize(eq.get_band_count()); + for(int i=0;i<gain.size();i++) { + gain[i]=0.0; + String name = "band_db/"+itos(eq.get_band_frequency(i))+"_hz"; + prop_band_map[name]=i; + band_names.push_back(name); + } +} diff --git a/servers/audio/effects/audio_effect_eq.h b/servers/audio/effects/audio_effect_eq.h new file mode 100644 index 0000000000..3fcc2c0056 --- /dev/null +++ b/servers/audio/effects/audio_effect_eq.h @@ -0,0 +1,72 @@ +#ifndef AUDIOEFFECTEQ_H +#define AUDIOEFFECTEQ_H + + +#include "servers/audio/audio_effect.h" +#include "servers/audio/effects/eq.h" + +class AudioEffectEQ; + +class AudioEffectEQInstance : public AudioEffectInstance { + GDCLASS(AudioEffectEQInstance,AudioEffectInstance) +friend class AudioEffectEQ; + Ref<AudioEffectEQ> base; + + Vector<EQ::BandProcess> bands[2]; + Vector<float> gains; +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +}; + + +class AudioEffectEQ : public AudioEffect { + GDCLASS(AudioEffectEQ,AudioEffect) + +friend class AudioEffectEQInstance; + + EQ eq; + Vector<float> gain; + Map<StringName,int> prop_band_map; + Vector<String> band_names; + +protected: + bool _set(const StringName& p_name, const Variant& p_value); + bool _get(const StringName& p_name,Variant &r_ret) const; + void _get_property_list( List<PropertyInfo> *p_list) const; + + + + static void _bind_methods(); +public: + + + Ref<AudioEffectInstance> instance(); + void set_band_gain_db(int p_band,float p_volume); + float get_band_gain_db(int p_band) const; + int get_band_count() const; + + AudioEffectEQ(EQ::Preset p_preset=EQ::PRESET_6_BANDS); +}; + + +class AudioEffectEQ6 : public AudioEffectEQ { + GDCLASS(AudioEffectEQ6,AudioEffectEQ) +public: + AudioEffectEQ6() : AudioEffectEQ(EQ::PRESET_6_BANDS) {} +}; + +class AudioEffectEQ10 : public AudioEffectEQ { + GDCLASS(AudioEffectEQ10,AudioEffectEQ) +public: + AudioEffectEQ10() : AudioEffectEQ(EQ::PRESET_10_BANDS) {} +}; + +class AudioEffectEQ21 : public AudioEffectEQ { + GDCLASS(AudioEffectEQ21,AudioEffectEQ) +public: + AudioEffectEQ21() : AudioEffectEQ(EQ::PRESET_21_BANDS) {} +}; + +#endif // AUDIOEFFECTEQ_H diff --git a/servers/audio/effects/audio_effect_filter.cpp b/servers/audio/effects/audio_effect_filter.cpp new file mode 100644 index 0000000000..4e54ea1f3e --- /dev/null +++ b/servers/audio/effects/audio_effect_filter.cpp @@ -0,0 +1,151 @@ +#include "audio_effect_filter.h" +#include "servers/audio_server.h" + +template<int S> +void AudioEffectFilterInstance::_process_filter(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + for(int i=0;i<p_frame_count;i++) { + float f = p_src_frames[i].l; + filter_process[0][0].process_one(f); + if (S>1) + filter_process[0][1].process_one(f); + if (S>2) + filter_process[0][2].process_one(f); + if (S>3) + filter_process[0][3].process_one(f); + + p_dst_frames[i].l=f; + } + + for(int i=0;i<p_frame_count;i++) { + float f = p_src_frames[i].r; + filter_process[1][0].process_one(f); + if (S>1) + filter_process[1][1].process_one(f); + if (S>2) + filter_process[1][2].process_one(f); + if (S>3) + filter_process[1][3].process_one(f); + + p_dst_frames[i].r=f; + } + +} + +void AudioEffectFilterInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + filter.set_cutoff(base->cutoff); + filter.set_gain(base->gain); + filter.set_resonance(base->resonance); + filter.set_mode(base->mode); + int stages = int(base->db)+1; + filter.set_stages(stages); + filter.set_sampling_rate(AudioServer::get_singleton()->get_mix_rate()); + + for(int i=0;i<2;i++) { + for(int j=0;j<4;j++) { + filter_process[i][j].update_coeffs(); + } + } + + + if (stages==1) { + _process_filter<1>(p_src_frames,p_dst_frames,p_frame_count); + } else if (stages==2) { + _process_filter<2>(p_src_frames,p_dst_frames,p_frame_count); + } else if (stages==3) { + _process_filter<3>(p_src_frames,p_dst_frames,p_frame_count); + } else if (stages==4) { + _process_filter<4>(p_src_frames,p_dst_frames,p_frame_count); + } + +} + + +AudioEffectFilterInstance::AudioEffectFilterInstance() { + + for(int i=0;i<2;i++) { + for(int j=0;j<4;j++) { + filter_process[i][j].set_filter(&filter); + } + } + +} + + +Ref<AudioEffectInstance> AudioEffectFilter::instance() { + Ref<AudioEffectFilterInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectFilter>(this); + + return ins; +} + +void AudioEffectFilter::set_cutoff(float p_freq) { + + cutoff=p_freq; +} + +float AudioEffectFilter::get_cutoff() const{ + + return cutoff; +} + +void AudioEffectFilter::set_resonance(float p_amount){ + + resonance=p_amount; +} +float AudioEffectFilter::get_resonance() const{ + + return resonance; +} + +void AudioEffectFilter::set_gain(float p_amount){ + + gain=p_amount; +} +float AudioEffectFilter::get_gain() const { + + return gain; +} + + + +void AudioEffectFilter::set_db(FilterDB p_db) { + db=p_db; +} + +AudioEffectFilter::FilterDB AudioEffectFilter::get_db() const { + + return db; +} + +void AudioEffectFilter::_bind_methods() { + + ClassDB::bind_method(_MD("set_cutoff","freq"),&AudioEffectFilter::set_cutoff); + ClassDB::bind_method(_MD("get_cutoff"),&AudioEffectFilter::get_cutoff); + + ClassDB::bind_method(_MD("set_resonance","amount"),&AudioEffectFilter::set_resonance); + ClassDB::bind_method(_MD("get_resonance"),&AudioEffectFilter::get_resonance); + + ClassDB::bind_method(_MD("set_gain","amount"),&AudioEffectFilter::set_gain); + ClassDB::bind_method(_MD("get_gain"),&AudioEffectFilter::get_gain); + + ClassDB::bind_method(_MD("set_db","amount"),&AudioEffectFilter::set_db); + ClassDB::bind_method(_MD("get_db"),&AudioEffectFilter::get_db); + + ADD_PROPERTY(PropertyInfo(Variant::REAL,"cutoff_hz",PROPERTY_HINT_RANGE,"1,40000,0.1"),_SCS("set_cutoff"),_SCS("get_cutoff")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"resonance",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_resonance"),_SCS("get_resonance")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"gain",PROPERTY_HINT_RANGE,"0,4,0.01"),_SCS("set_gain"),_SCS("get_gain")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"dB",PROPERTY_HINT_ENUM,"6db,12db,18db,24db"),_SCS("set_db"),_SCS("get_db")); +} + +AudioEffectFilter::AudioEffectFilter(AudioFilterSW::Mode p_mode) +{ + + mode=p_mode; + cutoff=2000; + resonance=0.5; + gain=1.0; + db=FILTER_6DB; +} diff --git a/servers/audio/effects/audio_effect_filter.h b/servers/audio/effects/audio_effect_filter.h new file mode 100644 index 0000000000..d0bc7a446a --- /dev/null +++ b/servers/audio/effects/audio_effect_filter.h @@ -0,0 +1,125 @@ +#ifndef AUDIOEFFECTFILTER_H +#define AUDIOEFFECTFILTER_H + +#include "servers/audio/audio_effect.h" +#include "servers/audio/audio_filter_sw.h" + +class AudioEffectFilter; + +class AudioEffectFilterInstance : public AudioEffectInstance { + GDCLASS(AudioEffectFilterInstance,AudioEffectInstance) +friend class AudioEffectFilter; + + Ref<AudioEffectFilter> base; + + AudioFilterSW filter; + AudioFilterSW::Processor filter_process[2][4]; + + template<int S> + void _process_filter(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + + AudioEffectFilterInstance(); +}; + + +class AudioEffectFilter : public AudioEffect { + GDCLASS(AudioEffectFilter,AudioEffect) +public: + + enum FilterDB { + FILTER_6DB, + FILTER_12DB, + FILTER_18DB, + FILTER_24DB, + }; + friend class AudioEffectFilterInstance; + + AudioFilterSW::Mode mode; + float cutoff; + float resonance; + float gain; + FilterDB db; + + +protected: + + + static void _bind_methods(); +public: + + void set_cutoff(float p_freq); + float get_cutoff() const; + + void set_resonance(float p_amount); + float get_resonance() const; + + void set_gain(float p_amount); + float get_gain() const; + + void set_db(FilterDB p_db); + FilterDB get_db() const; + + Ref<AudioEffectInstance> instance(); + + AudioEffectFilter(AudioFilterSW::Mode p_mode=AudioFilterSW::LOWPASS); +}; + +VARIANT_ENUM_CAST(AudioEffectFilter::FilterDB) + +class AudioEffectLowPassFilter : public AudioEffectFilter { + GDCLASS(AudioEffectLowPassFilter,AudioEffectFilter) +public: + + AudioEffectLowPassFilter() : AudioEffectFilter(AudioFilterSW::LOWPASS) {} +}; + +class AudioEffectHighPassFilter : public AudioEffectFilter { + GDCLASS(AudioEffectHighPassFilter,AudioEffectFilter) +public: + + AudioEffectHighPassFilter() : AudioEffectFilter(AudioFilterSW::HIGHPASS) {} +}; + +class AudioEffectBandPassFilter : public AudioEffectFilter { + GDCLASS(AudioEffectBandPassFilter,AudioEffectFilter) +public: + + AudioEffectBandPassFilter() : AudioEffectFilter(AudioFilterSW::BANDPASS) {} +}; + +class AudioEffectNotchFilter : public AudioEffectFilter { + GDCLASS(AudioEffectNotchFilter,AudioEffectFilter) +public: + + AudioEffectNotchFilter() : AudioEffectFilter(AudioFilterSW::NOTCH) {} +}; + +class AudioEffectBandLimitFilter : public AudioEffectFilter { + GDCLASS(AudioEffectBandLimitFilter,AudioEffectFilter) +public: + + AudioEffectBandLimitFilter() : AudioEffectFilter(AudioFilterSW::BANDLIMIT) {} +}; + + +class AudioEffectLowShelfFilter : public AudioEffectFilter { + GDCLASS(AudioEffectLowShelfFilter,AudioEffectFilter) +public: + + AudioEffectLowShelfFilter() : AudioEffectFilter(AudioFilterSW::LOWSHELF) {} +}; + + +class AudioEffectHighShelfFilter : public AudioEffectFilter { + GDCLASS(AudioEffectHighShelfFilter,AudioEffectFilter) +public: + + AudioEffectHighShelfFilter() : AudioEffectFilter(AudioFilterSW::HIGHSHELF) {} +}; + + + +#endif // AUDIOEFFECTFILTER_H diff --git a/servers/audio/effects/audio_effect_limiter.cpp b/servers/audio/effects/audio_effect_limiter.cpp new file mode 100644 index 0000000000..5cd02682ab --- /dev/null +++ b/servers/audio/effects/audio_effect_limiter.cpp @@ -0,0 +1,124 @@ +#include "audio_effect_limiter.h" + +void AudioEffectLimiterInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + float thresh = Math::db2linear(base->treshold); + float threshdb = base->treshold; + float ceiling = Math::db2linear(base->ceiling); + float ceildb = base->ceiling; + float makeup = Math::db2linear(ceildb - threshdb); + float makeupdb = ceildb - threshdb; + float sc = -base->soft_clip; + float scv = Math::db2linear(sc); + float sccomp = Math::db2linear(-sc); + float peakdb = ceildb + 25; + float peaklvl = Math::db2linear(peakdb); + float scratio = base->soft_clip_ratio; + float scmult = Math::abs((ceildb - sc) / (peakdb - sc)); + + for(int i=0;i<p_frame_count;i++) { + + float spl0 = p_src_frames[i].l; + float spl1 = p_src_frames[i].r; + spl0 = spl0 * makeup; + spl1 = spl1 * makeup; + float sign0 = (spl0 < 0.0 ? -1.0 : 1.0 ); + float sign1 = (spl1 < 0.0 ? -1.0 : 1.0 ); + float abs0 = Math::abs(spl0); + float abs1 = Math::abs(spl1); + float overdb0 = Math::linear2db(abs0) - ceildb; + float overdb1 = Math::linear2db(abs1) - ceildb; + + if (abs0 > scv) + { + spl0 = sign0 * (scv + Math::db2linear(overdb0 * scmult)); + } + if (abs1 > scv) + { + spl1 = sign1 * (scv + Math::db2linear(overdb1 * scmult)); + } + + spl0 = MIN(ceiling, Math::abs(spl0)) * (spl0 < 0.0 ? -1.0 : 1.0); + spl1 = MIN(ceiling, Math::abs(spl1)) * (spl1 < 0.0 ? -1.0 : 1.0); + + p_dst_frames[i].l = spl0; + p_dst_frames[i].r = spl1; + } + +} + + +Ref<AudioEffectInstance> AudioEffectLimiter::instance() { + Ref<AudioEffectLimiterInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectLimiter>(this); + + return ins; +} + + +void AudioEffectLimiter::set_treshold_db(float p_treshold) { + + treshold=p_treshold; +} + +float AudioEffectLimiter::get_treshold_db() const{ + + return treshold; +} + +void AudioEffectLimiter::set_ceiling_db(float p_ceiling){ + + ceiling=p_ceiling; +} +float AudioEffectLimiter::get_ceiling_db() const{ + + return ceiling; +} + +void AudioEffectLimiter::set_soft_clip_db(float p_soft_clip){ + + soft_clip=p_soft_clip; +} +float AudioEffectLimiter::get_soft_clip_db() const{ + + return soft_clip; +} + +void AudioEffectLimiter::set_soft_clip_ratio(float p_soft_clip){ + + soft_clip_ratio=p_soft_clip; +} +float AudioEffectLimiter::get_soft_clip_ratio() const{ + + return soft_clip; +} + + +void AudioEffectLimiter::_bind_methods() { + + ClassDB::bind_method(_MD("set_ceiling_db","ceiling"),&AudioEffectLimiter::set_ceiling_db); + ClassDB::bind_method(_MD("get_ceiling_db"),&AudioEffectLimiter::get_ceiling_db); + + ClassDB::bind_method(_MD("set_treshold_db","treshold"),&AudioEffectLimiter::set_treshold_db); + ClassDB::bind_method(_MD("get_treshold_db"),&AudioEffectLimiter::get_treshold_db); + + ClassDB::bind_method(_MD("set_soft_clip_db","soft_clip"),&AudioEffectLimiter::set_soft_clip_db); + ClassDB::bind_method(_MD("get_soft_clip_db"),&AudioEffectLimiter::get_soft_clip_db); + + ClassDB::bind_method(_MD("set_soft_clip_ratio","soft_clip"),&AudioEffectLimiter::set_soft_clip_ratio); + ClassDB::bind_method(_MD("get_soft_clip_ratio"),&AudioEffectLimiter::get_soft_clip_ratio); + + ADD_PROPERTY(PropertyInfo(Variant::REAL,"ceiling_db",PROPERTY_HINT_RANGE,"-20,-0.1,0.1"),_SCS("set_ceiling_db"),_SCS("get_ceiling_db")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"treshold_db",PROPERTY_HINT_RANGE,"-30,0,0.1"),_SCS("set_treshold_db"),_SCS("get_treshold_db")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"soft_clip_db",PROPERTY_HINT_RANGE,"0,6,0.1"),_SCS("set_soft_clip_db"),_SCS("get_soft_clip_db")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"soft_clip_ratio",PROPERTY_HINT_RANGE,"3,20,0.1"),_SCS("set_soft_clip_ratio"),_SCS("get_soft_clip_ratio")); +} + +AudioEffectLimiter::AudioEffectLimiter() +{ + treshold=0; + ceiling=-0.1; + soft_clip=2; + soft_clip_ratio=10; +} diff --git a/servers/audio/effects/audio_effect_limiter.h b/servers/audio/effects/audio_effect_limiter.h new file mode 100644 index 0000000000..b0d7321205 --- /dev/null +++ b/servers/audio/effects/audio_effect_limiter.h @@ -0,0 +1,58 @@ +#ifndef AUDIO_EFFECT_LIMITER_H +#define AUDIO_EFFECT_LIMITER_H + + +#include "servers/audio/audio_effect.h" + +class AudioEffectLimiter; + +class AudioEffectLimiterInstance : public AudioEffectInstance { + GDCLASS(AudioEffectLimiterInstance,AudioEffectInstance) +friend class AudioEffectLimiter; + Ref<AudioEffectLimiter> base; + + float mix_volume_db; +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +}; + + +class AudioEffectLimiter : public AudioEffect { + GDCLASS(AudioEffectLimiter,AudioEffect) + +friend class AudioEffectLimiterInstance; + float treshold; + float ceiling; + float soft_clip; + float soft_clip_ratio; + +protected: + + static void _bind_methods(); +public: + + + void set_treshold_db(float p_treshold); + float get_treshold_db() const; + + void set_ceiling_db(float p_ceiling); + float get_ceiling_db() const; + + void set_soft_clip_db(float p_soft_clip); + float get_soft_clip_db() const; + + void set_soft_clip_ratio(float p_soft_clip); + float get_soft_clip_ratio() const; + + + Ref<AudioEffectInstance> instance(); + void set_volume_db(float p_volume); + float get_volume_db() const; + + AudioEffectLimiter(); +}; + + +#endif // AUDIO_EFFECT_LIMITER_H diff --git a/servers/audio/effects/audio_effect_panner.cpp b/servers/audio/effects/audio_effect_panner.cpp new file mode 100644 index 0000000000..e296b0d998 --- /dev/null +++ b/servers/audio/effects/audio_effect_panner.cpp @@ -0,0 +1,47 @@ +#include "audio_effect_panner.h" + + +void AudioEffectPannerInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + + float lvol = CLAMP( 1.0 - base->pan, 0, 1); + float rvol = CLAMP( 1.0 + base->pan, 0, 1); + + for(int i=0;i<p_frame_count;i++) { + + p_dst_frames[i].l = p_src_frames[i].l * lvol + p_src_frames[i].r * (1.0 - rvol); + p_dst_frames[i].r = p_src_frames[i].r * rvol + p_src_frames[i].l * (1.0 - lvol); + + } + +} + + +Ref<AudioEffectInstance> AudioEffectPanner::instance() { + Ref<AudioEffectPannerInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectPanner>(this); + return ins; +} + +void AudioEffectPanner::set_pan(float p_cpanume) { + pan=p_cpanume; +} + +float AudioEffectPanner::get_pan() const { + + return pan; +} + +void AudioEffectPanner::_bind_methods() { + + ClassDB::bind_method(_MD("set_pan","cpanume"),&AudioEffectPanner::set_pan); + ClassDB::bind_method(_MD("get_pan"),&AudioEffectPanner::get_pan); + + ADD_PROPERTY(PropertyInfo(Variant::REAL,"pan",PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_pan"),_SCS("get_pan")); +} + +AudioEffectPanner::AudioEffectPanner() +{ + pan=0; +} diff --git a/servers/audio/effects/audio_effect_panner.h b/servers/audio/effects/audio_effect_panner.h new file mode 100644 index 0000000000..bc1bb00815 --- /dev/null +++ b/servers/audio/effects/audio_effect_panner.h @@ -0,0 +1,40 @@ +#ifndef AUDIOEFFECTPANNER_H +#define AUDIOEFFECTPANNER_H + +#include "servers/audio/audio_effect.h" + +class AudioEffectPanner; + +class AudioEffectPannerInstance : public AudioEffectInstance { + GDCLASS(AudioEffectPannerInstance,AudioEffectInstance) +friend class AudioEffectPanner; + Ref<AudioEffectPanner> base; + +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +}; + + +class AudioEffectPanner : public AudioEffect { + GDCLASS(AudioEffectPanner,AudioEffect) + +friend class AudioEffectPannerInstance; + float pan; + +protected: + + static void _bind_methods(); +public: + + + Ref<AudioEffectInstance> instance(); + void set_pan(float p_volume); + float get_pan() const; + + AudioEffectPanner(); +}; + + +#endif // AUDIOEFFECTPANNER_H diff --git a/servers/audio/effects/audio_effect_phaser.cpp b/servers/audio/effects/audio_effect_phaser.cpp new file mode 100644 index 0000000000..bfce608603 --- /dev/null +++ b/servers/audio/effects/audio_effect_phaser.cpp @@ -0,0 +1,148 @@ +#include "audio_effect_phaser.h" +#include "servers/audio_server.h" +#include "math_funcs.h" + +void AudioEffectPhaserInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + float sampling_rate = AudioServer::get_singleton()->get_mix_rate(); + + float dmin = base->range_min / (sampling_rate/2.0); + float dmax = base->range_max / (sampling_rate/2.0); + + float increment = 2.f * Math_PI * (base->rate / sampling_rate); + + for(int i=0;i<p_frame_count;i++) { + + phase += increment; + + while ( phase >= Math_PI * 2.f ) { + phase -= Math_PI * 2.f; + } + + float d = dmin + (dmax-dmin) * ((sin( phase ) + 1.f)/2.f); + + + //update filter coeffs + for( int j=0; j<6; j++ ) { + allpass[0][j].delay( d ); + allpass[1][j].delay( d ); + } + + //calculate output + float y = allpass[0][0].update( + allpass[0][1].update( + allpass[0][2].update( + allpass[0][3].update( + allpass[0][4].update( + allpass[0][5].update( p_src_frames[i].l + h.l * base->feedback )))))); + h.l=y; + + p_dst_frames[i].l = p_src_frames[i].l + y * base->depth; + + y = allpass[1][0].update( + allpass[1][1].update( + allpass[1][2].update( + allpass[1][3].update( + allpass[1][4].update( + allpass[1][5].update( p_src_frames[i].r + h.r * base->feedback )))))); + h.r=y; + + p_dst_frames[i].r = p_src_frames[i].r + y * base->depth; + + + } + +} + + +Ref<AudioEffectInstance> AudioEffectPhaser::instance() { + Ref<AudioEffectPhaserInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectPhaser>(this); + ins->phase=0; + ins->h=AudioFrame(0,0); + + return ins; +} + + +void AudioEffectPhaser::set_range_min_hz(float p_hz) { + + range_min=p_hz; +} + +float AudioEffectPhaser::get_range_min_hz() const{ + + return range_min; +} + +void AudioEffectPhaser::set_range_max_hz(float p_hz){ + + range_max=p_hz; +} +float AudioEffectPhaser::get_range_max_hz() const{ + + return range_max; +} + +void AudioEffectPhaser::set_rate_hz(float p_hz){ + + rate=p_hz; +} +float AudioEffectPhaser::get_rate_hz() const{ + + return rate; +} + +void AudioEffectPhaser::set_feedback(float p_fbk){ + + feedback=p_fbk; +} +float AudioEffectPhaser::get_feedback() const{ + + return feedback; +} + +void AudioEffectPhaser::set_depth(float p_depth) { + + depth=p_depth; +} + +float AudioEffectPhaser::get_depth() const { + + return depth; +} + +void AudioEffectPhaser::_bind_methods() { + + ClassDB::bind_method(_MD("set_range_min_hz","hz"),&AudioEffectPhaser::set_range_min_hz); + ClassDB::bind_method(_MD("get_range_min_hz"),&AudioEffectPhaser::get_range_min_hz); + + ClassDB::bind_method(_MD("set_range_max_hz","hz"),&AudioEffectPhaser::set_range_max_hz); + ClassDB::bind_method(_MD("get_range_max_hz"),&AudioEffectPhaser::get_range_max_hz); + + ClassDB::bind_method(_MD("set_rate_hz","hz"),&AudioEffectPhaser::set_rate_hz); + ClassDB::bind_method(_MD("get_rate_hz"),&AudioEffectPhaser::get_rate_hz); + + ClassDB::bind_method(_MD("set_feedback","fbk"),&AudioEffectPhaser::set_feedback); + ClassDB::bind_method(_MD("get_feedback"),&AudioEffectPhaser::get_feedback); + + ClassDB::bind_method(_MD("set_depth","depth"),&AudioEffectPhaser::set_depth); + ClassDB::bind_method(_MD("get_depth"),&AudioEffectPhaser::get_depth); + + ADD_PROPERTY(PropertyInfo(Variant::REAL,"range_min_hz",PROPERTY_HINT_RANGE,"10,10000"),_SCS("set_range_min_hz"),_SCS("get_range_min_hz")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"range_max_hz",PROPERTY_HINT_RANGE,"10,10000"),_SCS("set_range_max_hz"),_SCS("get_range_max_hz")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"rate_hz",PROPERTY_HINT_RANGE,"0.01,20"),_SCS("set_rate_hz"),_SCS("get_rate_hz")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"feedback",PROPERTY_HINT_RANGE,"0.1,0.9,0.1"),_SCS("set_feedback"),_SCS("get_feedback")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"depth",PROPERTY_HINT_RANGE,"0.1,4,0.1"),_SCS("set_depth"),_SCS("get_depth")); + +} + +AudioEffectPhaser::AudioEffectPhaser() +{ + range_min=440; + range_max=1600; + rate=0.5; + feedback=0.7; + depth=1; +} diff --git a/servers/audio/effects/audio_effect_phaser.h b/servers/audio/effects/audio_effect_phaser.h new file mode 100644 index 0000000000..53a8ab8bd8 --- /dev/null +++ b/servers/audio/effects/audio_effect_phaser.h @@ -0,0 +1,81 @@ +#ifndef AUDIO_EFFECT_PHASER_H +#define AUDIO_EFFECT_PHASER_H + + + +#include "servers/audio/audio_effect.h" + +class AudioEffectPhaser; + +class AudioEffectPhaserInstance : public AudioEffectInstance { + GDCLASS(AudioEffectPhaserInstance,AudioEffectInstance) +friend class AudioEffectPhaser; + Ref<AudioEffectPhaser> base; + + float phase; + AudioFrame h; + + class AllpassDelay{ + float a, h; + public: + + _ALWAYS_INLINE_ void delay( float d ) { + a = (1.f - d) / (1.f + d); + } + + _ALWAYS_INLINE_ float update( float s ){ + float y = s * -a + h; + h = y * a + s; + return y; + } + + AllpassDelay() { a =0; h = 0;} + + }; + + AllpassDelay allpass[2][6]; +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +}; + + +class AudioEffectPhaser : public AudioEffect { + GDCLASS(AudioEffectPhaser,AudioEffect) + +friend class AudioEffectPhaserInstance; + float range_min; + float range_max; + float rate; + float feedback; + float depth; + +protected: + + static void _bind_methods(); +public: + + + Ref<AudioEffectInstance> instance(); + + void set_range_min_hz(float p_hz); + float get_range_min_hz() const; + + void set_range_max_hz(float p_hz); + float get_range_max_hz() const; + + void set_rate_hz(float p_hz); + float get_rate_hz() const; + + void set_feedback(float p_fbk); + float get_feedback() const; + + void set_depth(float p_depth); + float get_depth() const; + + AudioEffectPhaser(); +}; + + +#endif // AUDIO_EFFECT_PHASER_H diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp new file mode 100644 index 0000000000..8331264208 --- /dev/null +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -0,0 +1,298 @@ +#include "audio_effect_pitch_shift.h" +#include "servers/audio_server.h" +#include "math_funcs.h" +/**************************************************************************** +* +* NAME: smbPitchShift.cpp +* VERSION: 1.2 +* HOME URL: http://blogs.zynaptiq.com/bernsee +* KNOWN BUGS: none +* +* SYNOPSIS: Routine for doing pitch shifting while maintaining +* duration using the Short Time Fourier Transform. +* +* DESCRIPTION: The routine takes a pitchShift factor value which is between 0.5 +* (one octave down) and 2. (one octave up). A value of exactly 1 does not change +* the pitch. numSampsToProcess tells the routine how many samples in indata[0... +* numSampsToProcess-1] should be pitch shifted and moved to outdata[0 ... +* numSampsToProcess-1]. The two buffers can be identical (ie. it can process the +* data in-place). fftFrameSize defines the FFT frame size used for the +* processing. Typical values are 1024, 2048 and 4096. It may be any value <= +* MAX_FRAME_LENGTH but it MUST be a power of 2. osamp is the STFT +* oversampling factor which also determines the overlap between adjacent STFT +* frames. It should at least be 4 for moderate scaling ratios. A value of 32 is +* recommended for best quality. sampleRate takes the sample rate for the signal +* in unit Hz, ie. 44100 for 44.1 kHz audio. The data passed to the routine in +* indata[] should be in the range [-1.0, 1.0), which is also the output range +* for the data, make sure you scale the data accordingly (for 16bit signed integers +* you would have to divide (and multiply) by 32768). +* +* COPYRIGHT 1999-2015 Stephan M. Bernsee <s.bernsee [AT] zynaptiq [DOT] com> +* +* The Wide Open License (WOL) +* +* Permission to use, copy, modify, distribute and sell this software and its +* documentation for any purpose is hereby granted without fee, provided that +* the above copyright notice and this license appear in all source copies. +* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF +* ANY KIND. See http://www.dspguru.com/wol.htm for more information. +* +*****************************************************************************/ + + +void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata,int stride) { + + + /* + Routine smbPitchShift(). See top of file for explanation + Purpose: doing pitch shifting while maintaining duration using the Short + Time Fourier Transform. + Author: (c)1999-2015 Stephan M. Bernsee <s.bernsee [AT] zynaptiq [DOT] com> + */ + + double magn, phase, tmp, window, real, imag; + double freqPerBin, expct; + long i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2; + + /* set up some handy variables */ + fftFrameSize2 = fftFrameSize/2; + stepSize = fftFrameSize/osamp; + freqPerBin = sampleRate/(double)fftFrameSize; + expct = 2.*Math_PI*(double)stepSize/(double)fftFrameSize; + inFifoLatency = fftFrameSize-stepSize; + if (gRover == 0) gRover = inFifoLatency; + + /* initialize our static arrays */ + + /* main processing loop */ + for (i = 0; i < numSampsToProcess; i++){ + + /* As long as we have not yet collected enough data just read in */ + gInFIFO[gRover] = indata[i*stride]; + outdata[i*stride] = gOutFIFO[gRover-inFifoLatency]; + gRover++; + + /* now we have enough data for processing */ + if (gRover >= fftFrameSize) { + gRover = inFifoLatency; + + /* do windowing and re,im interleave */ + for (k = 0; k < fftFrameSize;k++) { + window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5; + gFFTworksp[2*k] = gInFIFO[k] * window; + gFFTworksp[2*k+1] = 0.; + } + + + /* ***************** ANALYSIS ******************* */ + /* do transform */ + smbFft(gFFTworksp, fftFrameSize, -1); + + /* this is the analysis step */ + for (k = 0; k <= fftFrameSize2; k++) { + + /* de-interlace FFT buffer */ + real = gFFTworksp[2*k]; + imag = gFFTworksp[2*k+1]; + + /* compute magnitude and phase */ + magn = 2.*sqrt(real*real + imag*imag); + phase = atan2(imag,real); + + /* compute phase difference */ + tmp = phase - gLastPhase[k]; + gLastPhase[k] = phase; + + /* subtract expected phase difference */ + tmp -= (double)k*expct; + + /* map delta phase into +/- Pi interval */ + qpd = tmp/Math_PI; + if (qpd >= 0) qpd += qpd&1; + else qpd -= qpd&1; + tmp -= Math_PI*(double)qpd; + + /* get deviation from bin frequency from the +/- Pi interval */ + tmp = osamp*tmp/(2.*Math_PI); + + /* compute the k-th partials' true frequency */ + tmp = (double)k*freqPerBin + tmp*freqPerBin; + + /* store magnitude and true frequency in analysis arrays */ + gAnaMagn[k] = magn; + gAnaFreq[k] = tmp; + + } + + /* ***************** PROCESSING ******************* */ + /* this does the actual pitch shifting */ + memset(gSynMagn, 0, fftFrameSize*sizeof(float)); + memset(gSynFreq, 0, fftFrameSize*sizeof(float)); + for (k = 0; k <= fftFrameSize2; k++) { + index = k*pitchShift; + if (index <= fftFrameSize2) { + gSynMagn[index] += gAnaMagn[k]; + gSynFreq[index] = gAnaFreq[k] * pitchShift; + } + } + + /* ***************** SYNTHESIS ******************* */ + /* this is the synthesis step */ + for (k = 0; k <= fftFrameSize2; k++) { + + /* get magnitude and true frequency from synthesis arrays */ + magn = gSynMagn[k]; + tmp = gSynFreq[k]; + + /* subtract bin mid frequency */ + tmp -= (double)k*freqPerBin; + + /* get bin deviation from freq deviation */ + tmp /= freqPerBin; + + /* take osamp into account */ + tmp = 2.*Math_PI*tmp/osamp; + + /* add the overlap phase advance back in */ + tmp += (double)k*expct; + + /* accumulate delta phase to get bin phase */ + gSumPhase[k] += tmp; + phase = gSumPhase[k]; + + /* get real and imag part and re-interleave */ + gFFTworksp[2*k] = magn*cos(phase); + gFFTworksp[2*k+1] = magn*sin(phase); + } + + /* zero negative frequencies */ + for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) gFFTworksp[k] = 0.; + + /* do inverse transform */ + smbFft(gFFTworksp, fftFrameSize, 1); + + /* do windowing and add to output accumulator */ + for(k=0; k < fftFrameSize; k++) { + window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5; + gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp); + } + for (k = 0; k < stepSize; k++) gOutFIFO[k] = gOutputAccum[k]; + + /* shift accumulator */ + memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float)); + + /* move input FIFO */ + for (k = 0; k < inFifoLatency; k++) gInFIFO[k] = gInFIFO[k+stepSize]; + } + } + + + +} + + +void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign) +/* + FFT routine, (C)1996 S.M.Bernsee. Sign = -1 is FFT, 1 is iFFT (inverse) + Fills fftBuffer[0...2*fftFrameSize-1] with the Fourier transform of the + time domain data in fftBuffer[0...2*fftFrameSize-1]. The FFT array takes + and returns the cosine and sine parts in an interleaved manner, ie. + fftBuffer[0] = cosPart[0], fftBuffer[1] = sinPart[0], asf. fftFrameSize + must be a power of 2. It expects a complex input signal (see footnote 2), + ie. when working with 'common' audio signals our input signal has to be + passed as {in[0],0.,in[1],0.,in[2],0.,...} asf. In that case, the transform + of the frequencies of interest is in fftBuffer[0...fftFrameSize]. +*/ +{ + float wr, wi, arg, *p1, *p2, temp; + float tr, ti, ur, ui, *p1r, *p1i, *p2r, *p2i; + long i, bitm, j, le, le2, k; + + for (i = 2; i < 2*fftFrameSize-2; i += 2) { + for (bitm = 2, j = 0; bitm < 2*fftFrameSize; bitm <<= 1) { + if (i & bitm) j++; + j <<= 1; + } + if (i < j) { + p1 = fftBuffer+i; p2 = fftBuffer+j; + temp = *p1; *(p1++) = *p2; + *(p2++) = temp; temp = *p1; + *p1 = *p2; *p2 = temp; + } + } + for (k = 0, le = 2; k < (long)(log((double)fftFrameSize)/log(2.)+.5); k++) { + le <<= 1; + le2 = le>>1; + ur = 1.0; + ui = 0.0; + arg = Math_PI / (le2>>1); + wr = cos(arg); + wi = sign*sin(arg); + for (j = 0; j < le2; j += 2) { + p1r = fftBuffer+j; p1i = p1r+1; + p2r = p1r+le2; p2i = p2r+1; + for (i = j; i < 2*fftFrameSize; i += le) { + tr = *p2r * ur - *p2i * ui; + ti = *p2r * ui + *p2i * ur; + *p2r = *p1r - tr; *p2i = *p1i - ti; + *p1r += tr; *p1i += ti; + p1r += le; p1i += le; + p2r += le; p2i += le; + } + tr = ur*wr - ui*wi; + ui = ur*wi + ui*wr; + ur = tr; + } + } +} + + +void AudioEffectPitchShiftInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + float sample_rate = AudioServer::get_singleton()->get_mix_rate(); + + float *in_l = (float*)p_src_frames; + float *in_r = in_l + 1; + + float *out_l = (float*)p_dst_frames; + float *out_r = out_l + 1; + + shift_l.PitchShift(base->pitch_scale,p_frame_count,2048,4,sample_rate,in_l,out_l,2); + shift_r.PitchShift(base->pitch_scale,p_frame_count,2048,4,sample_rate,in_r,out_r,2); + +} + + +Ref<AudioEffectInstance> AudioEffectPitchShift::instance() { + Ref<AudioEffectPitchShiftInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectPitchShift>(this); + + + return ins; +} + +void AudioEffectPitchShift::set_pitch_scale(float p_adjust) { + + pitch_scale=p_adjust; +} + +float AudioEffectPitchShift::get_pitch_scale() const { + + return pitch_scale; +} + + +void AudioEffectPitchShift::_bind_methods() { + + ClassDB::bind_method(_MD("set_pitch_scale","rate"),&AudioEffectPitchShift::set_pitch_scale); + ClassDB::bind_method(_MD("get_pitch_scale"),&AudioEffectPitchShift::get_pitch_scale); + + ADD_PROPERTY(PropertyInfo(Variant::REAL,"pitch_scale",PROPERTY_HINT_RANGE,"0.01,16,0.01"),_SCS("set_pitch_scale"),_SCS("get_pitch_scale")); + +} + +AudioEffectPitchShift::AudioEffectPitchShift() { + pitch_scale=1.0; + +} diff --git a/servers/audio/effects/audio_effect_pitch_shift.h b/servers/audio/effects/audio_effect_pitch_shift.h new file mode 100644 index 0000000000..d1343a0745 --- /dev/null +++ b/servers/audio/effects/audio_effect_pitch_shift.h @@ -0,0 +1,89 @@ +#ifndef AUDIO_EFFECT_PITCH_SHIFT_H +#define AUDIO_EFFECT_PITCH_SHIFT_H + + +#include "servers/audio/audio_effect.h" + +class SMBPitchShift { + + enum { + MAX_FRAME_LENGTH=8192 + }; + + float gInFIFO[MAX_FRAME_LENGTH]; + float gOutFIFO[MAX_FRAME_LENGTH]; + float gFFTworksp[2*MAX_FRAME_LENGTH]; + float gLastPhase[MAX_FRAME_LENGTH/2+1]; + float gSumPhase[MAX_FRAME_LENGTH/2+1]; + float gOutputAccum[2*MAX_FRAME_LENGTH]; + float gAnaFreq[MAX_FRAME_LENGTH]; + float gAnaMagn[MAX_FRAME_LENGTH]; + float gSynFreq[MAX_FRAME_LENGTH]; + float gSynMagn[MAX_FRAME_LENGTH]; + long gRover; + + void smbFft(float *fftBuffer, long fftFrameSize, long sign); +public: + void PitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata, int stride); + + SMBPitchShift() { + gRover=0; + memset(gInFIFO, 0, MAX_FRAME_LENGTH*sizeof(float)); + memset(gOutFIFO, 0, MAX_FRAME_LENGTH*sizeof(float)); + memset(gFFTworksp, 0, 2*MAX_FRAME_LENGTH*sizeof(float)); + memset(gLastPhase, 0, (MAX_FRAME_LENGTH/2+1)*sizeof(float)); + memset(gSumPhase, 0, (MAX_FRAME_LENGTH/2+1)*sizeof(float)); + memset(gOutputAccum, 0, 2*MAX_FRAME_LENGTH*sizeof(float)); + memset(gAnaFreq, 0, MAX_FRAME_LENGTH*sizeof(float)); + memset(gAnaMagn, 0, MAX_FRAME_LENGTH*sizeof(float)); + } + + +}; + + +class AudioEffectPitchShift; + +class AudioEffectPitchShiftInstance : public AudioEffectInstance { + GDCLASS(AudioEffectPitchShiftInstance,AudioEffectInstance) +friend class AudioEffectPitchShift; + Ref<AudioEffectPitchShift> base; + + SMBPitchShift shift_l; + SMBPitchShift shift_r; + + +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + +}; + + +class AudioEffectPitchShift : public AudioEffect { + GDCLASS(AudioEffectPitchShift,AudioEffect) + +friend class AudioEffectPitchShiftInstance; + + float pitch_scale; + int window_size; + float wet; + float dry; + bool filter; + +protected: + + static void _bind_methods(); +public: + + + Ref<AudioEffectInstance> instance(); + + void set_pitch_scale(float p_adjust); + float get_pitch_scale() const; + + AudioEffectPitchShift(); +}; + + +#endif // AUDIO_EFFECT_PITCH_SHIFT_H diff --git a/servers/audio/effects/audio_effect_reverb.cpp b/servers/audio/effects/audio_effect_reverb.cpp new file mode 100644 index 0000000000..749814fd76 --- /dev/null +++ b/servers/audio/effects/audio_effect_reverb.cpp @@ -0,0 +1,182 @@ +#include "audio_effect_reverb.h" +#include "servers/audio_server.h" +void AudioEffectReverbInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + for(int i=0;i<2;i++) { + Reverb &r=reverb[i]; + + r.set_predelay( base->predelay); + r.set_predelay_feedback( base->predelay_fb ); + r.set_highpass( base->hpf ); + r.set_room_size( base->room_size ); + r.set_damp( base->damping ); + r.set_extra_spread( base->spread ); + r.set_wet( base->wet ); + r.set_dry( base->dry ); + } + + int todo = p_frame_count; + int offset=0; + + while(todo) { + + int to_mix = MIN(todo,Reverb::INPUT_BUFFER_MAX_SIZE); + + for(int j=0;j<to_mix;j++) { + tmp_src[j]=p_src_frames[offset+j].l; + } + + reverb[0].process(tmp_src,tmp_dst,to_mix); + + for(int j=0;j<to_mix;j++) { + p_dst_frames[offset+j].l=tmp_dst[j]; + tmp_src[j]=p_src_frames[offset+j].r; + } + + reverb[1].process(tmp_src,tmp_dst,to_mix); + + for(int j=0;j<to_mix;j++) { + p_dst_frames[offset+j].r=tmp_dst[j]; + } + + offset+=to_mix; + todo-=to_mix; + } +} + +AudioEffectReverbInstance::AudioEffectReverbInstance() { + + reverb[0].set_mix_rate( AudioServer::get_singleton()->get_mix_rate() ); + reverb[0].set_extra_spread_base(0); + reverb[1].set_mix_rate( AudioServer::get_singleton()->get_mix_rate() ); + reverb[1].set_extra_spread_base(0.000521); //for stereo effect + +} + +Ref<AudioEffectInstance> AudioEffectReverb::instance() { + Ref<AudioEffectReverbInstance> ins; + ins.instance(); + ins->base=Ref<AudioEffectReverb>(this); + return ins; +} + +void AudioEffectReverb::set_predelay_msec(float p_msec) { + + predelay=p_msec; +} + +void AudioEffectReverb::set_predelay_feedback(float p_feedback){ + + predelay_fb=p_feedback; +} +void AudioEffectReverb::set_room_size(float p_size){ + + room_size=p_size; +} +void AudioEffectReverb::set_damping(float p_damping){ + + damping=p_damping; +} +void AudioEffectReverb::set_spread(float p_spread){ + + spread=p_spread; +} + +void AudioEffectReverb::set_dry(float p_dry){ + + dry=p_dry; +} +void AudioEffectReverb::set_wet(float p_wet){ + + wet=p_wet; +} +void AudioEffectReverb::set_hpf(float p_hpf) { + + hpf=p_hpf; +} + +float AudioEffectReverb::get_predelay_msec() const { + + return predelay; +} +float AudioEffectReverb::get_predelay_feedback() const { + + return predelay_fb; +} +float AudioEffectReverb::get_room_size() const { + + return room_size; +} +float AudioEffectReverb::get_damping() const { + + return damping; +} +float AudioEffectReverb::get_spread() const { + + return spread; +} +float AudioEffectReverb::get_dry() const { + + return dry; +} +float AudioEffectReverb::get_wet() const { + + return wet; +} +float AudioEffectReverb::get_hpf() const { + + return hpf; +} + + +void AudioEffectReverb::_bind_methods() { + + + ClassDB::bind_method(_MD("set_predelay_msec","msec"),&AudioEffectReverb::set_predelay_msec); + ClassDB::bind_method(_MD("get_predelay_msec"),&AudioEffectReverb::get_predelay_msec); + + ClassDB::bind_method(_MD("set_predelay_feedback","feedback"),&AudioEffectReverb::set_predelay_feedback); + ClassDB::bind_method(_MD("get_predelay_feedback"),&AudioEffectReverb::get_predelay_feedback); + + ClassDB::bind_method(_MD("set_room_size","size"),&AudioEffectReverb::set_room_size); + ClassDB::bind_method(_MD("get_room_size"),&AudioEffectReverb::get_room_size); + + ClassDB::bind_method(_MD("set_damping","amount"),&AudioEffectReverb::set_damping); + ClassDB::bind_method(_MD("get_damping"),&AudioEffectReverb::get_damping); + + ClassDB::bind_method(_MD("set_spread","amount"),&AudioEffectReverb::set_spread); + ClassDB::bind_method(_MD("get_spread"),&AudioEffectReverb::get_spread); + + ClassDB::bind_method(_MD("set_dry","amount"),&AudioEffectReverb::set_dry); + ClassDB::bind_method(_MD("get_dry"),&AudioEffectReverb::get_dry); + + ClassDB::bind_method(_MD("set_wet","amount"),&AudioEffectReverb::set_wet); + ClassDB::bind_method(_MD("get_wet"),&AudioEffectReverb::get_wet); + + ClassDB::bind_method(_MD("set_hpf","amount"),&AudioEffectReverb::set_hpf); + ClassDB::bind_method(_MD("get_hpf"),&AudioEffectReverb::get_hpf); + + + ADD_GROUP("Predelay","predelay_"); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"predelay_msec",PROPERTY_HINT_RANGE,"20,500,1"),_SCS("set_predelay_msec"),_SCS("get_predelay_msec")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"predelay_feedback",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_predelay_msec"),_SCS("get_predelay_msec")); + ADD_GROUP("",""); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"room_size",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_room_size"),_SCS("get_room_size")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"damping",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_damping"),_SCS("get_damping")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"spread",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_spread"),_SCS("get_spread")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"hipass",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_hpf"),_SCS("get_hpf")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"dry",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_dry"),_SCS("get_dry")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"wet",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_wet"),_SCS("get_wet")); +} + +AudioEffectReverb::AudioEffectReverb() { + predelay=150; + predelay_fb=0.4; + hpf=0; + room_size=0.8; + damping=0.5; + spread=1.0; + dry=1.0; + wet=0.5; + +} diff --git a/servers/audio/effects/audio_effect_reverb.h b/servers/audio/effects/audio_effect_reverb.h new file mode 100644 index 0000000000..e05ffe422f --- /dev/null +++ b/servers/audio/effects/audio_effect_reverb.h @@ -0,0 +1,76 @@ +#ifndef AUDIOEFFECTREVERB_H +#define AUDIOEFFECTREVERB_H + + +#include "servers/audio/audio_effect.h" +#include "servers/audio/effects/reverb.h" + +class AudioEffectReverb; + +class AudioEffectReverbInstance : public AudioEffectInstance { + GDCLASS(AudioEffectReverbInstance,AudioEffectInstance) + + Ref<AudioEffectReverb> base; + + float tmp_src[Reverb::INPUT_BUFFER_MAX_SIZE]; + float tmp_dst[Reverb::INPUT_BUFFER_MAX_SIZE]; + +friend class AudioEffectReverb; + + Reverb reverb[2]; + + +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + AudioEffectReverbInstance(); +}; + + +class AudioEffectReverb : public AudioEffect { + GDCLASS(AudioEffectReverb,AudioEffect) + +friend class AudioEffectReverbInstance; + + float predelay; + float predelay_fb; + float hpf; + float room_size; + float damping; + float spread; + float dry; + float wet; + +protected: + + static void _bind_methods(); +public: + + + void set_predelay_msec(float p_msec); + void set_predelay_feedback(float p_feedback); + void set_room_size(float p_size); + void set_damping(float p_damping); + void set_spread(float p_spread); + void set_dry(float p_dry); + void set_wet(float p_wet); + void set_hpf(float p_hpf); + + float get_predelay_msec() const; + float get_predelay_feedback() const; + float get_room_size() const; + float get_damping() const; + float get_spread() const; + float get_dry() const; + float get_wet() const; + float get_hpf() const; + + Ref<AudioEffectInstance> instance(); + void set_volume_db(float p_volume); + float get_volume_db() const; + + AudioEffectReverb(); +}; + + +#endif // AUDIOEFFECTREVERB_H diff --git a/servers/audio/effects/audio_effect_stereo_enhance.cpp b/servers/audio/effects/audio_effect_stereo_enhance.cpp new file mode 100644 index 0000000000..c5968aa772 --- /dev/null +++ b/servers/audio/effects/audio_effect_stereo_enhance.cpp @@ -0,0 +1,135 @@ +#include "audio_effect_stereo_enhance.h" +#include "servers/audio_server.h" +void AudioEffectStereoEnhanceInstance::process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count) { + + + float intensity=base->pan_pullout; + bool surround_mode=base->surround>0; + float surround_amount=base->surround; + unsigned int delay_frames=(base->time_pullout/1000.0)*AudioServer::get_singleton()->get_mix_rate(); + + for (int i=0;i<p_frame_count;i++) { + + float l=p_src_frames[i].l; + float r=p_src_frames[i].r; + + float center=(l+r)/2.0f; + + l=( center+(l-center)*intensity ); + r=( center+(r-center)*intensity ); + + if (surround_mode) { + + float val=(l+r)/2.0; + + delay_ringbuff[ringbuff_pos&ringbuff_mask]=val; + + float out=delay_ringbuff[(ringbuff_pos-delay_frames)&ringbuff_mask]*surround_amount; + + l+=out; + r+=-out; + } else { + + float val=r; + + delay_ringbuff[ringbuff_pos&ringbuff_mask]=val; + + //r is delayed + r=delay_ringbuff[(ringbuff_pos-delay_frames)&ringbuff_mask];; + + + } + + p_dst_frames[i].l=l; + p_dst_frames[i].r=r; + ringbuff_pos++; + + } + +} + + +AudioEffectStereoEnhanceInstance::~AudioEffectStereoEnhanceInstance() { + + memdelete_arr(delay_ringbuff); +} + +Ref<AudioEffectInstance> AudioEffectStereoEnhance::instance() { + Ref<AudioEffectStereoEnhanceInstance> ins; + ins.instance(); + + ins->base=Ref<AudioEffectStereoEnhance>(this); + + + float ring_buffer_max_size=AudioEffectStereoEnhanceInstance::MAX_DELAY_MS+2; + ring_buffer_max_size/=1000.0;//convert to seconds + ring_buffer_max_size*=AudioServer::get_singleton()->get_mix_rate(); + + int ringbuff_size=(int)ring_buffer_max_size; + + int bits=0; + + while(ringbuff_size>0) { + bits++; + ringbuff_size/=2; + } + + ringbuff_size=1<<bits; + ins->ringbuff_mask=ringbuff_size-1; + ins->ringbuff_pos=0; + + ins->delay_ringbuff = memnew_arr(float,ringbuff_size ); + + return ins; +} + +void AudioEffectStereoEnhance::set_pan_pullout(float p_amount) { + + pan_pullout=p_amount; +} + +float AudioEffectStereoEnhance::get_pan_pullout() const { + + return pan_pullout; +} + +void AudioEffectStereoEnhance::set_time_pullout(float p_amount) { + + time_pullout=p_amount; +} +float AudioEffectStereoEnhance::get_time_pullout() const { + + return time_pullout; +} + +void AudioEffectStereoEnhance::set_surround(float p_amount) { + + surround=p_amount; +} +float AudioEffectStereoEnhance::get_surround() const { + + return surround; +} + +void AudioEffectStereoEnhance::_bind_methods() { + + ClassDB::bind_method(_MD("set_pan_pullout","amount"),&AudioEffectStereoEnhance::set_pan_pullout); + ClassDB::bind_method(_MD("get_pan_pullout"),&AudioEffectStereoEnhance::get_pan_pullout); + + ClassDB::bind_method(_MD("set_time_pullout","amount"),&AudioEffectStereoEnhance::set_time_pullout); + ClassDB::bind_method(_MD("get_time_pullout"),&AudioEffectStereoEnhance::get_time_pullout); + + ClassDB::bind_method(_MD("set_surround","amount"),&AudioEffectStereoEnhance::set_surround); + ClassDB::bind_method(_MD("get_surround"),&AudioEffectStereoEnhance::get_surround); + + ADD_PROPERTY(PropertyInfo(Variant::REAL,"pan_pullout",PROPERTY_HINT_RANGE,"0,4,0.01"),_SCS("set_pan_pullout"),_SCS("get_pan_pullout")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"time_pullout_ms",PROPERTY_HINT_RANGE,"0,50,0.01"),_SCS("set_time_pullout"),_SCS("get_time_pullout")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"surround",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_surround"),_SCS("get_surround")); +} + +AudioEffectStereoEnhance::AudioEffectStereoEnhance() +{ + pan_pullout=1; + time_pullout=0; + surround=0; +} diff --git a/servers/audio/effects/audio_effect_stereo_enhance.h b/servers/audio/effects/audio_effect_stereo_enhance.h new file mode 100644 index 0000000000..06762acbf3 --- /dev/null +++ b/servers/audio/effects/audio_effect_stereo_enhance.h @@ -0,0 +1,62 @@ +#ifndef AUDIOEFFECTSTEREOENHANCE_H +#define AUDIOEFFECTSTEREOENHANCE_H + + +#include "servers/audio/audio_effect.h" + +class AudioEffectStereoEnhance; + +class AudioEffectStereoEnhanceInstance : public AudioEffectInstance { + GDCLASS(AudioEffectStereoEnhanceInstance,AudioEffectInstance) +friend class AudioEffectStereoEnhance; + Ref<AudioEffectStereoEnhance> base; + + enum { + + MAX_DELAY_MS=50 + }; + + float *delay_ringbuff; + unsigned int ringbuff_pos; + unsigned int ringbuff_mask; + + +public: + + virtual void process(const AudioFrame *p_src_frames,AudioFrame *p_dst_frames,int p_frame_count); + + ~AudioEffectStereoEnhanceInstance(); +}; + + +class AudioEffectStereoEnhance : public AudioEffect { + GDCLASS(AudioEffectStereoEnhance,AudioEffect) + +friend class AudioEffectStereoEnhanceInstance; + float volume_db; + + float pan_pullout; + float time_pullout; + float surround; + +protected: + + static void _bind_methods(); +public: + + + Ref<AudioEffectInstance> instance(); + + void set_pan_pullout(float p_amount); + float get_pan_pullout() const; + + void set_time_pullout(float p_amount); + float get_time_pullout() const; + + void set_surround(float p_amount); + float get_surround() const; + + AudioEffectStereoEnhance(); +}; + +#endif // AUDIOEFFECTSTEREOENHANCE_H diff --git a/servers/audio/effects/eq.cpp b/servers/audio/effects/eq.cpp new file mode 100644 index 0000000000..5aab60a558 --- /dev/null +++ b/servers/audio/effects/eq.cpp @@ -0,0 +1,219 @@ +// +// C++ Interface: eq +// +// Description: +// +// +// Author: reduzio@gmail.com (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "eq.h" +#include <math.h> +#include "error_macros.h" +#include "math_funcs.h" + +#define POW2(v) ((v)*(v)) + +/* Helper */ + static int solve_quadratic(double a,double b,double c,double *r1, double *r2) { +//solves quadractic and returns number of roots + + double base=2*a; + if (base == 0.0f) + return 0; + + double squared=b*b-4*a*c; + if (squared<0.0) + return 0; + + squared=sqrt(squared); + + *r1=(-b+squared)/base; + *r2=(-b-squared)/base; + + if (*r1==*r2) + return 1; + else + return 2; + } + +EQ::BandProcess::BandProcess() { + + c1=c2=c3=history.a1=history.a2=history.a3=0; + history.b1=history.b2=history.b3=0; +} + +void EQ::recalculate_band_coefficients() { + +#define BAND_LOG( m_f ) ( log((m_f)) / log(2.) ) + + for (int i=0;i<band.size();i++) { + + double octave_size; + + double frq=band[i].freq; + + if (i==0) { + + octave_size=BAND_LOG(band[1].freq)-BAND_LOG(frq); + } else if (i==(band.size()-1)) { + + octave_size=BAND_LOG(frq)-BAND_LOG(band[i-1].freq); + } else { + + double next=BAND_LOG(band[i+1].freq)-BAND_LOG(frq); + double prev=BAND_LOG(frq)-BAND_LOG(band[i-1].freq); + octave_size=(next+prev)/2.0; + } + + + + double frq_l=round(frq/pow(2.0,octave_size/2.0)); + + + + double side_gain2=POW2(Math_SQRT12); + double th=2.0*Math_PI*frq/mix_rate; + double th_l=2.0*Math_PI*frq_l/mix_rate; + + double c2a=side_gain2 * POW2(cos(th)) + - 2.0 * side_gain2 * cos(th_l) * cos(th) + + side_gain2 + - POW2(sin(th_l)); + + double c2b=2.0 * side_gain2 * POW2(cos(th_l)) + + side_gain2 * POW2(cos(th)) + - 2.0 * side_gain2 * cos(th_l) * cos(th) + - side_gain2 + + POW2(sin(th_l)); + + double c2c=0.25 * side_gain2 * POW2(cos(th)) + - 0.5 * side_gain2 * cos(th_l) * cos(th) + + 0.25 * side_gain2 + - 0.25 * POW2(sin(th_l)); + + //printf("band %i, precoefs = %f,%f,%f\n",i,c2a,c2b,c2c); + + double r1,r2; //roots + int roots=solve_quadratic(c2a,c2b,c2c,&r1,&r2); + + ERR_CONTINUE( roots==0 ); + + band[i].c1=2.0 * ((0.5-r1)/2.0); + band[i].c2=2.0 * r1; + band[i].c3=2.0 * (0.5+r1) * cos(th); + //printf("band %i, coefs = %f,%f,%f\n",i,(float)bands[i].c1,(float)bands[i].c2,(float)bands[i].c3); + + } +} + +void EQ::set_preset_band_mode(Preset p_preset) { + + + band.clear(); + +#define PUSH_BANDS(m_bands) \ + for (int i=0;i<m_bands;i++) { \ + Band b; \ + b.freq=bands[i];\ + band.push_back(b);\ + } + + switch (p_preset) { + + case PRESET_6_BANDS: { + + static const double bands[] = { 32 , 100 , 320 , 1e3, 3200, 10e3 }; + PUSH_BANDS(6); + + } break; + + case PRESET_8_BANDS: { + + static const double bands[] = { 32,72,192,512,1200,3000,7500,16e3 }; + + PUSH_BANDS(8); + } break; + + case PRESET_10_BANDS: { + static const double bands[] = { 31.25, 62.5, 125 , 250 , 500 , 1e3, 2e3, 4e3, 8e3, 16e3 }; + + PUSH_BANDS(10); + + } break; + + case PRESET_21_BANDS: { + + static const double bands[] = { 22 , 32 , 44 , 63 , 90 , 125 , 175 , 250 , 350 , 500 , 700 , 1e3, 1400 , 2e3, 2800 , 4e3, 5600 , 8e3, 11e3, 16e3, 22e3 }; + PUSH_BANDS(21); + + } break; + + case PRESET_31_BANDS: { + + static const double bands[] = { 20, 25, 31.5, 40 , 50 , 63 , 80 , 100 , 125 , 160 , 200 , 250 , 315 , 400 , 500 , 630 , 800 , 1e3 , 1250 , 1600 , 2e3, 2500 , 3150 , 4e3, 5e3, 6300 , 8e3, 10e3, 12500 , 16e3, 20e3 }; + PUSH_BANDS(31); + } break; + + }; + + recalculate_band_coefficients(); +} + +int EQ::get_band_count() const { + + return band.size(); +} +float EQ::get_band_frequency(int p_band) { + + ERR_FAIL_INDEX_V(p_band,band.size(),0); + return band[p_band].freq; +} +void EQ::set_bands(const Vector<float>& p_bands) { + + band.resize(p_bands.size()); + for (int i=0;i<p_bands.size();i++) { + + band[i].freq=p_bands[i]; + } + + recalculate_band_coefficients(); + +} + +void EQ::set_mix_rate(float p_mix_rate) { + + mix_rate=p_mix_rate; + recalculate_band_coefficients(); +} + +EQ::BandProcess EQ::get_band_processor(int p_band) const { + + + EQ::BandProcess band_proc; + + ERR_FAIL_INDEX_V(p_band,band.size(),band_proc); + + band_proc.c1=band[p_band].c1; + band_proc.c2=band[p_band].c2; + band_proc.c3=band[p_band].c3; + + return band_proc; + + +} + + +EQ::EQ() +{ + mix_rate=44100; +} + + +EQ::~EQ() +{ +} + + diff --git a/servers/audio/effects/eq.h b/servers/audio/effects/eq.h new file mode 100644 index 0000000000..2c4668cd0b --- /dev/null +++ b/servers/audio/effects/eq.h @@ -0,0 +1,106 @@ +// +// C++ Interface: eq +// +// Description: +// +// +// Author: reduzio@gmail.com (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef EQ_FILTER_H +#define EQ_FILTER_H + + +#include "typedefs.h" +#include "vector.h" + + +/** +@author Juan Linietsky +*/ + +class EQ { +public: + + enum Preset { + + PRESET_6_BANDS, + PRESET_8_BANDS, + PRESET_10_BANDS, + PRESET_21_BANDS, + PRESET_31_BANDS + }; + + + + class BandProcess { + + friend class EQ; + float c1,c2,c3; + struct History { + float a1,a2,a3; + float b1,b2,b3; + + } history; + + public: + + inline void process_one(float & p_data); + + BandProcess(); + }; + +private: + struct Band { + + float freq; + float c1,c2,c3; + }; + + Vector<Band> band; + + float mix_rate; + + void recalculate_band_coefficients(); + +public: + + + void set_mix_rate(float p_mix_rate); + + int get_band_count() const; + void set_preset_band_mode(Preset p_preset); + void set_bands(const Vector<float>& p_bands); + BandProcess get_band_processor(int p_band) const; + float get_band_frequency(int p_band); + + EQ(); + ~EQ(); + +}; + + +/* Inline Function */ + +inline void EQ::BandProcess::process_one(float & p_data) { + + + history.a1=p_data; + + history.b1= c1 * ( history.a1 - history.a3 ) + + c3 * history.b2 + - c2 * history.b3; + + p_data = history.b1; + + history.a3=history.a2; + history.a2=history.a1; + history.b3=history.b2; + history.b2=history.b1; + +} + + +#endif diff --git a/servers/audio/effects/reverb.cpp b/servers/audio/effects/reverb.cpp new file mode 100644 index 0000000000..43ea0edb3a --- /dev/null +++ b/servers/audio/effects/reverb.cpp @@ -0,0 +1,364 @@ +// +// C++ Interface: reverb +// +// Description: +// +// +// Author: Juan Linietsky <reduzio@gmail.com>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "reverb.h" +#include <math.h> +#include "math_funcs.h" + + +const float Reverb::comb_tunings[MAX_COMBS]={ + //freeverb comb tunings + 0.025306122448979593, + 0.026938775510204082, + 0.028956916099773241, + 0.03074829931972789, + 0.032244897959183672, + 0.03380952380952381, + 0.035306122448979592, + 0.036666666666666667 +}; + +const float Reverb::allpass_tunings[MAX_ALLPASS]={ + //freeverb allpass tunings + 0.0051020408163265302, + 0.007732426303854875, + 0.01, + 0.012607709750566893 +}; + + + +void Reverb::process(float *p_src,float *p_dst,int p_frames) { + + if (p_frames>INPUT_BUFFER_MAX_SIZE) + p_frames=INPUT_BUFFER_MAX_SIZE; + + int predelay_frames=lrint((params.predelay/1000.0)*params.mix_rate); + if (predelay_frames<10) + predelay_frames=10; + if (predelay_frames>=echo_buffer_size) + predelay_frames=echo_buffer_size-1; + + for (int i=0;i<p_frames;i++) { + + if (echo_buffer_pos>=echo_buffer_size) + echo_buffer_pos=0; + + int read_pos=echo_buffer_pos-predelay_frames; + while (read_pos<0) + read_pos+=echo_buffer_size; + + float in=undenormalise(echo_buffer[read_pos]*params.predelay_fb+p_src[i]); + + echo_buffer[echo_buffer_pos]=in; + + input_buffer[i]=in; + + p_dst[i]=0; //take the chance and clear this + + echo_buffer_pos++; + } + + if (params.hpf>0) { + float hpaux=expf(-2.0*Math_PI*params.hpf*6000/params.mix_rate); + float hp_a1=(1.0+hpaux)/2.0; + float hp_a2=-(1.0+hpaux)/2.0; + float hp_b1=hpaux; + + for (int i=0;i<p_frames;i++) { + + float in=input_buffer[i]; + input_buffer[i]=in*hp_a1+hpf_h1*hp_a2+hpf_h2*hp_b1; + hpf_h2=input_buffer[i]; + hpf_h1=in; + } + } + + for (int i=0;i<MAX_COMBS;i++) { + + Comb &c=comb[i]; + + int size_limit=c.size-lrintf((float)c.extra_spread_frames*(1.0-params.extra_spread)); + for (int j=0;j<p_frames;j++) { + + if (c.pos>=size_limit) //reset this now just in case + c.pos=0; + + float out=undenormalise(c.buffer[c.pos]*c.feedback); + out=out*(1.0-c.damp)+c.damp_h*c.damp; //lowpass + c.damp_h=out; + c.buffer[c.pos]=input_buffer[j]+out; + p_dst[j]+=out; + c.pos++; + } + + } + + + static const float allpass_feedback=0.7; + /* this one works, but the other version is just nicer.... + int ap_size_limit[MAX_ALLPASS]; + + for (int i=0;i<MAX_ALLPASS;i++) { + + AllPass &a=allpass[i]; + ap_size_limit[i]=a.size-lrintf((float)a.extra_spread_frames*(1.0-params.extra_spread)); + } + + for (int i=0;i<p_frames;i++) { + + float sample=p_dst[i]; + float aux,in; + float AllPass*ap; + +#define PROCESS_ALLPASS(m_ap) \ + ap=&allpass[m_ap]; \ + if (ap->pos>=ap_size_limit[m_ap]) \ + ap->pos=0; \ + aux=undenormalise(ap->buffer[ap->pos]); \ + in=sample; \ + sample=-in+aux; \ + ap->pos++; + + + PROCESS_ALLPASS(0); + PROCESS_ALLPASS(1); + PROCESS_ALLPASS(2); + PROCESS_ALLPASS(3); + + p_dst[i]=sample; + } + */ + + for (int i=0;i<MAX_ALLPASS;i++) { + + AllPass &a=allpass[i]; + int size_limit=a.size-lrintf((float)a.extra_spread_frames*(1.0-params.extra_spread)); + + for (int j=0;j<p_frames;j++) { + + if (a.pos>=size_limit) + a.pos=0; + + float aux=a.buffer[a.pos]; + a.buffer[a.pos]=undenormalise(allpass_feedback*aux+p_dst[j]); + p_dst[j]=aux-allpass_feedback*a.buffer[a.pos]; + a.pos++; + + } + } + + static const float wet_scale=0.6; + + for (int i=0;i<p_frames;i++) { + + + p_dst[i]=p_dst[i]*params.wet*wet_scale+p_src[i]*params.dry; + } + +} + + +void Reverb::set_room_size(float p_size) { + + params.room_size=p_size; + update_parameters(); + +} +void Reverb::set_damp(float p_damp) { + + params.damp=p_damp; + update_parameters(); + +} +void Reverb::set_wet(float p_wet) { + + params.wet=p_wet; + +} + +void Reverb::set_dry(float p_dry) { + + params.dry=p_dry; + +} + +void Reverb::set_predelay(float p_predelay) { + + params.predelay=p_predelay; +} +void Reverb::set_predelay_feedback(float p_predelay_fb) { + + params.predelay_fb=p_predelay_fb; + +} + +void Reverb::set_highpass(float p_frq) { + + if (p_frq>1) + p_frq=1; + if (p_frq<0) + p_frq=0; + params.hpf=p_frq; +} + +void Reverb::set_extra_spread(float p_spread) { + + params.extra_spread=p_spread; + +} + + +void Reverb::set_mix_rate(float p_mix_rate) { + + params.mix_rate=p_mix_rate; + configure_buffers(); +} + +void Reverb::set_extra_spread_base(float p_sec) { + + params.extra_spread_base=p_sec; + configure_buffers(); +} + + +void Reverb::configure_buffers() { + + clear_buffers(); //clear if necesary + + for (int i=0;i<MAX_COMBS;i++) { + + Comb &c=comb[i]; + + + c.extra_spread_frames=lrint(params.extra_spread_base*params.mix_rate); + + int len=lrint(comb_tunings[i]*params.mix_rate)+c.extra_spread_frames; + if (len<5) + len=5; //may this happen? + + c.buffer = memnew_arr(float,len); + c.pos=0; + for (int j=0;j<len;j++) + c.buffer[j]=0; + c.size=len; + + } + + for (int i=0;i<MAX_ALLPASS;i++) { + + AllPass &a=allpass[i]; + + a.extra_spread_frames=lrint(params.extra_spread_base*params.mix_rate); + + int len=lrint(allpass_tunings[i]*params.mix_rate)+a.extra_spread_frames; + if (len<5) + len=5; //may this happen? + + a.buffer = memnew_arr(float,len); + a.pos=0; + for (int j=0;j<len;j++) + a.buffer[j]=0; + a.size=len; + } + + echo_buffer_size=(int)(((float)MAX_ECHO_MS/1000.0)*params.mix_rate+1.0); + echo_buffer = memnew_arr(float,echo_buffer_size); + for (int i=0;i<echo_buffer_size;i++) { + + echo_buffer[i]=0; + } + + echo_buffer_pos=0; +} + + +void Reverb::update_parameters() { + + //more freeverb derived constants + static const float room_scale = 0.28f; + static const float room_offset = 0.7f; + + for (int i=0;i<MAX_COMBS;i++) { + + Comb &c=comb[i]; + c.feedback=room_offset+params.room_size*room_scale; + if (c.feedback<room_offset) + c.feedback=room_offset; + else if (c.feedback>(room_offset+room_scale)) + c.feedback=(room_offset+room_scale); + + float auxdmp=params.damp/2.0+0.5; //only half the range (0.5 .. 1.0 is enough) + auxdmp*=auxdmp; + + c.damp=expf(-2.0*Math_PI*auxdmp*10000/params.mix_rate); // 0 .. 10khz + } + +} + +void Reverb::clear_buffers() { + + if (echo_buffer) + memdelete_arr(echo_buffer); + + for (int i=0;i<MAX_COMBS;i++) { + + if (comb[i].buffer) + memdelete_arr(comb[i].buffer); + + comb[i].buffer=0; + + } + + for (int i=0;i<MAX_ALLPASS;i++) { + + if (allpass[i].buffer) + memdelete_arr(allpass[i].buffer); + + allpass[i].buffer=0; + } + +} + +Reverb::Reverb() { + + params.room_size=0.8; + params.damp=0.5; + params.dry=1.0; + params.wet=0.0; + params.mix_rate=44100; + params.extra_spread_base=0; + params.extra_spread=1.0; + params.predelay=150; + params.predelay_fb=0.4; + params.hpf=0; + hpf_h1=0; + hpf_h2=0; + + + input_buffer=memnew_arr(float,INPUT_BUFFER_MAX_SIZE); + echo_buffer=0; + + configure_buffers(); + update_parameters(); + + +} + + +Reverb::~Reverb() { + + memdelete_arr(input_buffer); + clear_buffers(); +} + + diff --git a/servers/audio/effects/reverb.h b/servers/audio/effects/reverb.h new file mode 100644 index 0000000000..2c82be9156 --- /dev/null +++ b/servers/audio/effects/reverb.h @@ -0,0 +1,111 @@ +// +// C++ Interface: reverb +// +// Description: +// +// +// Author: Juan Linietsky <reduzio@gmail.com>, (C) 2006 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef REVERB_H +#define REVERB_H + +#include "typedefs.h" +#include "os/memory.h" +#include "audio_frame.h" + +class Reverb { +public: + enum { + INPUT_BUFFER_MAX_SIZE=1024, + + }; +private: + enum { + + MAX_COMBS=8, + MAX_ALLPASS=4, + MAX_ECHO_MS=500 + + }; + + + + static const float comb_tunings[MAX_COMBS]; + static const float allpass_tunings[MAX_ALLPASS]; + + struct Comb { + + int size; + float *buffer; + float feedback; + float damp; //lowpass + float damp_h; //history + int pos; + int extra_spread_frames; + + Comb() { size=0; buffer=0; feedback=0; damp_h=0; pos=0; } + }; + + struct AllPass { + + int size; + float *buffer; + int pos; + int extra_spread_frames; + AllPass() { size=0; buffer=0; pos=0; } + }; + + Comb comb[MAX_COMBS]; + AllPass allpass[MAX_ALLPASS]; + float *input_buffer; + float *echo_buffer; + int echo_buffer_size; + int echo_buffer_pos; + + float hpf_h1,hpf_h2; + + + struct Parameters { + + float room_size; + float damp; + float wet; + float dry; + float mix_rate; + float extra_spread_base; + float extra_spread; + float predelay; + float predelay_fb; + float hpf; + } params; + + void configure_buffers(); + void update_parameters(); + void clear_buffers(); +public: + + void set_room_size(float p_size); + void set_damp(float p_damp); + void set_wet(float p_wet); + void set_dry(float p_dry); + void set_predelay(float p_predelay); // in ms + void set_predelay_feedback(float p_predelay_fb); // in ms + void set_highpass(float p_frq); + void set_mix_rate(float p_mix_rate); + void set_extra_spread(float p_spread); + void set_extra_spread_base(float p_sec); + + void process(float *p_src,float *p_dst,int p_frames); + + Reverb(); + + ~Reverb(); + +}; + + + +#endif diff --git a/servers/audio/sample_manager_sw.cpp b/servers/audio/sample_manager_sw.cpp deleted file mode 100644 index fe4cc36776..0000000000 --- a/servers/audio/sample_manager_sw.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/*************************************************************************/ -/* sample_manager_sw.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "sample_manager_sw.h" - -#include "print_string.h" - -SampleManagerSW::~SampleManagerSW() -{ -} - - - -RID SampleManagerMallocSW::sample_create(AS::SampleFormat p_format, bool p_stereo, int p_length) { - - Sample *s = memnew( Sample ); - int datalen = p_length; - if (p_format==AS::SAMPLE_FORMAT_PCM16) - datalen*=2; - else if (p_format==AS::SAMPLE_FORMAT_IMA_ADPCM) { - if (datalen&1) { - datalen++; - } - datalen/=2; - datalen+=4; - } - - if (p_stereo) - datalen*=2; - -#define SAMPLE_EXTRA 16 - - s->data = memalloc(datalen+SAMPLE_EXTRA); //help the interpolator by allocating a little more.. - for(int i=0;i<SAMPLE_EXTRA;i++) { - - uint8_t *data = (uint8_t*)s->data; - data[datalen+i]=0; - } - if (!s->data) { - - memdelete(s); - ERR_EXPLAIN("Cannot allocate sample of requested size."); - ERR_FAIL_V(RID()); - } - - s->format=p_format; - s->length=p_length; - s->length_bytes=datalen; - s->stereo=p_stereo; - s->loop_begin=0; - s->loop_end=0; - s->loop_format=AS::SAMPLE_LOOP_NONE; - s->mix_rate=44100; - - AudioServer::get_singleton()->lock(); - RID rid = sample_owner.make_rid(s); - AudioServer::get_singleton()->unlock(); - - return rid; -} - -void SampleManagerMallocSW::sample_set_description(RID p_sample, const String& p_description) { - - Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND(!s); - - s->description=p_description; -} - -String SampleManagerMallocSW::sample_get_description(RID p_sample) const { - - const Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND_V(!s,String()); - - return s->description; -} - - -AS::SampleFormat SampleManagerMallocSW::sample_get_format(RID p_sample) const { - - const Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND_V(!s,AS::SAMPLE_FORMAT_PCM8); - - return s->format; -} - -bool SampleManagerMallocSW::sample_is_stereo(RID p_sample) const { - - const Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND_V(!s,false); - - return s->stereo; - -} -int SampleManagerMallocSW::sample_get_length(RID p_sample) const { - - const Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND_V(!s,-1); - - return s->length; -} - -void SampleManagerMallocSW::sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer) { - - Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND(!s); - - int buff_size=p_buffer.size(); - ERR_FAIL_COND(buff_size==0); - - - ERR_EXPLAIN("Sample buffer size does not match sample size."); - //print_line("len bytes: "+itos(s->length_bytes)+" bufsize: "+itos(buff_size)); - ERR_FAIL_COND(s->length_bytes!=buff_size); - PoolVector<uint8_t>::Read buffer_r=p_buffer.read(); - const uint8_t *src = buffer_r.ptr(); - uint8_t *dst = (uint8_t*)s->data; - //print_line("set data: "+itos(s->length_bytes)); - - for(int i=0;i<s->length_bytes;i++) { - - dst[i]=src[i]; - } - - switch(s->format) { - - case AS::SAMPLE_FORMAT_PCM8: { - - if (s->stereo) { - dst[s->length]=dst[s->length-2]; - dst[s->length+1]=dst[s->length-1]; - } else { - - dst[s->length]=dst[s->length-1]; - } - - } break; - case AS::SAMPLE_FORMAT_PCM16: { - - if (s->stereo) { - dst[s->length]=dst[s->length-4]; - dst[s->length+1]=dst[s->length-3]; - dst[s->length+2]=dst[s->length-2]; - dst[s->length+3]=dst[s->length-1]; - } else { - - dst[s->length]=dst[s->length-2]; - dst[s->length+1]=dst[s->length-1]; - } - - } break; - - } - - - -} - -const PoolVector<uint8_t> SampleManagerMallocSW::sample_get_data(RID p_sample) const { - - Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND_V(!s,PoolVector<uint8_t>()); - - PoolVector<uint8_t> ret_buffer; - ret_buffer.resize(s->length_bytes); - PoolVector<uint8_t>::Write buffer_w=ret_buffer.write(); - uint8_t *dst = buffer_w.ptr(); - const uint8_t *src = (const uint8_t*)s->data; - - for(int i=0;i<s->length_bytes;i++) { - - dst[i]=src[i]; - } - - buffer_w = PoolVector<uint8_t>::Write(); //unlock - - return ret_buffer; -} - -void *SampleManagerMallocSW::sample_get_data_ptr(RID p_sample) const { - - const Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND_V(!s,NULL); - - return s->data; - -} - -void SampleManagerMallocSW::sample_set_mix_rate(RID p_sample,int p_rate) { - - ERR_FAIL_COND(p_rate<1); - - Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND(!s); - - s->mix_rate=p_rate; - - -} -int SampleManagerMallocSW::sample_get_mix_rate(RID p_sample) const { - - const Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND_V(!s,-1); - - return s->mix_rate; - -} -void SampleManagerMallocSW::sample_set_loop_format(RID p_sample,AS::SampleLoopFormat p_format) { - - Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND(!s); - - s->loop_format=p_format; - -} -AS::SampleLoopFormat SampleManagerMallocSW::sample_get_loop_format(RID p_sample) const { - - const Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND_V(!s,AS::SAMPLE_LOOP_NONE); - - return s->loop_format; -} - -void SampleManagerMallocSW::sample_set_loop_begin(RID p_sample,int p_pos) { - - Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND(!s); - ERR_FAIL_INDEX(p_pos,s->length); - - s->loop_begin=p_pos; -} -int SampleManagerMallocSW::sample_get_loop_begin(RID p_sample) const { - - const Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND_V(!s,-1); - - return s->loop_begin; -} - -void SampleManagerMallocSW::sample_set_loop_end(RID p_sample,int p_pos) { - - Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND(!s); - if (p_pos>s->length) - p_pos=s->length; - s->loop_end=p_pos; - -} -int SampleManagerMallocSW::sample_get_loop_end(RID p_sample) const { - - const Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND_V(!s,-1); - - return s->loop_end; -} - -bool SampleManagerMallocSW::is_sample(RID p_sample) const { - - return sample_owner.owns(p_sample); - -} -void SampleManagerMallocSW::free(RID p_sample) { - - Sample *s = sample_owner.get(p_sample); - ERR_FAIL_COND(!s); - AudioServer::get_singleton()->lock(); - sample_owner.free(p_sample); - AudioServer::get_singleton()->unlock(); - - memfree(s->data); - memdelete(s); - -} - -SampleManagerMallocSW::SampleManagerMallocSW() { - - -} - -SampleManagerMallocSW::~SampleManagerMallocSW() { - - // check for sample leakage - List<RID> owned_list; - sample_owner.get_owned_list(&owned_list); - - while(owned_list.size()) { - - Sample *s = sample_owner.get(owned_list.front()->get()); - String err="Leaked sample of size: "+itos(s->length_bytes)+" description: "+s->description; - ERR_PRINT(err.utf8().get_data()); - free(owned_list.front()->get()); - owned_list.pop_front(); - } - -} diff --git a/servers/audio/sample_manager_sw.h b/servers/audio/sample_manager_sw.h deleted file mode 100644 index 93cad96f1a..0000000000 --- a/servers/audio/sample_manager_sw.h +++ /dev/null @@ -1,129 +0,0 @@ -/*************************************************************************/ -/* sample_manager_sw.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SAMPLE_MANAGER_SW_H -#define SAMPLE_MANAGER_SW_H - -#include "servers/audio_server.h" - -class SampleManagerSW { -public: - - /* SAMPLE API */ - - virtual RID sample_create(AS::SampleFormat p_format, bool p_stereo, int p_length)=0; - - virtual void sample_set_description(RID p_sample, const String& p_description)=0; - virtual String sample_get_description(RID p_sample) const=0; - - virtual AS::SampleFormat sample_get_format(RID p_sample) const=0; - virtual bool sample_is_stereo(RID p_sample) const=0; - virtual int sample_get_length(RID p_sample) const=0; - - virtual void sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer)=0; - virtual const PoolVector<uint8_t> sample_get_data(RID p_sample) const=0; - - virtual void *sample_get_data_ptr(RID p_sample) const=0; - - virtual void sample_set_mix_rate(RID p_sample,int p_rate)=0; - virtual int sample_get_mix_rate(RID p_sample) const=0; - - virtual void sample_set_loop_format(RID p_sample,AS::SampleLoopFormat p_format)=0; - virtual AS::SampleLoopFormat sample_get_loop_format(RID p_sample) const=0; - - virtual void sample_set_loop_begin(RID p_sample,int p_pos)=0; - virtual int sample_get_loop_begin(RID p_sample) const=0; - - virtual void sample_set_loop_end(RID p_sample,int p_pos)=0; - virtual int sample_get_loop_end(RID p_sample) const=0; - - virtual bool is_sample(RID) const=0; - virtual void free(RID p_sample)=0; - - - - virtual ~SampleManagerSW(); -}; - - -class SampleManagerMallocSW : public SampleManagerSW { - - - struct Sample : public RID_Data { - - void *data; - int length; - int length_bytes; - AS::SampleFormat format; - bool stereo; - AS::SampleLoopFormat loop_format; - int loop_begin; - int loop_end; - int mix_rate; - String description; - }; - - mutable RID_Owner<Sample> sample_owner; -public: - - /* SAMPLE API */ - - virtual RID sample_create(AS::SampleFormat p_format, bool p_stereo, int p_length); - - virtual void sample_set_description(RID p_sample, const String& p_description); - virtual String sample_get_description(RID p_sample) const; - - virtual AS::SampleFormat sample_get_format(RID p_sample) const; - virtual bool sample_is_stereo(RID p_sample) const; - virtual int sample_get_length(RID p_sample) const; - - virtual void sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer); - virtual const PoolVector<uint8_t> sample_get_data(RID p_sample) const; - - virtual void *sample_get_data_ptr(RID p_sample) const; - - virtual void sample_set_mix_rate(RID p_sample,int p_rate); - virtual int sample_get_mix_rate(RID p_sample) const; - - virtual void sample_set_loop_format(RID p_sample,AS::SampleLoopFormat p_format); - virtual AS::SampleLoopFormat sample_get_loop_format(RID p_sample) const; - - virtual void sample_set_loop_begin(RID p_sample,int p_pos); - virtual int sample_get_loop_begin(RID p_sample) const; - - virtual void sample_set_loop_end(RID p_sample,int p_pos); - virtual int sample_get_loop_end(RID p_sample) const; - - virtual bool is_sample(RID) const; - virtual void free(RID p_sample); - - SampleManagerMallocSW(); - virtual ~SampleManagerMallocSW(); -}; - -#endif // SAMPLE_MANAGER_SW_H diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index 5037b19924..8a8b9ebf76 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -28,177 +28,1194 @@ /*************************************************************************/ #include "audio_server.h" #include "globals.h" +#include "os/os.h" +#include "servers/audio/effects/audio_effect_compressor.h" +#include "io/resource_loader.h" +#include "os/file_access.h" +#ifdef TOOLS_ENABLED -void AudioMixer::audio_mixer_chunk_call(int p_frames) { +#define MARK_EDITED set_edited(true); - AudioServer::get_singleton()->audio_mixer_chunk_callback(p_frames); +#else + +#define MARK_EDITED + +#endif + +AudioDriver *AudioDriver::singleton=NULL; +AudioDriver *AudioDriver::get_singleton() { + + return singleton; } -AudioMixer *AudioServer::EventStream::get_mixer() const { +void AudioDriver::set_singleton() { - return AudioServer::get_singleton()->get_mixer(); + singleton=this; } -AudioServer *AudioServer::singleton=NULL; +void AudioDriver::audio_server_process(int p_frames,int32_t *p_buffer,bool p_update_mix_time) { -AudioServer *AudioServer::get_singleton() { - return singleton; + if (p_update_mix_time) + update_mix_time(p_frames); + + if (AudioServer::get_singleton()) + AudioServer::get_singleton()->_driver_process(p_frames,p_buffer); +} + + + +void AudioDriver::update_mix_time(int p_frames) { + + _mix_amount+=p_frames; + _last_mix_time=OS::get_singleton()->get_ticks_usec(); +} + +double AudioDriver::get_mix_time() const { + + double total = (OS::get_singleton()->get_ticks_usec() - _last_mix_time) / 1000000.0; + total+=_mix_amount/(double)get_mix_rate(); + return total; + +} + + +AudioDriver::AudioDriver() { + + _last_mix_time=0; + _mix_amount=0; +} + + +AudioDriver *AudioDriverManager::drivers[MAX_DRIVERS]; +int AudioDriverManager::driver_count=0; + + +void AudioDriverManager::add_driver(AudioDriver *p_driver) { + + ERR_FAIL_COND(driver_count>=MAX_DRIVERS); + drivers[driver_count++]=p_driver; } -void AudioServer::sample_set_signed_data(RID p_sample, const PoolVector<float>& p_buffer) { +int AudioDriverManager::get_driver_count() { - SampleFormat format = sample_get_format(p_sample); + return driver_count; +} +AudioDriver *AudioDriverManager::get_driver(int p_driver) { + + ERR_FAIL_INDEX_V(p_driver,driver_count,NULL); + return drivers[p_driver]; +} + + +////////////////////////////////////////////// +////////////////////////////////////////////// +////////////////////////////////////////////// +////////////////////////////////////////////// + +void AudioServer::_driver_process(int p_frames,int32_t* p_buffer) { + + int todo=p_frames; - ERR_EXPLAIN("IMA ADPCM is not supported."); - ERR_FAIL_COND(format==SAMPLE_FORMAT_IMA_ADPCM); + while(todo) { - int len = p_buffer.size(); - ERR_FAIL_COND( len == 0 ); + if (to_mix==0) { + _mix_step(); + } - PoolVector<uint8_t> data; - PoolVector<uint8_t>::Write w; - PoolVector<float>::Read r = p_buffer.read(); + int to_copy = MIN(to_mix,todo); - switch(format) { - case SAMPLE_FORMAT_PCM8: { - data.resize(len); - w=data.write(); + Bus *master = buses[0]; - int8_t *samples8 = (int8_t*)w.ptr(); + int from = buffer_size-to_mix; + int from_buf=p_frames-todo; - for(int i=0;i<len;i++) { + //master master, send to output + int cs = master->channels.size(); + for(int k=0;k<cs;k++) { - float sample = Math::floor( r[i] * (1<<8) ); - if (sample<-128) - sample=-128; - else if (sample>127) - sample=127; - samples8[i]=sample; + if (master->channels[k].active) { + + AudioFrame *buf = master->channels[k].buffer.ptr(); + + for(int j=0;j<to_copy;j++) { + + float l = CLAMP(buf[from+j].l,-1.0,1.0); + int32_t vl = l*((1<<20)-1); + p_buffer[(from_buf+j)*(cs*2)+k*2+0]=vl<<11; + + float r = CLAMP(buf[from+j].r,-1.0,1.0); + int32_t vr = r*((1<<20)-1); + p_buffer[(from_buf+j)*(cs*2)+k*2+1]=vr<<11; + } + + } else { + for(int j=0;j<to_copy;j++) { + + p_buffer[(from_buf+j)*(cs*2)+k*2+0]=0; + p_buffer[(from_buf+j)*(cs*2)+k*2+1]=0; + } } - } break; - case SAMPLE_FORMAT_PCM16: { - data.resize(len*2); - w=data.write(); - int16_t *samples16 = (int16_t*)w.ptr(); + } + + todo-=to_copy; + to_mix-=to_copy; + + } + +} + +void AudioServer::_mix_step() { + + for(int i=0;i<buses.size();i++) { + Bus *bus = buses[i]; + bus->index_cache=i; //might be moved around by editor, so.. + for(int k=0;k<bus->channels.size();k++) { + + bus->channels[k].used=false; + } + } + + //make callbacks for mixing the audio + for (Set<CallbackItem>::Element *E=callbacks.front();E;E=E->next()) { + + E->get().callback(E->get().userdata); + } + + for(int i=buses.size()-1;i>=0;i--) { + //go bus by bus + Bus *bus = buses[i]; + + + for(int k=0;k<bus->channels.size();k++) { + + if (bus->channels[k].active && !bus->channels[k].used) { + //buffer was not used, but it's still active, so it must be cleaned + AudioFrame *buf = bus->channels[k].buffer.ptr(); + + for(uint32_t j=0;j<buffer_size;j++) { + + buf[j]=AudioFrame(0,0); + } + } + + } + + + //process effects + for(int j=0;j<bus->effects.size();j++) { + + if (!bus->effects[j].enabled) + continue; + + for(int k=0;k<bus->channels.size();k++) { + + if (!bus->channels[k].active) + continue; + bus->channels[k].effect_instances[j]->process(bus->channels[k].buffer.ptr(),temp_buffer[k].ptr(),buffer_size); + } + + //swap buffers, so internal buffer always has the right data + for(int k=0;k<bus->channels.size();k++) { + + if (!buses[i]->channels[k].active) + continue; + SWAP(bus->channels[k].buffer,temp_buffer[k]); + } + } + + //process send + + Bus *send=NULL; + + if (i>0) { + //everything has a send save for master bus + if (!bus_map.has(bus->send)) { + send=buses[0]; + } else { + send=bus_map[bus->send]; + if (send->index_cache>=bus->index_cache) { //invalid, send to master + send=buses[0]; + } + } + } + + + for(int k=0;k<bus->channels.size();k++) { + + if (!bus->channels[k].active) + continue; + + AudioFrame *buf = bus->channels[k].buffer.ptr(); + + + AudioFrame peak = AudioFrame(0,0); + for(uint32_t j=0;j<buffer_size;j++) { + float l = ABS(buf[j].l); + if (l>peak.l) { + peak.l=l; + } + float r = ABS(buf[j].r); + if (r>peak.r) { + peak.r=r; + } + } + + bus->channels[k].peak_volume=AudioFrame(Math::linear2db(peak.l+0.0000000001),Math::linear2db(peak.r+0.0000000001)); + + + if (!bus->channels[k].used) { + //see if any audio is contained, because channel was not used + + + if (MAX(peak.r,peak.l) > Math::db2linear(channel_disable_treshold_db)) { + bus->channels[k].last_mix_with_audio=mix_frames; + } else if (mix_frames-bus->channels[k].last_mix_with_audio > channel_disable_frames ) { + bus->channels[k].active=false; + continue; //went inactive, dont mix. + } + } + + if (send) { + //if not master bus, send + AudioFrame *target_buf = thread_get_channel_mix_buffer(send->index_cache,k); + + for(uint32_t j=0;j<buffer_size;j++) { + target_buf[j]+=buf[j]; + } + } + + } + + } + + + mix_frames+=buffer_size; + to_mix=buffer_size; + +} + +AudioFrame *AudioServer::thread_get_channel_mix_buffer(int p_bus,int p_buffer) { + + ERR_FAIL_INDEX_V(p_bus,buses.size(),NULL); + ERR_FAIL_INDEX_V(p_buffer,buses[p_bus]->channels.size(),NULL); + + AudioFrame *data = buses[p_bus]->channels[p_buffer].buffer.ptr(); + + + if (!buses[p_bus]->channels[p_buffer].used) { + buses[p_bus]->channels[p_buffer].used=true; + buses[p_bus]->channels[p_buffer].active=true; + buses[p_bus]->channels[p_buffer].last_mix_with_audio=mix_frames; + for(uint32_t i=0;i<buffer_size;i++) { + data[i]=AudioFrame(0,0); + } + } + + return data; +} + +int AudioServer::thread_get_mix_buffer_size() const { + + return buffer_size; +} + +int AudioServer::thread_find_bus_index(const StringName& p_name) { + + if (bus_map.has(p_name)) { + return bus_map[p_name]->index_cache; + } else { + return 0; + } + +} + +void AudioServer::set_bus_count(int p_count) { + + ERR_FAIL_COND(p_count<1); + ERR_FAIL_INDEX(p_count,256); + + MARK_EDITED + + lock(); + int cb = buses.size(); + + if (p_count<buses.size()) { + for(int i=p_count;i<buses.size();i++) { + bus_map.erase(buses[i]->name); + memdelete(buses[i]); + } + } + + buses.resize(p_count); + + for(int i=cb;i<buses.size();i++) { + + String attempt="New Bus"; + int attempts=1; + while(true) { + + bool name_free=true; + for(int j=0;j<i;j++) { + + if (buses[j]->name==attempt) { + name_free=false; + break; + } + } + + if (!name_free) { + attempts++; + attempt="New Bus " +itos(attempts); + } else { + break; + } + + } + + + buses[i]=memnew(Bus); + buses[i]->channels.resize(_get_channel_count()); + for(int j=0;j<_get_channel_count();j++) { + buses[i]->channels[j].buffer.resize(buffer_size); + } + buses[i]->name=attempt; + buses[i]->solo=false; + buses[i]->mute=false; + buses[i]->bypass=false; + buses[i]->volume_db=0; + if (i>0) { + buses[i]->send="Master"; + } + + bus_map[attempt]=buses[i]; + + } + + unlock(); + + emit_signal("bus_layout_changed"); +} + + +void AudioServer::remove_bus(int p_index) { - for(int i=0;i<len;i++) { + ERR_FAIL_INDEX(p_index,buses.size()); + ERR_FAIL_COND(p_index==0); - float sample = Math::floor( r[i] * (1<<16) ); - if (sample<-32768) - sample=-32768; - else if (sample>32767) - sample=32767; - samples16[i]=sample; + MARK_EDITED + + lock(); + bus_map.erase(buses[p_index]->name); + memdelete(buses[p_index]); + buses.remove(p_index); + unlock(); +} + +void AudioServer::add_bus(int p_at_pos) { + + MARK_EDITED + + if (p_at_pos>=buses.size()) { + p_at_pos=-1; + } else if (p_at_pos==0) { + if (buses.size()>1) + p_at_pos=1; + else + p_at_pos=-1; + } + + String attempt="New Bus"; + int attempts=1; + while(true) { + + bool name_free=true; + for(int j=0;j<buses.size();j++) { + + if (buses[j]->name==attempt) { + name_free=false; + break; } + } + + if (!name_free) { + attempts++; + attempt="New Bus " +itos(attempts); + } else { + break; + } + + } + + Bus* bus =memnew(Bus); + bus->channels.resize(_get_channel_count()); + for(int j=0;j<_get_channel_count();j++) { + bus->channels[j].buffer.resize(buffer_size); + } + bus->name=attempt; + bus->solo=false; + bus->mute=false; + bus->bypass=false; + bus->volume_db=0; + + bus_map[attempt]=bus; + + if (p_at_pos==-1) + buses.push_back(bus); + else + buses.insert(p_at_pos,bus); + +} + +void AudioServer::move_bus(int p_bus,int p_to_pos) { + + ERR_FAIL_COND(p_bus<1 || p_bus>=buses.size()); + ERR_FAIL_COND(p_to_pos!=-1 && (p_to_pos<1 || p_to_pos>buses.size())); + + MARK_EDITED + + if (p_bus==p_to_pos) + return; + + Bus *bus = buses[p_bus]; + buses.remove(p_bus); + + if (p_to_pos==-1) { + buses.push_back(bus); + } else if (p_to_pos<p_bus) { + buses.insert(p_to_pos,bus); + } else { + buses.insert(p_to_pos-1,bus); + } +} + +int AudioServer::get_bus_count() const { + + return buses.size(); +} + + +void AudioServer::set_bus_name(int p_bus,const String& p_name) { + + ERR_FAIL_INDEX(p_bus,buses.size()); + if (p_bus==0 && p_name!="Master") + return; //bus 0 is always master + + MARK_EDITED + + lock(); + + if (buses[p_bus]->name==p_name) { + unlock(); + return; + } + + String attempt=p_name; + int attempts=1; + + while(true) { + + bool name_free=true; + for(int i=0;i<buses.size();i++) { + + if (buses[i]->name==attempt) { + name_free=false; + break; + } + } + + if (name_free) { + break; + } + + attempts++; + attempt=p_name+" "+itos(attempts); + } + bus_map.erase(buses[p_bus]->name); + buses[p_bus]->name=attempt; + bus_map[attempt]=buses[p_bus]; + unlock(); + + emit_signal("bus_layout_changed"); + +} +String AudioServer::get_bus_name(int p_bus) const { + + ERR_FAIL_INDEX_V(p_bus,buses.size(),String()); + return buses[p_bus]->name; +} + +void AudioServer::set_bus_volume_db(int p_bus,float p_volume_db) { + + ERR_FAIL_INDEX(p_bus,buses.size()); + + MARK_EDITED + + buses[p_bus]->volume_db=p_volume_db; + +} +float AudioServer::get_bus_volume_db(int p_bus) const { + + ERR_FAIL_INDEX_V(p_bus,buses.size(),0); + return buses[p_bus]->volume_db; + +} + +void AudioServer::set_bus_send(int p_bus,const StringName& p_send) { + + ERR_FAIL_INDEX(p_bus,buses.size()); + + MARK_EDITED + + buses[p_bus]->send=p_send; + +} + +StringName AudioServer::get_bus_send(int p_bus) const { + + ERR_FAIL_INDEX_V(p_bus,buses.size(),StringName()); + return buses[p_bus]->send; + +} + + +void AudioServer::set_bus_solo(int p_bus,bool p_enable) { + + ERR_FAIL_INDEX(p_bus,buses.size()); + + MARK_EDITED + + buses[p_bus]->solo=p_enable; + +} + +bool AudioServer::is_bus_solo(int p_bus) const{ + + ERR_FAIL_INDEX_V(p_bus,buses.size(),false); + + return buses[p_bus]->solo; + +} + +void AudioServer::set_bus_mute(int p_bus,bool p_enable){ + + ERR_FAIL_INDEX(p_bus,buses.size()); + + MARK_EDITED + + buses[p_bus]->mute=p_enable; +} +bool AudioServer::is_bus_mute(int p_bus) const{ + + ERR_FAIL_INDEX_V(p_bus,buses.size(),false); + + return buses[p_bus]->mute; + +} + +void AudioServer::set_bus_bypass_effects(int p_bus,bool p_enable){ + + ERR_FAIL_INDEX(p_bus,buses.size()); + + MARK_EDITED + + buses[p_bus]->bypass=p_enable; +} +bool AudioServer::is_bus_bypassing_effects(int p_bus) const{ + + ERR_FAIL_INDEX_V(p_bus,buses.size(),false); + + return buses[p_bus]->bypass; + +} + + +void AudioServer::_update_bus_effects(int p_bus) { + + for(int i=0;i<buses[p_bus]->channels.size();i++) { + buses[p_bus]->channels[i].effect_instances.resize(buses[p_bus]->effects.size()); + for(int j=0;j<buses[p_bus]->effects.size();j++) { + Ref<AudioEffectInstance> fx = buses[p_bus]->effects[j].effect->instance(); + if (fx->cast_to<AudioEffectCompressorInstance>()) { + fx->cast_to<AudioEffectCompressorInstance>()->set_current_channel(i); + } + buses[p_bus]->channels[i].effect_instances[j]=fx; + + } + } +} + + +void AudioServer::add_bus_effect(int p_bus,const Ref<AudioEffect>& p_effect,int p_at_pos) { + + ERR_FAIL_COND(p_effect.is_null()); + ERR_FAIL_INDEX(p_bus,buses.size()); + + MARK_EDITED + + + lock(); + + Bus::Effect fx; + fx.effect=p_effect; + //fx.instance=p_effect->instance(); + fx.enabled=true; + + if (p_at_pos>=buses[p_bus]->effects.size() || p_at_pos<0) { + buses[p_bus]->effects.push_back(fx); + } else { + buses[p_bus]->effects.insert(p_at_pos,fx); + } + + _update_bus_effects(p_bus); + + unlock(); +} + + +void AudioServer::remove_bus_effect(int p_bus,int p_effect) { + + ERR_FAIL_INDEX(p_bus,buses.size()); + + MARK_EDITED + + + lock(); + + buses[p_bus]->effects.remove(p_effect); + _update_bus_effects(p_bus); + + unlock(); +} + +int AudioServer::get_bus_effect_count(int p_bus) { + + ERR_FAIL_INDEX_V(p_bus,buses.size(),0); + + return buses[p_bus]->effects.size(); + +} + +Ref<AudioEffect> AudioServer::get_bus_effect(int p_bus,int p_effect) { + + ERR_FAIL_INDEX_V(p_bus,buses.size(),Ref<AudioEffect>()); + ERR_FAIL_INDEX_V(p_effect,buses[p_bus]->effects.size(),Ref<AudioEffect>()); + + return buses[p_bus]->effects[p_effect].effect; + +} + +void AudioServer::swap_bus_effects(int p_bus,int p_effect,int p_by_effect) { + + ERR_FAIL_INDEX(p_bus,buses.size()); + ERR_FAIL_INDEX(p_effect,buses[p_bus]->effects.size()); + ERR_FAIL_INDEX(p_by_effect,buses[p_bus]->effects.size()); + + MARK_EDITED + + + lock(); + SWAP( buses[p_bus]->effects[p_effect], buses[p_bus]->effects[p_by_effect] ); + _update_bus_effects(p_bus); + unlock(); +} + +void AudioServer::set_bus_effect_enabled(int p_bus,int p_effect,bool p_enabled) { + + ERR_FAIL_INDEX(p_bus,buses.size()); + ERR_FAIL_INDEX(p_effect,buses[p_bus]->effects.size()); + + MARK_EDITED + + + buses[p_bus]->effects[p_effect].enabled=p_enabled; + +} +bool AudioServer::is_bus_effect_enabled(int p_bus,int p_effect) const { + + ERR_FAIL_INDEX_V(p_bus,buses.size(),false); + ERR_FAIL_INDEX_V(p_effect,buses[p_bus]->effects.size(),false); + return buses[p_bus]->effects[p_effect].enabled; + +} + + +float AudioServer::get_bus_peak_volume_left_db(int p_bus,int p_channel) const { + + ERR_FAIL_INDEX_V(p_bus,buses.size(),0); + ERR_FAIL_INDEX_V(p_channel,buses[p_bus]->channels.size(),0); + + return buses[p_bus]->channels[p_channel].peak_volume.l; + +} +float AudioServer::get_bus_peak_volume_right_db(int p_bus,int p_channel) const { + + ERR_FAIL_INDEX_V(p_bus,buses.size(),0); + ERR_FAIL_INDEX_V(p_channel,buses[p_bus]->channels.size(),0); + + return buses[p_bus]->channels[p_channel].peak_volume.r; + +} + +bool AudioServer::is_bus_channel_active(int p_bus,int p_channel) const { + + ERR_FAIL_INDEX_V(p_bus,buses.size(),false); + ERR_FAIL_INDEX_V(p_channel,buses[p_bus]->channels.size(),false); + + return buses[p_bus]->channels[p_channel].active; + +} + +void AudioServer::init() { + + channel_disable_treshold_db=GLOBAL_DEF("audio/channel_disable_treshold_db",-60.0); + channel_disable_frames=float(GLOBAL_DEF("audio/channel_disable_time",2.0))*get_mix_rate(); + buffer_size=1024; //harcoded for now + switch( get_speaker_mode() ) { + case SPEAKER_MODE_STEREO: { + temp_buffer.resize(1); + } break; + case SPEAKER_SURROUND_51: { + temp_buffer.resize(3); + } break; + case SPEAKER_SURROUND_71: { + temp_buffer.resize(4); } break; } - w = PoolVector<uint8_t>::Write(); + for(int i=0;i<temp_buffer.size();i++) { + temp_buffer[i].resize(buffer_size); + } + + mix_count=0; + set_bus_count(1);; + set_bus_name(0,"Master"); - sample_set_data(p_sample,data); + if (AudioDriver::get_singleton()) + AudioDriver::get_singleton()->start(); +#ifdef TOOLS_ENABLED + set_edited(false); //avoid editors from thinking this was edited +#endif } -void AudioServer::_bind_methods() { +void AudioServer::load_default_bus_layout() { - ClassDB::bind_method(_MD("sample_create","format","stereo","length"), &AudioServer::sample_create ); - ClassDB::bind_method(_MD("sample_set_description","sample","description"), &AudioServer::sample_set_description ); - ClassDB::bind_method(_MD("sample_get_description","sample"), &AudioServer::sample_get_description ); + if (FileAccess::exists("res://default_bus_layout.tres")) { + Ref<AudioBusLayout> default_layout = ResourceLoader::load("res://default_bus_layout.tres"); + if (default_layout.is_valid()) { + set_bus_layout(default_layout); + } + } - ClassDB::bind_method(_MD("sample_get_format","sample"), &AudioServer::sample_get_format ); - ClassDB::bind_method(_MD("sample_is_stereo","sample"), &AudioServer::sample_is_stereo ); - ClassDB::bind_method(_MD("sample_get_length","sample"), &AudioServer::sample_get_length ); +} - ClassDB::bind_method(_MD("sample_set_signed_data","sample","data"), &AudioServer::sample_set_signed_data ); - ClassDB::bind_method(_MD("sample_set_data","sample","data"), &AudioServer::sample_set_data ); - ClassDB::bind_method(_MD("sample_get_data","sample"), &AudioServer::sample_get_data ); +void AudioServer::finish() { - ClassDB::bind_method(_MD("sample_set_mix_rate","sample","mix_rate"), &AudioServer::sample_set_mix_rate ); - ClassDB::bind_method(_MD("sample_get_mix_rate","sample"), &AudioServer::sample_get_mix_rate ); + for(int i=0;i<buses.size();i++) { + memdelete(buses[i]); + } - ClassDB::bind_method(_MD("sample_set_loop_format","sample","loop_format"), &AudioServer::sample_set_loop_format ); - ClassDB::bind_method(_MD("sample_get_loop_format","sample"), &AudioServer::sample_get_loop_format ); + buses.clear(); +} +void AudioServer::update() { - ClassDB::bind_method(_MD("sample_set_loop_begin","sample","pos"), &AudioServer::sample_set_loop_begin ); - ClassDB::bind_method(_MD("sample_get_loop_begin","sample"), &AudioServer::sample_get_loop_begin ); +} - ClassDB::bind_method(_MD("sample_set_loop_end","sample","pos"), &AudioServer::sample_set_loop_end ); - ClassDB::bind_method(_MD("sample_get_loop_end","sample"), &AudioServer::sample_get_loop_end ); +/* MISC config */ +void AudioServer::lock() { + AudioDriver::get_singleton()->lock(); +} +void AudioServer::unlock() { - ClassDB::bind_method(_MD("voice_create"), &AudioServer::voice_create ); - ClassDB::bind_method(_MD("voice_play","voice","sample"), &AudioServer::voice_play ); - ClassDB::bind_method(_MD("voice_set_volume","voice","volume"), &AudioServer::voice_set_volume ); - ClassDB::bind_method(_MD("voice_set_pan","voice","pan","depth","height"), &AudioServer::voice_set_pan,DEFVAL(0),DEFVAL(0) ); - ClassDB::bind_method(_MD("voice_set_filter","voice","type","cutoff","resonance","gain"), &AudioServer::voice_set_filter,DEFVAL(0) ); - ClassDB::bind_method(_MD("voice_set_chorus","voice","chorus"), &AudioServer::voice_set_chorus ); - ClassDB::bind_method(_MD("voice_set_reverb","voice","room","reverb"), &AudioServer::voice_set_reverb ); - ClassDB::bind_method(_MD("voice_set_mix_rate","voice","rate"), &AudioServer::voice_set_mix_rate ); - ClassDB::bind_method(_MD("voice_set_positional","voice","enabled"), &AudioServer::voice_set_positional ); + AudioDriver::get_singleton()->unlock(); +} - ClassDB::bind_method(_MD("voice_get_volume","voice"), &AudioServer::voice_get_volume ); - ClassDB::bind_method(_MD("voice_get_pan","voice"), &AudioServer::voice_get_pan ); - ClassDB::bind_method(_MD("voice_get_pan_height","voice"), &AudioServer::voice_get_pan_height ); - ClassDB::bind_method(_MD("voice_get_pan_depth","voice"), &AudioServer::voice_get_pan_depth ); - ClassDB::bind_method(_MD("voice_get_filter_type","voice"), &AudioServer::voice_get_filter_type ); - ClassDB::bind_method(_MD("voice_get_filter_cutoff","voice"), &AudioServer::voice_get_filter_cutoff ); - ClassDB::bind_method(_MD("voice_get_filter_resonance","voice"), &AudioServer::voice_get_filter_resonance ); - ClassDB::bind_method(_MD("voice_get_chorus","voice"), &AudioServer::voice_get_chorus ); - ClassDB::bind_method(_MD("voice_get_reverb_type","voice"), &AudioServer::voice_get_reverb_type ); - ClassDB::bind_method(_MD("voice_get_reverb","voice"), &AudioServer::voice_get_reverb ); - ClassDB::bind_method(_MD("voice_get_mix_rate","voice"), &AudioServer::voice_get_mix_rate ); - ClassDB::bind_method(_MD("voice_is_positional","voice"), &AudioServer::voice_is_positional ); - ClassDB::bind_method(_MD("voice_stop","voice"), &AudioServer::voice_stop ); +AudioServer::SpeakerMode AudioServer::get_speaker_mode() const { - ClassDB::bind_method(_MD("free_rid","rid"), &AudioServer::free ); + return (AudioServer::SpeakerMode)AudioDriver::get_singleton()->get_speaker_mode(); +} +float AudioServer::get_mix_rate() const { + + return AudioDriver::get_singleton()->get_mix_rate(); +} - ClassDB::bind_method(_MD("set_stream_global_volume_scale","scale"), &AudioServer::set_stream_global_volume_scale ); - ClassDB::bind_method(_MD("get_stream_global_volume_scale"), &AudioServer::get_stream_global_volume_scale ); +float AudioServer::read_output_peak_db() const { - ClassDB::bind_method(_MD("set_fx_global_volume_scale","scale"), &AudioServer::set_fx_global_volume_scale ); - ClassDB::bind_method(_MD("get_fx_global_volume_scale"), &AudioServer::get_fx_global_volume_scale ); + return 0; +} - ClassDB::bind_method(_MD("set_event_voice_global_volume_scale","scale"), &AudioServer::set_event_voice_global_volume_scale ); - ClassDB::bind_method(_MD("get_event_voice_global_volume_scale"), &AudioServer::get_event_voice_global_volume_scale ); +AudioServer *AudioServer::get_singleton() { + + return singleton; +} + +double AudioServer::get_mix_time() const { + + return 0; +} +double AudioServer::get_output_delay() const { + + return 0; +} - BIND_CONSTANT( SAMPLE_FORMAT_PCM8 ); - BIND_CONSTANT( SAMPLE_FORMAT_PCM16 ); - BIND_CONSTANT( SAMPLE_FORMAT_IMA_ADPCM ); +AudioServer* AudioServer::singleton=NULL; - BIND_CONSTANT( SAMPLE_LOOP_NONE ); - BIND_CONSTANT( SAMPLE_LOOP_FORWARD ); - BIND_CONSTANT( SAMPLE_LOOP_PING_PONG ); - BIND_CONSTANT( FILTER_NONE ); - BIND_CONSTANT( FILTER_LOWPASS ); - BIND_CONSTANT( FILTER_BANDPASS ); - BIND_CONSTANT( FILTER_HIPASS ); - BIND_CONSTANT( FILTER_NOTCH ); - BIND_CONSTANT( FILTER_BANDLIMIT ); ///< cutoff is LP resonace is HP - BIND_CONSTANT( REVERB_SMALL ); - BIND_CONSTANT( REVERB_MEDIUM ); - BIND_CONSTANT( REVERB_LARGE ); - BIND_CONSTANT( REVERB_HALL ); - GLOBAL_DEF("audio/stream_buffering_ms",500); - GLOBAL_DEF("audio/video_delay_compensation_ms",300); +void* AudioServer::audio_data_alloc(uint32_t p_data_len,const uint8_t *p_from_data) { + void * ad = memalloc( p_data_len ); + ERR_FAIL_COND_V(!ad,NULL); + if (p_from_data) { + copymem(ad,p_from_data,p_data_len); + } + + audio_data_lock->lock(); + audio_data[ad]=p_data_len; + audio_data_total_mem+=p_data_len; + audio_data_max_mem=MAX(audio_data_total_mem,audio_data_max_mem); + audio_data_lock->unlock(); + + return ad; +} + +void AudioServer::audio_data_free(void* p_data) { + + audio_data_lock->lock(); + if (!audio_data.has(p_data)) { + audio_data_lock->unlock(); + ERR_FAIL(); + } + + audio_data_total_mem-=audio_data[p_data]; + audio_data.erase(p_data); + memfree(p_data); + audio_data_lock->unlock(); + + +} + +size_t AudioServer::audio_data_get_total_memory_usage() const{ + + return audio_data_total_mem; +} +size_t AudioServer::audio_data_get_max_memory_usage() const{ + + return audio_data_max_mem; + +} + +void AudioServer::add_callback(AudioCallback p_callback,void *p_userdata) { + lock(); + CallbackItem ci; + ci.callback=p_callback; + ci.userdata=p_userdata; + callbacks.insert(ci); + unlock(); +} + +void AudioServer::remove_callback(AudioCallback p_callback,void *p_userdata) { + + lock(); + CallbackItem ci; + ci.callback=p_callback; + ci.userdata=p_userdata; + callbacks.erase(ci); + unlock(); + +} + +void AudioServer::set_bus_layout(const Ref<AudioBusLayout> &p_state) { + + ERR_FAIL_COND(p_state.is_null() || p_state->buses.size()==0); + + lock(); + for(int i=0;i<buses.size();i++) { + memdelete(buses[i]); + } + buses.resize(p_state->buses.size()); + bus_map.clear(); + for(int i=0;i<p_state->buses.size();i++) { + Bus * bus = memnew(Bus); + if (i==0) { + bus->name="Master"; + } else { + bus->name=p_state->buses[i].name; + bus->send=p_state->buses[i].send; + } + + bus->solo=p_state->buses[i].solo; + bus->mute=p_state->buses[i].mute; + bus->bypass=p_state->buses[i].bypass; + bus->volume_db=p_state->buses[i].volume_db; + + for(int j=0;j<p_state->buses[i].effects.size();j++) { + + Ref<AudioEffect> fx = p_state->buses[i].effects[j].effect; + + if (fx.is_valid()) { + + Bus::Effect bfx; + bfx.effect=fx; + bfx.enabled=p_state->buses[i].effects[j].enabled; + bus->effects.push_back(bfx); + } + } + + bus_map[bus->name]=bus; + buses[i]=bus; + + buses[i]->channels.resize(_get_channel_count()); + for(int j=0;j<_get_channel_count();j++) { + buses[i]->channels[j].buffer.resize(buffer_size); + } + _update_bus_effects(i); + } +#ifdef TOOLS_ENABLED + set_edited(false); +#endif + unlock(); + +} + + +Ref<AudioBusLayout> AudioServer::generate_bus_layout() const { + + Ref<AudioBusLayout> state; + state.instance(); + + state->buses.resize( buses.size() ); + + for(int i=0;i<buses.size();i++) { + + state->buses[i].name=buses[i]->name; + state->buses[i].send=buses[i]->send; + state->buses[i].mute=buses[i]->mute; + state->buses[i].solo=buses[i]->solo; + state->buses[i].bypass=buses[i]->bypass; + state->buses[i].volume_db=buses[i]->volume_db; + for(int j=0;j<buses[i]->effects.size();j++) { + AudioBusLayout::Bus::Effect fx; + fx.effect=buses[i]->effects[j].effect; + fx.enabled=buses[i]->effects[j].enabled; + state->buses[i].effects.push_back(fx); + + } + } + + return state; +} + + +void AudioServer::_bind_methods() { + + + ClassDB::bind_method(_MD("set_bus_count","amount"),&AudioServer::set_bus_count); + ClassDB::bind_method(_MD("get_bus_count"),&AudioServer::get_bus_count); + + ClassDB::bind_method(_MD("remove_bus","index"),&AudioServer::remove_bus); + ClassDB::bind_method(_MD("add_bus","at_pos"),&AudioServer::add_bus,DEFVAL(-1)); + ClassDB::bind_method(_MD("move_bus","index","to_index"),&AudioServer::move_bus); + + ClassDB::bind_method(_MD("set_bus_name","bus_idx","name"),&AudioServer::set_bus_name); + ClassDB::bind_method(_MD("get_bus_name","bus_idx"),&AudioServer::get_bus_name); + + ClassDB::bind_method(_MD("set_bus_volume_db","bus_idx","volume_db"),&AudioServer::set_bus_volume_db); + ClassDB::bind_method(_MD("get_bus_volume_db","bus_idx"),&AudioServer::get_bus_volume_db); + + ClassDB::bind_method(_MD("set_bus_send","bus_idx","send"),&AudioServer::set_bus_send); + ClassDB::bind_method(_MD("get_bus_send","bus_idx"),&AudioServer::get_bus_send); + + ClassDB::bind_method(_MD("set_bus_solo","bus_idx","enable"),&AudioServer::set_bus_solo); + ClassDB::bind_method(_MD("is_bus_solo","bus_idx"),&AudioServer::is_bus_solo); + + ClassDB::bind_method(_MD("set_bus_mute","bus_idx","enable"),&AudioServer::set_bus_mute); + ClassDB::bind_method(_MD("is_bus_mute","bus_idx"),&AudioServer::is_bus_mute); + + ClassDB::bind_method(_MD("set_bus_bypass_effects","bus_idx","enable"),&AudioServer::set_bus_bypass_effects); + ClassDB::bind_method(_MD("is_bus_bypassing_effects","bus_idx"),&AudioServer::is_bus_bypassing_effects); + + ClassDB::bind_method(_MD("add_bus_effect","bus_idx","effect:AudioEffect"),&AudioServer::add_bus_effect,DEFVAL(-1)); + ClassDB::bind_method(_MD("remove_bus_effect","bus_idx","effect_idx"),&AudioServer::remove_bus_effect); + + ClassDB::bind_method(_MD("get_bus_effect_count","bus_idx"),&AudioServer::add_bus_effect); + ClassDB::bind_method(_MD("get_bus_effect:AudioEffect","bus_idx","effect_idx"),&AudioServer::get_bus_effect); + ClassDB::bind_method(_MD("swap_bus_effects","bus_idx","effect_idx","by_effect_idx"),&AudioServer::swap_bus_effects); + + ClassDB::bind_method(_MD("set_bus_effect_enabled","bus_idx","effect_idx","enabled"),&AudioServer::set_bus_effect_enabled); + ClassDB::bind_method(_MD("is_bus_effect_enabled","bus_idx","effect_idx"),&AudioServer::is_bus_effect_enabled); + + ClassDB::bind_method(_MD("get_bus_peak_volume_left_db","bus_idx","channel"),&AudioServer::get_bus_peak_volume_left_db); + ClassDB::bind_method(_MD("get_bus_peak_volume_right_db","bus_idx","channel"),&AudioServer::get_bus_peak_volume_right_db); + + ClassDB::bind_method(_MD("lock"),&AudioServer::lock); + ClassDB::bind_method(_MD("unlock"),&AudioServer::unlock); + + ClassDB::bind_method(_MD("get_speaker_mode"),&AudioServer::get_speaker_mode); + ClassDB::bind_method(_MD("get_mix_rate"),&AudioServer::get_mix_rate); + + ClassDB::bind_method(_MD("set_state","state:AudioServerState"),&AudioServer::set_bus_layout); + ClassDB::bind_method(_MD("generate_state:AudioServerState"),&AudioServer::generate_bus_layout); + + ADD_SIGNAL(MethodInfo("bus_layout_changed") ); } AudioServer::AudioServer() { singleton=this; + audio_data_total_mem=0; + audio_data_max_mem=0; + audio_data_lock=Mutex::create(); + mix_frames=0; + to_mix=0; + } AudioServer::~AudioServer() { + memdelete(audio_data_lock); +} + +///////////////////////////////// + + + +bool AudioBusLayout::_set(const StringName& p_name, const Variant& p_value) { + + String s = p_name; + if (s.begins_with("bus/")) { + int index = s.get_slice("/",1).to_int(); + if (buses.size()<=index) { + buses.resize(index+1); + } + + Bus &bus = buses[index]; + + String what = s.get_slice("/",2); + + if (what=="name") { + bus.name=p_value; + } else if (what=="solo") { + bus.solo=p_value; + } else if (what=="mute") { + bus.mute=p_value; + } else if (what=="bypass_fx") { + bus.bypass=p_value; + } else if (what=="volume_db") { + bus.volume_db=p_value; + } else if (what=="send") { + bus.send=p_value; + } else if (what=="effect") { + int which = s.get_slice("/",3).to_int(); + if (bus.effects.size()<=which) { + bus.effects.resize(which+1); + } + + Bus::Effect &fx = bus.effects[which]; + + String fxwhat = s.get_slice("/",4); + if (fxwhat=="effect") { + fx.effect=p_value; + } else if (fxwhat=="enabled") { + fx.enabled=p_value; + } else { + return false; + } + + return true; + } else { + return false; + } + + return true; + } + + return false; + +} + +bool AudioBusLayout::_get(const StringName& p_name,Variant &r_ret) const{ + + String s = p_name; + if (s.begins_with("bus/")) { + + int index = s.get_slice("/",1).to_int(); + if (index<0 || index>=buses.size()) + return false; + + const Bus &bus = buses[index]; + + String what = s.get_slice("/",2); + + if (what=="name") { + r_ret=bus.name; + } else if (what=="solo") { + r_ret=bus.solo; + } else if (what=="mute") { + r_ret=bus.mute; + } else if (what=="bypass_fx") { + r_ret=bus.bypass; + } else if (what=="volume_db") { + r_ret=bus.volume_db; + } else if (what=="send") { + r_ret=bus.send; + } else if (what=="effect") { + int which = s.get_slice("/",3).to_int(); + if (which<0 || which>=bus.effects.size()) { + return false; + } + + const Bus::Effect &fx = bus.effects[which]; + + String fxwhat = s.get_slice("/",4); + if (fxwhat=="effect") { + r_ret=fx.effect; + } else if (fxwhat=="enabled") { + r_ret=fx.enabled; + } else { + return false; + } + + return true; + } else { + return false; + } + + return true; + } + + return false; + +} +void AudioBusLayout::_get_property_list( List<PropertyInfo> *p_list) const{ + + for(int i=0;i<buses.size();i++) { + p_list->push_back(PropertyInfo(Variant::STRING,"bus/"+itos(i)+"/name",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::BOOL,"bus/"+itos(i)+"/solo",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::BOOL,"bus/"+itos(i)+"/mute",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::BOOL,"bus/"+itos(i)+"/bypass_fx",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::REAL,"bus/"+itos(i)+"/volume_db",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::REAL,"bus/"+itos(i)+"/send",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); + + for(int j=0;j<buses[i].effects.size();j++) { + p_list->push_back(PropertyInfo(Variant::OBJECT,"bus/"+itos(i)+"/effect/"+itos(j)+"/effect",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); + p_list->push_back(PropertyInfo(Variant::BOOL,"bus/"+itos(i)+"/effect/"+itos(j)+"/enabled",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); + } + } +} + + +AudioBusLayout::AudioBusLayout() { + buses.resize(1); + buses[0].name="Master"; } diff --git a/servers/audio_server.h b/servers/audio_server.h index 1482b40d4c..88849bb591 100644 --- a/servers/audio_server.h +++ b/servers/audio_server.h @@ -31,261 +31,326 @@ #include "variant.h" #include "object.h" +#include "audio_frame.h" +#include "servers/audio/audio_effect.h" + + +class AudioDriver { + + + static AudioDriver *singleton; + uint64_t _last_mix_time; + uint64_t _mix_amount; + -class AudioMixer { protected: - void audio_mixer_chunk_call(int p_frames); + void audio_server_process(int p_frames,int32_t *p_buffer,bool p_update_mix_time=true); + void update_mix_time(int p_frames); + public: - enum { - INVALID_CHANNEL=0xFFFFFFFF + double get_mix_time() const; //useful for video -> audio sync + + enum SpeakerMode { + SPEAKER_MODE_STEREO, + SPEAKER_SURROUND_51, + SPEAKER_SURROUND_71, }; - typedef uint32_t ChannelID; + static AudioDriver *get_singleton(); + void set_singleton(); - /* CHANNEL API */ + virtual const char* get_name() const=0; - enum FilterType { - FILTER_NONE, - FILTER_LOWPASS, - FILTER_BANDPASS, - FILTER_HIPASS, - FILTER_NOTCH, - FILTER_PEAK, - FILTER_BANDLIMIT, ///< cutoff is LP resonace is HP - FILTER_LOW_SHELF, - FILTER_HIGH_SHELF + virtual Error init()=0; + virtual void start()=0; + virtual int get_mix_rate() const =0; + virtual SpeakerMode get_speaker_mode() const=0; + virtual void lock()=0; + virtual void unlock()=0; + virtual void finish()=0; - }; + virtual float get_latency() { return 0; } - enum ReverbRoomType { - REVERB_SMALL, - REVERB_MEDIUM, - REVERB_LARGE, - REVERB_HALL, - MAX_REVERBS - }; - virtual ChannelID channel_alloc(RID p_sample)=0; - virtual void channel_set_volume(ChannelID p_channel, float p_gain)=0; - virtual void channel_set_pan(ChannelID p_channel, float p_pan, float p_depth=0,float height=0)=0; //pan and depth go from -1 to 1 - virtual void channel_set_filter(ChannelID p_channel, FilterType p_type, float p_cutoff, float p_resonance, float p_gain=1.0)=0; - virtual void channel_set_chorus(ChannelID p_channel, float p_chorus )=0; - virtual void channel_set_reverb(ChannelID p_channel, ReverbRoomType p_room_type, float p_reverb)=0; - virtual void channel_set_mix_rate(ChannelID p_channel, int p_mix_rate)=0; - virtual void channel_set_positional(ChannelID p_channel, bool p_positional)=0; + AudioDriver(); + virtual ~AudioDriver() {} +}; - virtual float channel_get_volume(ChannelID p_channel) const=0; - virtual float channel_get_pan(ChannelID p_channel) const=0; //pan and depth go from -1 to 1 - virtual float channel_get_pan_depth(ChannelID p_channel) const=0; //pan and depth go from -1 to 1 - virtual float channel_get_pan_height(ChannelID p_channel) const=0; //pan and depth go from -1 to 1 - virtual FilterType channel_get_filter_type(ChannelID p_channel) const=0; - virtual float channel_get_filter_cutoff(ChannelID p_channel) const=0; - virtual float channel_get_filter_resonance(ChannelID p_channel) const=0; - virtual float channel_get_filter_gain(ChannelID p_channel) const=0; - virtual float channel_get_chorus(ChannelID p_channel) const=0; - virtual ReverbRoomType channel_get_reverb_type(ChannelID p_channel) const=0; - virtual float channel_get_reverb(ChannelID p_channel) const=0; - virtual int channel_get_mix_rate(ChannelID p_channel) const=0; - virtual bool channel_is_positional(ChannelID p_channel) const=0; - virtual bool channel_is_valid(ChannelID p_channel) const=0; +class AudioDriverManager { - virtual void channel_free(ChannelID p_channel)=0; + enum { - virtual void set_mixer_volume(float p_volume)=0; + MAX_DRIVERS=10 + }; + static AudioDriver *drivers[MAX_DRIVERS]; + static int driver_count; +public: - virtual ~AudioMixer() {} + static void add_driver(AudioDriver *p_driver); + static int get_driver_count(); + static AudioDriver *get_driver(int p_driver); }; +class AudioBusLayout; + class AudioServer : public Object { - GDCLASS( AudioServer, Object ); + GDCLASS( AudioServer, Object ) +public: + //re-expose this her, as AudioDriver is not exposed to script + enum SpeakerMode { + SPEAKER_MODE_STEREO, + SPEAKER_SURROUND_51, + SPEAKER_SURROUND_71, + }; + + enum { + AUDIO_DATA_INVALID_ID=-1 + }; - static AudioServer *singleton; -protected: -friend class AudioStream; -friend class EventStream; -friend class AudioMixer; + typedef void (*AudioCallback)(void* p_userdata); - virtual AudioMixer *get_mixer()=0; - virtual void audio_mixer_chunk_callback(int p_frames)=0; +private: + uint32_t buffer_size; + uint64_t mix_count; + uint64_t mix_frames; - static void _bind_methods(); -public: + float channel_disable_treshold_db; + uint32_t channel_disable_frames; + int to_mix; - class EventStream { - protected: - AudioMixer *get_mixer() const; - public: - virtual void update(uint64_t p_usec)=0; + struct Bus { - virtual ~EventStream() {} - }; + StringName name; + bool solo; + bool mute; + bool bypass; - class AudioStream { - public: - virtual int get_channel_count() const=0; - virtual void set_mix_rate(int p_rate)=0; //notify the stream of the mix rate - virtual bool mix(int32_t *p_buffer,int p_frames)=0; - virtual void update()=0; - virtual bool can_update_mt() const { return true; } - virtual ~AudioStream() {} - }; + //Each channel is a stereo pair. + struct Channel { + bool used; + bool active; + AudioFrame peak_volume; + Vector<AudioFrame> buffer; + Vector<Ref<AudioEffectInstance> > effect_instances; + uint64_t last_mix_with_audio; + Channel() { last_mix_with_audio=0; used=false; active=false; peak_volume=AudioFrame(0,0); } + }; + + Vector<Channel> channels; - enum SampleFormat { + struct Effect { + Ref<AudioEffect> effect; + bool enabled; + }; - SAMPLE_FORMAT_PCM8, - SAMPLE_FORMAT_PCM16, - SAMPLE_FORMAT_IMA_ADPCM + Vector<Effect> effects; + float volume_db; + StringName send; + int index_cache; }; - enum SampleLoopFormat { - SAMPLE_LOOP_NONE, - SAMPLE_LOOP_FORWARD, - SAMPLE_LOOP_PING_PONG // not supported in every platform - }; + Vector< Vector<AudioFrame> >temp_buffer; //temp_buffer for each level + Vector<Bus*> buses; + Map<StringName,Bus*> bus_map; - /* SAMPLE API */ + _FORCE_INLINE_ int _get_channel_count() const { + switch (AudioDriver::get_singleton()->get_speaker_mode()) { + case AudioDriver::SPEAKER_MODE_STEREO: return 1; + case AudioDriver::SPEAKER_SURROUND_51: return 3; + case AudioDriver::SPEAKER_SURROUND_71: return 4; - virtual RID sample_create(SampleFormat p_format, bool p_stereo, int p_length)=0; + } + ERR_FAIL_V(1); + } - virtual void sample_set_description(RID p_sample, const String& p_description)=0; - virtual String sample_get_description(RID p_sample) const=0; - virtual SampleFormat sample_get_format(RID p_sample) const=0; - virtual bool sample_is_stereo(RID p_sample) const=0; - virtual int sample_get_length(RID p_sample) const=0; - virtual const void* sample_get_data_ptr(RID p_sample) const=0; + void _update_bus_effects(int p_bus); - virtual void sample_set_signed_data(RID p_sample, const PoolVector<float>& p_buffer); - virtual void sample_set_data(RID p_sample, const PoolVector<uint8_t>& p_buffer)=0; - virtual PoolVector<uint8_t> sample_get_data(RID p_sample) const=0; - virtual void sample_set_mix_rate(RID p_sample,int p_rate)=0; - virtual int sample_get_mix_rate(RID p_sample) const=0; + static AudioServer* singleton; - virtual void sample_set_loop_format(RID p_sample,SampleLoopFormat p_format)=0; - virtual SampleLoopFormat sample_get_loop_format(RID p_sample) const=0; + // TODO create an audiodata pool to optimize memory - virtual void sample_set_loop_begin(RID p_sample,int p_pos)=0; - virtual int sample_get_loop_begin(RID p_sample) const=0; - virtual void sample_set_loop_end(RID p_sample,int p_pos)=0; - virtual int sample_get_loop_end(RID p_sample) const=0; + Map<void*,uint32_t> audio_data; + size_t audio_data_total_mem; + size_t audio_data_max_mem; + Mutex *audio_data_lock; - /* VOICE API */ + void _mix_step(); - enum FilterType { - FILTER_NONE, - FILTER_LOWPASS, - FILTER_BANDPASS, - FILTER_HIPASS, - FILTER_NOTCH, - FILTER_PEAK, - FILTER_BANDLIMIT, ///< cutoff is LP resonace is HP - FILTER_LOW_SHELF, - FILTER_HIGH_SHELF - }; + struct CallbackItem { - enum ReverbRoomType { + AudioCallback callback; + void *userdata; - REVERB_SMALL, - REVERB_MEDIUM, - REVERB_LARGE, - REVERB_HALL + bool operator<(const CallbackItem& p_item) const { + return (callback==p_item.callback ? userdata < p_item.userdata : callback < p_item.callback); + } }; - virtual RID voice_create()=0; + Set<CallbackItem> callbacks; - virtual void voice_play(RID p_voice, RID p_sample)=0; +friend class AudioDriver; + void _driver_process(int p_frames, int32_t *p_buffer); +protected: - virtual void voice_set_volume(RID p_voice, float p_volume)=0; - virtual void voice_set_pan(RID p_voice, float p_pan, float p_depth=0,float height=0)=0; //pan and depth go from -1 to 1 - virtual void voice_set_filter(RID p_voice, FilterType p_type, float p_cutoff, float p_resonance, float p_gain=0)=0; - virtual void voice_set_chorus(RID p_voice, float p_chorus )=0; - virtual void voice_set_reverb(RID p_voice, ReverbRoomType p_room_type, float p_reverb)=0; - virtual void voice_set_mix_rate(RID p_voice, int p_mix_rate)=0; - virtual void voice_set_positional(RID p_voice, bool p_positional)=0; + static void _bind_methods(); +public: - virtual float voice_get_volume(RID p_voice) const=0; - virtual float voice_get_pan(RID p_voice) const=0; //pan and depth go from -1 to 1 - virtual float voice_get_pan_depth(RID p_voice) const=0; //pan and depth go from -1 to 1 - virtual float voice_get_pan_height(RID p_voice) const=0; //pan and depth go from -1 to 1 - virtual FilterType voice_get_filter_type(RID p_voice) const=0; - virtual float voice_get_filter_cutoff(RID p_voice) const=0; - virtual float voice_get_filter_resonance(RID p_voice) const=0; - virtual float voice_get_chorus(RID p_voice) const=0; - virtual ReverbRoomType voice_get_reverb_type(RID p_voice) const=0; - virtual float voice_get_reverb(RID p_voice) const=0; + //do not use from outside audio thread + AudioFrame *thread_get_channel_mix_buffer(int p_bus,int p_buffer); + int thread_get_mix_buffer_size() const; + int thread_find_bus_index(const StringName& p_name); - virtual int voice_get_mix_rate(RID p_voice) const=0; - virtual bool voice_is_positional(RID p_voice) const=0; - virtual void voice_stop(RID p_voice)=0; - virtual bool voice_is_active(RID p_voice) const=0; + void set_bus_count(int p_count); + int get_bus_count() const; - /* STREAM API */ + void remove_bus(int p_index); + void add_bus(int p_at_pos=-1); - virtual RID audio_stream_create(AudioStream *p_stream)=0; - virtual RID event_stream_create(EventStream *p_stream)=0; + void move_bus(int p_bus,int p_to_pos); - virtual void stream_set_active(RID p_stream, bool p_active)=0; - virtual bool stream_is_active(RID p_stream) const=0; + void set_bus_name(int p_bus,const String& p_name); + String get_bus_name(int p_bus) const; - virtual void stream_set_volume_scale(RID p_stream, float p_scale)=0; - virtual float stream_set_volume_scale(RID p_stream) const=0; + void set_bus_volume_db(int p_bus,float p_volume_db); + float get_bus_volume_db(int p_bus) const; - /* Audio Physics API */ - virtual void free(RID p_id)=0; + void set_bus_send(int p_bus,const StringName& p_send); + StringName get_bus_send(int p_bus) const; - virtual void init()=0; - virtual void finish()=0; - virtual void update()=0; + void set_bus_solo(int p_bus,bool p_enable); + bool is_bus_solo(int p_bus) const; + + void set_bus_mute(int p_bus,bool p_enable); + bool is_bus_mute(int p_bus) const; + + void set_bus_bypass_effects(int p_bus,bool p_enable); + bool is_bus_bypassing_effects(int p_bus) const; + + void add_bus_effect(int p_bus,const Ref<AudioEffect>& p_effect,int p_at_pos=-1); + void remove_bus_effect(int p_bus,int p_effect); + + int get_bus_effect_count(int p_bus); + Ref<AudioEffect> get_bus_effect(int p_bus,int p_effect); + + void swap_bus_effects(int p_bus,int p_effect,int p_by_effect); + + void set_bus_effect_enabled(int p_bus,int p_effect,bool p_enabled); + bool is_bus_effect_enabled(int p_bus,int p_effect) const; + + float get_bus_peak_volume_left_db(int p_bus,int p_channel) const; + float get_bus_peak_volume_right_db(int p_bus,int p_channel) const; + + bool is_bus_channel_active(int p_bus,int p_channel) const; + + virtual void init(); + virtual void finish(); + virtual void update(); + virtual void load_default_bus_layout(); /* MISC config */ - virtual void lock()=0; - virtual void unlock()=0; - virtual int get_default_channel_count() const=0; - virtual int get_default_mix_rate() const=0; + virtual void lock(); + virtual void unlock(); - virtual void set_stream_global_volume_scale(float p_volume)=0; - virtual void set_fx_global_volume_scale(float p_volume)=0; - virtual void set_event_voice_global_volume_scale(float p_volume)=0; - virtual float get_stream_global_volume_scale() const=0; - virtual float get_fx_global_volume_scale() const=0; - virtual float get_event_voice_global_volume_scale() const=0; + virtual SpeakerMode get_speaker_mode() const; + virtual float get_mix_rate() const; - virtual uint32_t read_output_peak() const=0; + virtual float read_output_peak_db() const; static AudioServer *get_singleton(); - virtual double get_mix_time() const=0; //useful for video -> audio sync - virtual double get_output_delay() const=0; + virtual double get_mix_time() const; //useful for video -> audio sync + virtual double get_output_delay() const; + + void* audio_data_alloc(uint32_t p_data_len, const uint8_t *p_from_data=NULL); + void audio_data_free(void* p_data); + + size_t audio_data_get_total_memory_usage() const; + size_t audio_data_get_max_memory_usage() const; + + + void add_callback(AudioCallback p_callback,void *p_userdata); + void remove_callback(AudioCallback p_callback,void *p_userdata); + + void set_bus_layout(const Ref<AudioBusLayout>& p_state); + Ref<AudioBusLayout> generate_bus_layout() const; AudioServer(); virtual ~AudioServer(); }; -VARIANT_ENUM_CAST( AudioServer::SampleFormat ); -VARIANT_ENUM_CAST( AudioServer::SampleLoopFormat ); -VARIANT_ENUM_CAST( AudioServer::FilterType ); -VARIANT_ENUM_CAST( AudioServer::ReverbRoomType ); +VARIANT_ENUM_CAST( AudioServer::SpeakerMode ) + +class AudioBusLayout : public Resource { + + GDCLASS(AudioBusLayout,Resource) + +friend class AudioServer; + + struct Bus { + + StringName name; + bool solo; + bool mute; + bool bypass; + + struct Effect { + Ref<AudioEffect> effect; + bool enabled; + }; + + Vector<Effect> effects; + + float volume_db; + StringName send; + + Bus() { + solo=false; + mute=false; + bypass=false; + volume_db=0; + } + }; + + Vector<Bus> buses; + +protected: + + bool _set(const StringName& p_name, const Variant& p_value); + bool _get(const StringName& p_name,Variant &r_ret) const; + void _get_property_list( List<PropertyInfo> *p_list) const; + +public: + + AudioBusLayout(); +}; + + + + + typedef AudioServer AS; + #endif // AUDIO_SERVER_H diff --git a/servers/physics/area_sw.cpp b/servers/physics/area_sw.cpp index 84389c9b78..8aed07d5e5 100644 --- a/servers/physics/area_sw.cpp +++ b/servers/physics/area_sw.cpp @@ -126,14 +126,14 @@ void AreaSW::set_space_override_mode(PhysicsServer::AreaSpaceOverrideMode p_mode void AreaSW::set_param(PhysicsServer::AreaParameter p_param, const Variant& p_value) { switch(p_param) { - case PhysicsServer::AREA_PARAM_GRAVITY: gravity=p_value; ; break; - case PhysicsServer::AREA_PARAM_GRAVITY_VECTOR: gravity_vector=p_value; ; break; - case PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT: gravity_is_point=p_value; ; break; - case PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: gravity_distance_scale=p_value; ; break; - case PhysicsServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: point_attenuation=p_value; ; break; - case PhysicsServer::AREA_PARAM_LINEAR_DAMP: linear_damp=p_value; ; break; - case PhysicsServer::AREA_PARAM_ANGULAR_DAMP: angular_damp=p_value; ; break; - case PhysicsServer::AREA_PARAM_PRIORITY: priority=p_value; ; break; + case PhysicsServer::AREA_PARAM_GRAVITY: gravity=p_value; break; + case PhysicsServer::AREA_PARAM_GRAVITY_VECTOR: gravity_vector=p_value; break; + case PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT: gravity_is_point=p_value; break; + case PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: gravity_distance_scale=p_value; break; + case PhysicsServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: point_attenuation=p_value; break; + case PhysicsServer::AREA_PARAM_LINEAR_DAMP: linear_damp=p_value; break; + case PhysicsServer::AREA_PARAM_ANGULAR_DAMP: angular_damp=p_value; break; + case PhysicsServer::AREA_PARAM_PRIORITY: priority=p_value; break; } diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index 81604dd5e1..a67dda3a01 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -621,7 +621,7 @@ void BodySW::integrate_velocities(real_t p_step) { if (ang_vel!=0.0) { Vector3 ang_vel_axis = total_angular_velocity / ang_vel; - Basis rot( ang_vel_axis, -ang_vel*p_step ); + Basis rot( ang_vel_axis, ang_vel*p_step ); Basis identity3(1, 0, 0, 0, 1, 0, 0, 0, 1); transform.origin += ((identity3 - rot) * transform.basis).xform(center_of_mass_local); transform.basis = rot * transform.basis; diff --git a/servers/physics/broad_phase_sw.h b/servers/physics/broad_phase_sw.h index 2cc2d7d45e..20b3efc7fb 100644 --- a/servers/physics/broad_phase_sw.h +++ b/servers/physics/broad_phase_sw.h @@ -30,7 +30,7 @@ #define BROAD_PHASE_SW_H #include "math_funcs.h" -#include "aabb.h" +#include "rect3.h" class CollisionObjectSW; diff --git a/servers/physics/collision_solver_sat.cpp b/servers/physics/collision_solver_sat.cpp index d02303e23d..d41012caa4 100644 --- a/servers/physics/collision_solver_sat.cpp +++ b/servers/physics/collision_solver_sat.cpp @@ -639,7 +639,7 @@ static void _collision_sphere_convex_polygon(const ShapeSW *p_a,const Transform Vector3 n1=v2-v1; Vector3 n2=v2-v3; - Vector3 axis = n1.cross(n2).cross(n1).normalized();; + Vector3 axis = n1.cross(n2).cross(n1).normalized(); if (!separator.test_axis( axis )) return; diff --git a/servers/physics/joints/generic_6dof_joint_sw.cpp b/servers/physics/joints/generic_6dof_joint_sw.cpp index 48f70d9077..8d3fc4721a 100644 --- a/servers/physics/joints/generic_6dof_joint_sw.cpp +++ b/servers/physics/joints/generic_6dof_joint_sw.cpp @@ -676,7 +676,7 @@ float Generic6DOFJointSW::get_param(Vector3::Axis p_axis,PhysicsServer::G6DOFJoi } break; case PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT: { - return m_angularLimits[p_axis].m_maxLimitForce; + return m_angularLimits[p_axis].m_maxMotorForce; } break; } diff --git a/servers/physics/joints/hinge_joint_sw.cpp b/servers/physics/joints/hinge_joint_sw.cpp index 277346fbbb..d50d5a1a73 100644 --- a/servers/physics/joints/hinge_joint_sw.cpp +++ b/servers/physics/joints/hinge_joint_sw.cpp @@ -371,7 +371,7 @@ void HingeJointSW::solve(float p_step) { real_t desiredMotorVel = m_motorTargetVelocity; real_t motor_relvel = desiredMotorVel - projRelVel; - real_t unclippedMotorImpulse = m_kHinge * motor_relvel;; + real_t unclippedMotorImpulse = m_kHinge * motor_relvel; //todo: should clip against accumulated impulse real_t clippedMotorImpulse = unclippedMotorImpulse > m_maxMotorImpulse ? m_maxMotorImpulse : unclippedMotorImpulse; clippedMotorImpulse = clippedMotorImpulse < -m_maxMotorImpulse ? -m_maxMotorImpulse : clippedMotorImpulse; diff --git a/servers/physics/shape_sw.cpp b/servers/physics/shape_sw.cpp index 9f8d1107f4..4114980b82 100644 --- a/servers/physics/shape_sw.cpp +++ b/servers/physics/shape_sw.cpp @@ -1620,7 +1620,7 @@ void HeightMapShapeSW::_setup(PoolVector<real_t> p_heights,int p_width,int p_dep heights=p_heights; width=p_width; - depth=p_depth;; + depth=p_depth; cell_size=p_cell_size; PoolVector<real_t>::Read r = heights. read(); diff --git a/servers/physics_2d/area_2d_sw.cpp b/servers/physics_2d/area_2d_sw.cpp index 8ccdd51067..2625502717 100644 --- a/servers/physics_2d/area_2d_sw.cpp +++ b/servers/physics_2d/area_2d_sw.cpp @@ -125,14 +125,14 @@ void Area2DSW::set_space_override_mode(Physics2DServer::AreaSpaceOverrideMode p_ void Area2DSW::set_param(Physics2DServer::AreaParameter p_param, const Variant& p_value) { switch(p_param) { - case Physics2DServer::AREA_PARAM_GRAVITY: gravity=p_value; ; break; - case Physics2DServer::AREA_PARAM_GRAVITY_VECTOR: gravity_vector=p_value; ; break; - case Physics2DServer::AREA_PARAM_GRAVITY_IS_POINT: gravity_is_point=p_value; ; break; - case Physics2DServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: gravity_distance_scale=p_value; ; break; - case Physics2DServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: point_attenuation=p_value; ; break; - case Physics2DServer::AREA_PARAM_LINEAR_DAMP: linear_damp=p_value; ; break; - case Physics2DServer::AREA_PARAM_ANGULAR_DAMP: angular_damp=p_value; ; break; - case Physics2DServer::AREA_PARAM_PRIORITY: priority=p_value; ; break; + case Physics2DServer::AREA_PARAM_GRAVITY: gravity=p_value; break; + case Physics2DServer::AREA_PARAM_GRAVITY_VECTOR: gravity_vector=p_value; break; + case Physics2DServer::AREA_PARAM_GRAVITY_IS_POINT: gravity_is_point=p_value; break; + case Physics2DServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE: gravity_distance_scale=p_value; break; + case Physics2DServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: point_attenuation=p_value; break; + case Physics2DServer::AREA_PARAM_LINEAR_DAMP: linear_damp=p_value; break; + case Physics2DServer::AREA_PARAM_ANGULAR_DAMP: angular_damp=p_value; break; + case Physics2DServer::AREA_PARAM_PRIORITY: priority=p_value; break; } diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp index 72ae221c39..e6b62ffa66 100644 --- a/servers/physics_2d/body_pair_2d_sw.cpp +++ b/servers/physics_2d/body_pair_2d_sw.cpp @@ -249,7 +249,7 @@ bool BodyPair2DSW::setup(float p_step) { Transform2D xform_A = xform_Au * A->get_shape_transform(shape_A); Transform2D xform_Bu = B->get_transform(); - xform_Bu.translate(-A->get_transform().get_origin()); + xform_Bu.elements[2]-=A->get_transform().get_origin(); Transform2D xform_B = xform_Bu * B->get_shape_transform(shape_B); Shape2DSW *shape_A_ptr=A->get_shape(shape_A); diff --git a/servers/physics_2d/broad_phase_2d_hash_grid.cpp b/servers/physics_2d/broad_phase_2d_hash_grid.cpp index d2b37319ad..8b7a410b3d 100644 --- a/servers/physics_2d/broad_phase_2d_hash_grid.cpp +++ b/servers/physics_2d/broad_phase_2d_hash_grid.cpp @@ -539,14 +539,14 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2& p_from, const Vector2& p_t Vector2 max; if (dir.x<0) - max.x= (Math::floor(pos.x)*cell_size - p_from.x) / dir.x; + max.x= (Math::floor((double)pos.x)*cell_size - p_from.x) / dir.x; else - max.x= (Math::floor(pos.x + 1)*cell_size - p_from.x) / dir.x; + max.x= (Math::floor((double)pos.x + 1)*cell_size - p_from.x) / dir.x; if (dir.y<0) - max.y= (Math::floor(pos.y)*cell_size - p_from.y) / dir.y; + max.y= (Math::floor((double)pos.y)*cell_size - p_from.y) / dir.y; else - max.y= (Math::floor(pos.y + 1)*cell_size - p_from.y) / dir.y; + max.y= (Math::floor((double)pos.y + 1)*cell_size - p_from.y) / dir.y; int cullcount=0; _cull<false,true>(pos,Rect2(),p_from,p_to,p_results,p_max_results,p_result_indices,cullcount); diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp index 02d59b69f0..20a5934eb8 100644 --- a/servers/physics_2d/collision_solver_2d_sw.cpp +++ b/servers/physics_2d/collision_solver_2d_sw.cpp @@ -203,14 +203,14 @@ bool CollisionSolver2DSW::solve_concave(const Shape2DSW *p_shape_A,const Transfo cinfo.aabb_tests=0; Transform2D rel_transform = p_transform_A; - rel_transform.translate(-p_transform_B.get_origin()); + rel_transform.elements[2]-=p_transform_B.get_origin(); //quickly compute a local Rect2 Rect2 local_aabb; for(int i=0;i<2;i++) { - Vector2 axis( p_transform_B.get_axis(i) ); + Vector2 axis( p_transform_B.elements[i] ); float axis_scale = 1.0/axis.length(); axis*=axis_scale; diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.cpp b/servers/physics_2d/physics_2d_server_wrap_mt.cpp index 8730bb9ee8..027f318d2d 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.cpp +++ b/servers/physics_2d/physics_2d_server_wrap_mt.cpp @@ -95,7 +95,7 @@ void Physics2DServerWrapMT::sync() { else step_sem->wait(); //must not wait if a step was not issued } - physics_2d_server->sync();; + physics_2d_server->sync(); } void Physics2DServerWrapMT::flush_queries(){ @@ -105,7 +105,7 @@ void Physics2DServerWrapMT::flush_queries(){ void Physics2DServerWrapMT::end_sync() { - physics_2d_server->end_sync();; + physics_2d_server->end_sync(); } void Physics2DServerWrapMT::init() { diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h index 9160d064ef..07a9d84ec8 100644 --- a/servers/physics_2d/shape_2d_sw.h +++ b/servers/physics_2d/shape_2d_sw.h @@ -150,7 +150,7 @@ _FORCE_INLINE_ void project_range_cast(const Vector2& p_cast, const Vector2& p_n real_t mina,maxa;\ real_t minb,maxb;\ Transform2D ofsb=p_transform;\ - ofsb.translate(p_cast);\ + ofsb.elements[2]+=p_cast;\ project_range(p_normal,p_transform,mina,maxa);\ project_range(p_normal,ofsb,minb,maxb); \ r_min=MIN(mina,minb);\ diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index e95707f135..a48b6d3827 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -714,7 +714,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co break; } - body_transform.translate(recover_motion); + body_transform.elements[2]+=recover_motion; body_aabb.pos+=recover_motion; recover_attempts--; @@ -863,7 +863,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co //it collided, let's get the rest info in unsafe advance Transform2D ugt = body_transform; - ugt.translate(p_motion*unsafe); + ugt.elements[2]+=p_motion*unsafe; _RestCallbackData2D rcd; rcd.best_len=0; diff --git a/servers/physics_2d_server.cpp b/servers/physics_2d_server.cpp index bd5a58e57b..39b790111b 100644 --- a/servers/physics_2d_server.cpp +++ b/servers/physics_2d_server.cpp @@ -179,7 +179,7 @@ int Physics2DShapeQueryParameters::get_object_type_mask() const{ } void Physics2DShapeQueryParameters::set_exclude(const Vector<RID>& p_exclude) { - exclude.clear();; + exclude.clear(); for(int i=0;i<p_exclude.size();i++) exclude.insert(p_exclude[i]); diff --git a/servers/physics_server.cpp b/servers/physics_server.cpp index 93553efb27..ab13e2b3a5 100644 --- a/servers/physics_server.cpp +++ b/servers/physics_server.cpp @@ -178,7 +178,7 @@ int PhysicsShapeQueryParameters::get_object_type_mask() const{ } void PhysicsShapeQueryParameters::set_exclude(const Vector<RID>& p_exclude) { - exclude.clear();; + exclude.clear(); for(int i=0;i<p_exclude.size();i++) exclude.insert(p_exclude[i]); diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index 9a98890a26..01f8ffa504 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -33,10 +33,24 @@ #include "audio_server.h" #include "physics_server.h" #include "physics_2d_server.h" -#include "spatial_sound_server.h" -#include "spatial_sound_2d_server.h" #include "script_debugger_remote.h" #include "visual/shader_types.h" +#include "audio/audio_stream.h" +#include "audio/audio_effect.h" +#include "audio/effects/audio_effect_amplify.h" +#include "audio/effects/audio_effect_reverb.h" +#include "audio/effects/audio_effect_filter.h" +#include "audio/effects/audio_effect_eq.h" +#include "audio/effects/audio_effect_distortion.h" +#include "audio/effects/audio_effect_stereo_enhance.h" +#include "audio/effects/audio_effect_panner.h" +#include "audio/effects/audio_effect_chorus.h" +#include "audio/effects/audio_effect_delay.h" +#include "audio/effects/audio_effect_compressor.h" +#include "audio/effects/audio_effect_limiter.h" +#include "audio/effects/audio_effect_pitch_shift.h" +#include "audio/effects/audio_effect_phaser.h" + static void _debugger_get_resource_usage(List<ScriptDebuggerRemote::ResourceUsage>* r_usage) { List<VS::TextureInfo> tinfo; @@ -65,11 +79,45 @@ void register_server_types() { GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("AudioServer",AudioServer::get_singleton()) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("PhysicsServer",PhysicsServer::get_singleton()) ); GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("Physics2DServer",Physics2DServer::get_singleton()) ); - GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("SpatialSoundServer",SpatialSoundServer::get_singleton()) ); - GlobalConfig::get_singleton()->add_singleton( GlobalConfig::Singleton("SpatialSound2DServer",SpatialSound2DServer::get_singleton()) ); shader_types = memnew( ShaderTypes ); + ClassDB::register_virtual_class<AudioStream>(); + ClassDB::register_virtual_class<AudioStreamPlayback>(); + ClassDB::register_virtual_class<AudioEffect>(); + ClassDB::register_class<AudioBusLayout>(); + + { + //audio effects + ClassDB::register_class<AudioEffectAmplify>(); + + ClassDB::register_class<AudioEffectReverb>(); + + ClassDB::register_class<AudioEffectLowPassFilter>(); + ClassDB::register_class<AudioEffectHighPassFilter>(); + ClassDB::register_class<AudioEffectBandPassFilter>(); + ClassDB::register_class<AudioEffectNotchFilter>(); + ClassDB::register_class<AudioEffectBandLimitFilter>(); + ClassDB::register_class<AudioEffectLowShelfFilter>(); + ClassDB::register_class<AudioEffectHighShelfFilter>(); + + ClassDB::register_class<AudioEffectEQ6>(); + ClassDB::register_class<AudioEffectEQ10>(); + ClassDB::register_class<AudioEffectEQ21>(); + + ClassDB::register_class<AudioEffectDistortion>(); + + ClassDB::register_class<AudioEffectStereoEnhance>(); + + ClassDB::register_class<AudioEffectPanner>(); + ClassDB::register_class<AudioEffectChorus>(); + ClassDB::register_class<AudioEffectDelay>(); + ClassDB::register_class<AudioEffectCompressor>(); + ClassDB::register_class<AudioEffectLimiter>(); + ClassDB::register_class<AudioEffectPitchShift>(); + ClassDB::register_class<AudioEffectPhaser>(); + } + ClassDB::register_virtual_class<Physics2DDirectBodyState>(); ClassDB::register_virtual_class<Physics2DDirectSpaceState>(); diff --git a/servers/spatial_sound/spatial_sound_server_sw.cpp b/servers/spatial_sound/spatial_sound_server_sw.cpp deleted file mode 100644 index d550134d82..0000000000 --- a/servers/spatial_sound/spatial_sound_server_sw.cpp +++ /dev/null @@ -1,1071 +0,0 @@ -/*************************************************************************/ -/* spatial_sound_server_sw.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "spatial_sound_server_sw.h" -#include "os/os.h" -#include "servers/audio/audio_filter_sw.h" - - - -int SpatialSoundServerSW::InternalAudioStream::get_channel_count() const { - - return AudioServer::get_singleton()->get_default_channel_count(); -} - -void SpatialSoundServerSW::InternalAudioStream::set_mix_rate(int p_rate) { - - -} - -void SpatialSoundServerSW::InternalAudioStream::update() { - - owner->_update_sources(); -} - -bool SpatialSoundServerSW::InternalAudioStream::mix(int32_t *p_buffer,int p_frames) { - - return owner->internal_buffer_mix(p_buffer,p_frames); -} - -void SpatialSoundServerSW::_update_sources() { - - _THREAD_SAFE_METHOD_ - for (Set<Source*>::Element *E=streaming_sources.front();E;E=E->next()) { - - Source *s=E->get(); - ERR_CONTINUE(!s->stream); - s->stream->update(); - } -} - - -SpatialSoundServerSW::Room::Room() { - - //params[ROOM_PARAM_SPEED_OF_SOUND]=343.0; - params[ROOM_PARAM_SPEED_OF_SOUND_SCALE]=1; - params[ROOM_PARAM_DOPPLER_FACTOR]=1.0; - params[ROOM_PARAM_PITCH_SCALE]=1.0; - params[ROOM_PARAM_VOLUME_SCALE_DB]=0; - params[ROOM_PARAM_REVERB_SEND]=0; - params[ROOM_PARAM_CHORUS_SEND]=0; - params[ROOM_PARAM_ATTENUATION_SCALE]=1.0; - params[ROOM_PARAM_ATTENUATION_HF_CUTOFF]=5000; - params[ROOM_PARAM_ATTENUATION_HF_FLOOR_DB]=-24.0; - params[ROOM_PARAM_ATTENUATION_HF_RATIO_EXP]=1.0; - params[ROOM_PARAM_ATTENUATION_REVERB_SCALE]=0.0; - override_other_sources=false; - reverb=ROOM_REVERB_HALL; - octree_id=0; - level=-1; - - -} - - -SpatialSoundServerSW::Source::Source() { - - params[SOURCE_PARAM_VOLUME_DB]=0.0; - params[SOURCE_PARAM_PITCH_SCALE]=1.0; - params[SOURCE_PARAM_ATTENUATION_MIN_DISTANCE]=1; - params[SOURCE_PARAM_ATTENUATION_MAX_DISTANCE]=100; - params[SOURCE_PARAM_ATTENUATION_DISTANCE_EXP]=1.0; //linear (and not really good) - params[SOURCE_PARAM_EMISSION_CONE_DEGREES]=180.0; //cone disabled - params[SOURCE_PARAM_EMISSION_CONE_ATTENUATION_DB]=-6.0; //minus 6 db attenuation - stream=NULL; - voices.resize(1); - last_voice=0; -} - -SpatialSoundServerSW::Source::Voice::Voice() { - - active=false; - restart=false; - pitch_scale=1.0; - volume_scale=0.0; - voice_rid=AudioServer::get_singleton()->voice_create(); - -} -SpatialSoundServerSW::Source::Voice::~Voice() { - - AudioServer::get_singleton()->free(voice_rid); -} - - -SpatialSoundServerSW::Listener::Listener() { - - params[LISTENER_PARAM_VOLUME_SCALE_DB]=0.0; - params[LISTENER_PARAM_PITCH_SCALE]=1.0; - params[LISTENER_PARAM_ATTENUATION_SCALE]=1.0; - params[LISTENER_PARAM_RECEPTION_CONE_DEGREES]=60.0; - params[LISTENER_PARAM_RECEPTION_CONE_ATTENUATION_DB]=-6; // minus six decibels - -} - -/* SPACE */ -RID SpatialSoundServerSW::space_create() { - - Space* space = memnew( Space ); - RID space_rid = space_owner.make_rid(space); - space->default_room=room_create(); - room_set_space(space->default_room,space_rid); - return space_rid; -} - -/* ROOM */ - -RID SpatialSoundServerSW::room_create() { - - Room *room = memnew( Room ); - return room_owner.make_rid(room); -} - -void SpatialSoundServerSW::room_set_space(RID p_room,RID p_space) { - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - - if (room->space.is_valid()) { - - Space *space = space_owner.get(room->space); - space->rooms.erase(p_room); - space->octree.erase(room->octree_id); - //room->octree_id=0; - } - - room->space=RID(); - - if (p_space.is_valid()) { - - Space *space = space_owner.get(p_space); - ERR_FAIL_COND(!space); - space->rooms.insert(p_room); - room->octree_id=space->octree.create(room,Rect3()); - //set bounds - Rect3 aabb = room->bounds.is_empty()?Rect3():room->bounds.get_aabb(); - space->octree.move(room->octree_id,room->transform.xform(aabb)); - room->space=p_space; - } - - -} - -RID SpatialSoundServerSW::room_get_space(RID p_room) const { - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,RID()); - - - return room->space; -} - - - -void SpatialSoundServerSW::room_set_bounds(RID p_room, const BSP_Tree& p_bounds) { - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - - room->bounds=p_bounds; - - if (!room->space.is_valid()) - return; - - Rect3 aabb = room->bounds.is_empty()?Rect3():room->bounds.get_aabb(); - Space* space = space_owner.get(room->space); - ERR_FAIL_COND(!space); - - space->octree.move(room->octree_id,room->transform.xform(aabb)); - -} -BSP_Tree SpatialSoundServerSW::room_get_bounds(RID p_room) const { - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,BSP_Tree()); - - return room->bounds; -} - -void SpatialSoundServerSW::room_set_transform(RID p_room, const Transform& p_transform) { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - room->transform=p_transform; - room->inverse_transform=p_transform.affine_inverse(); // needs to be done to unscale BSP properly - - if (!room->space.is_valid()) - return; - - if (!room->bounds.is_empty()) { - - Space* space = space_owner.get(room->space); - ERR_FAIL_COND(!space); - - space->octree.move(room->octree_id,room->transform.xform(room->bounds.get_aabb())); - } -} - -Transform SpatialSoundServerSW::room_get_transform(RID p_room) const { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,Transform()); - return room->transform; -} - - -void SpatialSoundServerSW::room_set_param(RID p_room, RoomParam p_param, float p_value) { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - ERR_FAIL_INDEX(p_param,ROOM_PARAM_MAX); - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - room->params[p_param]=p_value; - -} -float SpatialSoundServerSW::room_get_param(RID p_room, RoomParam p_param) const { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - ERR_FAIL_INDEX_V(p_param,ROOM_PARAM_MAX,0); - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,0); - return room->params[p_param]; -} - -void SpatialSoundServerSW::room_set_level(RID p_room, int p_level) { - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - room->level =p_level; - -} - -int SpatialSoundServerSW::room_get_level(RID p_room) const { - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,0); - return room->level; - -} - - -void SpatialSoundServerSW::room_set_reverb(RID p_room, RoomReverb p_reverb) { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - room->reverb=p_reverb; - -} -SpatialSoundServerSW::RoomReverb SpatialSoundServerSW::room_get_reverb(RID p_room) const { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,ROOM_REVERB_SMALL); - return room->reverb; -} - -//useful for underwater or rooms with very strange conditions -void SpatialSoundServerSW::room_set_force_params_to_all_sources(RID p_room, bool p_force) { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - room->override_other_sources=p_force; - -} -bool SpatialSoundServerSW::room_is_forcing_params_to_all_sources(RID p_room) const { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,false); - return room->override_other_sources; -} - -/* SOURCE */ - -RID SpatialSoundServerSW::source_create(RID p_space) { - - Space *space = space_owner.get(p_space); - ERR_FAIL_COND_V(!space,RID()); - - Source *source = memnew( Source ); - source->space=p_space; - RID source_rid = source_owner.make_rid(source); - space->sources.insert(source_rid); - - return source_rid; -} - - -void SpatialSoundServerSW::source_set_polyphony(RID p_source,int p_voice_count) { - - - ERR_FAIL_COND(p_voice_count<=0); // more than 32 is too much, change this if you really need more - if (p_voice_count>32) { - - ERR_PRINT("Voices will be clipped to 32"); - p_voice_count=32; - } - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - - if (p_voice_count<source->voices.size()) { - - for(int i=p_voice_count;i<source->voices.size();i++) { - active_voices.erase(ActiveVoice(source,i)); //erase from active voices - } - } - source->voices.resize(p_voice_count); - -} - -int SpatialSoundServerSW::source_get_polyphony(RID p_source) const { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND_V(!source,-1); - return source->voices.size(); - -} - -void SpatialSoundServerSW::source_set_transform(RID p_source, const Transform& p_transform) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - source->transform=p_transform; - source->transform.orthonormalize(); -} -Transform SpatialSoundServerSW::source_get_transform(RID p_source) const { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND_V(!source,Transform()); - return source->transform; -} - -void SpatialSoundServerSW::source_set_param(RID p_source, SourceParam p_param, float p_value) { - - ERR_FAIL_INDEX(p_param,SOURCE_PARAM_MAX); - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - source->params[p_param]=p_value; - -} -float SpatialSoundServerSW::source_get_param(RID p_source, SourceParam p_param) const { - ERR_FAIL_INDEX_V(p_param,SOURCE_PARAM_MAX,0); - Source *source = source_owner.get(p_source); - ERR_FAIL_COND_V(!source,0); - return source->params[p_param]; - - -} - -void SpatialSoundServerSW::source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - AudioServer::get_singleton()->lock(); - source->stream=p_stream; - _THREAD_SAFE_METHOD_ - - if (!p_stream) { - streaming_sources.erase(source); - active_voices.erase(ActiveVoice(source,VOICE_IS_STREAM)); - } else { - streaming_sources.insert(source); - active_voices.insert(ActiveVoice(source,VOICE_IS_STREAM)); - zeromem(source->stream_data.filter_state,sizeof(Source::StreamData::FilterState)*4); //reset filter for safetyness - p_stream->set_mix_rate(AudioServer::get_singleton()->get_default_mix_rate()); - } - - AudioServer::get_singleton()->unlock(); - -} //null to unset - -SpatialSoundServer::SourceVoiceID SpatialSoundServerSW::source_play_sample(RID p_source, RID p_sample, int p_mix_rate, int p_voice) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND_V(!source,SOURCE_INVALID_VOICE); - - int to_play=0; - - if (p_voice==SOURCE_NEXT_VOICE) { - to_play=source->last_voice+1; - if (to_play>=source->voices.size()) - to_play=0; - - } else - to_play=p_voice; - - ERR_FAIL_INDEX_V(to_play,source->voices.size(),SOURCE_INVALID_VOICE); - - source->voices[to_play].restart=true; - source->voices[to_play].sample_rid=p_sample; - source->voices[to_play].sample_mix_rate=p_mix_rate; - source->voices[to_play].pitch_scale=1; - source->voices[to_play].volume_scale=0; - source->last_voice=to_play; - active_voices.insert(ActiveVoice(source,to_play)); - return to_play; -} - -/* VOICES */ -void SpatialSoundServerSW::source_voice_set_pitch_scale(RID p_source, SourceVoiceID p_voice, float p_pitch_scale) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - ERR_FAIL_INDEX(p_voice,source->voices.size()); - source->voices[p_voice].pitch_scale=p_pitch_scale; - -} -void SpatialSoundServerSW::source_voice_set_volume_scale_db(RID p_source, SourceVoiceID p_voice, float p_db) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - ERR_FAIL_INDEX(p_voice,source->voices.size()); - source->voices[p_voice].volume_scale=p_db; - -} - -bool SpatialSoundServerSW::source_is_voice_active(RID p_source, SourceVoiceID p_voice) const { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND_V(!source,false); - ERR_FAIL_INDEX_V(p_voice,source->voices.size(),false); - return source->voices[p_voice].active || source->voices[p_voice].restart; - -} -void SpatialSoundServerSW::source_stop_voice(RID p_source, SourceVoiceID p_voice) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - ERR_FAIL_INDEX(p_voice,source->voices.size()); - if (source->voices[p_voice].active) { - AudioServer::get_singleton()->voice_stop(source->voices[p_voice].voice_rid); - } - source->voices[p_voice].active=false; - source->voices[p_voice].restart=false; - active_voices.erase(ActiveVoice(source,p_voice)); -} - -/* LISTENER */ - -RID SpatialSoundServerSW::listener_create() { - - Listener *listener = memnew( Listener ); - RID listener_rid = listener_owner.make_rid(listener); - return listener_rid; - -} - -void SpatialSoundServerSW::listener_set_space(RID p_listener,RID p_space) { - - Listener *listener = listener_owner.get(p_listener); - ERR_FAIL_COND(!listener); - - if (listener->space.is_valid()) { - - Space *lspace = space_owner.get(listener->space); - ERR_FAIL_COND(!lspace); - lspace->listeners.erase(p_listener); - } - - listener->space=RID(); - - if (p_space.is_valid()) { - Space *space = space_owner.get(p_space); - ERR_FAIL_COND(!space); - - listener->space=p_space; - space->listeners.insert(p_listener); - } - -} - -void SpatialSoundServerSW::listener_set_transform(RID p_listener, const Transform& p_transform) { - - Listener *listener = listener_owner.get(p_listener); - ERR_FAIL_COND(!listener); - listener->transform=p_transform; - listener->transform.orthonormalize(); //must be done.. -} -Transform SpatialSoundServerSW::listener_get_transform(RID p_listener) const { - - Listener *listener = listener_owner.get(p_listener); - ERR_FAIL_COND_V(!listener,Transform()); - return listener->transform; -} - -void SpatialSoundServerSW::listener_set_param(RID p_listener, ListenerParam p_param, float p_value) { - - ERR_FAIL_INDEX(p_param,LISTENER_PARAM_MAX); - Listener *listener = listener_owner.get(p_listener); - ERR_FAIL_COND(!listener); - listener->params[p_param]=p_value; -} - -float SpatialSoundServerSW::listener_get_param(RID p_listener, ListenerParam p_param) const { - - ERR_FAIL_INDEX_V(p_param,LISTENER_PARAM_MAX,0); - Listener *listener = listener_owner.get(p_listener); - ERR_FAIL_COND_V(!listener,0); - return listener->params[p_param]; -} - - -/* MISC */ - -void SpatialSoundServerSW::free(RID p_id) { - - - if (space_owner.owns(p_id)) { - - Space *space = space_owner.get(p_id); - free(space->default_room); - - while(space->listeners.size()) { - listener_set_space(space->listeners.front()->get(),RID()); - } - while(space->sources.size()) { - free(space->sources.front()->get()); - } - while(space->rooms.size()) { - room_set_space(space->rooms.front()->get(),RID()); - } - space_owner.free(p_id); - memdelete(space); - - } else if (source_owner.owns(p_id)) { - - Source *source = source_owner.get(p_id); - if (source->stream) - source_set_audio_stream(p_id,NULL); - - Space *space = space_owner.get(source->space); - ERR_FAIL_COND(!space); - space->sources.erase(p_id); - for(int i=0;i<source->voices.size();i++) { - active_voices.erase(ActiveVoice(source,i)); - } - source_owner.free(p_id); - memdelete(source); - } else if (listener_owner.owns(p_id)) { - - Listener *listener = listener_owner.get(p_id); - if (listener->space.is_valid()) { - Space *space = space_owner.get(listener->space); - ERR_FAIL_COND(!space); - space->listeners.erase(p_id); - } - listener_owner.free(p_id); - memdelete(listener); - - } else if (room_owner.owns(p_id)) { - - Room *room = room_owner.get(p_id); - - if (room->space.is_valid()) { - Space *space = space_owner.get(room->space); - ERR_FAIL_COND(!space); - space->octree.erase(room->octree_id); - space->rooms.erase(p_id); - } - room_owner.free(p_id); - memdelete(room); - } else { - ERR_PRINT("Attempt to free invalid ID") ; - } - -} - -void SpatialSoundServerSW::_clean_up_owner(RID_OwnerBase *p_owner, const char *p_area) { - - List<RID> rids; - p_owner->get_owned_list(&rids); - - for(List<RID>::Element *I=rids.front();I;I=I->next()) { - if (OS::get_singleton()->is_stdout_verbose()) { - - print_line("Leaked RID ("+itos(I->get().get_id())+") of type "+String(p_area)); - } - free(I->get()); - } -} - -void SpatialSoundServerSW::init() { - - internal_buffer = memnew_arr(int32_t, INTERNAL_BUFFER_SIZE*INTERNAL_BUFFER_MAX_CHANNELS); - internal_buffer_channels=AudioServer::get_singleton()->get_default_channel_count(); - - internal_audio_stream = memnew( InternalAudioStream ); - internal_audio_stream->owner=this; - internal_audio_stream_rid = AudioServer::get_singleton()->audio_stream_create(internal_audio_stream); - - AudioServer::get_singleton()->stream_set_active(internal_audio_stream_rid,true); - -} - - - -static float _get_attenuation(float cosine, float angle, float attenuation) { - - - float listener_ang = Math::rad2deg(Math::acos(cosine))-angle; - - if (listener_ang>0 && angle<180.0) { - listener_ang/=(180.0-angle); - return Math::db2linear(Math::sin(listener_ang*(Math_PI/2.0))*attenuation); - } - return 1.0; -} - - -bool SpatialSoundServerSW::internal_buffer_mix(int32_t *p_buffer,int p_frames) { - - if (streaming_sources.size()==0) - return false; //nothing to mix - - - for (Set<Source*>::Element *E=streaming_sources.front();E;E=E->next()) { - - Source *s=E->get(); - ERR_CONTINUE(!s->stream); - - int channels = s->stream->get_channel_count(); - Source::StreamData &sd=s->stream_data; - - int todo=p_frames; - - AudioFilterSW filter; - filter.set_sampling_rate(AudioServer::get_singleton()->get_default_mix_rate()); - filter.set_cutoff(sd.filter_cutoff); - filter.set_gain(sd.filter_gain); - filter.set_resonance(1); - filter.set_mode(AudioFilterSW::HIGHSHELF); - filter.set_stages(1); - AudioFilterSW::Coeffs coefs; - filter.prepare_coefficients(&coefs); - - int32_t in[4]; -#ifndef SPATIAL_SOUND_SERVER_NO_FILTER -#define DO_FILTER(m_c)\ - {\ - float val = in[m_c];\ - float pre=val;\ - val = val*coefs.b0 + sd.filter_state[m_c].hb[0]*coefs.b1 + sd.filter_state[m_c].hb[1]*coefs.b2 + sd.filter_state[m_c].ha[0]*coefs.a1 + sd.filter_state[m_c].ha[1]*coefs.a2;\ - sd.filter_state[m_c].ha[1]=sd.filter_state[m_c].ha[0];\ - sd.filter_state[m_c].hb[1]=sd.filter_state[m_c].hb[0]; \ - sd.filter_state[m_c].hb[0]=pre;\ - sd.filter_state[m_c].ha[0]=val;\ - in[m_c]=Math::fast_ftoi(val);\ - } -#else -#define DO_FILTER(m_c) -#endif - - while(todo) { - - int to_mix=MIN(todo,INTERNAL_BUFFER_SIZE); - - s->stream->mix(internal_buffer,to_mix); - - switch(internal_buffer_channels) { - - case 2: { - - float p = sd.panning.x*0.5+0.5; - float panf[2]={ (1.0-p),p }; - panf[0]*=sd.volume; - panf[1]*=sd.volume; - - int32_t pan[2]={Math::fast_ftoi(panf[0]*(1<<16)),Math::fast_ftoi(panf[1]*(1<<16))}; - - switch(channels) { - case 1: { - - for(int i=0;i<to_mix;i++) { - - in[0]=internal_buffer[i]; - in[1]=internal_buffer[i]; - DO_FILTER(0); - DO_FILTER(1); - p_buffer[(i<<1)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<1)+1]=((in[1]>>16)*pan[1]); - } - } break; - case 2: { - - for(int i=0;i<to_mix;i++) { - - in[0]=internal_buffer[(i<<1)+0]; - in[1]=internal_buffer[(i<<1)+1]; - DO_FILTER(0); - DO_FILTER(1); - p_buffer[(i<<1)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<1)+1]=((in[1]>>16)*pan[1]); - } - } break; - case 4: { - - for(int i=0;i<to_mix;i++) { - - in[0]=(internal_buffer[(i<<2)+0]+internal_buffer[(i<<2)+2])>>1; - in[1]=(internal_buffer[(i<<2)+1]+internal_buffer[(i<<2)+3])>>1; - DO_FILTER(0); - DO_FILTER(1); - p_buffer[(i<<1)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<1)+1]=((in[1]>>16)*pan[1]); - } - } break; - - } break; - - } break; - case 4: { - - float xp = sd.panning.x*0.5+0.5; - float yp = sd.panning.y*0.5+0.5; - float panf[4]={ (1.0-xp)*(1.0-yp),(xp)*(1.0-yp),(1.0-xp)*(yp),(xp)*(yp) }; - panf[0]*=sd.volume; - panf[1]*=sd.volume; - panf[2]*=sd.volume; - panf[3]*=sd.volume; - - int32_t pan[4]={ - Math::fast_ftoi(panf[0]*(1<<16)), - Math::fast_ftoi(panf[1]*(1<<16)), - Math::fast_ftoi(panf[2]*(1<<16)), - Math::fast_ftoi(panf[3]*(1<<16))}; - - switch(channels) { - case 1: { - - for(int i=0;i<to_mix;i++) { - - in[0]=internal_buffer[i]; - in[1]=internal_buffer[i]; - in[2]=internal_buffer[i]; - in[3]=internal_buffer[i]; - DO_FILTER(0); - DO_FILTER(1); - DO_FILTER(2); - DO_FILTER(3); - p_buffer[(i<<2)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<2)+1]=((in[1]>>16)*pan[1]); - p_buffer[(i<<2)+2]=((in[2]>>16)*pan[2]); - p_buffer[(i<<2)+3]=((in[3]>>16)*pan[3]); - } - } break; - case 2: { - - for(int i=0;i<to_mix;i++) { - - in[0]=internal_buffer[(i<<1)+0]; - in[1]=internal_buffer[(i<<1)+1]; - in[2]=internal_buffer[(i<<1)+0]; - in[3]=internal_buffer[(i<<1)+1]; - DO_FILTER(0); - DO_FILTER(1); - DO_FILTER(2); - DO_FILTER(3); - p_buffer[(i<<2)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<2)+1]=((in[1]>>16)*pan[1]); - p_buffer[(i<<2)+2]=((in[2]>>16)*pan[2]); - p_buffer[(i<<2)+3]=((in[3]>>16)*pan[3]); - } - } break; - case 4: { - - for(int i=0;i<to_mix;i++) { - - in[0]=internal_buffer[(i<<2)+0]; - in[1]=internal_buffer[(i<<2)+1]; - in[2]=internal_buffer[(i<<2)+2]; - in[3]=internal_buffer[(i<<2)+3]; - DO_FILTER(0); - DO_FILTER(1); - DO_FILTER(2); - DO_FILTER(3); - p_buffer[(i<<2)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<2)+1]=((in[1]>>16)*pan[1]); - p_buffer[(i<<2)+2]=((in[2]>>16)*pan[2]); - p_buffer[(i<<2)+3]=((in[3]>>16)*pan[3]); - } - } break; - - } break; - - } break; - case 6: { - - - } break; - } - p_buffer+=to_mix*internal_buffer_channels; - todo-=to_mix; - - } - - } - - return true; -} - -void SpatialSoundServerSW::update(float p_delta) { - - List<ActiveVoice> to_disable; - - - for(Set<ActiveVoice>::Element *E=active_voices.front();E;E=E->next()) { - - Source *source = E->get().source; - int voice = E->get().voice; - - if (voice!=VOICE_IS_STREAM) { - Source::Voice &v=source->voices[voice]; - ERR_CONTINUE(!v.active && !v.restart); // likely a bug... - } - - //this could be optimized at some point... am not sure - Space *space=space_owner.get(source->space); - Room *room=room_owner.get(space->default_room); - int max_level=-0x80000000; - int rooms_culled = space->octree.cull_point(source->transform.origin,cull_rooms,MAX_CULL_ROOMS); - for(int i=0;i<rooms_culled;i++) { - - Room *r=cull_rooms[i]; - ERR_CONTINUE( r->bounds.is_empty() ); // how did this happen?? - if (r->level<=max_level) //ignore optimization (level too low) - continue; - Vector3 local_point = r->inverse_transform.xform(source->transform.origin); - if (!r->bounds.point_is_inside(local_point)) - continue; - room=r; - max_level=r->level; - - } - - - //compute mixing weights (support for multiple listeners in the same output) - float total_distance=0; - for(Set<RID>::Element *L=space->listeners.front();L;L=L->next()) { - Listener *listener=listener_owner.get(L->get()); - total_distance+=listener->transform.origin.distance_to(source->transform.origin); - } - - //compute spatialization variables, weighted according to distance - float volume_attenuation = 0.0; - float air_absorption_hf_cutoff = 0.0; - float air_absorption = 0.0; - float pitch_scale=1.0; - Vector3 panning; - - - //print_line("listeners: "+itos(space->listeners.size())); - - - for(Set<RID>::Element *L=space->listeners.front();L;L=L->next()) { - - Listener *listener=listener_owner.get(L->get()); - - Vector3 rel_vector = listener->transform.xform_inv(source->transform.origin); - Vector3 source_rel_vector = source->transform.xform_inv(listener->transform.origin).normalized(); - float distance=rel_vector.length(); - float weight = distance/total_distance; - float pscale=1.0; - - float distance_scale=listener->params[LISTENER_PARAM_ATTENUATION_SCALE]*room->params[ROOM_PARAM_ATTENUATION_SCALE]; - float distance_min=source->params[SOURCE_PARAM_ATTENUATION_MIN_DISTANCE]*distance_scale; - float distance_max=source->params[SOURCE_PARAM_ATTENUATION_MAX_DISTANCE]*distance_scale; - float attenuation_exp=source->params[SOURCE_PARAM_ATTENUATION_DISTANCE_EXP]; - float attenuation=1; - - //print_line("DIST MIN: "+rtos(distance_min)); - //print_line("DIST MAX: "+rtos(distance_max)); - if (distance_max>0) { - distance = CLAMP(distance,distance_min,distance_max); - attenuation = Math::pow(1.0 - ((distance - distance_min)/(distance_max-distance_min)),CLAMP(attenuation_exp,0.001,16)); - } - - float hf_attenuation_cutoff = room->params[ROOM_PARAM_ATTENUATION_HF_CUTOFF]; - float hf_attenuation_exp = room->params[ROOM_PARAM_ATTENUATION_HF_RATIO_EXP]; - float hf_attenuation_floor = room->params[ROOM_PARAM_ATTENUATION_HF_FLOOR_DB]; - float absorption=Math::db2linear(Math::lerp(hf_attenuation_floor,0,Math::pow(attenuation,hf_attenuation_exp))); - - // source emission cone - - float emission_deg=source->params[SOURCE_PARAM_EMISSION_CONE_DEGREES]; - float emission_attdb=source->params[SOURCE_PARAM_EMISSION_CONE_ATTENUATION_DB]; - absorption*=_get_attenuation(source_rel_vector.dot(Vector3(0,0,-1)),emission_deg,emission_attdb); - - Vector3 vpanning=rel_vector.normalized(); - - //listener stuff - - { - - // head cone - - float reception_deg=listener->params[LISTENER_PARAM_RECEPTION_CONE_DEGREES]; - float reception_attdb=listener->params[LISTENER_PARAM_RECEPTION_CONE_ATTENUATION_DB]; - - absorption*=_get_attenuation(vpanning.dot(Vector3(0,0,-1)),reception_deg,reception_attdb); - - // scale - - attenuation*=Math::db2linear(listener->params[LISTENER_PARAM_VOLUME_SCALE_DB]); - pscale*=Math::db2linear(listener->params[LISTENER_PARAM_PITCH_SCALE]); - - - } - - - - - //add values - - volume_attenuation+=weight*attenuation; // plus other stuff i guess - air_absorption+=weight*absorption; - air_absorption_hf_cutoff+=weight*hf_attenuation_cutoff; - panning+=vpanning*weight; - //pitch_scale+=pscale*weight; - - } - - RoomReverb reverb_room; - float reverb_send; - - /* APPLY ROOM SETTINGS */ - - { - pitch_scale*=room->params[ROOM_PARAM_PITCH_SCALE]; - volume_attenuation*=Math::db2linear(room->params[ROOM_PARAM_VOLUME_SCALE_DB]); - reverb_room=room->reverb; - reverb_send=Math::lerp(1.0,volume_attenuation,room->params[ROOM_PARAM_ATTENUATION_REVERB_SCALE])*room->params[ROOM_PARAM_REVERB_SEND]; - - } - - /* UPDATE VOICE & STREAM */ - - - - if (voice==VOICE_IS_STREAM) { - - //update voice!! - source->stream_data.panning=panning; - source->stream_data.volume=volume_attenuation*Math::db2linear(source->params[SOURCE_PARAM_VOLUME_DB]); - source->stream_data.reverb=reverb_room; - source->stream_data.reverb_send=reverb_send; - source->stream_data.filter_gain=air_absorption; - source->stream_data.filter_cutoff=air_absorption_hf_cutoff; - - if (!source->stream) //stream is gone bye bye - to_disable.push_back(ActiveVoice(source,voice)); // oh well.. - - } else if (voice>=0) { - //update stream!! - Source::Voice &v=source->voices[voice]; - - if (v.restart) - AudioServer::get_singleton()->voice_play(v.voice_rid,v.sample_rid); - - float volume_scale = Math::db2linear(v.volume_scale)*Math::db2linear(source->params[SOURCE_PARAM_VOLUME_DB]); - float volume = volume_attenuation*volume_scale; - reverb_send*=volume_scale; - int mix_rate = v.sample_mix_rate*v.pitch_scale*pitch_scale*source->params[SOURCE_PARAM_PITCH_SCALE]; - - - if (mix_rate<=0) { - ERR_PRINT("Invalid mix rate for voice (0) check for invalid pitch_scale param."); - to_disable.push_back(ActiveVoice(source,voice)); // oh well.. - continue; //invalid mix rate, disabling - } - if (v.restart || v.last_volume!=volume) - AudioServer::get_singleton()->voice_set_volume(v.voice_rid,volume); - if (v.restart || v.last_mix_rate!=mix_rate) - AudioServer::get_singleton()->voice_set_mix_rate(v.voice_rid,mix_rate); - if (v.restart || v.last_filter_gain!=air_absorption || v.last_filter_cutoff!=air_absorption_hf_cutoff) - AudioServer::get_singleton()->voice_set_filter(v.voice_rid,AudioServer::FILTER_HIGH_SHELF,air_absorption_hf_cutoff,1.0,air_absorption); - if (v.restart || v.last_panning!=panning) - AudioServer::get_singleton()->voice_set_pan(v.voice_rid,panning.x,panning.y,panning.z); - if (v.restart || v.last_reverb_room!=reverb_room || v.last_reverb_send!=reverb_send) - AudioServer::get_singleton()->voice_set_reverb(v.voice_rid,AudioServer::ReverbRoomType(reverb_room),reverb_send); - - v.last_volume=volume; - v.last_mix_rate=mix_rate; - v.last_filter_gain=air_absorption; - v.last_filter_cutoff=air_absorption_hf_cutoff; - v.last_panning=panning; - v.restart=false; - v.active=true; - - if (!AudioServer::get_singleton()->voice_is_active(v.voice_rid)) - to_disable.push_back(ActiveVoice(source,voice)); // oh well.. - } - } - - while(to_disable.size()) { - - ActiveVoice av = to_disable.front()->get(); - av.source->voices[av.voice].active=false; - av.source->voices[av.voice].restart=false; - active_voices.erase(av); - to_disable.pop_front(); - } - -} -void SpatialSoundServerSW::finish() { - - AudioServer::get_singleton()->free(internal_audio_stream_rid); - memdelete(internal_audio_stream); - - _clean_up_owner(&source_owner,"Source"); - _clean_up_owner(&listener_owner,"Listener"); - _clean_up_owner(&room_owner,"Room"); - _clean_up_owner(&space_owner,"Space"); - - memdelete_arr(internal_buffer); -} - -SpatialSoundServerSW::SpatialSoundServerSW() { - -} diff --git a/servers/spatial_sound/spatial_sound_server_sw.h b/servers/spatial_sound/spatial_sound_server_sw.h deleted file mode 100644 index 901b781ac2..0000000000 --- a/servers/spatial_sound/spatial_sound_server_sw.h +++ /dev/null @@ -1,266 +0,0 @@ -/*************************************************************************/ -/* spatial_sound_server_sw.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SPATIAL_SOUND_SERVER_SW_H -#define SPATIAL_SOUND_SERVER_SW_H - -#include "servers/spatial_sound_server.h" -#include "octree.h" -#include "os/thread_safe.h" - - -class SpatialSoundServerSW : public SpatialSoundServer { - - GDCLASS(SpatialSoundServerSW,SpatialSoundServer); - - _THREAD_SAFE_CLASS_ - - enum { - MAX_CULL_ROOMS=128, - INTERNAL_BUFFER_SIZE=4096, - INTERNAL_BUFFER_MAX_CHANNELS=4, - VOICE_IS_STREAM=-1 - - }; - - - struct InternalAudioStream : public AudioServer::AudioStream { - - ::SpatialSoundServerSW *owner; - virtual int get_channel_count() const; - virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate - virtual bool mix(int32_t *p_buffer,int p_frames); - virtual void update(); - }; - - InternalAudioStream *internal_audio_stream; - RID internal_audio_stream_rid; - int32_t *internal_buffer; - int internal_buffer_channels; - - bool internal_buffer_mix(int32_t *p_buffer,int p_frames); - - struct Room; - - struct Space : public RID_Data { - - RID default_room; - Set<RID> rooms; - Set<RID> sources; - Set<RID> listeners; - - Octree<Room> octree; - }; - - mutable RID_Owner<Space> space_owner; - - struct Room : public RID_Data{ - RID space; - Transform transform; - Transform inverse_transform; - BSP_Tree bounds; - RoomReverb reverb; - float params[ROOM_PARAM_MAX]; - bool override_other_sources; - OctreeElementID octree_id; - int level; - - Room(); - }; - - mutable RID_Owner<Room> room_owner; - - - - struct Source : public RID_Data { - - struct Voice { - - RID voice_rid; - RID sample_rid; - bool active; - bool restart; - float pitch_scale; - float volume_scale; - int sample_mix_rate; - - - float last_volume; - float last_filter_gain; - float last_filter_cutoff; - Vector3 last_panning; - int last_mix_rate; - RoomReverb last_reverb_room; - float last_reverb_send; - - Voice(); - ~Voice(); - }; - - struct StreamData { - - - Vector3 panning; - RoomReverb reverb; - float reverb_send; - float volume; - float filter_gain; - float filter_cutoff; - - struct FilterState { - - float ha[2]; - float hb[2]; - } filter_state[4]; - - StreamData() { - - reverb_send=0; - reverb=ROOM_REVERB_HALL; - volume=1.0; - filter_gain=1; - filter_cutoff=5000; - - } - } stream_data; - - RID space; - Transform transform; - float params[SOURCE_PARAM_MAX]; - AudioServer::AudioStream *stream; - Vector<Voice> voices; - int last_voice; - - Source(); - }; - - mutable RID_Owner<Source> source_owner; - - struct Listener : public RID_Data { - - RID space; - Transform transform; - float params[LISTENER_PARAM_MAX]; - - Listener(); - }; - - mutable RID_Owner<Listener> listener_owner; - - struct ActiveVoice { - - Source *source; - int voice; - bool operator<(const ActiveVoice& p_voice) const { return (voice==p_voice.voice)?(source<p_voice.source):(voice<p_voice.voice); } - ActiveVoice(Source *p_source=NULL,int p_voice=0) { source=p_source; voice=p_voice; } - }; - - Room *cull_rooms[MAX_CULL_ROOMS]; - - Set<Source*> streaming_sources; - Set<ActiveVoice> active_voices; - - void _clean_up_owner(RID_OwnerBase *p_owner, const char *p_area); - void _update_sources(); - -public: - - /* SPACE */ - virtual RID space_create(); - - /* ROOM */ - - virtual RID room_create(); - virtual void room_set_space(RID p_room,RID p_space); - virtual RID room_get_space(RID p_room) const; - - virtual void room_set_bounds(RID p_room, const BSP_Tree& p_bounds); - virtual BSP_Tree room_get_bounds(RID p_room) const; - virtual void room_set_transform(RID p_room, const Transform& p_transform); - virtual Transform room_get_transform(RID p_room) const; - - - virtual void room_set_param(RID p_room, RoomParam p_param, float p_value); - virtual float room_get_param(RID p_room, RoomParam p_param) const; - - virtual void room_set_level(RID p_room, int p_level); - virtual int room_get_level(RID p_room) const; - - virtual void room_set_reverb(RID p_room, RoomReverb p_reverb); - virtual RoomReverb room_get_reverb(RID p_room) const; - - //useful for underwater or rooms with very strange conditions - virtual void room_set_force_params_to_all_sources(RID p_room, bool p_force); - virtual bool room_is_forcing_params_to_all_sources(RID p_room) const; - - /* SOURCE */ - - virtual RID source_create(RID p_space); - - virtual void source_set_polyphony(RID p_source,int p_voice_count); - virtual int source_get_polyphony(RID p_source) const; - - virtual void source_set_transform(RID p_source, const Transform& p_transform); - virtual Transform source_get_transform(RID p_source) const; - - virtual void source_set_param(RID p_source, SourceParam p_param, float p_value); - virtual float source_get_param(RID p_source, SourceParam p_param) const; - - virtual void source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream); //null to unset - virtual SourceVoiceID source_play_sample(RID p_source, RID p_sample, int p_mix_rate, int p_voice=SOURCE_NEXT_VOICE); - /* VOICES */ - virtual void source_voice_set_pitch_scale(RID p_source, SourceVoiceID p_voice, float p_pitch_scale); - virtual void source_voice_set_volume_scale_db(RID p_source, SourceVoiceID p_voice, float p_volume); - - virtual bool source_is_voice_active(RID p_source, SourceVoiceID p_voice) const; - virtual void source_stop_voice(RID p_source, SourceVoiceID p_voice); - - /* LISTENER */ - - virtual RID listener_create(); - virtual void listener_set_space(RID p_listener, RID p_space); - - virtual void listener_set_transform(RID p_listener, const Transform& p_transform); - virtual Transform listener_get_transform(RID p_listener) const; - - virtual void listener_set_param(RID p_listener, ListenerParam p_param, float p_value); - virtual float listener_get_param(RID p_listener, ListenerParam p_param) const; - - - /* MISC */ - - virtual void free(RID p_id); - - virtual void init(); - virtual void update(float p_delta); - virtual void finish(); - - SpatialSoundServerSW(); -}; - -#endif // SPATIAL_SOUND_SERVER_SW_H diff --git a/servers/spatial_sound_2d/SCsub b/servers/spatial_sound_2d/SCsub deleted file mode 100644 index ccc76e823f..0000000000 --- a/servers/spatial_sound_2d/SCsub +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python - -Import('env') - -env.add_source_files(env.servers_sources, "*.cpp") - -Export('env') diff --git a/servers/spatial_sound_2d/spatial_sound_2d_server_sw.cpp b/servers/spatial_sound_2d/spatial_sound_2d_server_sw.cpp deleted file mode 100644 index 2bcc9644f1..0000000000 --- a/servers/spatial_sound_2d/spatial_sound_2d_server_sw.cpp +++ /dev/null @@ -1,1042 +0,0 @@ -/*************************************************************************/ -/* spatial_sound_2d_server_sw.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "spatial_sound_2d_server_sw.h" - -#include "os/os.h" -#include "servers/audio/audio_filter_sw.h" - - - -int SpatialSound2DServerSW::InternalAudioStream::get_channel_count() const { - - return AudioServer::get_singleton()->get_default_channel_count(); -} - -void SpatialSound2DServerSW::InternalAudioStream::set_mix_rate(int p_rate) { - - -} - -void SpatialSound2DServerSW::InternalAudioStream::update() { - - owner->_update_sources(); -} - -bool SpatialSound2DServerSW::InternalAudioStream::mix(int32_t *p_buffer,int p_frames) { - - return owner->internal_buffer_mix(p_buffer,p_frames); -} - -void SpatialSound2DServerSW::_update_sources() { - - _THREAD_SAFE_METHOD_ - for (Set<Source*>::Element *E=streaming_sources.front();E;E=E->next()) { - - Source *s=E->get(); - ERR_CONTINUE(!s->stream); - s->stream->update(); - } -} - - -SpatialSound2DServerSW::Room::Room() { - - //params[ROOM_PARAM_SPEED_OF_SOUND]=343.0; - params[ROOM_PARAM_PITCH_SCALE]=1.0; - params[ROOM_PARAM_VOLUME_SCALE_DB]=0; - params[ROOM_PARAM_REVERB_SEND]=0; - params[ROOM_PARAM_CHORUS_SEND]=0; - params[ROOM_PARAM_ATTENUATION_SCALE]=1.0; - params[ROOM_PARAM_ATTENUATION_HF_CUTOFF]=5000; - params[ROOM_PARAM_ATTENUATION_HF_FLOOR_DB]=-24.0; - params[ROOM_PARAM_ATTENUATION_HF_RATIO_EXP]=1.0; - params[ROOM_PARAM_ATTENUATION_REVERB_SCALE]=0.0; - override_other_sources=false; - reverb=ROOM_REVERB_HALL; - //octree_id=0; - level=-1; - - -} - - -SpatialSound2DServerSW::Source::Source() { - - params[SOURCE_PARAM_VOLUME_DB]=0.0; - params[SOURCE_PARAM_PITCH_SCALE]=1.0; - params[SOURCE_PARAM_ATTENUATION_MIN_DISTANCE]=1; - params[SOURCE_PARAM_ATTENUATION_MAX_DISTANCE]=100; - params[SOURCE_PARAM_ATTENUATION_DISTANCE_EXP]=1.0; //linear (and not really good) - stream=NULL; - voices.resize(1); - last_voice=0; -} - -SpatialSound2DServerSW::Source::Voice::Voice() { - - active=false; - restart=false; - pitch_scale=1.0; - volume_scale=0.0; - voice_rid=AudioServer::get_singleton()->voice_create(); - -} -SpatialSound2DServerSW::Source::Voice::~Voice() { - - AudioServer::get_singleton()->free(voice_rid); -} - - -SpatialSound2DServerSW::Listener::Listener() { - - params[LISTENER_PARAM_VOLUME_SCALE_DB]=0.0; - params[LISTENER_PARAM_PITCH_SCALE]=1.0; - params[LISTENER_PARAM_ATTENUATION_SCALE]=1.0; - params[LISTENER_PARAM_PAN_RANGE]=128; - -} - -/* SPACE */ -RID SpatialSound2DServerSW::space_create() { - - Space* space = memnew( Space ); - RID space_rid = space_owner.make_rid(space); - space->default_room=room_create(); - room_set_space(space->default_room,space_rid); - return space_rid; -} - -/* ROOM */ - -RID SpatialSound2DServerSW::room_create() { - - Room *room = memnew( Room ); - return room_owner.make_rid(room); -} - -void SpatialSound2DServerSW::room_set_space(RID p_room,RID p_space) { - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - - if (room->space.is_valid()) { - - Space *space = space_owner.get(room->space); - space->rooms.erase(p_room); - //space->octree.erase(room->octree_id); - //room->octree_id=0; - } - - room->space=RID(); - - if (p_space.is_valid()) { - - Space *space = space_owner.get(p_space); - ERR_FAIL_COND(!space); - space->rooms.insert(p_room); - //room->octree_id=space->octree.create(room,AABB()); - //set bounds - //AABB aabb = room->bounds.is_empty()?AABB():room->bounds.get_aabb(); - //space->octree.move(room->octree_id,room->transform.xform(aabb)); - room->space=p_space; - } - - -} - -RID SpatialSound2DServerSW::room_get_space(RID p_room) const { - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,RID()); - - - return room->space; -} - - - -void SpatialSound2DServerSW::room_set_bounds(RID p_room, const PoolVector<Point2>& p_bounds) { - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - - room->bounds=p_bounds; - - if (!room->space.is_valid()) - return; - - //AABB aabb = room->bounds.is_empty()?AABB():room->bounds.get_aabb(); - //Space* space = space_owner.get(room->space); - //ERR_FAIL_COND(!space); - - //space->octree.move(room->octree_id,room->transform.xform(aabb)); - -} -PoolVector<Point2> SpatialSound2DServerSW::room_get_bounds(RID p_room) const { - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,PoolVector<Point2>()); - - return room->bounds; -} - -void SpatialSound2DServerSW::room_set_transform(RID p_room, const Transform2D& p_transform) { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - room->transform=p_transform; - room->inverse_transform=p_transform.affine_inverse(); // needs to be done to unscale BSP properly - - if (!room->space.is_valid()) - return; - - /* - if (!room->bounds.is_empty()) { - - Space* space = space_owner.get(room->space); - ERR_FAIL_COND(!space); - - //space->octree.move(room->octree_id,room->transform.xform(room->bounds.get_aabb())); - }*/ -} - -Transform2D SpatialSound2DServerSW::room_get_transform(RID p_room) const { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,Transform2D()); - return room->transform; -} - - -void SpatialSound2DServerSW::room_set_param(RID p_room, RoomParam p_param, float p_value) { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - ERR_FAIL_INDEX(p_param,ROOM_PARAM_MAX); - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - room->params[p_param]=p_value; - -} -float SpatialSound2DServerSW::room_get_param(RID p_room, RoomParam p_param) const { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - ERR_FAIL_INDEX_V(p_param,ROOM_PARAM_MAX,0); - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,0); - return room->params[p_param]; -} - -void SpatialSound2DServerSW::room_set_level(RID p_room, int p_level) { - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - room->level =p_level; - -} - -int SpatialSound2DServerSW::room_get_level(RID p_room) const { - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,0); - return room->level; - -} - - -void SpatialSound2DServerSW::room_set_reverb(RID p_room, RoomReverb p_reverb) { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - room->reverb=p_reverb; - -} -SpatialSound2DServerSW::RoomReverb SpatialSound2DServerSW::room_get_reverb(RID p_room) const { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,ROOM_REVERB_SMALL); - return room->reverb; -} - -//useful for underwater or rooms with very strange conditions -void SpatialSound2DServerSW::room_set_force_params_to_all_sources(RID p_room, bool p_force) { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND(!room); - room->override_other_sources=p_force; - -} -bool SpatialSound2DServerSW::room_is_forcing_params_to_all_sources(RID p_room) const { - - if (space_owner.owns(p_room)) - p_room=space_owner.get(p_room)->default_room; - - Room *room = room_owner.get(p_room); - ERR_FAIL_COND_V(!room,false); - return room->override_other_sources; -} - -/* SOURCE */ - -RID SpatialSound2DServerSW::source_create(RID p_space) { - - Space *space = space_owner.get(p_space); - ERR_FAIL_COND_V(!space,RID()); - - Source *source = memnew( Source ); - source->space=p_space; - RID source_rid = source_owner.make_rid(source); - space->sources.insert(source_rid); - - return source_rid; -} - - -void SpatialSound2DServerSW::source_set_polyphony(RID p_source,int p_voice_count) { - - - ERR_FAIL_COND(p_voice_count<=0); // more than 32 is too much, change this if you really need more - if (p_voice_count>32) { - - ERR_PRINT("Voices will be clipped to 32"); - p_voice_count=32; - } - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - - if (p_voice_count<source->voices.size()) { - - for(int i=p_voice_count;i<source->voices.size();i++) { - active_voices.erase(ActiveVoice(source,i)); //erase from active voices - } - } - source->voices.resize(p_voice_count); - -} - -int SpatialSound2DServerSW::source_get_polyphony(RID p_source) const { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND_V(!source,-1); - return source->voices.size(); - -} - -void SpatialSound2DServerSW::source_set_transform(RID p_source, const Transform2D& p_transform) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - source->transform=p_transform; - source->transform.orthonormalize(); -} -Transform2D SpatialSound2DServerSW::source_get_transform(RID p_source) const { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND_V(!source,Transform2D()); - return source->transform; -} - -void SpatialSound2DServerSW::source_set_param(RID p_source, SourceParam p_param, float p_value) { - - ERR_FAIL_INDEX(p_param,SOURCE_PARAM_MAX); - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - source->params[p_param]=p_value; - -} -float SpatialSound2DServerSW::source_get_param(RID p_source, SourceParam p_param) const { - ERR_FAIL_INDEX_V(p_param,SOURCE_PARAM_MAX,0); - Source *source = source_owner.get(p_source); - ERR_FAIL_COND_V(!source,0); - return source->params[p_param]; - - -} - -void SpatialSound2DServerSW::source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - AudioServer::get_singleton()->lock(); - source->stream=p_stream; - _THREAD_SAFE_METHOD_ - - if (!p_stream) { - streaming_sources.erase(source); - active_voices.erase(ActiveVoice(source,VOICE_IS_STREAM)); - } else { - streaming_sources.insert(source); - active_voices.insert(ActiveVoice(source,VOICE_IS_STREAM)); - zeromem(source->stream_data.filter_state,sizeof(Source::StreamData::FilterState)*4); //reset filter for safetyness - p_stream->set_mix_rate(AudioServer::get_singleton()->get_default_mix_rate()); - } - - AudioServer::get_singleton()->unlock(); - -} //null to unset - -SpatialSound2DServer::SourceVoiceID SpatialSound2DServerSW::source_play_sample(RID p_source, RID p_sample, int p_mix_rate, int p_voice) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND_V(!source,SOURCE_INVALID_VOICE); - - int to_play=0; - - if (p_voice==SOURCE_NEXT_VOICE) { - to_play=source->last_voice+1; - if (to_play>=source->voices.size()) - to_play=0; - - } else - to_play=p_voice; - - ERR_FAIL_INDEX_V(to_play,source->voices.size(),SOURCE_INVALID_VOICE); - - source->voices[to_play].restart=true; - source->voices[to_play].sample_rid=p_sample; - source->voices[to_play].sample_mix_rate=p_mix_rate; - source->voices[to_play].pitch_scale=1; - source->voices[to_play].volume_scale=0; - source->last_voice=to_play; - active_voices.insert(ActiveVoice(source,to_play)); - return to_play; -} - -/* VOICES */ -void SpatialSound2DServerSW::source_voice_set_pitch_scale(RID p_source, SourceVoiceID p_voice, float p_pitch_scale) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - ERR_FAIL_INDEX(p_voice,source->voices.size()); - source->voices[p_voice].pitch_scale=p_pitch_scale; - -} -void SpatialSound2DServerSW::source_voice_set_volume_scale_db(RID p_source, SourceVoiceID p_voice, float p_db) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - ERR_FAIL_INDEX(p_voice,source->voices.size()); - source->voices[p_voice].volume_scale=p_db; - -} - -bool SpatialSound2DServerSW::source_is_voice_active(RID p_source, SourceVoiceID p_voice) const { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND_V(!source,false); - ERR_FAIL_INDEX_V(p_voice,source->voices.size(),false); - return source->voices[p_voice].active || source->voices[p_voice].restart; - -} -void SpatialSound2DServerSW::source_stop_voice(RID p_source, SourceVoiceID p_voice) { - - Source *source = source_owner.get(p_source); - ERR_FAIL_COND(!source); - ERR_FAIL_INDEX(p_voice,source->voices.size()); - if (source->voices[p_voice].active) { - AudioServer::get_singleton()->voice_stop(source->voices[p_voice].voice_rid); - } - source->voices[p_voice].active=false; - source->voices[p_voice].restart=false; - active_voices.erase(ActiveVoice(source,p_voice)); -} - -/* LISTENER */ - -RID SpatialSound2DServerSW::listener_create() { - - Listener *listener = memnew( Listener ); - RID listener_rid = listener_owner.make_rid(listener); - return listener_rid; - -} - -void SpatialSound2DServerSW::listener_set_space(RID p_listener,RID p_space) { - - Listener *listener = listener_owner.get(p_listener); - ERR_FAIL_COND(!listener); - - if (listener->space.is_valid()) { - - Space *lspace = space_owner.get(listener->space); - ERR_FAIL_COND(!lspace); - lspace->listeners.erase(p_listener); - } - - listener->space=RID(); - - if (p_space.is_valid()) { - Space *space = space_owner.get(p_space); - ERR_FAIL_COND(!space); - - listener->space=p_space; - space->listeners.insert(p_listener); - } - -} - -void SpatialSound2DServerSW::listener_set_transform(RID p_listener, const Transform2D& p_transform) { - - Listener *listener = listener_owner.get(p_listener); - ERR_FAIL_COND(!listener); - listener->transform=p_transform; - listener->transform.orthonormalize(); //must be done.. -} -Transform2D SpatialSound2DServerSW::listener_get_transform(RID p_listener) const { - - Listener *listener = listener_owner.get(p_listener); - ERR_FAIL_COND_V(!listener,Transform2D()); - return listener->transform; -} - -void SpatialSound2DServerSW::listener_set_param(RID p_listener, ListenerParam p_param, float p_value) { - - ERR_FAIL_INDEX(p_param,LISTENER_PARAM_MAX); - Listener *listener = listener_owner.get(p_listener); - ERR_FAIL_COND(!listener); - listener->params[p_param]=p_value; -} - -float SpatialSound2DServerSW::listener_get_param(RID p_listener, ListenerParam p_param) const { - - ERR_FAIL_INDEX_V(p_param,LISTENER_PARAM_MAX,0); - Listener *listener = listener_owner.get(p_listener); - ERR_FAIL_COND_V(!listener,0); - return listener->params[p_param]; -} - - -/* MISC */ - -void SpatialSound2DServerSW::free(RID p_id) { - - - if (space_owner.owns(p_id)) { - - Space *space = space_owner.get(p_id); - free(space->default_room); - - while(space->listeners.size()) { - listener_set_space(space->listeners.front()->get(),RID()); - } - while(space->sources.size()) { - free(space->sources.front()->get()); - } - while(space->rooms.size()) { - room_set_space(space->rooms.front()->get(),RID()); - } - space_owner.free(p_id); - memdelete(space); - - } else if (source_owner.owns(p_id)) { - - Source *source = source_owner.get(p_id); - if (source->stream) - source_set_audio_stream(p_id,NULL); - - Space *space = space_owner.get(source->space); - ERR_FAIL_COND(!space); - space->sources.erase(p_id); - for(int i=0;i<source->voices.size();i++) { - active_voices.erase(ActiveVoice(source,i)); - } - source_owner.free(p_id); - memdelete(source); - } else if (listener_owner.owns(p_id)) { - - Listener *listener = listener_owner.get(p_id); - if (listener->space.is_valid()) { - Space *space = space_owner.get(listener->space); - ERR_FAIL_COND(!space); - space->listeners.erase(p_id); - } - listener_owner.free(p_id); - memdelete(listener); - - } else if (room_owner.owns(p_id)) { - - Room *room = room_owner.get(p_id); - - if (room->space.is_valid()) { - Space *space = space_owner.get(room->space); - ERR_FAIL_COND(!space); - //space->octree.erase(room->octree_id); - space->rooms.erase(p_id); - } - room_owner.free(p_id); - memdelete(room); - } else { - ERR_PRINT("Attempt to free invalid ID") ; - } - -} - -void SpatialSound2DServerSW::_clean_up_owner(RID_OwnerBase *p_owner, const char *p_area) { - - List<RID> rids; - p_owner->get_owned_list(&rids); - - for(List<RID>::Element *I=rids.front();I;I=I->next()) { - if (OS::get_singleton()->is_stdout_verbose()) { - - print_line("Leaked RID ("+itos(I->get().get_id())+") of type "+String(p_area)); - } - free(I->get()); - } -} - -void SpatialSound2DServerSW::init() { - - internal_buffer = memnew_arr(int32_t, INTERNAL_BUFFER_SIZE*INTERNAL_BUFFER_MAX_CHANNELS); - internal_buffer_channels=AudioServer::get_singleton()->get_default_channel_count(); - - internal_audio_stream = memnew( InternalAudioStream ); - internal_audio_stream->owner=this; - internal_audio_stream_rid = AudioServer::get_singleton()->audio_stream_create(internal_audio_stream); - - AudioServer::get_singleton()->stream_set_active(internal_audio_stream_rid,true); - -} - - - -bool SpatialSound2DServerSW::internal_buffer_mix(int32_t *p_buffer,int p_frames) { - - if (streaming_sources.size()==0) - return false; //nothing to mix - - - for (Set<Source*>::Element *E=streaming_sources.front();E;E=E->next()) { - - Source *s=E->get(); - ERR_CONTINUE(!s->stream); - - int channels = s->stream->get_channel_count(); - Source::StreamData &sd=s->stream_data; - - int todo=p_frames; - - AudioFilterSW filter; - filter.set_sampling_rate(AudioServer::get_singleton()->get_default_mix_rate()); - filter.set_cutoff(sd.filter_cutoff); - filter.set_gain(sd.filter_gain); - filter.set_resonance(1); - filter.set_mode(AudioFilterSW::HIGHSHELF); - filter.set_stages(1); - AudioFilterSW::Coeffs coefs; - filter.prepare_coefficients(&coefs); - - int32_t in[4]; -#ifndef SPATIAL_SOUND_SERVER_NO_FILTER -#define DO_FILTER(m_c)\ - {\ - float val = in[m_c];\ - float pre=val;\ - val = val*coefs.b0 + sd.filter_state[m_c].hb[0]*coefs.b1 + sd.filter_state[m_c].hb[1]*coefs.b2 + sd.filter_state[m_c].ha[0]*coefs.a1 + sd.filter_state[m_c].ha[1]*coefs.a2;\ - sd.filter_state[m_c].ha[1]=sd.filter_state[m_c].ha[0];\ - sd.filter_state[m_c].hb[1]=sd.filter_state[m_c].hb[0]; \ - sd.filter_state[m_c].hb[0]=pre;\ - sd.filter_state[m_c].ha[0]=val;\ - in[m_c]=Math::fast_ftoi(val);\ - } -#else -#define DO_FILTER(m_c) -#endif - - while(todo) { - - int to_mix=MIN(todo,INTERNAL_BUFFER_SIZE); - - s->stream->mix(internal_buffer,to_mix); - - switch(internal_buffer_channels) { - - case 2: { - - float p = sd.panning.x*0.5+0.5; - float panf[2]={ (1.0-p),p }; - panf[0]*=sd.volume; - panf[1]*=sd.volume; - - int32_t pan[2]={Math::fast_ftoi(panf[0]*(1<<16)),Math::fast_ftoi(panf[1]*(1<<16))}; - - switch(channels) { - case 1: { - - for(int i=0;i<to_mix;i++) { - - in[0]=internal_buffer[i]; - in[1]=internal_buffer[i]; - DO_FILTER(0); - DO_FILTER(1); - p_buffer[(i<<1)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<1)+1]=((in[1]>>16)*pan[1]); - } - } break; - case 2: { - - for(int i=0;i<to_mix;i++) { - - in[0]=internal_buffer[(i<<1)+0]; - in[1]=internal_buffer[(i<<1)+1]; - DO_FILTER(0); - DO_FILTER(1); - p_buffer[(i<<1)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<1)+1]=((in[1]>>16)*pan[1]); - } - } break; - case 4: { - - for(int i=0;i<to_mix;i++) { - - in[0]=(internal_buffer[(i<<2)+0]+internal_buffer[(i<<2)+2])>>1; - in[1]=(internal_buffer[(i<<2)+1]+internal_buffer[(i<<2)+3])>>1; - DO_FILTER(0); - DO_FILTER(1); - p_buffer[(i<<1)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<1)+1]=((in[1]>>16)*pan[1]); - } - } break; - - } break; - - } break; - case 4: { - - float xp = sd.panning.x*0.5+0.5; - float yp = sd.panning.y*0.5+0.5; - float panf[4]={ (1.0-xp)*(1.0-yp),(xp)*(1.0-yp),(1.0-xp)*(yp),(xp)*(yp) }; - panf[0]*=sd.volume; - panf[1]*=sd.volume; - panf[2]*=sd.volume; - panf[3]*=sd.volume; - - int32_t pan[4]={ - Math::fast_ftoi(panf[0]*(1<<16)), - Math::fast_ftoi(panf[1]*(1<<16)), - Math::fast_ftoi(panf[2]*(1<<16)), - Math::fast_ftoi(panf[3]*(1<<16))}; - - switch(channels) { - case 1: { - - for(int i=0;i<to_mix;i++) { - - in[0]=internal_buffer[i]; - in[1]=internal_buffer[i]; - in[2]=internal_buffer[i]; - in[3]=internal_buffer[i]; - DO_FILTER(0); - DO_FILTER(1); - DO_FILTER(2); - DO_FILTER(3); - p_buffer[(i<<2)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<2)+1]=((in[1]>>16)*pan[1]); - p_buffer[(i<<2)+2]=((in[2]>>16)*pan[2]); - p_buffer[(i<<2)+3]=((in[3]>>16)*pan[3]); - } - } break; - case 2: { - - for(int i=0;i<to_mix;i++) { - - in[0]=internal_buffer[(i<<1)+0]; - in[1]=internal_buffer[(i<<1)+1]; - in[2]=internal_buffer[(i<<1)+0]; - in[3]=internal_buffer[(i<<1)+1]; - DO_FILTER(0); - DO_FILTER(1); - DO_FILTER(2); - DO_FILTER(3); - p_buffer[(i<<2)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<2)+1]=((in[1]>>16)*pan[1]); - p_buffer[(i<<2)+2]=((in[2]>>16)*pan[2]); - p_buffer[(i<<2)+3]=((in[3]>>16)*pan[3]); - } - } break; - case 4: { - - for(int i=0;i<to_mix;i++) { - - in[0]=internal_buffer[(i<<2)+0]; - in[1]=internal_buffer[(i<<2)+1]; - in[2]=internal_buffer[(i<<2)+2]; - in[3]=internal_buffer[(i<<2)+3]; - DO_FILTER(0); - DO_FILTER(1); - DO_FILTER(2); - DO_FILTER(3); - p_buffer[(i<<2)+0]=((in[0]>>16)*pan[0]); - p_buffer[(i<<2)+1]=((in[1]>>16)*pan[1]); - p_buffer[(i<<2)+2]=((in[2]>>16)*pan[2]); - p_buffer[(i<<2)+3]=((in[3]>>16)*pan[3]); - } - } break; - - } break; - - } break; - case 6: { - - - } break; - } - p_buffer+=to_mix*internal_buffer_channels; - todo-=to_mix; - - } - - } - - return true; -} - -void SpatialSound2DServerSW::update(float p_delta) { - - List<ActiveVoice> to_disable; - - for(Set<ActiveVoice>::Element *E=active_voices.front();E;E=E->next()) { - - Source *source = E->get().source; - int voice = E->get().voice; - - if (voice!=VOICE_IS_STREAM) { - Source::Voice &v=source->voices[voice]; - ERR_CONTINUE(!v.active && !v.restart); // likely a bug... - } - - //this could be optimized at some point... am not sure - Space *space=space_owner.get(source->space); - Room *room=room_owner.get(space->default_room); - - //compute mixing weights (support for multiple listeners in the same output) - float total_distance=0; - for(Set<RID>::Element *L=space->listeners.front();L;L=L->next()) { - Listener *listener=listener_owner.get(L->get()); - float d = listener->transform.get_origin().distance_to(source->transform.get_origin()); - if (d==0) - d=0.1; - total_distance+=d; - } - - //compute spatialization variables, weighted according to distance - float volume_attenuation = 0.0; - float air_absorption_hf_cutoff = 0.0; - float air_absorption = 0.0; - float pitch_scale=0.0; - Vector2 panning; - - for(Set<RID>::Element *L=space->listeners.front();L;L=L->next()) { - - Listener *listener=listener_owner.get(L->get()); - - Vector2 rel_vector = -listener->transform.xform_inv(source->transform.get_origin()); - //Vector2 source_rel_vector = source->transform.xform_inv(listener->transform.get_origin()).normalized(); - float distance=rel_vector.length(); - float weight = distance/total_distance; - float pscale=1.0; - - float distance_scale=listener->params[LISTENER_PARAM_ATTENUATION_SCALE]*room->params[ROOM_PARAM_ATTENUATION_SCALE]; - float distance_min=source->params[SOURCE_PARAM_ATTENUATION_MIN_DISTANCE]*distance_scale; - float distance_max=source->params[SOURCE_PARAM_ATTENUATION_MAX_DISTANCE]*distance_scale; - float attenuation_exp=source->params[SOURCE_PARAM_ATTENUATION_DISTANCE_EXP]; - float attenuation=1; - - if (distance_max>0) { - distance = CLAMP(distance,distance_min,distance_max); - attenuation = Math::pow(1.0 - ((distance - distance_min)/(distance_max-distance_min)),CLAMP(attenuation_exp,0.001,16)); - } - - float hf_attenuation_cutoff = room->params[ROOM_PARAM_ATTENUATION_HF_CUTOFF]; - float hf_attenuation_exp = room->params[ROOM_PARAM_ATTENUATION_HF_RATIO_EXP]; - float hf_attenuation_floor = room->params[ROOM_PARAM_ATTENUATION_HF_FLOOR_DB]; - float absorption=Math::db2linear(Math::lerp(hf_attenuation_floor,0,Math::pow(attenuation,hf_attenuation_exp))); - - // source emission cone -/* only for 3D - float emission_deg=source->params[SOURCE_PARAM_EMISSION_CONE_DEGREES]; - float emission_attdb=source->params[SOURCE_PARAM_EMISSION_CONE_ATTENUATION_DB]; - absorption*=_get_attenuation(source_rel_vector.dot(Vector2(0,0,-1)),emission_deg,emission_attdb); -*/ - Vector2 vpanning=rel_vector.normalized(); - if (distance < listener->params[LISTENER_PARAM_PAN_RANGE]) - vpanning*=distance/listener->params[LISTENER_PARAM_PAN_RANGE]; - - //listener stuff - - { - - // head cone -/* only for 3D - float reception_deg=listener->params[LISTENER_PARAM_RECEPTION_CONE_DEGREES]; - float reception_attdb=listener->params[LISTENER_PARAM_RECEPTION_CONE_ATTENUATION_DB]; - - absorption*=_get_attenuation(vpanning.dot(Vector2(0,0,-1)),reception_deg,reception_attdb); -*/ - - // scale - - attenuation*=Math::db2linear(listener->params[LISTENER_PARAM_VOLUME_SCALE_DB]); - pscale*=Math::db2linear(listener->params[LISTENER_PARAM_PITCH_SCALE]); - - - } - - - - - //add values - - volume_attenuation+=weight*attenuation; // plus other stuff i guess - air_absorption+=weight*absorption; - air_absorption_hf_cutoff+=weight*hf_attenuation_cutoff; - panning+=vpanning*weight; - pitch_scale+=pscale*weight; - - } - - RoomReverb reverb_room=ROOM_REVERB_HALL; - float reverb_send=0; - - /* APPLY ROOM SETTINGS */ - - { - pitch_scale*=room->params[ROOM_PARAM_PITCH_SCALE]; - volume_attenuation*=Math::db2linear(room->params[ROOM_PARAM_VOLUME_SCALE_DB]); - reverb_room=room->reverb; - reverb_send=Math::lerp(1.0,volume_attenuation,room->params[ROOM_PARAM_ATTENUATION_REVERB_SCALE])*room->params[ROOM_PARAM_REVERB_SEND]; - - } - - /* UPDATE VOICE & STREAM */ - - - - if (voice==VOICE_IS_STREAM) { - - //update voice!! - source->stream_data.panning=panning; - source->stream_data.volume=volume_attenuation*Math::db2linear(source->params[SOURCE_PARAM_VOLUME_DB]); - source->stream_data.reverb=reverb_room; - source->stream_data.reverb_send=reverb_send; - source->stream_data.filter_gain=air_absorption; - source->stream_data.filter_cutoff=air_absorption_hf_cutoff; - - if (!source->stream) //stream is gone bye bye - to_disable.push_back(ActiveVoice(source,voice)); // oh well.. - - } else if (voice>=0) { - //update stream!! - Source::Voice &v=source->voices[voice]; - - if (v.restart) - AudioServer::get_singleton()->voice_play(v.voice_rid,v.sample_rid); - - float volume_scale = Math::db2linear(v.volume_scale)*Math::db2linear(source->params[SOURCE_PARAM_VOLUME_DB]); - float volume = volume_attenuation*volume_scale; - reverb_send*=volume_scale; - int mix_rate = v.sample_mix_rate*v.pitch_scale*pitch_scale*source->params[SOURCE_PARAM_PITCH_SCALE]; - - - if (mix_rate<=0) { - - ERR_PRINT("Invalid mix rate for voice (0) check for invalid pitch_scale param."); - to_disable.push_back(ActiveVoice(source,voice)); // oh well.. - continue; //invalid mix rate, disabling - } - if (v.restart || v.last_volume!=volume) - AudioServer::get_singleton()->voice_set_volume(v.voice_rid,volume); - if (v.restart || v.last_mix_rate!=mix_rate) - AudioServer::get_singleton()->voice_set_mix_rate(v.voice_rid,mix_rate); - if (v.restart || v.last_filter_gain!=air_absorption || v.last_filter_cutoff!=air_absorption_hf_cutoff) - AudioServer::get_singleton()->voice_set_filter(v.voice_rid,AudioServer::FILTER_HIGH_SHELF,air_absorption_hf_cutoff,1.0,air_absorption); - if (v.restart || v.last_panning!=panning) { - AudioServer::get_singleton()->voice_set_pan(v.voice_rid,-panning.x,panning.y,0); - } - if (v.restart || v.last_reverb_room!=reverb_room || v.last_reverb_send!=reverb_send) - AudioServer::get_singleton()->voice_set_reverb(v.voice_rid,AudioServer::ReverbRoomType(reverb_room),reverb_send); - - v.last_volume=volume; - v.last_mix_rate=mix_rate; - v.last_filter_gain=air_absorption; - v.last_filter_cutoff=air_absorption_hf_cutoff; - v.last_panning=panning; - v.last_reverb_room=reverb_room; - v.last_reverb_send=reverb_send; - v.restart=false; - v.active=true; - - if (!AudioServer::get_singleton()->voice_is_active(v.voice_rid)) - to_disable.push_back(ActiveVoice(source,voice)); // oh well.. - } - } - - while(to_disable.size()) { - - ActiveVoice av = to_disable.front()->get(); - av.source->voices[av.voice].active=false; - av.source->voices[av.voice].restart=false; - active_voices.erase(av); - to_disable.pop_front(); - } - -} -void SpatialSound2DServerSW::finish() { - - AudioServer::get_singleton()->free(internal_audio_stream_rid); - memdelete(internal_audio_stream); - - _clean_up_owner(&source_owner,"Source"); - _clean_up_owner(&listener_owner,"Listener"); - _clean_up_owner(&room_owner,"Room"); - _clean_up_owner(&space_owner,"Space"); - - memdelete_arr(internal_buffer); -} - -SpatialSound2DServerSW::SpatialSound2DServerSW() { - -} diff --git a/servers/spatial_sound_2d/spatial_sound_2d_server_sw.h b/servers/spatial_sound_2d/spatial_sound_2d_server_sw.h deleted file mode 100644 index 7999a8c22b..0000000000 --- a/servers/spatial_sound_2d/spatial_sound_2d_server_sw.h +++ /dev/null @@ -1,265 +0,0 @@ -/*************************************************************************/ -/* spatial_sound_2d_server_sw.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SPATIAL_SOUND_2D_SERVER_SW_H -#define SPATIAL_SOUND_2D_SERVER_SW_H - -#include "servers/spatial_sound_2d_server.h" - -#include "os/thread_safe.h" - - -class SpatialSound2DServerSW : public SpatialSound2DServer { - - GDCLASS(SpatialSound2DServerSW,SpatialSound2DServer); - - _THREAD_SAFE_CLASS_ - - enum { - INTERNAL_BUFFER_SIZE=4096, - INTERNAL_BUFFER_MAX_CHANNELS=4, - VOICE_IS_STREAM=-1 - - }; - - - struct InternalAudioStream : public AudioServer::AudioStream { - - ::SpatialSound2DServerSW *owner; - virtual int get_channel_count() const; - virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate - virtual bool mix(int32_t *p_buffer,int p_frames); - virtual void update(); - }; - - InternalAudioStream *internal_audio_stream; - RID internal_audio_stream_rid; - int32_t *internal_buffer; - int internal_buffer_channels; - - bool internal_buffer_mix(int32_t *p_buffer,int p_frames); - - struct Room; - - struct Space : public RID_Data { - - RID default_room; - Set<RID> rooms; - Set<RID> sources; - Set<RID> listeners; - - //Octree<Room> octree; - }; - - mutable RID_Owner<Space> space_owner; - - struct Room : public RID_Data { - RID space; - Transform2D transform; - Transform2D inverse_transform; - PoolVector<Point2> bounds; - RoomReverb reverb; - float params[ROOM_PARAM_MAX]; - bool override_other_sources; - //OctreeElementID octree_id; - int level; - - Room(); - }; - - mutable RID_Owner<Room> room_owner; - - - - struct Source : public RID_Data { - - struct Voice { - - RID voice_rid; - RID sample_rid; - bool active; - bool restart; - float pitch_scale; - float volume_scale; - int sample_mix_rate; - - - float last_volume; - float last_filter_gain; - float last_filter_cutoff; - Vector2 last_panning; - int last_mix_rate; - RoomReverb last_reverb_room; - float last_reverb_send; - - Voice(); - ~Voice(); - }; - - struct StreamData { - - - Vector2 panning; - RoomReverb reverb; - float reverb_send; - float volume; - float filter_gain; - float filter_cutoff; - - struct FilterState { - - float ha[2]; - float hb[2]; - } filter_state[4]; - - StreamData() { - - reverb_send=0; - reverb=ROOM_REVERB_HALL; - volume=1.0; - filter_gain=1; - filter_cutoff=5000; - - } - } stream_data; - - RID space; - Transform2D transform; - float params[SOURCE_PARAM_MAX]; - AudioServer::AudioStream *stream; - Vector<Voice> voices; - int last_voice; - - Source(); - }; - - mutable RID_Owner<Source> source_owner; - - struct Listener : public RID_Data { - - RID space; - Transform2D transform; - float params[LISTENER_PARAM_MAX]; - - Listener(); - }; - - mutable RID_Owner<Listener> listener_owner; - - struct ActiveVoice { - - Source *source; - int voice; - bool operator<(const ActiveVoice& p_voice) const { return (voice==p_voice.voice)?(source<p_voice.source):(voice<p_voice.voice); } - ActiveVoice(Source *p_source=NULL,int p_voice=0) { source=p_source; voice=p_voice; } - }; - - //Room *cull_rooms[MAX_CULL_ROOMS]; - - Set<Source*> streaming_sources; - Set<ActiveVoice> active_voices; - - void _clean_up_owner(RID_OwnerBase *p_owner, const char *p_area); - void _update_sources(); - -public: - - /* SPACE */ - virtual RID space_create(); - - /* ROOM */ - - virtual RID room_create(); - virtual void room_set_space(RID p_room,RID p_space); - virtual RID room_get_space(RID p_room) const; - - virtual void room_set_bounds(RID p_room, const PoolVector<Point2>& p_bounds); - virtual PoolVector<Point2> room_get_bounds(RID p_room) const; - virtual void room_set_transform(RID p_room, const Transform2D& p_transform); - virtual Transform2D room_get_transform(RID p_room) const; - - - virtual void room_set_param(RID p_room, RoomParam p_param, float p_value); - virtual float room_get_param(RID p_room, RoomParam p_param) const; - - virtual void room_set_level(RID p_room, int p_level); - virtual int room_get_level(RID p_room) const; - - virtual void room_set_reverb(RID p_room, RoomReverb p_reverb); - virtual RoomReverb room_get_reverb(RID p_room) const; - - //useful for underwater or rooms with very strange conditions - virtual void room_set_force_params_to_all_sources(RID p_room, bool p_force); - virtual bool room_is_forcing_params_to_all_sources(RID p_room) const; - - /* SOURCE */ - - virtual RID source_create(RID p_space); - - virtual void source_set_polyphony(RID p_source,int p_voice_count); - virtual int source_get_polyphony(RID p_source) const; - - virtual void source_set_transform(RID p_source, const Transform2D& p_transform); - virtual Transform2D source_get_transform(RID p_source) const; - - virtual void source_set_param(RID p_source, SourceParam p_param, float p_value); - virtual float source_get_param(RID p_source, SourceParam p_param) const; - - virtual void source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream); //null to unset - virtual SourceVoiceID source_play_sample(RID p_source, RID p_sample, int p_mix_rate, int p_voice=SOURCE_NEXT_VOICE); - /* VOICES */ - virtual void source_voice_set_pitch_scale(RID p_source, SourceVoiceID p_voice, float p_pitch_scale); - virtual void source_voice_set_volume_scale_db(RID p_source, SourceVoiceID p_voice, float p_volume); - - virtual bool source_is_voice_active(RID p_source, SourceVoiceID p_voice) const; - virtual void source_stop_voice(RID p_source, SourceVoiceID p_voice); - - /* LISTENER */ - - virtual RID listener_create(); - virtual void listener_set_space(RID p_listener, RID p_space); - - virtual void listener_set_transform(RID p_listener, const Transform2D& p_transform); - virtual Transform2D listener_get_transform(RID p_listener) const; - - virtual void listener_set_param(RID p_listener, ListenerParam p_param, float p_value); - virtual float listener_get_param(RID p_listener, ListenerParam p_param) const; - - - /* MISC */ - - virtual void free(RID p_id); - - virtual void init(); - virtual void update(float p_delta); - virtual void finish(); - - SpatialSound2DServerSW(); -}; - -#endif // SPATIAL_SOUND_2D_SERVER_SW_H diff --git a/servers/spatial_sound_2d_server.cpp b/servers/spatial_sound_2d_server.cpp deleted file mode 100644 index 90f384ea2e..0000000000 --- a/servers/spatial_sound_2d_server.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*************************************************************************/ -/* spatial_sound_2d_server.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "spatial_sound_2d_server.h" - -SpatialSound2DServer *SpatialSound2DServer::singleton=NULL; - - -SpatialSound2DServer *SpatialSound2DServer::get_singleton() { - - return singleton; -} - - -SpatialSound2DServer::SpatialSound2DServer() { - - ERR_FAIL_COND(singleton!=NULL); - singleton=this; -} diff --git a/servers/spatial_sound_2d_server.h b/servers/spatial_sound_2d_server.h deleted file mode 100644 index 331caf8198..0000000000 --- a/servers/spatial_sound_2d_server.h +++ /dev/null @@ -1,164 +0,0 @@ -/*************************************************************************/ -/* spatial_sound_2d_server.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SPATIAL_SOUND_2D_SERVER_H -#define SPATIAL_SOUND_2D_SERVER_H - -#include "object.h" -#include "bsp_tree.h" -#include "servers/audio_server.h" - -class SpatialSound2DServer : public Object { - - GDCLASS(SpatialSound2DServer,Object); - static SpatialSound2DServer *singleton; -public: - - - enum { - SOURCE_INVALID_VOICE=-1, - SOURCE_NEXT_VOICE=-2, - }; - - typedef int SourceVoiceID; - - /* SPACE */ - virtual RID space_create()=0; - - /* ROOM */ - - virtual RID room_create()=0; - virtual void room_set_space(RID p_room,RID p_space)=0; - virtual RID room_get_space(RID p_room) const=0; - - - virtual void room_set_bounds(RID p_room, const PoolVector<Point2>& p_bounds)=0; - virtual PoolVector<Point2> room_get_bounds(RID p_room) const=0; - virtual void room_set_transform(RID p_room, const Transform2D& p_transform)=0; - virtual Transform2D room_get_transform(RID p_room) const=0; - - enum RoomParam { - ROOM_PARAM_PITCH_SCALE, - ROOM_PARAM_VOLUME_SCALE_DB, - ROOM_PARAM_REVERB_SEND, - ROOM_PARAM_CHORUS_SEND, - ROOM_PARAM_ATTENUATION_SCALE, - ROOM_PARAM_ATTENUATION_HF_CUTOFF, - ROOM_PARAM_ATTENUATION_HF_FLOOR_DB, - ROOM_PARAM_ATTENUATION_HF_RATIO_EXP, - ROOM_PARAM_ATTENUATION_REVERB_SCALE, - ROOM_PARAM_MAX - }; - - virtual void room_set_param(RID p_room, RoomParam p_param, float p_value)=0; - virtual float room_get_param(RID p_room, RoomParam p_param) const=0; - - enum RoomReverb { - ROOM_REVERB_SMALL, - ROOM_REVERB_MEDIUM, - ROOM_REVERB_LARGE, - ROOM_REVERB_HALL - }; - - virtual void room_set_reverb(RID p_room, RoomReverb p_reverb)=0; - virtual RoomReverb room_get_reverb(RID p_room) const=0; - - virtual void room_set_level(RID p_room, int p_level)=0; - virtual int room_get_level(RID p_room) const=0; - - //useful for underwater or rooms with very strange conditions - virtual void room_set_force_params_to_all_sources(RID p_room, bool p_force)=0; - virtual bool room_is_forcing_params_to_all_sources(RID p_room) const=0; - - /* SOURCE */ - - virtual RID source_create(RID p_space)=0; - - virtual void source_set_transform(RID p_source, const Transform2D& p_transform)=0; - virtual Transform2D source_get_transform(RID p_source) const=0; - - virtual void source_set_polyphony(RID p_source,int p_voice_count)=0; - virtual int source_get_polyphony(RID p_source) const=0; - - enum SourceParam { - - SOURCE_PARAM_VOLUME_DB, - SOURCE_PARAM_PITCH_SCALE, - SOURCE_PARAM_ATTENUATION_MIN_DISTANCE, - SOURCE_PARAM_ATTENUATION_MAX_DISTANCE, - SOURCE_PARAM_ATTENUATION_DISTANCE_EXP, - SOURCE_PARAM_MAX - }; - - virtual void source_set_param(RID p_source, SourceParam p_param, float p_value)=0; - virtual float source_get_param(RID p_source, SourceParam p_param) const=0; - - virtual void source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream)=0; //null to unset - virtual SourceVoiceID source_play_sample(RID p_source, RID p_sample, int p_mix_rate, int p_voice=SOURCE_NEXT_VOICE)=0; - //voices - virtual void source_voice_set_pitch_scale(RID p_source,SourceVoiceID p_voice, float p_pitch_scale)=0; - virtual void source_voice_set_volume_scale_db(RID p_source,SourceVoiceID p_voice, float p_volume_db)=0; - - virtual bool source_is_voice_active(RID p_source,SourceVoiceID p_voice) const=0; - virtual void source_stop_voice(RID p_source,SourceVoiceID p_voice)=0; - - /* LISTENER */ - - enum ListenerParam { - - LISTENER_PARAM_VOLUME_SCALE_DB, - LISTENER_PARAM_PITCH_SCALE, - LISTENER_PARAM_ATTENUATION_SCALE, - LISTENER_PARAM_PAN_RANGE, - LISTENER_PARAM_MAX - }; - - virtual RID listener_create()=0; - virtual void listener_set_space(RID p_listener, RID p_space)=0; - - virtual void listener_set_transform(RID p_listener, const Transform2D& p_transform)=0; - virtual Transform2D listener_get_transform(RID p_listener) const=0; - - virtual void listener_set_param(RID p_listener, ListenerParam p_param, float p_value)=0; - virtual float listener_get_param(RID p_listener, ListenerParam p_param) const=0; - - /* MISC */ - - virtual void free(RID p_id)=0; - - virtual void init()=0; - virtual void update(float p_delta)=0; - virtual void finish()=0; - - static SpatialSound2DServer *get_singleton(); - - SpatialSound2DServer(); - -}; - -#endif // SPATIAL_SOUND_2D_SERVER_H diff --git a/servers/spatial_sound_server.cpp b/servers/spatial_sound_server.cpp deleted file mode 100644 index f49367d4c0..0000000000 --- a/servers/spatial_sound_server.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*************************************************************************/ -/* spatial_sound_server.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "spatial_sound_server.h" - -SpatialSoundServer *SpatialSoundServer::singleton=NULL; - - -SpatialSoundServer *SpatialSoundServer::get_singleton() { - - return singleton; -} - - -SpatialSoundServer::SpatialSoundServer() { - - ERR_FAIL_COND(singleton!=NULL); - singleton=this; -} diff --git a/servers/spatial_sound_server.h b/servers/spatial_sound_server.h deleted file mode 100644 index 69ef71c84f..0000000000 --- a/servers/spatial_sound_server.h +++ /dev/null @@ -1,168 +0,0 @@ -/*************************************************************************/ -/* spatial_sound_server.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef SPATIAL_SOUND_SERVER_H -#define SPATIAL_SOUND_SERVER_H - -#include "object.h" -#include "bsp_tree.h" -#include "servers/audio_server.h" - -class SpatialSoundServer : public Object { - GDCLASS(SpatialSoundServer,Object); - - static SpatialSoundServer *singleton; -public: - - - enum { - SOURCE_INVALID_VOICE=-1, - SOURCE_NEXT_VOICE=-2, - }; - - typedef int SourceVoiceID; - - /* SPACE */ - virtual RID space_create()=0; - - /* ROOM */ - - virtual RID room_create()=0; - virtual void room_set_space(RID p_room,RID p_space)=0; - virtual RID room_get_space(RID p_room) const=0; - - - virtual void room_set_bounds(RID p_room, const BSP_Tree& p_bounds)=0; - virtual BSP_Tree room_get_bounds(RID p_room) const=0; - virtual void room_set_transform(RID p_room, const Transform& p_transform)=0; - virtual Transform room_get_transform(RID p_room) const=0; - - enum RoomParam { - ROOM_PARAM_SPEED_OF_SOUND_SCALE, - ROOM_PARAM_DOPPLER_FACTOR, - ROOM_PARAM_PITCH_SCALE, - ROOM_PARAM_VOLUME_SCALE_DB, - ROOM_PARAM_REVERB_SEND, - ROOM_PARAM_CHORUS_SEND, - ROOM_PARAM_ATTENUATION_SCALE, - ROOM_PARAM_ATTENUATION_HF_CUTOFF, - ROOM_PARAM_ATTENUATION_HF_FLOOR_DB, - ROOM_PARAM_ATTENUATION_HF_RATIO_EXP, - ROOM_PARAM_ATTENUATION_REVERB_SCALE, - ROOM_PARAM_MAX - }; - - virtual void room_set_param(RID p_room, RoomParam p_param, float p_value)=0; - virtual float room_get_param(RID p_room, RoomParam p_param) const=0; - - enum RoomReverb { - ROOM_REVERB_SMALL, - ROOM_REVERB_MEDIUM, - ROOM_REVERB_LARGE, - ROOM_REVERB_HALL - }; - - virtual void room_set_reverb(RID p_room, RoomReverb p_reverb)=0; - virtual RoomReverb room_get_reverb(RID p_room) const=0; - - virtual void room_set_level(RID p_room, int p_level)=0; - virtual int room_get_level(RID p_room) const=0; - - //useful for underwater or rooms with very strange conditions - virtual void room_set_force_params_to_all_sources(RID p_room, bool p_force)=0; - virtual bool room_is_forcing_params_to_all_sources(RID p_room) const=0; - - /* SOURCE */ - - virtual RID source_create(RID p_space)=0; - - virtual void source_set_transform(RID p_source, const Transform& p_transform)=0; - virtual Transform source_get_transform(RID p_source) const=0; - - virtual void source_set_polyphony(RID p_source,int p_voice_count)=0; - virtual int source_get_polyphony(RID p_source) const=0; - - enum SourceParam { - - SOURCE_PARAM_VOLUME_DB, - SOURCE_PARAM_PITCH_SCALE, - SOURCE_PARAM_ATTENUATION_MIN_DISTANCE, - SOURCE_PARAM_ATTENUATION_MAX_DISTANCE, - SOURCE_PARAM_ATTENUATION_DISTANCE_EXP, - SOURCE_PARAM_EMISSION_CONE_DEGREES, - SOURCE_PARAM_EMISSION_CONE_ATTENUATION_DB, - SOURCE_PARAM_MAX - }; - - virtual void source_set_param(RID p_source, SourceParam p_param, float p_value)=0; - virtual float source_get_param(RID p_source, SourceParam p_param) const=0; - - virtual void source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream)=0; //null to unset - virtual SourceVoiceID source_play_sample(RID p_source, RID p_sample, int p_mix_rate, int p_voice=SOURCE_NEXT_VOICE)=0; - //voices - virtual void source_voice_set_pitch_scale(RID p_source,SourceVoiceID p_voice, float p_pitch_scale)=0; - virtual void source_voice_set_volume_scale_db(RID p_source,SourceVoiceID p_voice, float p_volume_db)=0; - - virtual bool source_is_voice_active(RID p_source,SourceVoiceID p_voice) const=0; - virtual void source_stop_voice(RID p_source,SourceVoiceID p_voice)=0; - - /* LISTENER */ - - enum ListenerParam { - - LISTENER_PARAM_VOLUME_SCALE_DB, - LISTENER_PARAM_PITCH_SCALE, - LISTENER_PARAM_ATTENUATION_SCALE, - LISTENER_PARAM_RECEPTION_CONE_DEGREES, - LISTENER_PARAM_RECEPTION_CONE_ATTENUATION_DB, - LISTENER_PARAM_MAX - }; - - virtual RID listener_create()=0; - virtual void listener_set_space(RID p_listener, RID p_space)=0; - - virtual void listener_set_transform(RID p_listener, const Transform& p_transform)=0; - virtual Transform listener_get_transform(RID p_listener) const=0; - - virtual void listener_set_param(RID p_listener, ListenerParam p_param, float p_value)=0; - virtual float listener_get_param(RID p_listener, ListenerParam p_param) const=0; - - /* MISC */ - - virtual void free(RID p_id)=0; - - virtual void init()=0; - virtual void update(float p_delta)=0; - virtual void finish()=0; - - static SpatialSoundServer *get_singleton(); - - SpatialSoundServer(); -}; - -#endif // SPATIAL_SOUND_SERVER_H diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 94a514e7c1..21f7f0769f 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -196,6 +196,8 @@ public: virtual RID texture_create_radiance_cubemap(RID p_source,int p_resolution=-1) const=0; + virtual void texture_set_detect_3d_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata)=0; + virtual void texture_set_detect_srgb_callback(RID p_texture,VisualServer::TextureDetectCallback p_callback,void* p_userdata)=0; virtual void textures_keep_original(bool p_enable)=0; @@ -430,6 +432,9 @@ public: virtual void gi_probe_set_energy(RID p_probe,float p_range)=0; virtual float gi_probe_get_energy(RID p_probe) const=0; + virtual void gi_probe_set_propagation(RID p_probe,float p_range)=0; + virtual float gi_probe_get_propagation(RID p_probe) const=0; + virtual void gi_probe_set_interior(RID p_probe,bool p_enable)=0; virtual bool gi_probe_is_interior(RID p_probe) const=0; @@ -512,6 +517,7 @@ public: virtual VS::InstanceType get_base_type(RID p_rid) const=0; virtual bool free(RID p_rid)=0; + virtual bool has_os_feature(const String& p_feature) const=0; static RasterizerStorage*base_signleton; RasterizerStorage(); @@ -1226,7 +1232,7 @@ public: virtual void multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color)=0; virtual RID multimesh_get_mesh(RID p_multimesh) const=0; - virtual AABB multimesh_get_aabb(RID p_multimesh) const=0;; + virtual AABB multimesh_get_aabb(RID p_multimesh) const=0; virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const=0; virtual Color multimesh_instance_get_color(RID p_multimesh,int p_index) const=0; diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 6a6f437816..7dfd9822f7 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -374,7 +374,7 @@ ShaderLanguage::Token ShaderLanguage::_get_token() { char_idx++; return _make_token(TK_OP_GREATER_EQUAL); } else if (GETCHAR(0)=='<') { - char_idx++;; + char_idx++; if (GETCHAR(0)=='=') { char_idx++; return _make_token(TK_OP_ASSIGN_SHIFT_RIGHT); @@ -1966,7 +1966,7 @@ bool ShaderLanguage::_parse_function_arguments(BlockNode* p_block,const Map<Stri return true; } - _set_tkpos(pos);; + _set_tkpos(pos); while(true) { @@ -2557,7 +2557,7 @@ ShaderLanguage::Node* ShaderLanguage::_parse_expression(BlockNode* p_block,const } else if (l==2) { member_type=DataType(dt-2); } else if (l==3) { - member_type=DataType(dt-1);; + member_type=DataType(dt-1); } else if (l==4) { member_type=dt; } else { diff --git a/servers/visual/visual_server_canvas.cpp b/servers/visual/visual_server_canvas.cpp index 2f7bcccf73..f4031b711d 100644 --- a/servers/visual/visual_server_canvas.cpp +++ b/servers/visual/visual_server_canvas.cpp @@ -934,7 +934,7 @@ void VisualServerCanvas::canvas_light_set_shadow_buffer_size(RID p_light, int p_ RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); ERR_FAIL_COND(!clight); - int new_size = nearest_power_of_2(p_size);; + int new_size = nearest_power_of_2(p_size); if (new_size==clight->shadow_buffer_size) return; diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index e3bc0fb6c6..8f87425212 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -123,6 +123,7 @@ void VisualServerRaster::finish(){ VSG::rasterizer->finalize(); } + /* STATUS INFORMATION */ @@ -156,6 +157,12 @@ RID VisualServerRaster::get_test_cube() { return test_cube; } + +bool VisualServerRaster::has_os_feature(const String& p_feature) const { + + return VSG::storage->has_os_feature(p_feature); +} + VisualServerRaster::VisualServerRaster() { VSG::canvas = memnew( VisualServerCanvas); diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 5c8105681a..ad0cb664c5 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -622,7 +622,8 @@ public: BIND3(texture_set_size_override,RID,int,int) BIND2RC(RID,texture_create_radiance_cubemap,RID,int) - + BIND3(texture_set_detect_3d_callback,RID,TextureDetectCallback,void*) + BIND3(texture_set_detect_srgb_callback,RID,TextureDetectCallback,void*) BIND2(texture_set_path,RID,const String&) BIND1RC(String,texture_get_path,RID) @@ -824,6 +825,9 @@ public: BIND2(gi_probe_set_energy,RID,float) BIND1RC(float,gi_probe_get_energy,RID) + BIND2(gi_probe_set_propagation,RID,float) + BIND1RC(float,gi_probe_get_propagation,RID) + BIND2(gi_probe_set_interior,RID,bool) BIND1RC(bool,gi_probe_is_interior,RID) @@ -1135,6 +1139,8 @@ public: virtual bool has_feature(Features p_feature) const; + virtual bool has_os_feature(const String& p_feature) const; + VisualServerRaster(); ~VisualServerRaster(); diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index 157a85be98..c54f3dbca5 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -2239,7 +2239,6 @@ void VisualServerScene::_render_scene(const Transform p_cam_transform,const Came bool redraw = VSG::scene_render->shadow_atlas_update_light(p_shadow_atlas,light->instance,coverage,light->last_version); if (redraw) { - print_line("redraw shadow"); //must redraw! _light_instance_update_shadow(ins,p_cam_transform,p_cam_projection,p_cam_orthogonal,p_shadow_atlas,scenario); } @@ -2448,6 +2447,7 @@ void VisualServerScene::_setup_gi_probe(Instance *p_instance) { probe->dynamic.bake_dynamic_range=VSG::storage->gi_probe_get_dynamic_range(p_instance->base); probe->dynamic.mipmaps_3d.clear(); + probe->dynamic.propagate=VSG::storage->gi_probe_get_propagation(p_instance->base); probe->dynamic.grid_size[0]=header->width; probe->dynamic.grid_size[1]=header->height; @@ -2942,14 +2942,12 @@ void VisualServerScene::_bake_gi_probe_light(const GIProbeDataHeader *header,con } -void VisualServerScene::_bake_gi_downscale_light(int p_idx, int p_level, const GIProbeDataCell* p_cells, const GIProbeDataHeader *p_header, InstanceGIProbeData::LocalData *p_local_data) { +void VisualServerScene::_bake_gi_downscale_light(int p_idx, int p_level, const GIProbeDataCell* p_cells, const GIProbeDataHeader *p_header, InstanceGIProbeData::LocalData *p_local_data,float p_propagate) { //average light to upper level - p_local_data[p_idx].energy[0]=0; - p_local_data[p_idx].energy[1]=0; - p_local_data[p_idx].energy[2]=0; - int divisor=0; + float divisor=0; + float sum[3]={0.0,0.0,0.0}; for(int i=0;i<8;i++) { @@ -2959,20 +2957,25 @@ void VisualServerScene::_bake_gi_downscale_light(int p_idx, int p_level, const G continue; if (p_level+1 < (int)p_header->cell_subdiv-1) { - _bake_gi_downscale_light(child,p_level+1,p_cells,p_header,p_local_data); + _bake_gi_downscale_light(child,p_level+1,p_cells,p_header,p_local_data,p_propagate); } - p_local_data[p_idx].energy[0]+=p_local_data[child].energy[0]; - p_local_data[p_idx].energy[1]+=p_local_data[child].energy[1]; - p_local_data[p_idx].energy[2]+=p_local_data[child].energy[2]; - divisor++; + sum[0]+=p_local_data[child].energy[0]; + sum[1]+=p_local_data[child].energy[1]; + sum[2]+=p_local_data[child].energy[2]; + divisor+=1.0; } + divisor=Math::lerp((float)8.0,divisor,p_propagate); + sum[0]/=divisor; + sum[1]/=divisor; + sum[2]/=divisor; + //divide by eight for average - p_local_data[p_idx].energy[0]/=divisor; - p_local_data[p_idx].energy[1]/=divisor; - p_local_data[p_idx].energy[2]/=divisor; + p_local_data[p_idx].energy[0]=Math::fast_ftoi(sum[0]); + p_local_data[p_idx].energy[1]=Math::fast_ftoi(sum[1]); + p_local_data[p_idx].energy[2]=Math::fast_ftoi(sum[2]); } @@ -3024,7 +3027,7 @@ void VisualServerScene::_bake_gi_probe(Instance *p_gi_probe) { SWAP(probe_data->dynamic.light_cache_changes,probe_data->dynamic.light_cache); //downscale to lower res levels - _bake_gi_downscale_light(0,0,cells,header,local_data); + _bake_gi_downscale_light(0,0,cells,header,local_data,probe_data->dynamic.propagate); //plot result to 3D texture! @@ -3337,6 +3340,14 @@ void VisualServerScene::render_probes() { force_lighting=true; } + float propagate = VSG::storage->gi_probe_get_propagation(instance_probe->base); + + if (probe->dynamic.propagate!=propagate) { + probe->dynamic.propagate=propagate; + force_lighting=true; + } + + if (probe->invalid==false && probe->dynamic.enabled) { switch(probe->dynamic.updating_stage) { diff --git a/servers/visual/visual_server_scene.h b/servers/visual/visual_server_scene.h index 1f7de3d005..f9a5dde1ac 100644 --- a/servers/visual/visual_server_scene.h +++ b/servers/visual/visual_server_scene.h @@ -445,6 +445,7 @@ public: Vector< PoolVector<CompBlockS3TC> > mipmaps_s3tc; //for s3tc int updating_stage; + float propagate; int grid_size[3]; @@ -570,7 +571,7 @@ public: void _gi_probe_fill_local_data(int p_idx,int p_level,int p_x,int p_y,int p_z,const GIProbeDataCell* p_cell,const GIProbeDataHeader *p_header,InstanceGIProbeData::LocalData *p_local_data,Vector<uint32_t> *prev_cell); _FORCE_INLINE_ uint32_t _gi_bake_find_cell(const GIProbeDataCell *cells,int x,int y, int z,int p_cell_subdiv); - void _bake_gi_downscale_light(int p_idx, int p_level, const GIProbeDataCell* p_cells, const GIProbeDataHeader *p_header, InstanceGIProbeData::LocalData *p_local_data); + void _bake_gi_downscale_light(int p_idx, int p_level, const GIProbeDataCell* p_cells, const GIProbeDataHeader *p_header, InstanceGIProbeData::LocalData *p_local_data, float p_propagate); void _bake_gi_probe_light(const GIProbeDataHeader *header,const GIProbeDataCell *cells,InstanceGIProbeData::LocalData *local_data,const uint32_t *leaves,int p_leaf_count, const InstanceGIProbeData::LightCache& light_cache,int p_sign); void _bake_gi_probe(Instance *p_probe); bool _check_gi_probe(Instance *p_gi_probe); diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index da73980e08..1799585576 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -156,7 +156,7 @@ RID VisualServer::_make_test_cube() { PoolVector<Vector3> uvs; int vtx_idx=0; -#define ADD_VTX(m_idx);\ +#define ADD_VTX(m_idx) \ vertices.push_back( face_points[m_idx] );\ normals.push_back( normal_points[m_idx] );\ tangents.push_back( normal_points[m_idx][1] );\ diff --git a/servers/visual_server.h b/servers/visual_server.h index f75223e378..5c835c2287 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -129,6 +129,11 @@ public: virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable)=0; + typedef void (*TextureDetectCallback)(void*); + + virtual void texture_set_detect_3d_callback(RID p_texture,TextureDetectCallback p_callback,void* p_userdata)=0; + virtual void texture_set_detect_srgb_callback(RID p_texture,TextureDetectCallback p_callback,void* p_userdata)=0; + struct TextureInfo { RID texture; Size2 size; @@ -360,6 +365,7 @@ public: LIGHT_PARAM_ATTENUATION, LIGHT_PARAM_SPOT_ANGLE, LIGHT_PARAM_SPOT_ATTENUATION, + LIGHT_PARAM_CONTACT_SHADOW_SIZE, LIGHT_PARAM_SHADOW_MAX_DISTANCE, LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET, LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET, @@ -469,6 +475,9 @@ public: virtual void gi_probe_set_energy(RID p_probe,float p_range)=0; virtual float gi_probe_get_energy(RID p_probe) const=0; + virtual void gi_probe_set_propagation(RID p_probe,float p_range)=0; + virtual float gi_probe_get_propagation(RID p_probe) const=0; + virtual void gi_probe_set_interior(RID p_probe,bool p_enable)=0; virtual bool gi_probe_is_interior(RID p_probe) const=0; @@ -938,6 +947,8 @@ public: virtual bool has_feature(Features p_feature) const=0; + virtual bool has_os_feature(const String& p_feature) const=0; + VisualServer(); virtual ~VisualServer(); diff --git a/thirdparty/README.md b/thirdparty/README.md index 42642c09b7..54930c1ebe 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -1,6 +1,13 @@ # Third party libraries +## certs + +- Upstream: ? + +TODO. + + ## enet - Upstream: http://enet.bespin.org @@ -18,6 +25,13 @@ for all platforms (especially UWP). Check the diff with the 1.3.13 tarball before the next update. +## fonts + +- Upstream: ? + +TODO. + + ## freetype - Upstream: https://www.freetype.org @@ -209,7 +223,7 @@ Files extracted from upstream source: ## zlib - Upstream: http://www.zlib.net/ -- Version: 1.2.10 +- Version: 1.2.11 - License: zlib Files extracted from upstream source: diff --git a/tools/certs/ca-certificates.crt b/thirdparty/certs/ca-certificates.crt index 862096d85a..862096d85a 100644 --- a/tools/certs/ca-certificates.crt +++ b/thirdparty/certs/ca-certificates.crt diff --git a/tools/editor_fonts/DroidSans.ttf b/thirdparty/fonts/DroidSans.ttf Binary files differindex 767c63ad00..767c63ad00 100644 --- a/tools/editor_fonts/DroidSans.ttf +++ b/thirdparty/fonts/DroidSans.ttf diff --git a/tools/editor_fonts/DroidSansArabic.ttf b/thirdparty/fonts/DroidSansArabic.ttf Binary files differindex 660e2a9916..660e2a9916 100644 --- a/tools/editor_fonts/DroidSansArabic.ttf +++ b/thirdparty/fonts/DroidSansArabic.ttf diff --git a/tools/editor_fonts/DroidSansFallback.ttf b/thirdparty/fonts/DroidSansFallback.ttf Binary files differindex 206621fc6c..206621fc6c 100644 --- a/tools/editor_fonts/DroidSansFallback.ttf +++ b/thirdparty/fonts/DroidSansFallback.ttf diff --git a/tools/editor_fonts/DroidSansHebrew.ttf b/thirdparty/fonts/DroidSansHebrew.ttf Binary files differindex 8d77e3e4cf..8d77e3e4cf 100644 --- a/tools/editor_fonts/DroidSansHebrew.ttf +++ b/thirdparty/fonts/DroidSansHebrew.ttf diff --git a/tools/editor_fonts/DroidSansJapanese.ttf b/thirdparty/fonts/DroidSansJapanese.ttf Binary files differindex 412fa3de05..412fa3de05 100644 --- a/tools/editor_fonts/DroidSansJapanese.ttf +++ b/thirdparty/fonts/DroidSansJapanese.ttf diff --git a/tools/editor_fonts/DroidSansThai.ttf b/thirdparty/fonts/DroidSansThai.ttf Binary files differindex f849baeff9..f849baeff9 100644 --- a/tools/editor_fonts/DroidSansThai.ttf +++ b/thirdparty/fonts/DroidSansThai.ttf diff --git a/tools/editor_fonts/LICENSE.DroidSans.txt b/thirdparty/fonts/LICENSE.DroidSans.txt index 636f1e2975..636f1e2975 100644 --- a/tools/editor_fonts/LICENSE.DroidSans.txt +++ b/thirdparty/fonts/LICENSE.DroidSans.txt diff --git a/tools/editor_fonts/LICENSE.SourceCodePro.txt b/thirdparty/fonts/LICENSE.SourceCodePro.txt index f430ee5dbe..f430ee5dbe 100644 --- a/tools/editor_fonts/LICENSE.SourceCodePro.txt +++ b/thirdparty/fonts/LICENSE.SourceCodePro.txt diff --git a/tools/editor_fonts/source_code_pro.otf b/thirdparty/fonts/source_code_pro.otf Binary files differindex 4e3b9d0bcd..4e3b9d0bcd 100644 --- a/tools/editor_fonts/source_code_pro.otf +++ b/thirdparty/fonts/source_code_pro.otf diff --git a/thirdparty/stb_vorbis/stb_vorbis.c b/thirdparty/stb_vorbis/stb_vorbis.c new file mode 100644 index 0000000000..c4f24d5898 --- /dev/null +++ b/thirdparty/stb_vorbis/stb_vorbis.c @@ -0,0 +1,5399 @@ +// Ogg Vorbis audio decoder - v1.09 - public domain +// http://nothings.org/stb_vorbis/ +// +// Original version written by Sean Barrett in 2007. +// +// Originally sponsored by RAD Game Tools. Seeking sponsored +// by Phillip Bennefall, Marc Andersen, Aaron Baker, Elias Software, +// Aras Pranckevicius, and Sean Barrett. +// +// LICENSE +// +// This software is dual-licensed to the public domain and under the following +// license: you are granted a perpetual, irrevocable license to copy, modify, +// publish, and distribute this file as you see fit. +// +// No warranty for any purpose is expressed or implied by the author (nor +// by RAD Game Tools). Report bugs and send enhancements to the author. +// +// Limitations: +// +// - floor 0 not supported (used in old ogg vorbis files pre-2004) +// - lossless sample-truncation at beginning ignored +// - cannot concatenate multiple vorbis streams +// - sample positions are 32-bit, limiting seekable 192Khz +// files to around 6 hours (Ogg supports 64-bit) +// +// Feature contributors: +// Dougall Johnson (sample-exact seeking) +// +// Bugfix/warning contributors: +// Terje Mathisen Niklas Frykholm Andy Hill +// Casey Muratori John Bolton Gargaj +// Laurent Gomila Marc LeBlanc Ronny Chevalier +// Bernhard Wodo Evan Balster alxprd@github +// Tom Beaumont Ingo Leitgeb Nicolas Guillemot +// Phillip Bennefall Rohit Thiago Goulart +// manxorist@github saga musix +// +// Partial history: +// 1.09 - 2016/04/04 - back out 'truncation of last frame' fix from previous version +// 1.08 - 2016/04/02 - warnings; setup memory leaks; truncation of last frame +// 1.07 - 2015/01/16 - fixes for crashes on invalid files; warning fixes; const +// 1.06 - 2015/08/31 - full, correct support for seeking API (Dougall Johnson) +// some crash fixes when out of memory or with corrupt files +// fix some inappropriately signed shifts +// 1.05 - 2015/04/19 - don't define __forceinline if it's redundant +// 1.04 - 2014/08/27 - fix missing const-correct case in API +// 1.03 - 2014/08/07 - warning fixes +// 1.02 - 2014/07/09 - declare qsort comparison as explicitly _cdecl in Windows +// 1.01 - 2014/06/18 - fix stb_vorbis_get_samples_float (interleaved was correct) +// 1.0 - 2014/05/26 - fix memory leaks; fix warnings; fix bugs in >2-channel; +// (API change) report sample rate for decode-full-file funcs +// +// See end of file for full version history. + + +////////////////////////////////////////////////////////////////////////////// +// +// HEADER BEGINS HERE +// + +#ifndef STB_VORBIS_INCLUDE_STB_VORBIS_H +#define STB_VORBIS_INCLUDE_STB_VORBIS_H + +#if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO) +#define STB_VORBIS_NO_STDIO 1 +#endif + +#ifndef STB_VORBIS_NO_STDIO +#include <stdio.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/////////// THREAD SAFETY + +// Individual stb_vorbis* handles are not thread-safe; you cannot decode from +// them from multiple threads at the same time. However, you can have multiple +// stb_vorbis* handles and decode from them independently in multiple thrads. + + +/////////// MEMORY ALLOCATION + +// normally stb_vorbis uses malloc() to allocate memory at startup, +// and alloca() to allocate temporary memory during a frame on the +// stack. (Memory consumption will depend on the amount of setup +// data in the file and how you set the compile flags for speed +// vs. size. In my test files the maximal-size usage is ~150KB.) +// +// You can modify the wrapper functions in the source (setup_malloc, +// setup_temp_malloc, temp_malloc) to change this behavior, or you +// can use a simpler allocation model: you pass in a buffer from +// which stb_vorbis will allocate _all_ its memory (including the +// temp memory). "open" may fail with a VORBIS_outofmem if you +// do not pass in enough data; there is no way to determine how +// much you do need except to succeed (at which point you can +// query get_info to find the exact amount required. yes I know +// this is lame). +// +// If you pass in a non-NULL buffer of the type below, allocation +// will occur from it as described above. Otherwise just pass NULL +// to use malloc()/alloca() + +typedef struct +{ + char *alloc_buffer; + int alloc_buffer_length_in_bytes; +} stb_vorbis_alloc; + + +/////////// FUNCTIONS USEABLE WITH ALL INPUT MODES + +typedef struct stb_vorbis stb_vorbis; + +typedef struct +{ + unsigned int sample_rate; + int channels; + + unsigned int setup_memory_required; + unsigned int setup_temp_memory_required; + unsigned int temp_memory_required; + + int max_frame_size; +} stb_vorbis_info; + +// get general information about the file +extern stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f); + +// get the last error detected (clears it, too) +extern int stb_vorbis_get_error(stb_vorbis *f); + +// close an ogg vorbis file and free all memory in use +extern void stb_vorbis_close(stb_vorbis *f); + +// this function returns the offset (in samples) from the beginning of the +// file that will be returned by the next decode, if it is known, or -1 +// otherwise. after a flush_pushdata() call, this may take a while before +// it becomes valid again. +// NOT WORKING YET after a seek with PULLDATA API +extern int stb_vorbis_get_sample_offset(stb_vorbis *f); + +// returns the current seek point within the file, or offset from the beginning +// of the memory buffer. In pushdata mode it returns 0. +extern unsigned int stb_vorbis_get_file_offset(stb_vorbis *f); + +/////////// PUSHDATA API + +#ifndef STB_VORBIS_NO_PUSHDATA_API + +// this API allows you to get blocks of data from any source and hand +// them to stb_vorbis. you have to buffer them; stb_vorbis will tell +// you how much it used, and you have to give it the rest next time; +// and stb_vorbis may not have enough data to work with and you will +// need to give it the same data again PLUS more. Note that the Vorbis +// specification does not bound the size of an individual frame. + +extern stb_vorbis *stb_vorbis_open_pushdata( + const unsigned char * datablock, int datablock_length_in_bytes, + int *datablock_memory_consumed_in_bytes, + int *error, + const stb_vorbis_alloc *alloc_buffer); +// create a vorbis decoder by passing in the initial data block containing +// the ogg&vorbis headers (you don't need to do parse them, just provide +// the first N bytes of the file--you're told if it's not enough, see below) +// on success, returns an stb_vorbis *, does not set error, returns the amount of +// data parsed/consumed on this call in *datablock_memory_consumed_in_bytes; +// on failure, returns NULL on error and sets *error, does not change *datablock_memory_consumed +// if returns NULL and *error is VORBIS_need_more_data, then the input block was +// incomplete and you need to pass in a larger block from the start of the file + +extern int stb_vorbis_decode_frame_pushdata( + stb_vorbis *f, + const unsigned char *datablock, int datablock_length_in_bytes, + int *channels, // place to write number of float * buffers + float ***output, // place to write float ** array of float * buffers + int *samples // place to write number of output samples + ); +// decode a frame of audio sample data if possible from the passed-in data block +// +// return value: number of bytes we used from datablock +// +// possible cases: +// 0 bytes used, 0 samples output (need more data) +// N bytes used, 0 samples output (resynching the stream, keep going) +// N bytes used, M samples output (one frame of data) +// note that after opening a file, you will ALWAYS get one N-bytes,0-sample +// frame, because Vorbis always "discards" the first frame. +// +// Note that on resynch, stb_vorbis will rarely consume all of the buffer, +// instead only datablock_length_in_bytes-3 or less. This is because it wants +// to avoid missing parts of a page header if they cross a datablock boundary, +// without writing state-machiney code to record a partial detection. +// +// The number of channels returned are stored in *channels (which can be +// NULL--it is always the same as the number of channels reported by +// get_info). *output will contain an array of float* buffers, one per +// channel. In other words, (*output)[0][0] contains the first sample from +// the first channel, and (*output)[1][0] contains the first sample from +// the second channel. + +extern void stb_vorbis_flush_pushdata(stb_vorbis *f); +// inform stb_vorbis that your next datablock will not be contiguous with +// previous ones (e.g. you've seeked in the data); future attempts to decode +// frames will cause stb_vorbis to resynchronize (as noted above), and +// once it sees a valid Ogg page (typically 4-8KB, as large as 64KB), it +// will begin decoding the _next_ frame. +// +// if you want to seek using pushdata, you need to seek in your file, then +// call stb_vorbis_flush_pushdata(), then start calling decoding, then once +// decoding is returning you data, call stb_vorbis_get_sample_offset, and +// if you don't like the result, seek your file again and repeat. +#endif + + +////////// PULLING INPUT API + +#ifndef STB_VORBIS_NO_PULLDATA_API +// This API assumes stb_vorbis is allowed to pull data from a source-- +// either a block of memory containing the _entire_ vorbis stream, or a +// FILE * that you or it create, or possibly some other reading mechanism +// if you go modify the source to replace the FILE * case with some kind +// of callback to your code. (But if you don't support seeking, you may +// just want to go ahead and use pushdata.) + +#if !defined(STB_VORBIS_NO_STDIO) && !defined(STB_VORBIS_NO_INTEGER_CONVERSION) +extern int stb_vorbis_decode_filename(const char *filename, int *channels, int *sample_rate, short **output); +#endif +#if !defined(STB_VORBIS_NO_INTEGER_CONVERSION) +extern int stb_vorbis_decode_memory(const unsigned char *mem, int len, int *channels, int *sample_rate, short **output); +#endif +// decode an entire file and output the data interleaved into a malloc()ed +// buffer stored in *output. The return value is the number of samples +// decoded, or -1 if the file could not be opened or was not an ogg vorbis file. +// When you're done with it, just free() the pointer returned in *output. + +extern stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, + int *error, const stb_vorbis_alloc *alloc_buffer); +// create an ogg vorbis decoder from an ogg vorbis stream in memory (note +// this must be the entire stream!). on failure, returns NULL and sets *error + +#ifndef STB_VORBIS_NO_STDIO +extern stb_vorbis * stb_vorbis_open_filename(const char *filename, + int *error, const stb_vorbis_alloc *alloc_buffer); +// create an ogg vorbis decoder from a filename via fopen(). on failure, +// returns NULL and sets *error (possibly to VORBIS_file_open_failure). + +extern stb_vorbis * stb_vorbis_open_file(FILE *f, int close_handle_on_close, + int *error, const stb_vorbis_alloc *alloc_buffer); +// create an ogg vorbis decoder from an open FILE *, looking for a stream at +// the _current_ seek point (ftell). on failure, returns NULL and sets *error. +// note that stb_vorbis must "own" this stream; if you seek it in between +// calls to stb_vorbis, it will become confused. Morever, if you attempt to +// perform stb_vorbis_seek_*() operations on this file, it will assume it +// owns the _entire_ rest of the file after the start point. Use the next +// function, stb_vorbis_open_file_section(), to limit it. + +extern stb_vorbis * stb_vorbis_open_file_section(FILE *f, int close_handle_on_close, + int *error, const stb_vorbis_alloc *alloc_buffer, unsigned int len); +// create an ogg vorbis decoder from an open FILE *, looking for a stream at +// the _current_ seek point (ftell); the stream will be of length 'len' bytes. +// on failure, returns NULL and sets *error. note that stb_vorbis must "own" +// this stream; if you seek it in between calls to stb_vorbis, it will become +// confused. +#endif + +extern int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number); +extern int stb_vorbis_seek(stb_vorbis *f, unsigned int sample_number); +// these functions seek in the Vorbis file to (approximately) 'sample_number'. +// after calling seek_frame(), the next call to get_frame_*() will include +// the specified sample. after calling stb_vorbis_seek(), the next call to +// stb_vorbis_get_samples_* will start with the specified sample. If you +// do not need to seek to EXACTLY the target sample when using get_samples_*, +// you can also use seek_frame(). + +extern void stb_vorbis_seek_start(stb_vorbis *f); +// this function is equivalent to stb_vorbis_seek(f,0) + +extern unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f); +extern float stb_vorbis_stream_length_in_seconds(stb_vorbis *f); +// these functions return the total length of the vorbis stream + +extern int stb_vorbis_get_frame_float(stb_vorbis *f, int *channels, float ***output); +// decode the next frame and return the number of samples. the number of +// channels returned are stored in *channels (which can be NULL--it is always +// the same as the number of channels reported by get_info). *output will +// contain an array of float* buffers, one per channel. These outputs will +// be overwritten on the next call to stb_vorbis_get_frame_*. +// +// You generally should not intermix calls to stb_vorbis_get_frame_*() +// and stb_vorbis_get_samples_*(), since the latter calls the former. + +#ifndef STB_VORBIS_NO_INTEGER_CONVERSION +extern int stb_vorbis_get_frame_short_interleaved(stb_vorbis *f, int num_c, short *buffer, int num_shorts); +extern int stb_vorbis_get_frame_short (stb_vorbis *f, int num_c, short **buffer, int num_samples); +#endif +// decode the next frame and return the number of *samples* per channel. +// Note that for interleaved data, you pass in the number of shorts (the +// size of your array), but the return value is the number of samples per +// channel, not the total number of samples. +// +// The data is coerced to the number of channels you request according to the +// channel coercion rules (see below). You must pass in the size of your +// buffer(s) so that stb_vorbis will not overwrite the end of the buffer. +// The maximum buffer size needed can be gotten from get_info(); however, +// the Vorbis I specification implies an absolute maximum of 4096 samples +// per channel. + +// Channel coercion rules: +// Let M be the number of channels requested, and N the number of channels present, +// and Cn be the nth channel; let stereo L be the sum of all L and center channels, +// and stereo R be the sum of all R and center channels (channel assignment from the +// vorbis spec). +// M N output +// 1 k sum(Ck) for all k +// 2 * stereo L, stereo R +// k l k > l, the first l channels, then 0s +// k l k <= l, the first k channels +// Note that this is not _good_ surround etc. mixing at all! It's just so +// you get something useful. + +extern int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float *buffer, int num_floats); +extern int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, int num_samples); +// gets num_samples samples, not necessarily on a frame boundary--this requires +// buffering so you have to supply the buffers. DOES NOT APPLY THE COERCION RULES. +// Returns the number of samples stored per channel; it may be less than requested +// at the end of the file. If there are no more samples in the file, returns 0. + +#ifndef STB_VORBIS_NO_INTEGER_CONVERSION +extern int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short *buffer, int num_shorts); +extern int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, int num_samples); +#endif +// gets num_samples samples, not necessarily on a frame boundary--this requires +// buffering so you have to supply the buffers. Applies the coercion rules above +// to produce 'channels' channels. Returns the number of samples stored per channel; +// it may be less than requested at the end of the file. If there are no more +// samples in the file, returns 0. + +#endif + +//////// ERROR CODES + +enum STBVorbisError +{ + VORBIS__no_error, + + VORBIS_need_more_data=1, // not a real error + + VORBIS_invalid_api_mixing, // can't mix API modes + VORBIS_outofmem, // not enough memory + VORBIS_feature_not_supported, // uses floor 0 + VORBIS_too_many_channels, // STB_VORBIS_MAX_CHANNELS is too small + VORBIS_file_open_failure, // fopen() failed + VORBIS_seek_without_length, // can't seek in unknown-length file + + VORBIS_unexpected_eof=10, // file is truncated? + VORBIS_seek_invalid, // seek past EOF + + // decoding errors (corrupt/invalid stream) -- you probably + // don't care about the exact details of these + + // vorbis errors: + VORBIS_invalid_setup=20, + VORBIS_invalid_stream, + + // ogg errors: + VORBIS_missing_capture_pattern=30, + VORBIS_invalid_stream_structure_version, + VORBIS_continued_packet_flag_invalid, + VORBIS_incorrect_stream_serial_number, + VORBIS_invalid_first_page, + VORBIS_bad_packet_type, + VORBIS_cant_find_last_page, + VORBIS_seek_failed +}; + + +#ifdef __cplusplus +} +#endif + +#endif // STB_VORBIS_INCLUDE_STB_VORBIS_H +// +// HEADER ENDS HERE +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef STB_VORBIS_HEADER_ONLY + +// global configuration settings (e.g. set these in the project/makefile), +// or just set them in this file at the top (although ideally the first few +// should be visible when the header file is compiled too, although it's not +// crucial) + +// STB_VORBIS_NO_PUSHDATA_API +// does not compile the code for the various stb_vorbis_*_pushdata() +// functions +// #define STB_VORBIS_NO_PUSHDATA_API + +// STB_VORBIS_NO_PULLDATA_API +// does not compile the code for the non-pushdata APIs +// #define STB_VORBIS_NO_PULLDATA_API + +// STB_VORBIS_NO_STDIO +// does not compile the code for the APIs that use FILE *s internally +// or externally (implied by STB_VORBIS_NO_PULLDATA_API) +// #define STB_VORBIS_NO_STDIO + +// STB_VORBIS_NO_INTEGER_CONVERSION +// does not compile the code for converting audio sample data from +// float to integer (implied by STB_VORBIS_NO_PULLDATA_API) +// #define STB_VORBIS_NO_INTEGER_CONVERSION + +// STB_VORBIS_NO_FAST_SCALED_FLOAT +// does not use a fast float-to-int trick to accelerate float-to-int on +// most platforms which requires endianness be defined correctly. +//#define STB_VORBIS_NO_FAST_SCALED_FLOAT + + +// STB_VORBIS_MAX_CHANNELS [number] +// globally define this to the maximum number of channels you need. +// The spec does not put a restriction on channels except that +// the count is stored in a byte, so 255 is the hard limit. +// Reducing this saves about 16 bytes per value, so using 16 saves +// (255-16)*16 or around 4KB. Plus anything other memory usage +// I forgot to account for. Can probably go as low as 8 (7.1 audio), +// 6 (5.1 audio), or 2 (stereo only). +#ifndef STB_VORBIS_MAX_CHANNELS +#define STB_VORBIS_MAX_CHANNELS 16 // enough for anyone? +#endif + +// STB_VORBIS_PUSHDATA_CRC_COUNT [number] +// after a flush_pushdata(), stb_vorbis begins scanning for the +// next valid page, without backtracking. when it finds something +// that looks like a page, it streams through it and verifies its +// CRC32. Should that validation fail, it keeps scanning. But it's +// possible that _while_ streaming through to check the CRC32 of +// one candidate page, it sees another candidate page. This #define +// determines how many "overlapping" candidate pages it can search +// at once. Note that "real" pages are typically ~4KB to ~8KB, whereas +// garbage pages could be as big as 64KB, but probably average ~16KB. +// So don't hose ourselves by scanning an apparent 64KB page and +// missing a ton of real ones in the interim; so minimum of 2 +#ifndef STB_VORBIS_PUSHDATA_CRC_COUNT +#define STB_VORBIS_PUSHDATA_CRC_COUNT 4 +#endif + +// STB_VORBIS_FAST_HUFFMAN_LENGTH [number] +// sets the log size of the huffman-acceleration table. Maximum +// supported value is 24. with larger numbers, more decodings are O(1), +// but the table size is larger so worse cache missing, so you'll have +// to probe (and try multiple ogg vorbis files) to find the sweet spot. +#ifndef STB_VORBIS_FAST_HUFFMAN_LENGTH +#define STB_VORBIS_FAST_HUFFMAN_LENGTH 10 +#endif + +// STB_VORBIS_FAST_BINARY_LENGTH [number] +// sets the log size of the binary-search acceleration table. this +// is used in similar fashion to the fast-huffman size to set initial +// parameters for the binary search + +// STB_VORBIS_FAST_HUFFMAN_INT +// The fast huffman tables are much more efficient if they can be +// stored as 16-bit results instead of 32-bit results. This restricts +// the codebooks to having only 65535 possible outcomes, though. +// (At least, accelerated by the huffman table.) +#ifndef STB_VORBIS_FAST_HUFFMAN_INT +#define STB_VORBIS_FAST_HUFFMAN_SHORT +#endif + +// STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH +// If the 'fast huffman' search doesn't succeed, then stb_vorbis falls +// back on binary searching for the correct one. This requires storing +// extra tables with the huffman codes in sorted order. Defining this +// symbol trades off space for speed by forcing a linear search in the +// non-fast case, except for "sparse" codebooks. +// #define STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH + +// STB_VORBIS_DIVIDES_IN_RESIDUE +// stb_vorbis precomputes the result of the scalar residue decoding +// that would otherwise require a divide per chunk. you can trade off +// space for time by defining this symbol. +// #define STB_VORBIS_DIVIDES_IN_RESIDUE + +// STB_VORBIS_DIVIDES_IN_CODEBOOK +// vorbis VQ codebooks can be encoded two ways: with every case explicitly +// stored, or with all elements being chosen from a small range of values, +// and all values possible in all elements. By default, stb_vorbis expands +// this latter kind out to look like the former kind for ease of decoding, +// because otherwise an integer divide-per-vector-element is required to +// unpack the index. If you define STB_VORBIS_DIVIDES_IN_CODEBOOK, you can +// trade off storage for speed. +//#define STB_VORBIS_DIVIDES_IN_CODEBOOK + +#ifdef STB_VORBIS_CODEBOOK_SHORTS +#error "STB_VORBIS_CODEBOOK_SHORTS is no longer supported as it produced incorrect results for some input formats" +#endif + +// STB_VORBIS_DIVIDE_TABLE +// this replaces small integer divides in the floor decode loop with +// table lookups. made less than 1% difference, so disabled by default. + +// STB_VORBIS_NO_INLINE_DECODE +// disables the inlining of the scalar codebook fast-huffman decode. +// might save a little codespace; useful for debugging +// #define STB_VORBIS_NO_INLINE_DECODE + +// STB_VORBIS_NO_DEFER_FLOOR +// Normally we only decode the floor without synthesizing the actual +// full curve. We can instead synthesize the curve immediately. This +// requires more memory and is very likely slower, so I don't think +// you'd ever want to do it except for debugging. +// #define STB_VORBIS_NO_DEFER_FLOOR + + + + +////////////////////////////////////////////////////////////////////////////// + +#ifdef STB_VORBIS_NO_PULLDATA_API + #define STB_VORBIS_NO_INTEGER_CONVERSION + #define STB_VORBIS_NO_STDIO +#endif + +#if defined(STB_VORBIS_NO_CRT) && !defined(STB_VORBIS_NO_STDIO) + #define STB_VORBIS_NO_STDIO 1 +#endif + +#ifndef STB_VORBIS_NO_INTEGER_CONVERSION +#ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT + + // only need endianness for fast-float-to-int, which we don't + // use for pushdata + + #ifndef STB_VORBIS_BIG_ENDIAN + #define STB_VORBIS_ENDIAN 0 + #else + #define STB_VORBIS_ENDIAN 1 + #endif + +#endif +#endif + + +#ifndef STB_VORBIS_NO_STDIO +#include <stdio.h> +#endif + +#ifndef STB_VORBIS_NO_CRT + #include <stdlib.h> + #include <string.h> + #include <assert.h> + #include <math.h> + + // find definition of alloca if it's not in stdlib.h: + #ifdef _MSC_VER + #include <malloc.h> + #endif + #if defined(__linux__) || defined(__linux) || defined(__EMSCRIPTEN__) + #include <alloca.h> + #endif +#else // STB_VORBIS_NO_CRT + #define NULL 0 + #define malloc(s) 0 + #define free(s) ((void) 0) + #define realloc(s) 0 +#endif // STB_VORBIS_NO_CRT + +#include <limits.h> + +#ifdef __MINGW32__ + // eff you mingw: + // "fixed": + // http://sourceforge.net/p/mingw-w64/mailman/message/32882927/ + // "no that broke the build, reverted, who cares about C": + // http://sourceforge.net/p/mingw-w64/mailman/message/32890381/ + #ifdef __forceinline + #undef __forceinline + #endif + #define __forceinline +#elif !defined(_MSC_VER) + #if __GNUC__ + #define __forceinline inline + #else + #define __forceinline + #endif +#endif + +#if STB_VORBIS_MAX_CHANNELS > 256 +#error "Value of STB_VORBIS_MAX_CHANNELS outside of allowed range" +#endif + +#if STB_VORBIS_FAST_HUFFMAN_LENGTH > 24 +#error "Value of STB_VORBIS_FAST_HUFFMAN_LENGTH outside of allowed range" +#endif + + +#if 0 +#include <crtdbg.h> +#define CHECK(f) _CrtIsValidHeapPointer(f->channel_buffers[1]) +#else +#define CHECK(f) ((void) 0) +#endif + +#define MAX_BLOCKSIZE_LOG 13 // from specification +#define MAX_BLOCKSIZE (1 << MAX_BLOCKSIZE_LOG) + + +typedef unsigned char uint8; +typedef signed char int8; +typedef unsigned short uint16; +typedef signed short int16; +typedef unsigned int uint32; +typedef signed int int32; + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif + +typedef float codetype; + +// @NOTE +// +// Some arrays below are tagged "//varies", which means it's actually +// a variable-sized piece of data, but rather than malloc I assume it's +// small enough it's better to just allocate it all together with the +// main thing +// +// Most of the variables are specified with the smallest size I could pack +// them into. It might give better performance to make them all full-sized +// integers. It should be safe to freely rearrange the structures or change +// the sizes larger--nothing relies on silently truncating etc., nor the +// order of variables. + +#define FAST_HUFFMAN_TABLE_SIZE (1 << STB_VORBIS_FAST_HUFFMAN_LENGTH) +#define FAST_HUFFMAN_TABLE_MASK (FAST_HUFFMAN_TABLE_SIZE - 1) + +typedef struct +{ + int dimensions, entries; + uint8 *codeword_lengths; + float minimum_value; + float delta_value; + uint8 value_bits; + uint8 lookup_type; + uint8 sequence_p; + uint8 sparse; + uint32 lookup_values; + codetype *multiplicands; + uint32 *codewords; + #ifdef STB_VORBIS_FAST_HUFFMAN_SHORT + int16 fast_huffman[FAST_HUFFMAN_TABLE_SIZE]; + #else + int32 fast_huffman[FAST_HUFFMAN_TABLE_SIZE]; + #endif + uint32 *sorted_codewords; + int *sorted_values; + int sorted_entries; +} Codebook; + +typedef struct +{ + uint8 order; + uint16 rate; + uint16 bark_map_size; + uint8 amplitude_bits; + uint8 amplitude_offset; + uint8 number_of_books; + uint8 book_list[16]; // varies +} Floor0; + +typedef struct +{ + uint8 partitions; + uint8 partition_class_list[32]; // varies + uint8 class_dimensions[16]; // varies + uint8 class_subclasses[16]; // varies + uint8 class_masterbooks[16]; // varies + int16 subclass_books[16][8]; // varies + uint16 Xlist[31*8+2]; // varies + uint8 sorted_order[31*8+2]; + uint8 neighbors[31*8+2][2]; + uint8 floor1_multiplier; + uint8 rangebits; + int values; +} Floor1; + +typedef union +{ + Floor0 floor0; + Floor1 floor1; +} Floor; + +typedef struct +{ + uint32 begin, end; + uint32 part_size; + uint8 classifications; + uint8 classbook; + uint8 **classdata; + int16 (*residue_books)[8]; +} Residue; + +typedef struct +{ + uint8 magnitude; + uint8 angle; + uint8 mux; +} MappingChannel; + +typedef struct +{ + uint16 coupling_steps; + MappingChannel *chan; + uint8 submaps; + uint8 submap_floor[15]; // varies + uint8 submap_residue[15]; // varies +} Mapping; + +typedef struct +{ + uint8 blockflag; + uint8 mapping; + uint16 windowtype; + uint16 transformtype; +} Mode; + +typedef struct +{ + uint32 goal_crc; // expected crc if match + int bytes_left; // bytes left in packet + uint32 crc_so_far; // running crc + int bytes_done; // bytes processed in _current_ chunk + uint32 sample_loc; // granule pos encoded in page +} CRCscan; + +typedef struct +{ + uint32 page_start, page_end; + uint32 last_decoded_sample; +} ProbedPage; + +struct stb_vorbis +{ + // user-accessible info + unsigned int sample_rate; + int channels; + + unsigned int setup_memory_required; + unsigned int temp_memory_required; + unsigned int setup_temp_memory_required; + + // input config +#ifndef STB_VORBIS_NO_STDIO + FILE *f; + uint32 f_start; + int close_on_free; +#endif + + uint8 *stream; + uint8 *stream_start; + uint8 *stream_end; + + uint32 stream_len; + + uint8 push_mode; + + uint32 first_audio_page_offset; + + ProbedPage p_first, p_last; + + // memory management + stb_vorbis_alloc alloc; + int setup_offset; + int temp_offset; + + // run-time results + int eof; + enum STBVorbisError error; + + // user-useful data + + // header info + int blocksize[2]; + int blocksize_0, blocksize_1; + int codebook_count; + Codebook *codebooks; + int floor_count; + uint16 floor_types[64]; // varies + Floor *floor_config; + int residue_count; + uint16 residue_types[64]; // varies + Residue *residue_config; + int mapping_count; + Mapping *mapping; + int mode_count; + Mode mode_config[64]; // varies + + uint32 total_samples; + + // decode buffer + float *channel_buffers[STB_VORBIS_MAX_CHANNELS]; + float *outputs [STB_VORBIS_MAX_CHANNELS]; + + float *previous_window[STB_VORBIS_MAX_CHANNELS]; + int previous_length; + + #ifndef STB_VORBIS_NO_DEFER_FLOOR + int16 *finalY[STB_VORBIS_MAX_CHANNELS]; + #else + float *floor_buffers[STB_VORBIS_MAX_CHANNELS]; + #endif + + uint32 current_loc; // sample location of next frame to decode + int current_loc_valid; + + // per-blocksize precomputed data + + // twiddle factors + float *A[2],*B[2],*C[2]; + float *window[2]; + uint16 *bit_reverse[2]; + + // current page/packet/segment streaming info + uint32 serial; // stream serial number for verification + int last_page; + int segment_count; + uint8 segments[255]; + uint8 page_flag; + uint8 bytes_in_seg; + uint8 first_decode; + int next_seg; + int last_seg; // flag that we're on the last segment + int last_seg_which; // what was the segment number of the last seg? + uint32 acc; + int valid_bits; + int packet_bytes; + int end_seg_with_known_loc; + uint32 known_loc_for_packet; + int discard_samples_deferred; + uint32 samples_output; + + // push mode scanning + int page_crc_tests; // only in push_mode: number of tests active; -1 if not searching +#ifndef STB_VORBIS_NO_PUSHDATA_API + CRCscan scan[STB_VORBIS_PUSHDATA_CRC_COUNT]; +#endif + + // sample-access + int channel_buffer_start; + int channel_buffer_end; +}; + +#if defined(STB_VORBIS_NO_PUSHDATA_API) + #define IS_PUSH_MODE(f) FALSE +#elif defined(STB_VORBIS_NO_PULLDATA_API) + #define IS_PUSH_MODE(f) TRUE +#else + #define IS_PUSH_MODE(f) ((f)->push_mode) +#endif + +typedef struct stb_vorbis vorb; + +static int error(vorb *f, enum STBVorbisError e) +{ + f->error = e; + if (!f->eof && e != VORBIS_need_more_data) { + f->error=e; // breakpoint for debugging + } + return 0; +} + + +// these functions are used for allocating temporary memory +// while decoding. if you can afford the stack space, use +// alloca(); otherwise, provide a temp buffer and it will +// allocate out of those. + +#define array_size_required(count,size) (count*(sizeof(void *)+(size))) + +#define temp_alloc(f,size) (f->alloc.alloc_buffer ? setup_temp_malloc(f,size) : alloca(size)) +#ifdef dealloca +#define temp_free(f,p) (f->alloc.alloc_buffer ? 0 : dealloca(size)) +#else +#define temp_free(f,p) 0 +#endif +#define temp_alloc_save(f) ((f)->temp_offset) +#define temp_alloc_restore(f,p) ((f)->temp_offset = (p)) + +#define temp_block_array(f,count,size) make_block_array(temp_alloc(f,array_size_required(count,size)), count, size) + +// given a sufficiently large block of memory, make an array of pointers to subblocks of it +static void *make_block_array(void *mem, int count, int size) +{ + int i; + void ** p = (void **) mem; + char *q = (char *) (p + count); + for (i=0; i < count; ++i) { + p[i] = q; + q += size; + } + return p; +} + +static void *setup_malloc(vorb *f, int sz) +{ + sz = (sz+3) & ~3; + f->setup_memory_required += sz; + if (f->alloc.alloc_buffer) { + void *p = (char *) f->alloc.alloc_buffer + f->setup_offset; + if (f->setup_offset + sz > f->temp_offset) return NULL; + f->setup_offset += sz; + return p; + } + return sz ? malloc(sz) : NULL; +} + +static void setup_free(vorb *f, void *p) +{ + if (f->alloc.alloc_buffer) return; // do nothing; setup mem is a stack + free(p); +} + +static void *setup_temp_malloc(vorb *f, int sz) +{ + sz = (sz+3) & ~3; + if (f->alloc.alloc_buffer) { + if (f->temp_offset - sz < f->setup_offset) return NULL; + f->temp_offset -= sz; + return (char *) f->alloc.alloc_buffer + f->temp_offset; + } + return malloc(sz); +} + +static void setup_temp_free(vorb *f, void *p, int sz) +{ + if (f->alloc.alloc_buffer) { + f->temp_offset += (sz+3)&~3; + return; + } + free(p); +} + +#define CRC32_POLY 0x04c11db7 // from spec + +static uint32 crc_table[256]; +static void crc32_init(void) +{ + int i,j; + uint32 s; + for(i=0; i < 256; i++) { + for (s=(uint32) i << 24, j=0; j < 8; ++j) + s = (s << 1) ^ (s >= (1U<<31) ? CRC32_POLY : 0); + crc_table[i] = s; + } +} + +static __forceinline uint32 crc32_update(uint32 crc, uint8 byte) +{ + return (crc << 8) ^ crc_table[byte ^ (crc >> 24)]; +} + + +// used in setup, and for huffman that doesn't go fast path +static unsigned int bit_reverse(unsigned int n) +{ + n = ((n & 0xAAAAAAAA) >> 1) | ((n & 0x55555555) << 1); + n = ((n & 0xCCCCCCCC) >> 2) | ((n & 0x33333333) << 2); + n = ((n & 0xF0F0F0F0) >> 4) | ((n & 0x0F0F0F0F) << 4); + n = ((n & 0xFF00FF00) >> 8) | ((n & 0x00FF00FF) << 8); + return (n >> 16) | (n << 16); +} + +static float square(float x) +{ + return x*x; +} + +// this is a weird definition of log2() for which log2(1) = 1, log2(2) = 2, log2(4) = 3 +// as required by the specification. fast(?) implementation from stb.h +// @OPTIMIZE: called multiple times per-packet with "constants"; move to setup +static int ilog(int32 n) +{ + static signed char log2_4[16] = { 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4 }; + + // 2 compares if n < 16, 3 compares otherwise (4 if signed or n > 1<<29) + if (n < (1 << 14)) + if (n < (1 << 4)) return 0 + log2_4[n ]; + else if (n < (1 << 9)) return 5 + log2_4[n >> 5]; + else return 10 + log2_4[n >> 10]; + else if (n < (1 << 24)) + if (n < (1 << 19)) return 15 + log2_4[n >> 15]; + else return 20 + log2_4[n >> 20]; + else if (n < (1 << 29)) return 25 + log2_4[n >> 25]; + else if (n < (1 << 31)) return 30 + log2_4[n >> 30]; + else return 0; // signed n returns 0 +} + +#ifndef M_PI + #define M_PI 3.14159265358979323846264f // from CRC +#endif + +// code length assigned to a value with no huffman encoding +#define NO_CODE 255 + +/////////////////////// LEAF SETUP FUNCTIONS ////////////////////////// +// +// these functions are only called at setup, and only a few times +// per file + +static float float32_unpack(uint32 x) +{ + // from the specification + uint32 mantissa = x & 0x1fffff; + uint32 sign = x & 0x80000000; + uint32 exp = (x & 0x7fe00000) >> 21; + double res = sign ? -(double)mantissa : (double)mantissa; + return (float) ldexp((float)res, exp-788); +} + + +// zlib & jpeg huffman tables assume that the output symbols +// can either be arbitrarily arranged, or have monotonically +// increasing frequencies--they rely on the lengths being sorted; +// this makes for a very simple generation algorithm. +// vorbis allows a huffman table with non-sorted lengths. This +// requires a more sophisticated construction, since symbols in +// order do not map to huffman codes "in order". +static void add_entry(Codebook *c, uint32 huff_code, int symbol, int count, int len, uint32 *values) +{ + if (!c->sparse) { + c->codewords [symbol] = huff_code; + } else { + c->codewords [count] = huff_code; + c->codeword_lengths[count] = len; + values [count] = symbol; + } +} + +static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values) +{ + int i,k,m=0; + uint32 available[32]; + + memset(available, 0, sizeof(available)); + // find the first entry + for (k=0; k < n; ++k) if (len[k] < NO_CODE) break; + if (k == n) { assert(c->sorted_entries == 0); return TRUE; } + // add to the list + add_entry(c, 0, k, m++, len[k], values); + // add all available leaves + for (i=1; i <= len[k]; ++i) + available[i] = 1U << (32-i); + // note that the above code treats the first case specially, + // but it's really the same as the following code, so they + // could probably be combined (except the initial code is 0, + // and I use 0 in available[] to mean 'empty') + for (i=k+1; i < n; ++i) { + uint32 res; + int z = len[i], y; + if (z == NO_CODE) continue; + // find lowest available leaf (should always be earliest, + // which is what the specification calls for) + // note that this property, and the fact we can never have + // more than one free leaf at a given level, isn't totally + // trivial to prove, but it seems true and the assert never + // fires, so! + while (z > 0 && !available[z]) --z; + if (z == 0) { return FALSE; } + res = available[z]; + assert(z >= 0 && z < 32); + available[z] = 0; + add_entry(c, bit_reverse(res), i, m++, len[i], values); + // propogate availability up the tree + if (z != len[i]) { + assert(len[i] >= 0 && len[i] < 32); + for (y=len[i]; y > z; --y) { + assert(available[y] == 0); + available[y] = res + (1 << (32-y)); + } + } + } + return TRUE; +} + +// accelerated huffman table allows fast O(1) match of all symbols +// of length <= STB_VORBIS_FAST_HUFFMAN_LENGTH +static void compute_accelerated_huffman(Codebook *c) +{ + int i, len; + for (i=0; i < FAST_HUFFMAN_TABLE_SIZE; ++i) + c->fast_huffman[i] = -1; + + len = c->sparse ? c->sorted_entries : c->entries; + #ifdef STB_VORBIS_FAST_HUFFMAN_SHORT + if (len > 32767) len = 32767; // largest possible value we can encode! + #endif + for (i=0; i < len; ++i) { + if (c->codeword_lengths[i] <= STB_VORBIS_FAST_HUFFMAN_LENGTH) { + uint32 z = c->sparse ? bit_reverse(c->sorted_codewords[i]) : c->codewords[i]; + // set table entries for all bit combinations in the higher bits + while (z < FAST_HUFFMAN_TABLE_SIZE) { + c->fast_huffman[z] = i; + z += 1 << c->codeword_lengths[i]; + } + } + } +} + +#ifdef _MSC_VER +#define STBV_CDECL __cdecl +#else +#define STBV_CDECL +#endif + +static int STBV_CDECL uint32_compare(const void *p, const void *q) +{ + uint32 x = * (uint32 *) p; + uint32 y = * (uint32 *) q; + return x < y ? -1 : x > y; +} + +static int include_in_sort(Codebook *c, uint8 len) +{ + if (c->sparse) { assert(len != NO_CODE); return TRUE; } + if (len == NO_CODE) return FALSE; + if (len > STB_VORBIS_FAST_HUFFMAN_LENGTH) return TRUE; + return FALSE; +} + +// if the fast table above doesn't work, we want to binary +// search them... need to reverse the bits +static void compute_sorted_huffman(Codebook *c, uint8 *lengths, uint32 *values) +{ + int i, len; + // build a list of all the entries + // OPTIMIZATION: don't include the short ones, since they'll be caught by FAST_HUFFMAN. + // this is kind of a frivolous optimization--I don't see any performance improvement, + // but it's like 4 extra lines of code, so. + if (!c->sparse) { + int k = 0; + for (i=0; i < c->entries; ++i) + if (include_in_sort(c, lengths[i])) + c->sorted_codewords[k++] = bit_reverse(c->codewords[i]); + assert(k == c->sorted_entries); + } else { + for (i=0; i < c->sorted_entries; ++i) + c->sorted_codewords[i] = bit_reverse(c->codewords[i]); + } + + qsort(c->sorted_codewords, c->sorted_entries, sizeof(c->sorted_codewords[0]), uint32_compare); + c->sorted_codewords[c->sorted_entries] = 0xffffffff; + + len = c->sparse ? c->sorted_entries : c->entries; + // now we need to indicate how they correspond; we could either + // #1: sort a different data structure that says who they correspond to + // #2: for each sorted entry, search the original list to find who corresponds + // #3: for each original entry, find the sorted entry + // #1 requires extra storage, #2 is slow, #3 can use binary search! + for (i=0; i < len; ++i) { + int huff_len = c->sparse ? lengths[values[i]] : lengths[i]; + if (include_in_sort(c,huff_len)) { + uint32 code = bit_reverse(c->codewords[i]); + int x=0, n=c->sorted_entries; + while (n > 1) { + // invariant: sc[x] <= code < sc[x+n] + int m = x + (n >> 1); + if (c->sorted_codewords[m] <= code) { + x = m; + n -= (n>>1); + } else { + n >>= 1; + } + } + assert(c->sorted_codewords[x] == code); + if (c->sparse) { + c->sorted_values[x] = values[i]; + c->codeword_lengths[x] = huff_len; + } else { + c->sorted_values[x] = i; + } + } + } +} + +// only run while parsing the header (3 times) +static int vorbis_validate(uint8 *data) +{ + static uint8 vorbis[6] = { 'v', 'o', 'r', 'b', 'i', 's' }; + return memcmp(data, vorbis, 6) == 0; +} + +// called from setup only, once per code book +// (formula implied by specification) +static int lookup1_values(int entries, int dim) +{ + int r = (int) floor(exp((float) log((float) entries) / dim)); + if ((int) floor(pow((float) r+1, dim)) <= entries) // (int) cast for MinGW warning; + ++r; // floor() to avoid _ftol() when non-CRT + assert(pow((float) r+1, dim) > entries); + assert((int) floor(pow((float) r, dim)) <= entries); // (int),floor() as above + return r; +} + +// called twice per file +static void compute_twiddle_factors(int n, float *A, float *B, float *C) +{ + int n4 = n >> 2, n8 = n >> 3; + int k,k2; + + for (k=k2=0; k < n4; ++k,k2+=2) { + A[k2 ] = (float) cos(4*k*M_PI/n); + A[k2+1] = (float) -sin(4*k*M_PI/n); + B[k2 ] = (float) cos((k2+1)*M_PI/n/2) * 0.5f; + B[k2+1] = (float) sin((k2+1)*M_PI/n/2) * 0.5f; + } + for (k=k2=0; k < n8; ++k,k2+=2) { + C[k2 ] = (float) cos(2*(k2+1)*M_PI/n); + C[k2+1] = (float) -sin(2*(k2+1)*M_PI/n); + } +} + +static void compute_window(int n, float *window) +{ + int n2 = n >> 1, i; + for (i=0; i < n2; ++i) + window[i] = (float) sin(0.5 * M_PI * square((float) sin((i - 0 + 0.5) / n2 * 0.5 * M_PI))); +} + +static void compute_bitreverse(int n, uint16 *rev) +{ + int ld = ilog(n) - 1; // ilog is off-by-one from normal definitions + int i, n8 = n >> 3; + for (i=0; i < n8; ++i) + rev[i] = (bit_reverse(i) >> (32-ld+3)) << 2; +} + +static int init_blocksize(vorb *f, int b, int n) +{ + int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3; + f->A[b] = (float *) setup_malloc(f, sizeof(float) * n2); + f->B[b] = (float *) setup_malloc(f, sizeof(float) * n2); + f->C[b] = (float *) setup_malloc(f, sizeof(float) * n4); + if (!f->A[b] || !f->B[b] || !f->C[b]) return error(f, VORBIS_outofmem); + compute_twiddle_factors(n, f->A[b], f->B[b], f->C[b]); + f->window[b] = (float *) setup_malloc(f, sizeof(float) * n2); + if (!f->window[b]) return error(f, VORBIS_outofmem); + compute_window(n, f->window[b]); + f->bit_reverse[b] = (uint16 *) setup_malloc(f, sizeof(uint16) * n8); + if (!f->bit_reverse[b]) return error(f, VORBIS_outofmem); + compute_bitreverse(n, f->bit_reverse[b]); + return TRUE; +} + +static void neighbors(uint16 *x, int n, int *plow, int *phigh) +{ + int low = -1; + int high = 65536; + int i; + for (i=0; i < n; ++i) { + if (x[i] > low && x[i] < x[n]) { *plow = i; low = x[i]; } + if (x[i] < high && x[i] > x[n]) { *phigh = i; high = x[i]; } + } +} + +// this has been repurposed so y is now the original index instead of y +typedef struct +{ + uint16 x,y; +} Point; + +static int STBV_CDECL point_compare(const void *p, const void *q) +{ + Point *a = (Point *) p; + Point *b = (Point *) q; + return a->x < b->x ? -1 : a->x > b->x; +} + +// +/////////////////////// END LEAF SETUP FUNCTIONS ////////////////////////// + + +#if defined(STB_VORBIS_NO_STDIO) + #define USE_MEMORY(z) TRUE +#else + #define USE_MEMORY(z) ((z)->stream) +#endif + +static uint8 get8(vorb *z) +{ + if (USE_MEMORY(z)) { + if (z->stream >= z->stream_end) { z->eof = TRUE; return 0; } + return *z->stream++; + } + + #ifndef STB_VORBIS_NO_STDIO + { + int c = fgetc(z->f); + if (c == EOF) { z->eof = TRUE; return 0; } + return c; + } + #endif +} + +static uint32 get32(vorb *f) +{ + uint32 x; + x = get8(f); + x += get8(f) << 8; + x += get8(f) << 16; + x += (uint32) get8(f) << 24; + return x; +} + +static int getn(vorb *z, uint8 *data, int n) +{ + if (USE_MEMORY(z)) { + if (z->stream+n > z->stream_end) { z->eof = 1; return 0; } + memcpy(data, z->stream, n); + z->stream += n; + return 1; + } + + #ifndef STB_VORBIS_NO_STDIO + if (fread(data, n, 1, z->f) == 1) + return 1; + else { + z->eof = 1; + return 0; + } + #endif +} + +static void skip(vorb *z, int n) +{ + if (USE_MEMORY(z)) { + z->stream += n; + if (z->stream >= z->stream_end) z->eof = 1; + return; + } + #ifndef STB_VORBIS_NO_STDIO + { + long x = ftell(z->f); + fseek(z->f, x+n, SEEK_SET); + } + #endif +} + +static int set_file_offset(stb_vorbis *f, unsigned int loc) +{ + #ifndef STB_VORBIS_NO_PUSHDATA_API + if (f->push_mode) return 0; + #endif + f->eof = 0; + if (USE_MEMORY(f)) { + if (f->stream_start + loc >= f->stream_end || f->stream_start + loc < f->stream_start) { + f->stream = f->stream_end; + f->eof = 1; + return 0; + } else { + f->stream = f->stream_start + loc; + return 1; + } + } + #ifndef STB_VORBIS_NO_STDIO + if (loc + f->f_start < loc || loc >= 0x80000000) { + loc = 0x7fffffff; + f->eof = 1; + } else { + loc += f->f_start; + } + if (!fseek(f->f, loc, SEEK_SET)) + return 1; + f->eof = 1; + fseek(f->f, f->f_start, SEEK_END); + return 0; + #endif +} + + +static uint8 ogg_page_header[4] = { 0x4f, 0x67, 0x67, 0x53 }; + +static int capture_pattern(vorb *f) +{ + if (0x4f != get8(f)) return FALSE; + if (0x67 != get8(f)) return FALSE; + if (0x67 != get8(f)) return FALSE; + if (0x53 != get8(f)) return FALSE; + return TRUE; +} + +#define PAGEFLAG_continued_packet 1 +#define PAGEFLAG_first_page 2 +#define PAGEFLAG_last_page 4 + +static int start_page_no_capturepattern(vorb *f) +{ + uint32 loc0,loc1,n; + // stream structure version + if (0 != get8(f)) return error(f, VORBIS_invalid_stream_structure_version); + // header flag + f->page_flag = get8(f); + // absolute granule position + loc0 = get32(f); + loc1 = get32(f); + // @TODO: validate loc0,loc1 as valid positions? + // stream serial number -- vorbis doesn't interleave, so discard + get32(f); + //if (f->serial != get32(f)) return error(f, VORBIS_incorrect_stream_serial_number); + // page sequence number + n = get32(f); + f->last_page = n; + // CRC32 + get32(f); + // page_segments + f->segment_count = get8(f); + if (!getn(f, f->segments, f->segment_count)) + return error(f, VORBIS_unexpected_eof); + // assume we _don't_ know any the sample position of any segments + f->end_seg_with_known_loc = -2; + if (loc0 != ~0U || loc1 != ~0U) { + int i; + // determine which packet is the last one that will complete + for (i=f->segment_count-1; i >= 0; --i) + if (f->segments[i] < 255) + break; + // 'i' is now the index of the _last_ segment of a packet that ends + if (i >= 0) { + f->end_seg_with_known_loc = i; + f->known_loc_for_packet = loc0; + } + } + if (f->first_decode) { + int i,len; + ProbedPage p; + len = 0; + for (i=0; i < f->segment_count; ++i) + len += f->segments[i]; + len += 27 + f->segment_count; + p.page_start = f->first_audio_page_offset; + p.page_end = p.page_start + len; + p.last_decoded_sample = loc0; + f->p_first = p; + } + f->next_seg = 0; + return TRUE; +} + +static int start_page(vorb *f) +{ + if (!capture_pattern(f)) return error(f, VORBIS_missing_capture_pattern); + return start_page_no_capturepattern(f); +} + +static int start_packet(vorb *f) +{ + while (f->next_seg == -1) { + if (!start_page(f)) return FALSE; + if (f->page_flag & PAGEFLAG_continued_packet) + return error(f, VORBIS_continued_packet_flag_invalid); + } + f->last_seg = FALSE; + f->valid_bits = 0; + f->packet_bytes = 0; + f->bytes_in_seg = 0; + // f->next_seg is now valid + return TRUE; +} + +static int maybe_start_packet(vorb *f) +{ + if (f->next_seg == -1) { + int x = get8(f); + if (f->eof) return FALSE; // EOF at page boundary is not an error! + if (0x4f != x ) return error(f, VORBIS_missing_capture_pattern); + if (0x67 != get8(f)) return error(f, VORBIS_missing_capture_pattern); + if (0x67 != get8(f)) return error(f, VORBIS_missing_capture_pattern); + if (0x53 != get8(f)) return error(f, VORBIS_missing_capture_pattern); + if (!start_page_no_capturepattern(f)) return FALSE; + if (f->page_flag & PAGEFLAG_continued_packet) { + // set up enough state that we can read this packet if we want, + // e.g. during recovery + f->last_seg = FALSE; + f->bytes_in_seg = 0; + return error(f, VORBIS_continued_packet_flag_invalid); + } + } + return start_packet(f); +} + +static int next_segment(vorb *f) +{ + int len; + if (f->last_seg) return 0; + if (f->next_seg == -1) { + f->last_seg_which = f->segment_count-1; // in case start_page fails + if (!start_page(f)) { f->last_seg = 1; return 0; } + if (!(f->page_flag & PAGEFLAG_continued_packet)) return error(f, VORBIS_continued_packet_flag_invalid); + } + len = f->segments[f->next_seg++]; + if (len < 255) { + f->last_seg = TRUE; + f->last_seg_which = f->next_seg-1; + } + if (f->next_seg >= f->segment_count) + f->next_seg = -1; + assert(f->bytes_in_seg == 0); + f->bytes_in_seg = len; + return len; +} + +#define EOP (-1) +#define INVALID_BITS (-1) + +static int get8_packet_raw(vorb *f) +{ + if (!f->bytes_in_seg) { // CLANG! + if (f->last_seg) return EOP; + else if (!next_segment(f)) return EOP; + } + assert(f->bytes_in_seg > 0); + --f->bytes_in_seg; + ++f->packet_bytes; + return get8(f); +} + +static int get8_packet(vorb *f) +{ + int x = get8_packet_raw(f); + f->valid_bits = 0; + return x; +} + +static void flush_packet(vorb *f) +{ + while (get8_packet_raw(f) != EOP); +} + +// @OPTIMIZE: this is the secondary bit decoder, so it's probably not as important +// as the huffman decoder? +static uint32 get_bits(vorb *f, int n) +{ + uint32 z; + + if (f->valid_bits < 0) return 0; + if (f->valid_bits < n) { + if (n > 24) { + // the accumulator technique below would not work correctly in this case + z = get_bits(f, 24); + z += get_bits(f, n-24) << 24; + return z; + } + if (f->valid_bits == 0) f->acc = 0; + while (f->valid_bits < n) { + int z = get8_packet_raw(f); + if (z == EOP) { + f->valid_bits = INVALID_BITS; + return 0; + } + f->acc += z << f->valid_bits; + f->valid_bits += 8; + } + } + if (f->valid_bits < 0) return 0; + z = f->acc & ((1 << n)-1); + f->acc >>= n; + f->valid_bits -= n; + return z; +} + +// @OPTIMIZE: primary accumulator for huffman +// expand the buffer to as many bits as possible without reading off end of packet +// it might be nice to allow f->valid_bits and f->acc to be stored in registers, +// e.g. cache them locally and decode locally +static __forceinline void prep_huffman(vorb *f) +{ + if (f->valid_bits <= 24) { + if (f->valid_bits == 0) f->acc = 0; + do { + int z; + if (f->last_seg && !f->bytes_in_seg) return; + z = get8_packet_raw(f); + if (z == EOP) return; + f->acc += (unsigned) z << f->valid_bits; + f->valid_bits += 8; + } while (f->valid_bits <= 24); + } +} + +enum +{ + VORBIS_packet_id = 1, + VORBIS_packet_comment = 3, + VORBIS_packet_setup = 5 +}; + +static int codebook_decode_scalar_raw(vorb *f, Codebook *c) +{ + int i; + prep_huffman(f); + + if (c->codewords == NULL && c->sorted_codewords == NULL) + return -1; + + // cases to use binary search: sorted_codewords && !c->codewords + // sorted_codewords && c->entries > 8 + if (c->entries > 8 ? c->sorted_codewords!=NULL : !c->codewords) { + // binary search + uint32 code = bit_reverse(f->acc); + int x=0, n=c->sorted_entries, len; + + while (n > 1) { + // invariant: sc[x] <= code < sc[x+n] + int m = x + (n >> 1); + if (c->sorted_codewords[m] <= code) { + x = m; + n -= (n>>1); + } else { + n >>= 1; + } + } + // x is now the sorted index + if (!c->sparse) x = c->sorted_values[x]; + // x is now sorted index if sparse, or symbol otherwise + len = c->codeword_lengths[x]; + if (f->valid_bits >= len) { + f->acc >>= len; + f->valid_bits -= len; + return x; + } + + f->valid_bits = 0; + return -1; + } + + // if small, linear search + assert(!c->sparse); + for (i=0; i < c->entries; ++i) { + if (c->codeword_lengths[i] == NO_CODE) continue; + if (c->codewords[i] == (f->acc & ((1 << c->codeword_lengths[i])-1))) { + if (f->valid_bits >= c->codeword_lengths[i]) { + f->acc >>= c->codeword_lengths[i]; + f->valid_bits -= c->codeword_lengths[i]; + return i; + } + f->valid_bits = 0; + return -1; + } + } + + error(f, VORBIS_invalid_stream); + f->valid_bits = 0; + return -1; +} + +#ifndef STB_VORBIS_NO_INLINE_DECODE + +#define DECODE_RAW(var, f,c) \ + if (f->valid_bits < STB_VORBIS_FAST_HUFFMAN_LENGTH) \ + prep_huffman(f); \ + var = f->acc & FAST_HUFFMAN_TABLE_MASK; \ + var = c->fast_huffman[var]; \ + if (var >= 0) { \ + int n = c->codeword_lengths[var]; \ + f->acc >>= n; \ + f->valid_bits -= n; \ + if (f->valid_bits < 0) { f->valid_bits = 0; var = -1; } \ + } else { \ + var = codebook_decode_scalar_raw(f,c); \ + } + +#else + +static int codebook_decode_scalar(vorb *f, Codebook *c) +{ + int i; + if (f->valid_bits < STB_VORBIS_FAST_HUFFMAN_LENGTH) + prep_huffman(f); + // fast huffman table lookup + i = f->acc & FAST_HUFFMAN_TABLE_MASK; + i = c->fast_huffman[i]; + if (i >= 0) { + f->acc >>= c->codeword_lengths[i]; + f->valid_bits -= c->codeword_lengths[i]; + if (f->valid_bits < 0) { f->valid_bits = 0; return -1; } + return i; + } + return codebook_decode_scalar_raw(f,c); +} + +#define DECODE_RAW(var,f,c) var = codebook_decode_scalar(f,c); + +#endif + +#define DECODE(var,f,c) \ + DECODE_RAW(var,f,c) \ + if (c->sparse) var = c->sorted_values[var]; + +#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK + #define DECODE_VQ(var,f,c) DECODE_RAW(var,f,c) +#else + #define DECODE_VQ(var,f,c) DECODE(var,f,c) +#endif + + + + + + +// CODEBOOK_ELEMENT_FAST is an optimization for the CODEBOOK_FLOATS case +// where we avoid one addition +#define CODEBOOK_ELEMENT(c,off) (c->multiplicands[off]) +#define CODEBOOK_ELEMENT_FAST(c,off) (c->multiplicands[off]) +#define CODEBOOK_ELEMENT_BASE(c) (0) + +static int codebook_decode_start(vorb *f, Codebook *c) +{ + int z = -1; + + // type 0 is only legal in a scalar context + if (c->lookup_type == 0) + error(f, VORBIS_invalid_stream); + else { + DECODE_VQ(z,f,c); + if (c->sparse) assert(z < c->sorted_entries); + if (z < 0) { // check for EOP + if (!f->bytes_in_seg) + if (f->last_seg) + return z; + error(f, VORBIS_invalid_stream); + } + } + return z; +} + +static int codebook_decode(vorb *f, Codebook *c, float *output, int len) +{ + int i,z = codebook_decode_start(f,c); + if (z < 0) return FALSE; + if (len > c->dimensions) len = c->dimensions; + +#ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK + if (c->lookup_type == 1) { + float last = CODEBOOK_ELEMENT_BASE(c); + int div = 1; + for (i=0; i < len; ++i) { + int off = (z / div) % c->lookup_values; + float val = CODEBOOK_ELEMENT_FAST(c,off) + last; + output[i] += val; + if (c->sequence_p) last = val + c->minimum_value; + div *= c->lookup_values; + } + return TRUE; + } +#endif + + z *= c->dimensions; + if (c->sequence_p) { + float last = CODEBOOK_ELEMENT_BASE(c); + for (i=0; i < len; ++i) { + float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last; + output[i] += val; + last = val + c->minimum_value; + } + } else { + float last = CODEBOOK_ELEMENT_BASE(c); + for (i=0; i < len; ++i) { + output[i] += CODEBOOK_ELEMENT_FAST(c,z+i) + last; + } + } + + return TRUE; +} + +static int codebook_decode_step(vorb *f, Codebook *c, float *output, int len, int step) +{ + int i,z = codebook_decode_start(f,c); + float last = CODEBOOK_ELEMENT_BASE(c); + if (z < 0) return FALSE; + if (len > c->dimensions) len = c->dimensions; + +#ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK + if (c->lookup_type == 1) { + int div = 1; + for (i=0; i < len; ++i) { + int off = (z / div) % c->lookup_values; + float val = CODEBOOK_ELEMENT_FAST(c,off) + last; + output[i*step] += val; + if (c->sequence_p) last = val; + div *= c->lookup_values; + } + return TRUE; + } +#endif + + z *= c->dimensions; + for (i=0; i < len; ++i) { + float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last; + output[i*step] += val; + if (c->sequence_p) last = val; + } + + return TRUE; +} + +static int codebook_decode_deinterleave_repeat(vorb *f, Codebook *c, float **outputs, int ch, int *c_inter_p, int *p_inter_p, int len, int total_decode) +{ + int c_inter = *c_inter_p; + int p_inter = *p_inter_p; + int i,z, effective = c->dimensions; + + // type 0 is only legal in a scalar context + if (c->lookup_type == 0) return error(f, VORBIS_invalid_stream); + + while (total_decode > 0) { + float last = CODEBOOK_ELEMENT_BASE(c); + DECODE_VQ(z,f,c); + #ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK + assert(!c->sparse || z < c->sorted_entries); + #endif + if (z < 0) { + if (!f->bytes_in_seg) + if (f->last_seg) return FALSE; + return error(f, VORBIS_invalid_stream); + } + + // if this will take us off the end of the buffers, stop short! + // we check by computing the length of the virtual interleaved + // buffer (len*ch), our current offset within it (p_inter*ch)+(c_inter), + // and the length we'll be using (effective) + if (c_inter + p_inter*ch + effective > len * ch) { + effective = len*ch - (p_inter*ch - c_inter); + } + + #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK + if (c->lookup_type == 1) { + int div = 1; + for (i=0; i < effective; ++i) { + int off = (z / div) % c->lookup_values; + float val = CODEBOOK_ELEMENT_FAST(c,off) + last; + if (outputs[c_inter]) + outputs[c_inter][p_inter] += val; + if (++c_inter == ch) { c_inter = 0; ++p_inter; } + if (c->sequence_p) last = val; + div *= c->lookup_values; + } + } else + #endif + { + z *= c->dimensions; + if (c->sequence_p) { + for (i=0; i < effective; ++i) { + float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last; + if (outputs[c_inter]) + outputs[c_inter][p_inter] += val; + if (++c_inter == ch) { c_inter = 0; ++p_inter; } + last = val; + } + } else { + for (i=0; i < effective; ++i) { + float val = CODEBOOK_ELEMENT_FAST(c,z+i) + last; + if (outputs[c_inter]) + outputs[c_inter][p_inter] += val; + if (++c_inter == ch) { c_inter = 0; ++p_inter; } + } + } + } + + total_decode -= effective; + } + *c_inter_p = c_inter; + *p_inter_p = p_inter; + return TRUE; +} + +static int predict_point(int x, int x0, int x1, int y0, int y1) +{ + int dy = y1 - y0; + int adx = x1 - x0; + // @OPTIMIZE: force int division to round in the right direction... is this necessary on x86? + int err = abs(dy) * (x - x0); + int off = err / adx; + return dy < 0 ? y0 - off : y0 + off; +} + +// the following table is block-copied from the specification +static float inverse_db_table[256] = +{ + 1.0649863e-07f, 1.1341951e-07f, 1.2079015e-07f, 1.2863978e-07f, + 1.3699951e-07f, 1.4590251e-07f, 1.5538408e-07f, 1.6548181e-07f, + 1.7623575e-07f, 1.8768855e-07f, 1.9988561e-07f, 2.1287530e-07f, + 2.2670913e-07f, 2.4144197e-07f, 2.5713223e-07f, 2.7384213e-07f, + 2.9163793e-07f, 3.1059021e-07f, 3.3077411e-07f, 3.5226968e-07f, + 3.7516214e-07f, 3.9954229e-07f, 4.2550680e-07f, 4.5315863e-07f, + 4.8260743e-07f, 5.1396998e-07f, 5.4737065e-07f, 5.8294187e-07f, + 6.2082472e-07f, 6.6116941e-07f, 7.0413592e-07f, 7.4989464e-07f, + 7.9862701e-07f, 8.5052630e-07f, 9.0579828e-07f, 9.6466216e-07f, + 1.0273513e-06f, 1.0941144e-06f, 1.1652161e-06f, 1.2409384e-06f, + 1.3215816e-06f, 1.4074654e-06f, 1.4989305e-06f, 1.5963394e-06f, + 1.7000785e-06f, 1.8105592e-06f, 1.9282195e-06f, 2.0535261e-06f, + 2.1869758e-06f, 2.3290978e-06f, 2.4804557e-06f, 2.6416497e-06f, + 2.8133190e-06f, 2.9961443e-06f, 3.1908506e-06f, 3.3982101e-06f, + 3.6190449e-06f, 3.8542308e-06f, 4.1047004e-06f, 4.3714470e-06f, + 4.6555282e-06f, 4.9580707e-06f, 5.2802740e-06f, 5.6234160e-06f, + 5.9888572e-06f, 6.3780469e-06f, 6.7925283e-06f, 7.2339451e-06f, + 7.7040476e-06f, 8.2047000e-06f, 8.7378876e-06f, 9.3057248e-06f, + 9.9104632e-06f, 1.0554501e-05f, 1.1240392e-05f, 1.1970856e-05f, + 1.2748789e-05f, 1.3577278e-05f, 1.4459606e-05f, 1.5399272e-05f, + 1.6400004e-05f, 1.7465768e-05f, 1.8600792e-05f, 1.9809576e-05f, + 2.1096914e-05f, 2.2467911e-05f, 2.3928002e-05f, 2.5482978e-05f, + 2.7139006e-05f, 2.8902651e-05f, 3.0780908e-05f, 3.2781225e-05f, + 3.4911534e-05f, 3.7180282e-05f, 3.9596466e-05f, 4.2169667e-05f, + 4.4910090e-05f, 4.7828601e-05f, 5.0936773e-05f, 5.4246931e-05f, + 5.7772202e-05f, 6.1526565e-05f, 6.5524908e-05f, 6.9783085e-05f, + 7.4317983e-05f, 7.9147585e-05f, 8.4291040e-05f, 8.9768747e-05f, + 9.5602426e-05f, 0.00010181521f, 0.00010843174f, 0.00011547824f, + 0.00012298267f, 0.00013097477f, 0.00013948625f, 0.00014855085f, + 0.00015820453f, 0.00016848555f, 0.00017943469f, 0.00019109536f, + 0.00020351382f, 0.00021673929f, 0.00023082423f, 0.00024582449f, + 0.00026179955f, 0.00027881276f, 0.00029693158f, 0.00031622787f, + 0.00033677814f, 0.00035866388f, 0.00038197188f, 0.00040679456f, + 0.00043323036f, 0.00046138411f, 0.00049136745f, 0.00052329927f, + 0.00055730621f, 0.00059352311f, 0.00063209358f, 0.00067317058f, + 0.00071691700f, 0.00076350630f, 0.00081312324f, 0.00086596457f, + 0.00092223983f, 0.00098217216f, 0.0010459992f, 0.0011139742f, + 0.0011863665f, 0.0012634633f, 0.0013455702f, 0.0014330129f, + 0.0015261382f, 0.0016253153f, 0.0017309374f, 0.0018434235f, + 0.0019632195f, 0.0020908006f, 0.0022266726f, 0.0023713743f, + 0.0025254795f, 0.0026895994f, 0.0028643847f, 0.0030505286f, + 0.0032487691f, 0.0034598925f, 0.0036847358f, 0.0039241906f, + 0.0041792066f, 0.0044507950f, 0.0047400328f, 0.0050480668f, + 0.0053761186f, 0.0057254891f, 0.0060975636f, 0.0064938176f, + 0.0069158225f, 0.0073652516f, 0.0078438871f, 0.0083536271f, + 0.0088964928f, 0.009474637f, 0.010090352f, 0.010746080f, + 0.011444421f, 0.012188144f, 0.012980198f, 0.013823725f, + 0.014722068f, 0.015678791f, 0.016697687f, 0.017782797f, + 0.018938423f, 0.020169149f, 0.021479854f, 0.022875735f, + 0.024362330f, 0.025945531f, 0.027631618f, 0.029427276f, + 0.031339626f, 0.033376252f, 0.035545228f, 0.037855157f, + 0.040315199f, 0.042935108f, 0.045725273f, 0.048696758f, + 0.051861348f, 0.055231591f, 0.058820850f, 0.062643361f, + 0.066714279f, 0.071049749f, 0.075666962f, 0.080584227f, + 0.085821044f, 0.091398179f, 0.097337747f, 0.10366330f, + 0.11039993f, 0.11757434f, 0.12521498f, 0.13335215f, + 0.14201813f, 0.15124727f, 0.16107617f, 0.17154380f, + 0.18269168f, 0.19456402f, 0.20720788f, 0.22067342f, + 0.23501402f, 0.25028656f, 0.26655159f, 0.28387361f, + 0.30232132f, 0.32196786f, 0.34289114f, 0.36517414f, + 0.38890521f, 0.41417847f, 0.44109412f, 0.46975890f, + 0.50028648f, 0.53279791f, 0.56742212f, 0.60429640f, + 0.64356699f, 0.68538959f, 0.72993007f, 0.77736504f, + 0.82788260f, 0.88168307f, 0.9389798f, 1.0f +}; + + +// @OPTIMIZE: if you want to replace this bresenham line-drawing routine, +// note that you must produce bit-identical output to decode correctly; +// this specific sequence of operations is specified in the spec (it's +// drawing integer-quantized frequency-space lines that the encoder +// expects to be exactly the same) +// ... also, isn't the whole point of Bresenham's algorithm to NOT +// have to divide in the setup? sigh. +#ifndef STB_VORBIS_NO_DEFER_FLOOR +#define LINE_OP(a,b) a *= b +#else +#define LINE_OP(a,b) a = b +#endif + +#ifdef STB_VORBIS_DIVIDE_TABLE +#define DIVTAB_NUMER 32 +#define DIVTAB_DENOM 64 +int8 integer_divide_table[DIVTAB_NUMER][DIVTAB_DENOM]; // 2KB +#endif + +static __forceinline void draw_line(float *output, int x0, int y0, int x1, int y1, int n) +{ + int dy = y1 - y0; + int adx = x1 - x0; + int ady = abs(dy); + int base; + int x=x0,y=y0; + int err = 0; + int sy; + +#ifdef STB_VORBIS_DIVIDE_TABLE + if (adx < DIVTAB_DENOM && ady < DIVTAB_NUMER) { + if (dy < 0) { + base = -integer_divide_table[ady][adx]; + sy = base-1; + } else { + base = integer_divide_table[ady][adx]; + sy = base+1; + } + } else { + base = dy / adx; + if (dy < 0) + sy = base - 1; + else + sy = base+1; + } +#else + base = dy / adx; + if (dy < 0) + sy = base - 1; + else + sy = base+1; +#endif + ady -= abs(base) * adx; + if (x1 > n) x1 = n; + if (x < x1) { + LINE_OP(output[x], inverse_db_table[y]); + for (++x; x < x1; ++x) { + err += ady; + if (err >= adx) { + err -= adx; + y += sy; + } else + y += base; + LINE_OP(output[x], inverse_db_table[y]); + } + } +} + +static int residue_decode(vorb *f, Codebook *book, float *target, int offset, int n, int rtype) +{ + int k; + if (rtype == 0) { + int step = n / book->dimensions; + for (k=0; k < step; ++k) + if (!codebook_decode_step(f, book, target+offset+k, n-offset-k, step)) + return FALSE; + } else { + for (k=0; k < n; ) { + if (!codebook_decode(f, book, target+offset, n-k)) + return FALSE; + k += book->dimensions; + offset += book->dimensions; + } + } + return TRUE; +} + +static void decode_residue(vorb *f, float *residue_buffers[], int ch, int n, int rn, uint8 *do_not_decode) +{ + int i,j,pass; + Residue *r = f->residue_config + rn; + int rtype = f->residue_types[rn]; + int c = r->classbook; + int classwords = f->codebooks[c].dimensions; + int n_read = r->end - r->begin; + int part_read = n_read / r->part_size; + int temp_alloc_point = temp_alloc_save(f); + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + uint8 ***part_classdata = (uint8 ***) temp_block_array(f,f->channels, part_read * sizeof(**part_classdata)); + #else + int **classifications = (int **) temp_block_array(f,f->channels, part_read * sizeof(**classifications)); + #endif + + CHECK(f); + + for (i=0; i < ch; ++i) + if (!do_not_decode[i]) + memset(residue_buffers[i], 0, sizeof(float) * n); + + if (rtype == 2 && ch != 1) { + for (j=0; j < ch; ++j) + if (!do_not_decode[j]) + break; + if (j == ch) + goto done; + + for (pass=0; pass < 8; ++pass) { + int pcount = 0, class_set = 0; + if (ch == 2) { + while (pcount < part_read) { + int z = r->begin + pcount*r->part_size; + int c_inter = (z & 1), p_inter = z>>1; + if (pass == 0) { + Codebook *c = f->codebooks+r->classbook; + int q; + DECODE(q,f,c); + if (q == EOP) goto done; + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + part_classdata[0][class_set] = r->classdata[q]; + #else + for (i=classwords-1; i >= 0; --i) { + classifications[0][i+pcount] = q % r->classifications; + q /= r->classifications; + } + #endif + } + for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) { + int z = r->begin + pcount*r->part_size; + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + int c = part_classdata[0][class_set][i]; + #else + int c = classifications[0][pcount]; + #endif + int b = r->residue_books[c][pass]; + if (b >= 0) { + Codebook *book = f->codebooks + b; + #ifdef STB_VORBIS_DIVIDES_IN_CODEBOOK + if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size)) + goto done; + #else + // saves 1% + if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size)) + goto done; + #endif + } else { + z += r->part_size; + c_inter = z & 1; + p_inter = z >> 1; + } + } + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + ++class_set; + #endif + } + } else if (ch == 1) { + while (pcount < part_read) { + int z = r->begin + pcount*r->part_size; + int c_inter = 0, p_inter = z; + if (pass == 0) { + Codebook *c = f->codebooks+r->classbook; + int q; + DECODE(q,f,c); + if (q == EOP) goto done; + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + part_classdata[0][class_set] = r->classdata[q]; + #else + for (i=classwords-1; i >= 0; --i) { + classifications[0][i+pcount] = q % r->classifications; + q /= r->classifications; + } + #endif + } + for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) { + int z = r->begin + pcount*r->part_size; + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + int c = part_classdata[0][class_set][i]; + #else + int c = classifications[0][pcount]; + #endif + int b = r->residue_books[c][pass]; + if (b >= 0) { + Codebook *book = f->codebooks + b; + if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size)) + goto done; + } else { + z += r->part_size; + c_inter = 0; + p_inter = z; + } + } + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + ++class_set; + #endif + } + } else { + while (pcount < part_read) { + int z = r->begin + pcount*r->part_size; + int c_inter = z % ch, p_inter = z/ch; + if (pass == 0) { + Codebook *c = f->codebooks+r->classbook; + int q; + DECODE(q,f,c); + if (q == EOP) goto done; + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + part_classdata[0][class_set] = r->classdata[q]; + #else + for (i=classwords-1; i >= 0; --i) { + classifications[0][i+pcount] = q % r->classifications; + q /= r->classifications; + } + #endif + } + for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) { + int z = r->begin + pcount*r->part_size; + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + int c = part_classdata[0][class_set][i]; + #else + int c = classifications[0][pcount]; + #endif + int b = r->residue_books[c][pass]; + if (b >= 0) { + Codebook *book = f->codebooks + b; + if (!codebook_decode_deinterleave_repeat(f, book, residue_buffers, ch, &c_inter, &p_inter, n, r->part_size)) + goto done; + } else { + z += r->part_size; + c_inter = z % ch; + p_inter = z / ch; + } + } + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + ++class_set; + #endif + } + } + } + goto done; + } + CHECK(f); + + for (pass=0; pass < 8; ++pass) { + int pcount = 0, class_set=0; + while (pcount < part_read) { + if (pass == 0) { + for (j=0; j < ch; ++j) { + if (!do_not_decode[j]) { + Codebook *c = f->codebooks+r->classbook; + int temp; + DECODE(temp,f,c); + if (temp == EOP) goto done; + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + part_classdata[j][class_set] = r->classdata[temp]; + #else + for (i=classwords-1; i >= 0; --i) { + classifications[j][i+pcount] = temp % r->classifications; + temp /= r->classifications; + } + #endif + } + } + } + for (i=0; i < classwords && pcount < part_read; ++i, ++pcount) { + for (j=0; j < ch; ++j) { + if (!do_not_decode[j]) { + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + int c = part_classdata[j][class_set][i]; + #else + int c = classifications[j][pcount]; + #endif + int b = r->residue_books[c][pass]; + if (b >= 0) { + float *target = residue_buffers[j]; + int offset = r->begin + pcount * r->part_size; + int n = r->part_size; + Codebook *book = f->codebooks + b; + if (!residue_decode(f, book, target, offset, n, rtype)) + goto done; + } + } + } + } + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + ++class_set; + #endif + } + } + done: + CHECK(f); + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + temp_free(f,part_classdata); + #else + temp_free(f,classifications); + #endif + temp_alloc_restore(f,temp_alloc_point); +} + + +#if 0 +// slow way for debugging +void inverse_mdct_slow(float *buffer, int n) +{ + int i,j; + int n2 = n >> 1; + float *x = (float *) malloc(sizeof(*x) * n2); + memcpy(x, buffer, sizeof(*x) * n2); + for (i=0; i < n; ++i) { + float acc = 0; + for (j=0; j < n2; ++j) + // formula from paper: + //acc += n/4.0f * x[j] * (float) cos(M_PI / 2 / n * (2 * i + 1 + n/2.0)*(2*j+1)); + // formula from wikipedia + //acc += 2.0f / n2 * x[j] * (float) cos(M_PI/n2 * (i + 0.5 + n2/2)*(j + 0.5)); + // these are equivalent, except the formula from the paper inverts the multiplier! + // however, what actually works is NO MULTIPLIER!?! + //acc += 64 * 2.0f / n2 * x[j] * (float) cos(M_PI/n2 * (i + 0.5 + n2/2)*(j + 0.5)); + acc += x[j] * (float) cos(M_PI / 2 / n * (2 * i + 1 + n/2.0)*(2*j+1)); + buffer[i] = acc; + } + free(x); +} +#elif 0 +// same as above, but just barely able to run in real time on modern machines +void inverse_mdct_slow(float *buffer, int n, vorb *f, int blocktype) +{ + float mcos[16384]; + int i,j; + int n2 = n >> 1, nmask = (n << 2) -1; + float *x = (float *) malloc(sizeof(*x) * n2); + memcpy(x, buffer, sizeof(*x) * n2); + for (i=0; i < 4*n; ++i) + mcos[i] = (float) cos(M_PI / 2 * i / n); + + for (i=0; i < n; ++i) { + float acc = 0; + for (j=0; j < n2; ++j) + acc += x[j] * mcos[(2 * i + 1 + n2)*(2*j+1) & nmask]; + buffer[i] = acc; + } + free(x); +} +#elif 0 +// transform to use a slow dct-iv; this is STILL basically trivial, +// but only requires half as many ops +void dct_iv_slow(float *buffer, int n) +{ + float mcos[16384]; + float x[2048]; + int i,j; + int n2 = n >> 1, nmask = (n << 3) - 1; + memcpy(x, buffer, sizeof(*x) * n); + for (i=0; i < 8*n; ++i) + mcos[i] = (float) cos(M_PI / 4 * i / n); + for (i=0; i < n; ++i) { + float acc = 0; + for (j=0; j < n; ++j) + acc += x[j] * mcos[((2 * i + 1)*(2*j+1)) & nmask]; + buffer[i] = acc; + } +} + +void inverse_mdct_slow(float *buffer, int n, vorb *f, int blocktype) +{ + int i, n4 = n >> 2, n2 = n >> 1, n3_4 = n - n4; + float temp[4096]; + + memcpy(temp, buffer, n2 * sizeof(float)); + dct_iv_slow(temp, n2); // returns -c'-d, a-b' + + for (i=0; i < n4 ; ++i) buffer[i] = temp[i+n4]; // a-b' + for ( ; i < n3_4; ++i) buffer[i] = -temp[n3_4 - i - 1]; // b-a', c+d' + for ( ; i < n ; ++i) buffer[i] = -temp[i - n3_4]; // c'+d +} +#endif + +#ifndef LIBVORBIS_MDCT +#define LIBVORBIS_MDCT 0 +#endif + +#if LIBVORBIS_MDCT +// directly call the vorbis MDCT using an interface documented +// by Jeff Roberts... useful for performance comparison +typedef struct +{ + int n; + int log2n; + + float *trig; + int *bitrev; + + float scale; +} mdct_lookup; + +extern void mdct_init(mdct_lookup *lookup, int n); +extern void mdct_clear(mdct_lookup *l); +extern void mdct_backward(mdct_lookup *init, float *in, float *out); + +mdct_lookup M1,M2; + +void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) +{ + mdct_lookup *M; + if (M1.n == n) M = &M1; + else if (M2.n == n) M = &M2; + else if (M1.n == 0) { mdct_init(&M1, n); M = &M1; } + else { + if (M2.n) __asm int 3; + mdct_init(&M2, n); + M = &M2; + } + + mdct_backward(M, buffer, buffer); +} +#endif + + +// the following were split out into separate functions while optimizing; +// they could be pushed back up but eh. __forceinline showed no change; +// they're probably already being inlined. +static void imdct_step3_iter0_loop(int n, float *e, int i_off, int k_off, float *A) +{ + float *ee0 = e + i_off; + float *ee2 = ee0 + k_off; + int i; + + assert((n & 3) == 0); + for (i=(n>>2); i > 0; --i) { + float k00_20, k01_21; + k00_20 = ee0[ 0] - ee2[ 0]; + k01_21 = ee0[-1] - ee2[-1]; + ee0[ 0] += ee2[ 0];//ee0[ 0] = ee0[ 0] + ee2[ 0]; + ee0[-1] += ee2[-1];//ee0[-1] = ee0[-1] + ee2[-1]; + ee2[ 0] = k00_20 * A[0] - k01_21 * A[1]; + ee2[-1] = k01_21 * A[0] + k00_20 * A[1]; + A += 8; + + k00_20 = ee0[-2] - ee2[-2]; + k01_21 = ee0[-3] - ee2[-3]; + ee0[-2] += ee2[-2];//ee0[-2] = ee0[-2] + ee2[-2]; + ee0[-3] += ee2[-3];//ee0[-3] = ee0[-3] + ee2[-3]; + ee2[-2] = k00_20 * A[0] - k01_21 * A[1]; + ee2[-3] = k01_21 * A[0] + k00_20 * A[1]; + A += 8; + + k00_20 = ee0[-4] - ee2[-4]; + k01_21 = ee0[-5] - ee2[-5]; + ee0[-4] += ee2[-4];//ee0[-4] = ee0[-4] + ee2[-4]; + ee0[-5] += ee2[-5];//ee0[-5] = ee0[-5] + ee2[-5]; + ee2[-4] = k00_20 * A[0] - k01_21 * A[1]; + ee2[-5] = k01_21 * A[0] + k00_20 * A[1]; + A += 8; + + k00_20 = ee0[-6] - ee2[-6]; + k01_21 = ee0[-7] - ee2[-7]; + ee0[-6] += ee2[-6];//ee0[-6] = ee0[-6] + ee2[-6]; + ee0[-7] += ee2[-7];//ee0[-7] = ee0[-7] + ee2[-7]; + ee2[-6] = k00_20 * A[0] - k01_21 * A[1]; + ee2[-7] = k01_21 * A[0] + k00_20 * A[1]; + A += 8; + ee0 -= 8; + ee2 -= 8; + } +} + +static void imdct_step3_inner_r_loop(int lim, float *e, int d0, int k_off, float *A, int k1) +{ + int i; + float k00_20, k01_21; + + float *e0 = e + d0; + float *e2 = e0 + k_off; + + for (i=lim >> 2; i > 0; --i) { + k00_20 = e0[-0] - e2[-0]; + k01_21 = e0[-1] - e2[-1]; + e0[-0] += e2[-0];//e0[-0] = e0[-0] + e2[-0]; + e0[-1] += e2[-1];//e0[-1] = e0[-1] + e2[-1]; + e2[-0] = (k00_20)*A[0] - (k01_21) * A[1]; + e2[-1] = (k01_21)*A[0] + (k00_20) * A[1]; + + A += k1; + + k00_20 = e0[-2] - e2[-2]; + k01_21 = e0[-3] - e2[-3]; + e0[-2] += e2[-2];//e0[-2] = e0[-2] + e2[-2]; + e0[-3] += e2[-3];//e0[-3] = e0[-3] + e2[-3]; + e2[-2] = (k00_20)*A[0] - (k01_21) * A[1]; + e2[-3] = (k01_21)*A[0] + (k00_20) * A[1]; + + A += k1; + + k00_20 = e0[-4] - e2[-4]; + k01_21 = e0[-5] - e2[-5]; + e0[-4] += e2[-4];//e0[-4] = e0[-4] + e2[-4]; + e0[-5] += e2[-5];//e0[-5] = e0[-5] + e2[-5]; + e2[-4] = (k00_20)*A[0] - (k01_21) * A[1]; + e2[-5] = (k01_21)*A[0] + (k00_20) * A[1]; + + A += k1; + + k00_20 = e0[-6] - e2[-6]; + k01_21 = e0[-7] - e2[-7]; + e0[-6] += e2[-6];//e0[-6] = e0[-6] + e2[-6]; + e0[-7] += e2[-7];//e0[-7] = e0[-7] + e2[-7]; + e2[-6] = (k00_20)*A[0] - (k01_21) * A[1]; + e2[-7] = (k01_21)*A[0] + (k00_20) * A[1]; + + e0 -= 8; + e2 -= 8; + + A += k1; + } +} + +static void imdct_step3_inner_s_loop(int n, float *e, int i_off, int k_off, float *A, int a_off, int k0) +{ + int i; + float A0 = A[0]; + float A1 = A[0+1]; + float A2 = A[0+a_off]; + float A3 = A[0+a_off+1]; + float A4 = A[0+a_off*2+0]; + float A5 = A[0+a_off*2+1]; + float A6 = A[0+a_off*3+0]; + float A7 = A[0+a_off*3+1]; + + float k00,k11; + + float *ee0 = e +i_off; + float *ee2 = ee0+k_off; + + for (i=n; i > 0; --i) { + k00 = ee0[ 0] - ee2[ 0]; + k11 = ee0[-1] - ee2[-1]; + ee0[ 0] = ee0[ 0] + ee2[ 0]; + ee0[-1] = ee0[-1] + ee2[-1]; + ee2[ 0] = (k00) * A0 - (k11) * A1; + ee2[-1] = (k11) * A0 + (k00) * A1; + + k00 = ee0[-2] - ee2[-2]; + k11 = ee0[-3] - ee2[-3]; + ee0[-2] = ee0[-2] + ee2[-2]; + ee0[-3] = ee0[-3] + ee2[-3]; + ee2[-2] = (k00) * A2 - (k11) * A3; + ee2[-3] = (k11) * A2 + (k00) * A3; + + k00 = ee0[-4] - ee2[-4]; + k11 = ee0[-5] - ee2[-5]; + ee0[-4] = ee0[-4] + ee2[-4]; + ee0[-5] = ee0[-5] + ee2[-5]; + ee2[-4] = (k00) * A4 - (k11) * A5; + ee2[-5] = (k11) * A4 + (k00) * A5; + + k00 = ee0[-6] - ee2[-6]; + k11 = ee0[-7] - ee2[-7]; + ee0[-6] = ee0[-6] + ee2[-6]; + ee0[-7] = ee0[-7] + ee2[-7]; + ee2[-6] = (k00) * A6 - (k11) * A7; + ee2[-7] = (k11) * A6 + (k00) * A7; + + ee0 -= k0; + ee2 -= k0; + } +} + +static __forceinline void iter_54(float *z) +{ + float k00,k11,k22,k33; + float y0,y1,y2,y3; + + k00 = z[ 0] - z[-4]; + y0 = z[ 0] + z[-4]; + y2 = z[-2] + z[-6]; + k22 = z[-2] - z[-6]; + + z[-0] = y0 + y2; // z0 + z4 + z2 + z6 + z[-2] = y0 - y2; // z0 + z4 - z2 - z6 + + // done with y0,y2 + + k33 = z[-3] - z[-7]; + + z[-4] = k00 + k33; // z0 - z4 + z3 - z7 + z[-6] = k00 - k33; // z0 - z4 - z3 + z7 + + // done with k33 + + k11 = z[-1] - z[-5]; + y1 = z[-1] + z[-5]; + y3 = z[-3] + z[-7]; + + z[-1] = y1 + y3; // z1 + z5 + z3 + z7 + z[-3] = y1 - y3; // z1 + z5 - z3 - z7 + z[-5] = k11 - k22; // z1 - z5 + z2 - z6 + z[-7] = k11 + k22; // z1 - z5 - z2 + z6 +} + +static void imdct_step3_inner_s_loop_ld654(int n, float *e, int i_off, float *A, int base_n) +{ + int a_off = base_n >> 3; + float A2 = A[0+a_off]; + float *z = e + i_off; + float *base = z - 16 * n; + + while (z > base) { + float k00,k11; + + k00 = z[-0] - z[-8]; + k11 = z[-1] - z[-9]; + z[-0] = z[-0] + z[-8]; + z[-1] = z[-1] + z[-9]; + z[-8] = k00; + z[-9] = k11 ; + + k00 = z[ -2] - z[-10]; + k11 = z[ -3] - z[-11]; + z[ -2] = z[ -2] + z[-10]; + z[ -3] = z[ -3] + z[-11]; + z[-10] = (k00+k11) * A2; + z[-11] = (k11-k00) * A2; + + k00 = z[-12] - z[ -4]; // reverse to avoid a unary negation + k11 = z[ -5] - z[-13]; + z[ -4] = z[ -4] + z[-12]; + z[ -5] = z[ -5] + z[-13]; + z[-12] = k11; + z[-13] = k00; + + k00 = z[-14] - z[ -6]; // reverse to avoid a unary negation + k11 = z[ -7] - z[-15]; + z[ -6] = z[ -6] + z[-14]; + z[ -7] = z[ -7] + z[-15]; + z[-14] = (k00+k11) * A2; + z[-15] = (k00-k11) * A2; + + iter_54(z); + iter_54(z-8); + z -= 16; + } +} + +static void inverse_mdct(float *buffer, int n, vorb *f, int blocktype) +{ + int n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l; + int ld; + // @OPTIMIZE: reduce register pressure by using fewer variables? + int save_point = temp_alloc_save(f); + float *buf2 = (float *) temp_alloc(f, n2 * sizeof(*buf2)); + float *u=NULL,*v=NULL; + // twiddle factors + float *A = f->A[blocktype]; + + // IMDCT algorithm from "The use of multirate filter banks for coding of high quality digital audio" + // See notes about bugs in that paper in less-optimal implementation 'inverse_mdct_old' after this function. + + // kernel from paper + + + // merged: + // copy and reflect spectral data + // step 0 + + // note that it turns out that the items added together during + // this step are, in fact, being added to themselves (as reflected + // by step 0). inexplicable inefficiency! this became obvious + // once I combined the passes. + + // so there's a missing 'times 2' here (for adding X to itself). + // this propogates through linearly to the end, where the numbers + // are 1/2 too small, and need to be compensated for. + + { + float *d,*e, *AA, *e_stop; + d = &buf2[n2-2]; + AA = A; + e = &buffer[0]; + e_stop = &buffer[n2]; + while (e != e_stop) { + d[1] = (e[0] * AA[0] - e[2]*AA[1]); + d[0] = (e[0] * AA[1] + e[2]*AA[0]); + d -= 2; + AA += 2; + e += 4; + } + + e = &buffer[n2-3]; + while (d >= buf2) { + d[1] = (-e[2] * AA[0] - -e[0]*AA[1]); + d[0] = (-e[2] * AA[1] + -e[0]*AA[0]); + d -= 2; + AA += 2; + e -= 4; + } + } + + // now we use symbolic names for these, so that we can + // possibly swap their meaning as we change which operations + // are in place + + u = buffer; + v = buf2; + + // step 2 (paper output is w, now u) + // this could be in place, but the data ends up in the wrong + // place... _somebody_'s got to swap it, so this is nominated + { + float *AA = &A[n2-8]; + float *d0,*d1, *e0, *e1; + + e0 = &v[n4]; + e1 = &v[0]; + + d0 = &u[n4]; + d1 = &u[0]; + + while (AA >= A) { + float v40_20, v41_21; + + v41_21 = e0[1] - e1[1]; + v40_20 = e0[0] - e1[0]; + d0[1] = e0[1] + e1[1]; + d0[0] = e0[0] + e1[0]; + d1[1] = v41_21*AA[4] - v40_20*AA[5]; + d1[0] = v40_20*AA[4] + v41_21*AA[5]; + + v41_21 = e0[3] - e1[3]; + v40_20 = e0[2] - e1[2]; + d0[3] = e0[3] + e1[3]; + d0[2] = e0[2] + e1[2]; + d1[3] = v41_21*AA[0] - v40_20*AA[1]; + d1[2] = v40_20*AA[0] + v41_21*AA[1]; + + AA -= 8; + + d0 += 4; + d1 += 4; + e0 += 4; + e1 += 4; + } + } + + // step 3 + ld = ilog(n) - 1; // ilog is off-by-one from normal definitions + + // optimized step 3: + + // the original step3 loop can be nested r inside s or s inside r; + // it's written originally as s inside r, but this is dumb when r + // iterates many times, and s few. So I have two copies of it and + // switch between them halfway. + + // this is iteration 0 of step 3 + imdct_step3_iter0_loop(n >> 4, u, n2-1-n4*0, -(n >> 3), A); + imdct_step3_iter0_loop(n >> 4, u, n2-1-n4*1, -(n >> 3), A); + + // this is iteration 1 of step 3 + imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*0, -(n >> 4), A, 16); + imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*1, -(n >> 4), A, 16); + imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*2, -(n >> 4), A, 16); + imdct_step3_inner_r_loop(n >> 5, u, n2-1 - n8*3, -(n >> 4), A, 16); + + l=2; + for (; l < (ld-3)>>1; ++l) { + int k0 = n >> (l+2), k0_2 = k0>>1; + int lim = 1 << (l+1); + int i; + for (i=0; i < lim; ++i) + imdct_step3_inner_r_loop(n >> (l+4), u, n2-1 - k0*i, -k0_2, A, 1 << (l+3)); + } + + for (; l < ld-6; ++l) { + int k0 = n >> (l+2), k1 = 1 << (l+3), k0_2 = k0>>1; + int rlim = n >> (l+6), r; + int lim = 1 << (l+1); + int i_off; + float *A0 = A; + i_off = n2-1; + for (r=rlim; r > 0; --r) { + imdct_step3_inner_s_loop(lim, u, i_off, -k0_2, A0, k1, k0); + A0 += k1*4; + i_off -= 8; + } + } + + // iterations with count: + // ld-6,-5,-4 all interleaved together + // the big win comes from getting rid of needless flops + // due to the constants on pass 5 & 4 being all 1 and 0; + // combining them to be simultaneous to improve cache made little difference + imdct_step3_inner_s_loop_ld654(n >> 5, u, n2-1, A, n); + + // output is u + + // step 4, 5, and 6 + // cannot be in-place because of step 5 + { + uint16 *bitrev = f->bit_reverse[blocktype]; + // weirdly, I'd have thought reading sequentially and writing + // erratically would have been better than vice-versa, but in + // fact that's not what my testing showed. (That is, with + // j = bitreverse(i), do you read i and write j, or read j and write i.) + + float *d0 = &v[n4-4]; + float *d1 = &v[n2-4]; + while (d0 >= v) { + int k4; + + k4 = bitrev[0]; + d1[3] = u[k4+0]; + d1[2] = u[k4+1]; + d0[3] = u[k4+2]; + d0[2] = u[k4+3]; + + k4 = bitrev[1]; + d1[1] = u[k4+0]; + d1[0] = u[k4+1]; + d0[1] = u[k4+2]; + d0[0] = u[k4+3]; + + d0 -= 4; + d1 -= 4; + bitrev += 2; + } + } + // (paper output is u, now v) + + + // data must be in buf2 + assert(v == buf2); + + // step 7 (paper output is v, now v) + // this is now in place + { + float *C = f->C[blocktype]; + float *d, *e; + + d = v; + e = v + n2 - 4; + + while (d < e) { + float a02,a11,b0,b1,b2,b3; + + a02 = d[0] - e[2]; + a11 = d[1] + e[3]; + + b0 = C[1]*a02 + C[0]*a11; + b1 = C[1]*a11 - C[0]*a02; + + b2 = d[0] + e[ 2]; + b3 = d[1] - e[ 3]; + + d[0] = b2 + b0; + d[1] = b3 + b1; + e[2] = b2 - b0; + e[3] = b1 - b3; + + a02 = d[2] - e[0]; + a11 = d[3] + e[1]; + + b0 = C[3]*a02 + C[2]*a11; + b1 = C[3]*a11 - C[2]*a02; + + b2 = d[2] + e[ 0]; + b3 = d[3] - e[ 1]; + + d[2] = b2 + b0; + d[3] = b3 + b1; + e[0] = b2 - b0; + e[1] = b1 - b3; + + C += 4; + d += 4; + e -= 4; + } + } + + // data must be in buf2 + + + // step 8+decode (paper output is X, now buffer) + // this generates pairs of data a la 8 and pushes them directly through + // the decode kernel (pushing rather than pulling) to avoid having + // to make another pass later + + // this cannot POSSIBLY be in place, so we refer to the buffers directly + + { + float *d0,*d1,*d2,*d3; + + float *B = f->B[blocktype] + n2 - 8; + float *e = buf2 + n2 - 8; + d0 = &buffer[0]; + d1 = &buffer[n2-4]; + d2 = &buffer[n2]; + d3 = &buffer[n-4]; + while (e >= v) { + float p0,p1,p2,p3; + + p3 = e[6]*B[7] - e[7]*B[6]; + p2 = -e[6]*B[6] - e[7]*B[7]; + + d0[0] = p3; + d1[3] = - p3; + d2[0] = p2; + d3[3] = p2; + + p1 = e[4]*B[5] - e[5]*B[4]; + p0 = -e[4]*B[4] - e[5]*B[5]; + + d0[1] = p1; + d1[2] = - p1; + d2[1] = p0; + d3[2] = p0; + + p3 = e[2]*B[3] - e[3]*B[2]; + p2 = -e[2]*B[2] - e[3]*B[3]; + + d0[2] = p3; + d1[1] = - p3; + d2[2] = p2; + d3[1] = p2; + + p1 = e[0]*B[1] - e[1]*B[0]; + p0 = -e[0]*B[0] - e[1]*B[1]; + + d0[3] = p1; + d1[0] = - p1; + d2[3] = p0; + d3[0] = p0; + + B -= 8; + e -= 8; + d0 += 4; + d2 += 4; + d1 -= 4; + d3 -= 4; + } + } + + temp_free(f,buf2); + temp_alloc_restore(f,save_point); +} + +#if 0 +// this is the original version of the above code, if you want to optimize it from scratch +void inverse_mdct_naive(float *buffer, int n) +{ + float s; + float A[1 << 12], B[1 << 12], C[1 << 11]; + int i,k,k2,k4, n2 = n >> 1, n4 = n >> 2, n8 = n >> 3, l; + int n3_4 = n - n4, ld; + // how can they claim this only uses N words?! + // oh, because they're only used sparsely, whoops + float u[1 << 13], X[1 << 13], v[1 << 13], w[1 << 13]; + // set up twiddle factors + + for (k=k2=0; k < n4; ++k,k2+=2) { + A[k2 ] = (float) cos(4*k*M_PI/n); + A[k2+1] = (float) -sin(4*k*M_PI/n); + B[k2 ] = (float) cos((k2+1)*M_PI/n/2); + B[k2+1] = (float) sin((k2+1)*M_PI/n/2); + } + for (k=k2=0; k < n8; ++k,k2+=2) { + C[k2 ] = (float) cos(2*(k2+1)*M_PI/n); + C[k2+1] = (float) -sin(2*(k2+1)*M_PI/n); + } + + // IMDCT algorithm from "The use of multirate filter banks for coding of high quality digital audio" + // Note there are bugs in that pseudocode, presumably due to them attempting + // to rename the arrays nicely rather than representing the way their actual + // implementation bounces buffers back and forth. As a result, even in the + // "some formulars corrected" version, a direct implementation fails. These + // are noted below as "paper bug". + + // copy and reflect spectral data + for (k=0; k < n2; ++k) u[k] = buffer[k]; + for ( ; k < n ; ++k) u[k] = -buffer[n - k - 1]; + // kernel from paper + // step 1 + for (k=k2=k4=0; k < n4; k+=1, k2+=2, k4+=4) { + v[n-k4-1] = (u[k4] - u[n-k4-1]) * A[k2] - (u[k4+2] - u[n-k4-3])*A[k2+1]; + v[n-k4-3] = (u[k4] - u[n-k4-1]) * A[k2+1] + (u[k4+2] - u[n-k4-3])*A[k2]; + } + // step 2 + for (k=k4=0; k < n8; k+=1, k4+=4) { + w[n2+3+k4] = v[n2+3+k4] + v[k4+3]; + w[n2+1+k4] = v[n2+1+k4] + v[k4+1]; + w[k4+3] = (v[n2+3+k4] - v[k4+3])*A[n2-4-k4] - (v[n2+1+k4]-v[k4+1])*A[n2-3-k4]; + w[k4+1] = (v[n2+1+k4] - v[k4+1])*A[n2-4-k4] + (v[n2+3+k4]-v[k4+3])*A[n2-3-k4]; + } + // step 3 + ld = ilog(n) - 1; // ilog is off-by-one from normal definitions + for (l=0; l < ld-3; ++l) { + int k0 = n >> (l+2), k1 = 1 << (l+3); + int rlim = n >> (l+4), r4, r; + int s2lim = 1 << (l+2), s2; + for (r=r4=0; r < rlim; r4+=4,++r) { + for (s2=0; s2 < s2lim; s2+=2) { + u[n-1-k0*s2-r4] = w[n-1-k0*s2-r4] + w[n-1-k0*(s2+1)-r4]; + u[n-3-k0*s2-r4] = w[n-3-k0*s2-r4] + w[n-3-k0*(s2+1)-r4]; + u[n-1-k0*(s2+1)-r4] = (w[n-1-k0*s2-r4] - w[n-1-k0*(s2+1)-r4]) * A[r*k1] + - (w[n-3-k0*s2-r4] - w[n-3-k0*(s2+1)-r4]) * A[r*k1+1]; + u[n-3-k0*(s2+1)-r4] = (w[n-3-k0*s2-r4] - w[n-3-k0*(s2+1)-r4]) * A[r*k1] + + (w[n-1-k0*s2-r4] - w[n-1-k0*(s2+1)-r4]) * A[r*k1+1]; + } + } + if (l+1 < ld-3) { + // paper bug: ping-ponging of u&w here is omitted + memcpy(w, u, sizeof(u)); + } + } + + // step 4 + for (i=0; i < n8; ++i) { + int j = bit_reverse(i) >> (32-ld+3); + assert(j < n8); + if (i == j) { + // paper bug: original code probably swapped in place; if copying, + // need to directly copy in this case + int i8 = i << 3; + v[i8+1] = u[i8+1]; + v[i8+3] = u[i8+3]; + v[i8+5] = u[i8+5]; + v[i8+7] = u[i8+7]; + } else if (i < j) { + int i8 = i << 3, j8 = j << 3; + v[j8+1] = u[i8+1], v[i8+1] = u[j8 + 1]; + v[j8+3] = u[i8+3], v[i8+3] = u[j8 + 3]; + v[j8+5] = u[i8+5], v[i8+5] = u[j8 + 5]; + v[j8+7] = u[i8+7], v[i8+7] = u[j8 + 7]; + } + } + // step 5 + for (k=0; k < n2; ++k) { + w[k] = v[k*2+1]; + } + // step 6 + for (k=k2=k4=0; k < n8; ++k, k2 += 2, k4 += 4) { + u[n-1-k2] = w[k4]; + u[n-2-k2] = w[k4+1]; + u[n3_4 - 1 - k2] = w[k4+2]; + u[n3_4 - 2 - k2] = w[k4+3]; + } + // step 7 + for (k=k2=0; k < n8; ++k, k2 += 2) { + v[n2 + k2 ] = ( u[n2 + k2] + u[n-2-k2] + C[k2+1]*(u[n2+k2]-u[n-2-k2]) + C[k2]*(u[n2+k2+1]+u[n-2-k2+1]))/2; + v[n-2 - k2] = ( u[n2 + k2] + u[n-2-k2] - C[k2+1]*(u[n2+k2]-u[n-2-k2]) - C[k2]*(u[n2+k2+1]+u[n-2-k2+1]))/2; + v[n2+1+ k2] = ( u[n2+1+k2] - u[n-1-k2] + C[k2+1]*(u[n2+1+k2]+u[n-1-k2]) - C[k2]*(u[n2+k2]-u[n-2-k2]))/2; + v[n-1 - k2] = (-u[n2+1+k2] + u[n-1-k2] + C[k2+1]*(u[n2+1+k2]+u[n-1-k2]) - C[k2]*(u[n2+k2]-u[n-2-k2]))/2; + } + // step 8 + for (k=k2=0; k < n4; ++k,k2 += 2) { + X[k] = v[k2+n2]*B[k2 ] + v[k2+1+n2]*B[k2+1]; + X[n2-1-k] = v[k2+n2]*B[k2+1] - v[k2+1+n2]*B[k2 ]; + } + + // decode kernel to output + // determined the following value experimentally + // (by first figuring out what made inverse_mdct_slow work); then matching that here + // (probably vorbis encoder premultiplies by n or n/2, to save it on the decoder?) + s = 0.5; // theoretically would be n4 + + // [[[ note! the s value of 0.5 is compensated for by the B[] in the current code, + // so it needs to use the "old" B values to behave correctly, or else + // set s to 1.0 ]]] + for (i=0; i < n4 ; ++i) buffer[i] = s * X[i+n4]; + for ( ; i < n3_4; ++i) buffer[i] = -s * X[n3_4 - i - 1]; + for ( ; i < n ; ++i) buffer[i] = -s * X[i - n3_4]; +} +#endif + +static float *get_window(vorb *f, int len) +{ + len <<= 1; + if (len == f->blocksize_0) return f->window[0]; + if (len == f->blocksize_1) return f->window[1]; + assert(0); + return NULL; +} + +#ifndef STB_VORBIS_NO_DEFER_FLOOR +typedef int16 YTYPE; +#else +typedef int YTYPE; +#endif +static int do_floor(vorb *f, Mapping *map, int i, int n, float *target, YTYPE *finalY, uint8 *step2_flag) +{ + int n2 = n >> 1; + int s = map->chan[i].mux, floor; + floor = map->submap_floor[s]; + if (f->floor_types[floor] == 0) { + return error(f, VORBIS_invalid_stream); + } else { + Floor1 *g = &f->floor_config[floor].floor1; + int j,q; + int lx = 0, ly = finalY[0] * g->floor1_multiplier; + for (q=1; q < g->values; ++q) { + j = g->sorted_order[q]; + #ifndef STB_VORBIS_NO_DEFER_FLOOR + if (finalY[j] >= 0) + #else + if (step2_flag[j]) + #endif + { + int hy = finalY[j] * g->floor1_multiplier; + int hx = g->Xlist[j]; + if (lx != hx) + draw_line(target, lx,ly, hx,hy, n2); + CHECK(f); + lx = hx, ly = hy; + } + } + if (lx < n2) { + // optimization of: draw_line(target, lx,ly, n,ly, n2); + for (j=lx; j < n2; ++j) + LINE_OP(target[j], inverse_db_table[ly]); + CHECK(f); + } + } + return TRUE; +} + +// The meaning of "left" and "right" +// +// For a given frame: +// we compute samples from 0..n +// window_center is n/2 +// we'll window and mix the samples from left_start to left_end with data from the previous frame +// all of the samples from left_end to right_start can be output without mixing; however, +// this interval is 0-length except when transitioning between short and long frames +// all of the samples from right_start to right_end need to be mixed with the next frame, +// which we don't have, so those get saved in a buffer +// frame N's right_end-right_start, the number of samples to mix with the next frame, +// has to be the same as frame N+1's left_end-left_start (which they are by +// construction) + +static int vorbis_decode_initial(vorb *f, int *p_left_start, int *p_left_end, int *p_right_start, int *p_right_end, int *mode) +{ + Mode *m; + int i, n, prev, next, window_center; + f->channel_buffer_start = f->channel_buffer_end = 0; + + retry: + if (f->eof) return FALSE; + if (!maybe_start_packet(f)) + return FALSE; + // check packet type + if (get_bits(f,1) != 0) { + if (IS_PUSH_MODE(f)) + return error(f,VORBIS_bad_packet_type); + while (EOP != get8_packet(f)); + goto retry; + } + + if (f->alloc.alloc_buffer) + assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset); + + i = get_bits(f, ilog(f->mode_count-1)); + if (i == EOP) return FALSE; + if (i >= f->mode_count) return FALSE; + *mode = i; + m = f->mode_config + i; + if (m->blockflag) { + n = f->blocksize_1; + prev = get_bits(f,1); + next = get_bits(f,1); + } else { + prev = next = 0; + n = f->blocksize_0; + } + +// WINDOWING + + window_center = n >> 1; + if (m->blockflag && !prev) { + *p_left_start = (n - f->blocksize_0) >> 2; + *p_left_end = (n + f->blocksize_0) >> 2; + } else { + *p_left_start = 0; + *p_left_end = window_center; + } + if (m->blockflag && !next) { + *p_right_start = (n*3 - f->blocksize_0) >> 2; + *p_right_end = (n*3 + f->blocksize_0) >> 2; + } else { + *p_right_start = window_center; + *p_right_end = n; + } + + return TRUE; +} + +static int vorbis_decode_packet_rest(vorb *f, int *len, Mode *m, int left_start, int left_end, int right_start, int right_end, int *p_left) +{ + Mapping *map; + int i,j,k,n,n2; + int zero_channel[256]; + int really_zero_channel[256]; + +// WINDOWING + + n = f->blocksize[m->blockflag]; + map = &f->mapping[m->mapping]; + +// FLOORS + n2 = n >> 1; + + CHECK(f); + + for (i=0; i < f->channels; ++i) { + int s = map->chan[i].mux, floor; + zero_channel[i] = FALSE; + floor = map->submap_floor[s]; + if (f->floor_types[floor] == 0) { + return error(f, VORBIS_invalid_stream); + } else { + Floor1 *g = &f->floor_config[floor].floor1; + if (get_bits(f, 1)) { + short *finalY; + uint8 step2_flag[256]; + static int range_list[4] = { 256, 128, 86, 64 }; + int range = range_list[g->floor1_multiplier-1]; + int offset = 2; + finalY = f->finalY[i]; + finalY[0] = get_bits(f, ilog(range)-1); + finalY[1] = get_bits(f, ilog(range)-1); + for (j=0; j < g->partitions; ++j) { + int pclass = g->partition_class_list[j]; + int cdim = g->class_dimensions[pclass]; + int cbits = g->class_subclasses[pclass]; + int csub = (1 << cbits)-1; + int cval = 0; + if (cbits) { + Codebook *c = f->codebooks + g->class_masterbooks[pclass]; + DECODE(cval,f,c); + } + for (k=0; k < cdim; ++k) { + int book = g->subclass_books[pclass][cval & csub]; + cval = cval >> cbits; + if (book >= 0) { + int temp; + Codebook *c = f->codebooks + book; + DECODE(temp,f,c); + finalY[offset++] = temp; + } else + finalY[offset++] = 0; + } + } + if (f->valid_bits == INVALID_BITS) goto error; // behavior according to spec + step2_flag[0] = step2_flag[1] = 1; + for (j=2; j < g->values; ++j) { + int low, high, pred, highroom, lowroom, room, val; + low = g->neighbors[j][0]; + high = g->neighbors[j][1]; + //neighbors(g->Xlist, j, &low, &high); + pred = predict_point(g->Xlist[j], g->Xlist[low], g->Xlist[high], finalY[low], finalY[high]); + val = finalY[j]; + highroom = range - pred; + lowroom = pred; + if (highroom < lowroom) + room = highroom * 2; + else + room = lowroom * 2; + if (val) { + step2_flag[low] = step2_flag[high] = 1; + step2_flag[j] = 1; + if (val >= room) + if (highroom > lowroom) + finalY[j] = val - lowroom + pred; + else + finalY[j] = pred - val + highroom - 1; + else + if (val & 1) + finalY[j] = pred - ((val+1)>>1); + else + finalY[j] = pred + (val>>1); + } else { + step2_flag[j] = 0; + finalY[j] = pred; + } + } + +#ifdef STB_VORBIS_NO_DEFER_FLOOR + do_floor(f, map, i, n, f->floor_buffers[i], finalY, step2_flag); +#else + // defer final floor computation until _after_ residue + for (j=0; j < g->values; ++j) { + if (!step2_flag[j]) + finalY[j] = -1; + } +#endif + } else { + error: + zero_channel[i] = TRUE; + } + // So we just defer everything else to later + + // at this point we've decoded the floor into buffer + } + } + CHECK(f); + // at this point we've decoded all floors + + if (f->alloc.alloc_buffer) + assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset); + + // re-enable coupled channels if necessary + memcpy(really_zero_channel, zero_channel, sizeof(really_zero_channel[0]) * f->channels); + for (i=0; i < map->coupling_steps; ++i) + if (!zero_channel[map->chan[i].magnitude] || !zero_channel[map->chan[i].angle]) { + zero_channel[map->chan[i].magnitude] = zero_channel[map->chan[i].angle] = FALSE; + } + + CHECK(f); +// RESIDUE DECODE + for (i=0; i < map->submaps; ++i) { + float *residue_buffers[STB_VORBIS_MAX_CHANNELS]; + int r; + uint8 do_not_decode[256]; + int ch = 0; + for (j=0; j < f->channels; ++j) { + if (map->chan[j].mux == i) { + if (zero_channel[j]) { + do_not_decode[ch] = TRUE; + residue_buffers[ch] = NULL; + } else { + do_not_decode[ch] = FALSE; + residue_buffers[ch] = f->channel_buffers[j]; + } + ++ch; + } + } + r = map->submap_residue[i]; + decode_residue(f, residue_buffers, ch, n2, r, do_not_decode); + } + + if (f->alloc.alloc_buffer) + assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset); + CHECK(f); + +// INVERSE COUPLING + for (i = map->coupling_steps-1; i >= 0; --i) { + int n2 = n >> 1; + float *m = f->channel_buffers[map->chan[i].magnitude]; + float *a = f->channel_buffers[map->chan[i].angle ]; + for (j=0; j < n2; ++j) { + float a2,m2; + if (m[j] > 0) + if (a[j] > 0) + m2 = m[j], a2 = m[j] - a[j]; + else + a2 = m[j], m2 = m[j] + a[j]; + else + if (a[j] > 0) + m2 = m[j], a2 = m[j] + a[j]; + else + a2 = m[j], m2 = m[j] - a[j]; + m[j] = m2; + a[j] = a2; + } + } + CHECK(f); + + // finish decoding the floors +#ifndef STB_VORBIS_NO_DEFER_FLOOR + for (i=0; i < f->channels; ++i) { + if (really_zero_channel[i]) { + memset(f->channel_buffers[i], 0, sizeof(*f->channel_buffers[i]) * n2); + } else { + do_floor(f, map, i, n, f->channel_buffers[i], f->finalY[i], NULL); + } + } +#else + for (i=0; i < f->channels; ++i) { + if (really_zero_channel[i]) { + memset(f->channel_buffers[i], 0, sizeof(*f->channel_buffers[i]) * n2); + } else { + for (j=0; j < n2; ++j) + f->channel_buffers[i][j] *= f->floor_buffers[i][j]; + } + } +#endif + +// INVERSE MDCT + CHECK(f); + for (i=0; i < f->channels; ++i) + inverse_mdct(f->channel_buffers[i], n, f, m->blockflag); + CHECK(f); + + // this shouldn't be necessary, unless we exited on an error + // and want to flush to get to the next packet + flush_packet(f); + + if (f->first_decode) { + // assume we start so first non-discarded sample is sample 0 + // this isn't to spec, but spec would require us to read ahead + // and decode the size of all current frames--could be done, + // but presumably it's not a commonly used feature + f->current_loc = -n2; // start of first frame is positioned for discard + // we might have to discard samples "from" the next frame too, + // if we're lapping a large block then a small at the start? + f->discard_samples_deferred = n - right_end; + f->current_loc_valid = TRUE; + f->first_decode = FALSE; + } else if (f->discard_samples_deferred) { + if (f->discard_samples_deferred >= right_start - left_start) { + f->discard_samples_deferred -= (right_start - left_start); + left_start = right_start; + *p_left = left_start; + } else { + left_start += f->discard_samples_deferred; + *p_left = left_start; + f->discard_samples_deferred = 0; + } + } else if (f->previous_length == 0 && f->current_loc_valid) { + // we're recovering from a seek... that means we're going to discard + // the samples from this packet even though we know our position from + // the last page header, so we need to update the position based on + // the discarded samples here + // but wait, the code below is going to add this in itself even + // on a discard, so we don't need to do it here... + } + + // check if we have ogg information about the sample # for this packet + if (f->last_seg_which == f->end_seg_with_known_loc) { + // if we have a valid current loc, and this is final: + if (f->current_loc_valid && (f->page_flag & PAGEFLAG_last_page)) { + uint32 current_end = f->known_loc_for_packet - (n-right_end); + // then let's infer the size of the (probably) short final frame + if (current_end < f->current_loc + (right_end-left_start)) { + if (current_end < f->current_loc) { + // negative truncation, that's impossible! + *len = 0; + } else { + *len = current_end - f->current_loc; + } + *len += left_start; + if (*len > right_end) *len = right_end; // this should never happen + f->current_loc += *len; + return TRUE; + } + } + // otherwise, just set our sample loc + // guess that the ogg granule pos refers to the _middle_ of the + // last frame? + // set f->current_loc to the position of left_start + f->current_loc = f->known_loc_for_packet - (n2-left_start); + f->current_loc_valid = TRUE; + } + if (f->current_loc_valid) + f->current_loc += (right_start - left_start); + + if (f->alloc.alloc_buffer) + assert(f->alloc.alloc_buffer_length_in_bytes == f->temp_offset); + *len = right_end; // ignore samples after the window goes to 0 + CHECK(f); + + return TRUE; +} + +static int vorbis_decode_packet(vorb *f, int *len, int *p_left, int *p_right) +{ + int mode, left_end, right_end; + if (!vorbis_decode_initial(f, p_left, &left_end, p_right, &right_end, &mode)) return 0; + return vorbis_decode_packet_rest(f, len, f->mode_config + mode, *p_left, left_end, *p_right, right_end, p_left); +} + +static int vorbis_finish_frame(stb_vorbis *f, int len, int left, int right) +{ + int prev,i,j; + // we use right&left (the start of the right- and left-window sin()-regions) + // to determine how much to return, rather than inferring from the rules + // (same result, clearer code); 'left' indicates where our sin() window + // starts, therefore where the previous window's right edge starts, and + // therefore where to start mixing from the previous buffer. 'right' + // indicates where our sin() ending-window starts, therefore that's where + // we start saving, and where our returned-data ends. + + // mixin from previous window + if (f->previous_length) { + int i,j, n = f->previous_length; + float *w = get_window(f, n); + for (i=0; i < f->channels; ++i) { + for (j=0; j < n; ++j) + f->channel_buffers[i][left+j] = + f->channel_buffers[i][left+j]*w[ j] + + f->previous_window[i][ j]*w[n-1-j]; + } + } + + prev = f->previous_length; + + // last half of this data becomes previous window + f->previous_length = len - right; + + // @OPTIMIZE: could avoid this copy by double-buffering the + // output (flipping previous_window with channel_buffers), but + // then previous_window would have to be 2x as large, and + // channel_buffers couldn't be temp mem (although they're NOT + // currently temp mem, they could be (unless we want to level + // performance by spreading out the computation)) + for (i=0; i < f->channels; ++i) + for (j=0; right+j < len; ++j) + f->previous_window[i][j] = f->channel_buffers[i][right+j]; + + if (!prev) + // there was no previous packet, so this data isn't valid... + // this isn't entirely true, only the would-have-overlapped data + // isn't valid, but this seems to be what the spec requires + return 0; + + // truncate a short frame + if (len < right) right = len; + + f->samples_output += right-left; + + return right - left; +} + +static void vorbis_pump_first_frame(stb_vorbis *f) +{ + int len, right, left; + if (vorbis_decode_packet(f, &len, &left, &right)) + vorbis_finish_frame(f, len, left, right); +} + +#ifndef STB_VORBIS_NO_PUSHDATA_API +static int is_whole_packet_present(stb_vorbis *f, int end_page) +{ + // make sure that we have the packet available before continuing... + // this requires a full ogg parse, but we know we can fetch from f->stream + + // instead of coding this out explicitly, we could save the current read state, + // read the next packet with get8() until end-of-packet, check f->eof, then + // reset the state? but that would be slower, esp. since we'd have over 256 bytes + // of state to restore (primarily the page segment table) + + int s = f->next_seg, first = TRUE; + uint8 *p = f->stream; + + if (s != -1) { // if we're not starting the packet with a 'continue on next page' flag + for (; s < f->segment_count; ++s) { + p += f->segments[s]; + if (f->segments[s] < 255) // stop at first short segment + break; + } + // either this continues, or it ends it... + if (end_page) + if (s < f->segment_count-1) return error(f, VORBIS_invalid_stream); + if (s == f->segment_count) + s = -1; // set 'crosses page' flag + if (p > f->stream_end) return error(f, VORBIS_need_more_data); + first = FALSE; + } + for (; s == -1;) { + uint8 *q; + int n; + + // check that we have the page header ready + if (p + 26 >= f->stream_end) return error(f, VORBIS_need_more_data); + // validate the page + if (memcmp(p, ogg_page_header, 4)) return error(f, VORBIS_invalid_stream); + if (p[4] != 0) return error(f, VORBIS_invalid_stream); + if (first) { // the first segment must NOT have 'continued_packet', later ones MUST + if (f->previous_length) + if ((p[5] & PAGEFLAG_continued_packet)) return error(f, VORBIS_invalid_stream); + // if no previous length, we're resynching, so we can come in on a continued-packet, + // which we'll just drop + } else { + if (!(p[5] & PAGEFLAG_continued_packet)) return error(f, VORBIS_invalid_stream); + } + n = p[26]; // segment counts + q = p+27; // q points to segment table + p = q + n; // advance past header + // make sure we've read the segment table + if (p > f->stream_end) return error(f, VORBIS_need_more_data); + for (s=0; s < n; ++s) { + p += q[s]; + if (q[s] < 255) + break; + } + if (end_page) + if (s < n-1) return error(f, VORBIS_invalid_stream); + if (s == n) + s = -1; // set 'crosses page' flag + if (p > f->stream_end) return error(f, VORBIS_need_more_data); + first = FALSE; + } + return TRUE; +} +#endif // !STB_VORBIS_NO_PUSHDATA_API + +static int start_decoder(vorb *f) +{ + uint8 header[6], x,y; + int len,i,j,k, max_submaps = 0; + int longest_floorlist=0; + + // first page, first packet + + if (!start_page(f)) return FALSE; + // validate page flag + if (!(f->page_flag & PAGEFLAG_first_page)) return error(f, VORBIS_invalid_first_page); + if (f->page_flag & PAGEFLAG_last_page) return error(f, VORBIS_invalid_first_page); + if (f->page_flag & PAGEFLAG_continued_packet) return error(f, VORBIS_invalid_first_page); + // check for expected packet length + if (f->segment_count != 1) return error(f, VORBIS_invalid_first_page); + if (f->segments[0] != 30) return error(f, VORBIS_invalid_first_page); + // read packet + // check packet header + if (get8(f) != VORBIS_packet_id) return error(f, VORBIS_invalid_first_page); + if (!getn(f, header, 6)) return error(f, VORBIS_unexpected_eof); + if (!vorbis_validate(header)) return error(f, VORBIS_invalid_first_page); + // vorbis_version + if (get32(f) != 0) return error(f, VORBIS_invalid_first_page); + f->channels = get8(f); if (!f->channels) return error(f, VORBIS_invalid_first_page); + if (f->channels > STB_VORBIS_MAX_CHANNELS) return error(f, VORBIS_too_many_channels); + f->sample_rate = get32(f); if (!f->sample_rate) return error(f, VORBIS_invalid_first_page); + get32(f); // bitrate_maximum + get32(f); // bitrate_nominal + get32(f); // bitrate_minimum + x = get8(f); + { + int log0,log1; + log0 = x & 15; + log1 = x >> 4; + f->blocksize_0 = 1 << log0; + f->blocksize_1 = 1 << log1; + if (log0 < 6 || log0 > 13) return error(f, VORBIS_invalid_setup); + if (log1 < 6 || log1 > 13) return error(f, VORBIS_invalid_setup); + if (log0 > log1) return error(f, VORBIS_invalid_setup); + } + + // framing_flag + x = get8(f); + if (!(x & 1)) return error(f, VORBIS_invalid_first_page); + + // second packet! + if (!start_page(f)) return FALSE; + + if (!start_packet(f)) return FALSE; + do { + len = next_segment(f); + skip(f, len); + f->bytes_in_seg = 0; + } while (len); + + // third packet! + if (!start_packet(f)) return FALSE; + + #ifndef STB_VORBIS_NO_PUSHDATA_API + if (IS_PUSH_MODE(f)) { + if (!is_whole_packet_present(f, TRUE)) { + // convert error in ogg header to write type + if (f->error == VORBIS_invalid_stream) + f->error = VORBIS_invalid_setup; + return FALSE; + } + } + #endif + + crc32_init(); // always init it, to avoid multithread race conditions + + if (get8_packet(f) != VORBIS_packet_setup) return error(f, VORBIS_invalid_setup); + for (i=0; i < 6; ++i) header[i] = get8_packet(f); + if (!vorbis_validate(header)) return error(f, VORBIS_invalid_setup); + + // codebooks + + f->codebook_count = get_bits(f,8) + 1; + f->codebooks = (Codebook *) setup_malloc(f, sizeof(*f->codebooks) * f->codebook_count); + if (f->codebooks == NULL) return error(f, VORBIS_outofmem); + memset(f->codebooks, 0, sizeof(*f->codebooks) * f->codebook_count); + for (i=0; i < f->codebook_count; ++i) { + uint32 *values; + int ordered, sorted_count; + int total=0; + uint8 *lengths; + Codebook *c = f->codebooks+i; + CHECK(f); + x = get_bits(f, 8); if (x != 0x42) return error(f, VORBIS_invalid_setup); + x = get_bits(f, 8); if (x != 0x43) return error(f, VORBIS_invalid_setup); + x = get_bits(f, 8); if (x != 0x56) return error(f, VORBIS_invalid_setup); + x = get_bits(f, 8); + c->dimensions = (get_bits(f, 8)<<8) + x; + x = get_bits(f, 8); + y = get_bits(f, 8); + c->entries = (get_bits(f, 8)<<16) + (y<<8) + x; + ordered = get_bits(f,1); + c->sparse = ordered ? 0 : get_bits(f,1); + + if (c->dimensions == 0 && c->entries != 0) return error(f, VORBIS_invalid_setup); + + if (c->sparse) + lengths = (uint8 *) setup_temp_malloc(f, c->entries); + else + lengths = c->codeword_lengths = (uint8 *) setup_malloc(f, c->entries); + + if (!lengths) return error(f, VORBIS_outofmem); + + if (ordered) { + int current_entry = 0; + int current_length = get_bits(f,5) + 1; + while (current_entry < c->entries) { + int limit = c->entries - current_entry; + int n = get_bits(f, ilog(limit)); + if (current_entry + n > (int) c->entries) { return error(f, VORBIS_invalid_setup); } + memset(lengths + current_entry, current_length, n); + current_entry += n; + ++current_length; + } + } else { + for (j=0; j < c->entries; ++j) { + int present = c->sparse ? get_bits(f,1) : 1; + if (present) { + lengths[j] = get_bits(f, 5) + 1; + ++total; + if (lengths[j] == 32) + return error(f, VORBIS_invalid_setup); + } else { + lengths[j] = NO_CODE; + } + } + } + + if (c->sparse && total >= c->entries >> 2) { + // convert sparse items to non-sparse! + if (c->entries > (int) f->setup_temp_memory_required) + f->setup_temp_memory_required = c->entries; + + c->codeword_lengths = (uint8 *) setup_malloc(f, c->entries); + if (c->codeword_lengths == NULL) return error(f, VORBIS_outofmem); + memcpy(c->codeword_lengths, lengths, c->entries); + setup_temp_free(f, lengths, c->entries); // note this is only safe if there have been no intervening temp mallocs! + lengths = c->codeword_lengths; + c->sparse = 0; + } + + // compute the size of the sorted tables + if (c->sparse) { + sorted_count = total; + } else { + sorted_count = 0; + #ifndef STB_VORBIS_NO_HUFFMAN_BINARY_SEARCH + for (j=0; j < c->entries; ++j) + if (lengths[j] > STB_VORBIS_FAST_HUFFMAN_LENGTH && lengths[j] != NO_CODE) + ++sorted_count; + #endif + } + + c->sorted_entries = sorted_count; + values = NULL; + + CHECK(f); + if (!c->sparse) { + c->codewords = (uint32 *) setup_malloc(f, sizeof(c->codewords[0]) * c->entries); + if (!c->codewords) return error(f, VORBIS_outofmem); + } else { + unsigned int size; + if (c->sorted_entries) { + c->codeword_lengths = (uint8 *) setup_malloc(f, c->sorted_entries); + if (!c->codeword_lengths) return error(f, VORBIS_outofmem); + c->codewords = (uint32 *) setup_temp_malloc(f, sizeof(*c->codewords) * c->sorted_entries); + if (!c->codewords) return error(f, VORBIS_outofmem); + values = (uint32 *) setup_temp_malloc(f, sizeof(*values) * c->sorted_entries); + if (!values) return error(f, VORBIS_outofmem); + } + size = c->entries + (sizeof(*c->codewords) + sizeof(*values)) * c->sorted_entries; + if (size > f->setup_temp_memory_required) + f->setup_temp_memory_required = size; + } + + if (!compute_codewords(c, lengths, c->entries, values)) { + if (c->sparse) setup_temp_free(f, values, 0); + return error(f, VORBIS_invalid_setup); + } + + if (c->sorted_entries) { + // allocate an extra slot for sentinels + c->sorted_codewords = (uint32 *) setup_malloc(f, sizeof(*c->sorted_codewords) * (c->sorted_entries+1)); + if (c->sorted_codewords == NULL) return error(f, VORBIS_outofmem); + // allocate an extra slot at the front so that c->sorted_values[-1] is defined + // so that we can catch that case without an extra if + c->sorted_values = ( int *) setup_malloc(f, sizeof(*c->sorted_values ) * (c->sorted_entries+1)); + if (c->sorted_values == NULL) return error(f, VORBIS_outofmem); + ++c->sorted_values; + c->sorted_values[-1] = -1; + compute_sorted_huffman(c, lengths, values); + } + + if (c->sparse) { + setup_temp_free(f, values, sizeof(*values)*c->sorted_entries); + setup_temp_free(f, c->codewords, sizeof(*c->codewords)*c->sorted_entries); + setup_temp_free(f, lengths, c->entries); + c->codewords = NULL; + } + + compute_accelerated_huffman(c); + + CHECK(f); + c->lookup_type = get_bits(f, 4); + if (c->lookup_type > 2) return error(f, VORBIS_invalid_setup); + if (c->lookup_type > 0) { + uint16 *mults; + c->minimum_value = float32_unpack(get_bits(f, 32)); + c->delta_value = float32_unpack(get_bits(f, 32)); + c->value_bits = get_bits(f, 4)+1; + c->sequence_p = get_bits(f,1); + if (c->lookup_type == 1) { + c->lookup_values = lookup1_values(c->entries, c->dimensions); + } else { + c->lookup_values = c->entries * c->dimensions; + } + if (c->lookup_values == 0) return error(f, VORBIS_invalid_setup); + mults = (uint16 *) setup_temp_malloc(f, sizeof(mults[0]) * c->lookup_values); + if (mults == NULL) return error(f, VORBIS_outofmem); + for (j=0; j < (int) c->lookup_values; ++j) { + int q = get_bits(f, c->value_bits); + if (q == EOP) { setup_temp_free(f,mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_invalid_setup); } + mults[j] = q; + } + +#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK + if (c->lookup_type == 1) { + int len, sparse = c->sparse; + float last=0; + // pre-expand the lookup1-style multiplicands, to avoid a divide in the inner loop + if (sparse) { + if (c->sorted_entries == 0) goto skip; + c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->sorted_entries * c->dimensions); + } else + c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->entries * c->dimensions); + if (c->multiplicands == NULL) { setup_temp_free(f,mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_outofmem); } + len = sparse ? c->sorted_entries : c->entries; + for (j=0; j < len; ++j) { + unsigned int z = sparse ? c->sorted_values[j] : j; + unsigned int div=1; + for (k=0; k < c->dimensions; ++k) { + int off = (z / div) % c->lookup_values; + float val = mults[off]; + val = mults[off]*c->delta_value + c->minimum_value + last; + c->multiplicands[j*c->dimensions + k] = val; + if (c->sequence_p) + last = val; + if (k+1 < c->dimensions) { + if (div > UINT_MAX / (unsigned int) c->lookup_values) { + setup_temp_free(f, mults,sizeof(mults[0])*c->lookup_values); + return error(f, VORBIS_invalid_setup); + } + div *= c->lookup_values; + } + } + } + c->lookup_type = 2; + } + else +#endif + { + float last=0; + CHECK(f); + c->multiplicands = (codetype *) setup_malloc(f, sizeof(c->multiplicands[0]) * c->lookup_values); + if (c->multiplicands == NULL) { setup_temp_free(f, mults,sizeof(mults[0])*c->lookup_values); return error(f, VORBIS_outofmem); } + for (j=0; j < (int) c->lookup_values; ++j) { + float val = mults[j] * c->delta_value + c->minimum_value + last; + c->multiplicands[j] = val; + if (c->sequence_p) + last = val; + } + } +#ifndef STB_VORBIS_DIVIDES_IN_CODEBOOK + skip:; +#endif + setup_temp_free(f, mults, sizeof(mults[0])*c->lookup_values); + + CHECK(f); + } + CHECK(f); + } + + // time domain transfers (notused) + + x = get_bits(f, 6) + 1; + for (i=0; i < x; ++i) { + uint32 z = get_bits(f, 16); + if (z != 0) return error(f, VORBIS_invalid_setup); + } + + // Floors + f->floor_count = get_bits(f, 6)+1; + f->floor_config = (Floor *) setup_malloc(f, f->floor_count * sizeof(*f->floor_config)); + if (f->floor_config == NULL) return error(f, VORBIS_outofmem); + for (i=0; i < f->floor_count; ++i) { + f->floor_types[i] = get_bits(f, 16); + if (f->floor_types[i] > 1) return error(f, VORBIS_invalid_setup); + if (f->floor_types[i] == 0) { + Floor0 *g = &f->floor_config[i].floor0; + g->order = get_bits(f,8); + g->rate = get_bits(f,16); + g->bark_map_size = get_bits(f,16); + g->amplitude_bits = get_bits(f,6); + g->amplitude_offset = get_bits(f,8); + g->number_of_books = get_bits(f,4) + 1; + for (j=0; j < g->number_of_books; ++j) + g->book_list[j] = get_bits(f,8); + return error(f, VORBIS_feature_not_supported); + } else { + Point p[31*8+2]; + Floor1 *g = &f->floor_config[i].floor1; + int max_class = -1; + g->partitions = get_bits(f, 5); + for (j=0; j < g->partitions; ++j) { + g->partition_class_list[j] = get_bits(f, 4); + if (g->partition_class_list[j] > max_class) + max_class = g->partition_class_list[j]; + } + for (j=0; j <= max_class; ++j) { + g->class_dimensions[j] = get_bits(f, 3)+1; + g->class_subclasses[j] = get_bits(f, 2); + if (g->class_subclasses[j]) { + g->class_masterbooks[j] = get_bits(f, 8); + if (g->class_masterbooks[j] >= f->codebook_count) return error(f, VORBIS_invalid_setup); + } + for (k=0; k < 1 << g->class_subclasses[j]; ++k) { + g->subclass_books[j][k] = get_bits(f,8)-1; + if (g->subclass_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup); + } + } + g->floor1_multiplier = get_bits(f,2)+1; + g->rangebits = get_bits(f,4); + g->Xlist[0] = 0; + g->Xlist[1] = 1 << g->rangebits; + g->values = 2; + for (j=0; j < g->partitions; ++j) { + int c = g->partition_class_list[j]; + for (k=0; k < g->class_dimensions[c]; ++k) { + g->Xlist[g->values] = get_bits(f, g->rangebits); + ++g->values; + } + } + // precompute the sorting + for (j=0; j < g->values; ++j) { + p[j].x = g->Xlist[j]; + p[j].y = j; + } + qsort(p, g->values, sizeof(p[0]), point_compare); + for (j=0; j < g->values; ++j) + g->sorted_order[j] = (uint8) p[j].y; + // precompute the neighbors + for (j=2; j < g->values; ++j) { + int low,hi; + neighbors(g->Xlist, j, &low,&hi); + g->neighbors[j][0] = low; + g->neighbors[j][1] = hi; + } + + if (g->values > longest_floorlist) + longest_floorlist = g->values; + } + } + + // Residue + f->residue_count = get_bits(f, 6)+1; + f->residue_config = (Residue *) setup_malloc(f, f->residue_count * sizeof(f->residue_config[0])); + if (f->residue_config == NULL) return error(f, VORBIS_outofmem); + memset(f->residue_config, 0, f->residue_count * sizeof(f->residue_config[0])); + for (i=0; i < f->residue_count; ++i) { + uint8 residue_cascade[64]; + Residue *r = f->residue_config+i; + f->residue_types[i] = get_bits(f, 16); + if (f->residue_types[i] > 2) return error(f, VORBIS_invalid_setup); + r->begin = get_bits(f, 24); + r->end = get_bits(f, 24); + if (r->end < r->begin) return error(f, VORBIS_invalid_setup); + r->part_size = get_bits(f,24)+1; + r->classifications = get_bits(f,6)+1; + r->classbook = get_bits(f,8); + if (r->classbook >= f->codebook_count) return error(f, VORBIS_invalid_setup); + for (j=0; j < r->classifications; ++j) { + uint8 high_bits=0; + uint8 low_bits=get_bits(f,3); + if (get_bits(f,1)) + high_bits = get_bits(f,5); + residue_cascade[j] = high_bits*8 + low_bits; + } + r->residue_books = (short (*)[8]) setup_malloc(f, sizeof(r->residue_books[0]) * r->classifications); + if (r->residue_books == NULL) return error(f, VORBIS_outofmem); + for (j=0; j < r->classifications; ++j) { + for (k=0; k < 8; ++k) { + if (residue_cascade[j] & (1 << k)) { + r->residue_books[j][k] = get_bits(f, 8); + if (r->residue_books[j][k] >= f->codebook_count) return error(f, VORBIS_invalid_setup); + } else { + r->residue_books[j][k] = -1; + } + } + } + // precompute the classifications[] array to avoid inner-loop mod/divide + // call it 'classdata' since we already have r->classifications + r->classdata = (uint8 **) setup_malloc(f, sizeof(*r->classdata) * f->codebooks[r->classbook].entries); + if (!r->classdata) return error(f, VORBIS_outofmem); + memset(r->classdata, 0, sizeof(*r->classdata) * f->codebooks[r->classbook].entries); + for (j=0; j < f->codebooks[r->classbook].entries; ++j) { + int classwords = f->codebooks[r->classbook].dimensions; + int temp = j; + r->classdata[j] = (uint8 *) setup_malloc(f, sizeof(r->classdata[j][0]) * classwords); + if (r->classdata[j] == NULL) return error(f, VORBIS_outofmem); + for (k=classwords-1; k >= 0; --k) { + r->classdata[j][k] = temp % r->classifications; + temp /= r->classifications; + } + } + } + + f->mapping_count = get_bits(f,6)+1; + f->mapping = (Mapping *) setup_malloc(f, f->mapping_count * sizeof(*f->mapping)); + if (f->mapping == NULL) return error(f, VORBIS_outofmem); + memset(f->mapping, 0, f->mapping_count * sizeof(*f->mapping)); + for (i=0; i < f->mapping_count; ++i) { + Mapping *m = f->mapping + i; + int mapping_type = get_bits(f,16); + if (mapping_type != 0) return error(f, VORBIS_invalid_setup); + m->chan = (MappingChannel *) setup_malloc(f, f->channels * sizeof(*m->chan)); + if (m->chan == NULL) return error(f, VORBIS_outofmem); + if (get_bits(f,1)) + m->submaps = get_bits(f,4)+1; + else + m->submaps = 1; + if (m->submaps > max_submaps) + max_submaps = m->submaps; + if (get_bits(f,1)) { + m->coupling_steps = get_bits(f,8)+1; + for (k=0; k < m->coupling_steps; ++k) { + m->chan[k].magnitude = get_bits(f, ilog(f->channels-1)); + m->chan[k].angle = get_bits(f, ilog(f->channels-1)); + if (m->chan[k].magnitude >= f->channels) return error(f, VORBIS_invalid_setup); + if (m->chan[k].angle >= f->channels) return error(f, VORBIS_invalid_setup); + if (m->chan[k].magnitude == m->chan[k].angle) return error(f, VORBIS_invalid_setup); + } + } else + m->coupling_steps = 0; + + // reserved field + if (get_bits(f,2)) return error(f, VORBIS_invalid_setup); + if (m->submaps > 1) { + for (j=0; j < f->channels; ++j) { + m->chan[j].mux = get_bits(f, 4); + if (m->chan[j].mux >= m->submaps) return error(f, VORBIS_invalid_setup); + } + } else + // @SPECIFICATION: this case is missing from the spec + for (j=0; j < f->channels; ++j) + m->chan[j].mux = 0; + + for (j=0; j < m->submaps; ++j) { + get_bits(f,8); // discard + m->submap_floor[j] = get_bits(f,8); + m->submap_residue[j] = get_bits(f,8); + if (m->submap_floor[j] >= f->floor_count) return error(f, VORBIS_invalid_setup); + if (m->submap_residue[j] >= f->residue_count) return error(f, VORBIS_invalid_setup); + } + } + + // Modes + f->mode_count = get_bits(f, 6)+1; + for (i=0; i < f->mode_count; ++i) { + Mode *m = f->mode_config+i; + m->blockflag = get_bits(f,1); + m->windowtype = get_bits(f,16); + m->transformtype = get_bits(f,16); + m->mapping = get_bits(f,8); + if (m->windowtype != 0) return error(f, VORBIS_invalid_setup); + if (m->transformtype != 0) return error(f, VORBIS_invalid_setup); + if (m->mapping >= f->mapping_count) return error(f, VORBIS_invalid_setup); + } + + flush_packet(f); + + f->previous_length = 0; + + for (i=0; i < f->channels; ++i) { + f->channel_buffers[i] = (float *) setup_malloc(f, sizeof(float) * f->blocksize_1); + f->previous_window[i] = (float *) setup_malloc(f, sizeof(float) * f->blocksize_1/2); + f->finalY[i] = (int16 *) setup_malloc(f, sizeof(int16) * longest_floorlist); + if (f->channel_buffers[i] == NULL || f->previous_window[i] == NULL || f->finalY[i] == NULL) return error(f, VORBIS_outofmem); + #ifdef STB_VORBIS_NO_DEFER_FLOOR + f->floor_buffers[i] = (float *) setup_malloc(f, sizeof(float) * f->blocksize_1/2); + if (f->floor_buffers[i] == NULL) return error(f, VORBIS_outofmem); + #endif + } + + if (!init_blocksize(f, 0, f->blocksize_0)) return FALSE; + if (!init_blocksize(f, 1, f->blocksize_1)) return FALSE; + f->blocksize[0] = f->blocksize_0; + f->blocksize[1] = f->blocksize_1; + +#ifdef STB_VORBIS_DIVIDE_TABLE + if (integer_divide_table[1][1]==0) + for (i=0; i < DIVTAB_NUMER; ++i) + for (j=1; j < DIVTAB_DENOM; ++j) + integer_divide_table[i][j] = i / j; +#endif + + // compute how much temporary memory is needed + + // 1. + { + uint32 imdct_mem = (f->blocksize_1 * sizeof(float) >> 1); + uint32 classify_mem; + int i,max_part_read=0; + for (i=0; i < f->residue_count; ++i) { + Residue *r = f->residue_config + i; + int n_read = r->end - r->begin; + int part_read = n_read / r->part_size; + if (part_read > max_part_read) + max_part_read = part_read; + } + #ifndef STB_VORBIS_DIVIDES_IN_RESIDUE + classify_mem = f->channels * (sizeof(void*) + max_part_read * sizeof(uint8 *)); + #else + classify_mem = f->channels * (sizeof(void*) + max_part_read * sizeof(int *)); + #endif + + f->temp_memory_required = classify_mem; + if (imdct_mem > f->temp_memory_required) + f->temp_memory_required = imdct_mem; + } + + f->first_decode = TRUE; + + if (f->alloc.alloc_buffer) { + assert(f->temp_offset == f->alloc.alloc_buffer_length_in_bytes); + // check if there's enough temp memory so we don't error later + if (f->setup_offset + sizeof(*f) + f->temp_memory_required > (unsigned) f->temp_offset) + return error(f, VORBIS_outofmem); + } + + f->first_audio_page_offset = stb_vorbis_get_file_offset(f); + + return TRUE; +} + +static void vorbis_deinit(stb_vorbis *p) +{ + int i,j; + if (p->residue_config) { + for (i=0; i < p->residue_count; ++i) { + Residue *r = p->residue_config+i; + if (r->classdata) { + for (j=0; j < p->codebooks[r->classbook].entries; ++j) + setup_free(p, r->classdata[j]); + setup_free(p, r->classdata); + } + setup_free(p, r->residue_books); + } + } + + if (p->codebooks) { + CHECK(p); + for (i=0; i < p->codebook_count; ++i) { + Codebook *c = p->codebooks + i; + setup_free(p, c->codeword_lengths); + setup_free(p, c->multiplicands); + setup_free(p, c->codewords); + setup_free(p, c->sorted_codewords); + // c->sorted_values[-1] is the first entry in the array + setup_free(p, c->sorted_values ? c->sorted_values-1 : NULL); + } + setup_free(p, p->codebooks); + } + setup_free(p, p->floor_config); + setup_free(p, p->residue_config); + if (p->mapping) { + for (i=0; i < p->mapping_count; ++i) + setup_free(p, p->mapping[i].chan); + setup_free(p, p->mapping); + } + CHECK(p); + for (i=0; i < p->channels && i < STB_VORBIS_MAX_CHANNELS; ++i) { + setup_free(p, p->channel_buffers[i]); + setup_free(p, p->previous_window[i]); + #ifdef STB_VORBIS_NO_DEFER_FLOOR + setup_free(p, p->floor_buffers[i]); + #endif + setup_free(p, p->finalY[i]); + } + for (i=0; i < 2; ++i) { + setup_free(p, p->A[i]); + setup_free(p, p->B[i]); + setup_free(p, p->C[i]); + setup_free(p, p->window[i]); + setup_free(p, p->bit_reverse[i]); + } + #ifndef STB_VORBIS_NO_STDIO + if (p->close_on_free) fclose(p->f); + #endif +} + +void stb_vorbis_close(stb_vorbis *p) +{ + if (p == NULL) return; + vorbis_deinit(p); + setup_free(p,p); +} + +static void vorbis_init(stb_vorbis *p, const stb_vorbis_alloc *z) +{ + memset(p, 0, sizeof(*p)); // NULL out all malloc'd pointers to start + if (z) { + p->alloc = *z; + p->alloc.alloc_buffer_length_in_bytes = (p->alloc.alloc_buffer_length_in_bytes+3) & ~3; + p->temp_offset = p->alloc.alloc_buffer_length_in_bytes; + } + p->eof = 0; + p->error = VORBIS__no_error; + p->stream = NULL; + p->codebooks = NULL; + p->page_crc_tests = -1; + #ifndef STB_VORBIS_NO_STDIO + p->close_on_free = FALSE; + p->f = NULL; + #endif +} + +int stb_vorbis_get_sample_offset(stb_vorbis *f) +{ + if (f->current_loc_valid) + return f->current_loc; + else + return -1; +} + +stb_vorbis_info stb_vorbis_get_info(stb_vorbis *f) +{ + stb_vorbis_info d; + d.channels = f->channels; + d.sample_rate = f->sample_rate; + d.setup_memory_required = f->setup_memory_required; + d.setup_temp_memory_required = f->setup_temp_memory_required; + d.temp_memory_required = f->temp_memory_required; + d.max_frame_size = f->blocksize_1 >> 1; + return d; +} + +int stb_vorbis_get_error(stb_vorbis *f) +{ + int e = f->error; + f->error = VORBIS__no_error; + return e; +} + +static stb_vorbis * vorbis_alloc(stb_vorbis *f) +{ + stb_vorbis *p = (stb_vorbis *) setup_malloc(f, sizeof(*p)); + return p; +} + +#ifndef STB_VORBIS_NO_PUSHDATA_API + +void stb_vorbis_flush_pushdata(stb_vorbis *f) +{ + f->previous_length = 0; + f->page_crc_tests = 0; + f->discard_samples_deferred = 0; + f->current_loc_valid = FALSE; + f->first_decode = FALSE; + f->samples_output = 0; + f->channel_buffer_start = 0; + f->channel_buffer_end = 0; +} + +static int vorbis_search_for_page_pushdata(vorb *f, uint8 *data, int data_len) +{ + int i,n; + for (i=0; i < f->page_crc_tests; ++i) + f->scan[i].bytes_done = 0; + + // if we have room for more scans, search for them first, because + // they may cause us to stop early if their header is incomplete + if (f->page_crc_tests < STB_VORBIS_PUSHDATA_CRC_COUNT) { + if (data_len < 4) return 0; + data_len -= 3; // need to look for 4-byte sequence, so don't miss + // one that straddles a boundary + for (i=0; i < data_len; ++i) { + if (data[i] == 0x4f) { + if (0==memcmp(data+i, ogg_page_header, 4)) { + int j,len; + uint32 crc; + // make sure we have the whole page header + if (i+26 >= data_len || i+27+data[i+26] >= data_len) { + // only read up to this page start, so hopefully we'll + // have the whole page header start next time + data_len = i; + break; + } + // ok, we have it all; compute the length of the page + len = 27 + data[i+26]; + for (j=0; j < data[i+26]; ++j) + len += data[i+27+j]; + // scan everything up to the embedded crc (which we must 0) + crc = 0; + for (j=0; j < 22; ++j) + crc = crc32_update(crc, data[i+j]); + // now process 4 0-bytes + for ( ; j < 26; ++j) + crc = crc32_update(crc, 0); + // len is the total number of bytes we need to scan + n = f->page_crc_tests++; + f->scan[n].bytes_left = len-j; + f->scan[n].crc_so_far = crc; + f->scan[n].goal_crc = data[i+22] + (data[i+23] << 8) + (data[i+24]<<16) + (data[i+25]<<24); + // if the last frame on a page is continued to the next, then + // we can't recover the sample_loc immediately + if (data[i+27+data[i+26]-1] == 255) + f->scan[n].sample_loc = ~0; + else + f->scan[n].sample_loc = data[i+6] + (data[i+7] << 8) + (data[i+ 8]<<16) + (data[i+ 9]<<24); + f->scan[n].bytes_done = i+j; + if (f->page_crc_tests == STB_VORBIS_PUSHDATA_CRC_COUNT) + break; + // keep going if we still have room for more + } + } + } + } + + for (i=0; i < f->page_crc_tests;) { + uint32 crc; + int j; + int n = f->scan[i].bytes_done; + int m = f->scan[i].bytes_left; + if (m > data_len - n) m = data_len - n; + // m is the bytes to scan in the current chunk + crc = f->scan[i].crc_so_far; + for (j=0; j < m; ++j) + crc = crc32_update(crc, data[n+j]); + f->scan[i].bytes_left -= m; + f->scan[i].crc_so_far = crc; + if (f->scan[i].bytes_left == 0) { + // does it match? + if (f->scan[i].crc_so_far == f->scan[i].goal_crc) { + // Houston, we have page + data_len = n+m; // consumption amount is wherever that scan ended + f->page_crc_tests = -1; // drop out of page scan mode + f->previous_length = 0; // decode-but-don't-output one frame + f->next_seg = -1; // start a new page + f->current_loc = f->scan[i].sample_loc; // set the current sample location + // to the amount we'd have decoded had we decoded this page + f->current_loc_valid = f->current_loc != ~0U; + return data_len; + } + // delete entry + f->scan[i] = f->scan[--f->page_crc_tests]; + } else { + ++i; + } + } + + return data_len; +} + +// return value: number of bytes we used +int stb_vorbis_decode_frame_pushdata( + stb_vorbis *f, // the file we're decoding + const uint8 *data, int data_len, // the memory available for decoding + int *channels, // place to write number of float * buffers + float ***output, // place to write float ** array of float * buffers + int *samples // place to write number of output samples + ) +{ + int i; + int len,right,left; + + if (!IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing); + + if (f->page_crc_tests >= 0) { + *samples = 0; + return vorbis_search_for_page_pushdata(f, (uint8 *) data, data_len); + } + + f->stream = (uint8 *) data; + f->stream_end = (uint8 *) data + data_len; + f->error = VORBIS__no_error; + + // check that we have the entire packet in memory + if (!is_whole_packet_present(f, FALSE)) { + *samples = 0; + return 0; + } + + if (!vorbis_decode_packet(f, &len, &left, &right)) { + // save the actual error we encountered + enum STBVorbisError error = f->error; + if (error == VORBIS_bad_packet_type) { + // flush and resynch + f->error = VORBIS__no_error; + while (get8_packet(f) != EOP) + if (f->eof) break; + *samples = 0; + return (int) (f->stream - data); + } + if (error == VORBIS_continued_packet_flag_invalid) { + if (f->previous_length == 0) { + // we may be resynching, in which case it's ok to hit one + // of these; just discard the packet + f->error = VORBIS__no_error; + while (get8_packet(f) != EOP) + if (f->eof) break; + *samples = 0; + return (int) (f->stream - data); + } + } + // if we get an error while parsing, what to do? + // well, it DEFINITELY won't work to continue from where we are! + stb_vorbis_flush_pushdata(f); + // restore the error that actually made us bail + f->error = error; + *samples = 0; + return 1; + } + + // success! + len = vorbis_finish_frame(f, len, left, right); + for (i=0; i < f->channels; ++i) + f->outputs[i] = f->channel_buffers[i] + left; + + if (channels) *channels = f->channels; + *samples = len; + *output = f->outputs; + return (int) (f->stream - data); +} + +stb_vorbis *stb_vorbis_open_pushdata( + const unsigned char *data, int data_len, // the memory available for decoding + int *data_used, // only defined if result is not NULL + int *error, const stb_vorbis_alloc *alloc) +{ + stb_vorbis *f, p; + vorbis_init(&p, alloc); + p.stream = (uint8 *) data; + p.stream_end = (uint8 *) data + data_len; + p.push_mode = TRUE; + if (!start_decoder(&p)) { + if (p.eof) + *error = VORBIS_need_more_data; + else + *error = p.error; + return NULL; + } + f = vorbis_alloc(&p); + if (f) { + *f = p; + *data_used = (int) (f->stream - data); + *error = 0; + return f; + } else { + vorbis_deinit(&p); + return NULL; + } +} +#endif // STB_VORBIS_NO_PUSHDATA_API + +unsigned int stb_vorbis_get_file_offset(stb_vorbis *f) +{ + #ifndef STB_VORBIS_NO_PUSHDATA_API + if (f->push_mode) return 0; + #endif + if (USE_MEMORY(f)) return (unsigned int) (f->stream - f->stream_start); + #ifndef STB_VORBIS_NO_STDIO + return (unsigned int) (ftell(f->f) - f->f_start); + #endif +} + +#ifndef STB_VORBIS_NO_PULLDATA_API +// +// DATA-PULLING API +// + +static uint32 vorbis_find_page(stb_vorbis *f, uint32 *end, uint32 *last) +{ + for(;;) { + int n; + if (f->eof) return 0; + n = get8(f); + if (n == 0x4f) { // page header candidate + unsigned int retry_loc = stb_vorbis_get_file_offset(f); + int i; + // check if we're off the end of a file_section stream + if (retry_loc - 25 > f->stream_len) + return 0; + // check the rest of the header + for (i=1; i < 4; ++i) + if (get8(f) != ogg_page_header[i]) + break; + if (f->eof) return 0; + if (i == 4) { + uint8 header[27]; + uint32 i, crc, goal, len; + for (i=0; i < 4; ++i) + header[i] = ogg_page_header[i]; + for (; i < 27; ++i) + header[i] = get8(f); + if (f->eof) return 0; + if (header[4] != 0) goto invalid; + goal = header[22] + (header[23] << 8) + (header[24]<<16) + (header[25]<<24); + for (i=22; i < 26; ++i) + header[i] = 0; + crc = 0; + for (i=0; i < 27; ++i) + crc = crc32_update(crc, header[i]); + len = 0; + for (i=0; i < header[26]; ++i) { + int s = get8(f); + crc = crc32_update(crc, s); + len += s; + } + if (len && f->eof) return 0; + for (i=0; i < len; ++i) + crc = crc32_update(crc, get8(f)); + // finished parsing probable page + if (crc == goal) { + // we could now check that it's either got the last + // page flag set, OR it's followed by the capture + // pattern, but I guess TECHNICALLY you could have + // a file with garbage between each ogg page and recover + // from it automatically? So even though that paranoia + // might decrease the chance of an invalid decode by + // another 2^32, not worth it since it would hose those + // invalid-but-useful files? + if (end) + *end = stb_vorbis_get_file_offset(f); + if (last) { + if (header[5] & 0x04) + *last = 1; + else + *last = 0; + } + set_file_offset(f, retry_loc-1); + return 1; + } + } + invalid: + // not a valid page, so rewind and look for next one + set_file_offset(f, retry_loc); + } + } +} + + +#define SAMPLE_unknown 0xffffffff + +// seeking is implemented with a binary search, which narrows down the range to +// 64K, before using a linear search (because finding the synchronization +// pattern can be expensive, and the chance we'd find the end page again is +// relatively high for small ranges) +// +// two initial interpolation-style probes are used at the start of the search +// to try to bound either side of the binary search sensibly, while still +// working in O(log n) time if they fail. + +static int get_seek_page_info(stb_vorbis *f, ProbedPage *z) +{ + uint8 header[27], lacing[255]; + int i,len; + + // record where the page starts + z->page_start = stb_vorbis_get_file_offset(f); + + // parse the header + getn(f, header, 27); + if (header[0] != 'O' || header[1] != 'g' || header[2] != 'g' || header[3] != 'S') + return 0; + getn(f, lacing, header[26]); + + // determine the length of the payload + len = 0; + for (i=0; i < header[26]; ++i) + len += lacing[i]; + + // this implies where the page ends + z->page_end = z->page_start + 27 + header[26] + len; + + // read the last-decoded sample out of the data + z->last_decoded_sample = header[6] + (header[7] << 8) + (header[8] << 16) + (header[9] << 24); + + // restore file state to where we were + set_file_offset(f, z->page_start); + return 1; +} + +// rarely used function to seek back to the preceeding page while finding the +// start of a packet +static int go_to_page_before(stb_vorbis *f, unsigned int limit_offset) +{ + unsigned int previous_safe, end; + + // now we want to seek back 64K from the limit + if (limit_offset >= 65536 && limit_offset-65536 >= f->first_audio_page_offset) + previous_safe = limit_offset - 65536; + else + previous_safe = f->first_audio_page_offset; + + set_file_offset(f, previous_safe); + + while (vorbis_find_page(f, &end, NULL)) { + if (end >= limit_offset && stb_vorbis_get_file_offset(f) < limit_offset) + return 1; + set_file_offset(f, end); + } + + return 0; +} + +// implements the search logic for finding a page and starting decoding. if +// the function succeeds, current_loc_valid will be true and current_loc will +// be less than or equal to the provided sample number (the closer the +// better). +static int seek_to_sample_coarse(stb_vorbis *f, uint32 sample_number) +{ + ProbedPage left, right, mid; + int i, start_seg_with_known_loc, end_pos, page_start; + uint32 delta, stream_length, padding; + double offset, bytes_per_sample; + int probe = 0; + + // find the last page and validate the target sample + stream_length = stb_vorbis_stream_length_in_samples(f); + if (stream_length == 0) return error(f, VORBIS_seek_without_length); + if (sample_number > stream_length) return error(f, VORBIS_seek_invalid); + + // this is the maximum difference between the window-center (which is the + // actual granule position value), and the right-start (which the spec + // indicates should be the granule position (give or take one)). + padding = ((f->blocksize_1 - f->blocksize_0) >> 2); + if (sample_number < padding) + sample_number = 0; + else + sample_number -= padding; + + left = f->p_first; + while (left.last_decoded_sample == ~0U) { + // (untested) the first page does not have a 'last_decoded_sample' + set_file_offset(f, left.page_end); + if (!get_seek_page_info(f, &left)) goto error; + } + + right = f->p_last; + assert(right.last_decoded_sample != ~0U); + + // starting from the start is handled differently + if (sample_number <= left.last_decoded_sample) { + stb_vorbis_seek_start(f); + return 1; + } + + while (left.page_end != right.page_start) { + assert(left.page_end < right.page_start); + // search range in bytes + delta = right.page_start - left.page_end; + if (delta <= 65536) { + // there's only 64K left to search - handle it linearly + set_file_offset(f, left.page_end); + } else { + if (probe < 2) { + if (probe == 0) { + // first probe (interpolate) + double data_bytes = right.page_end - left.page_start; + bytes_per_sample = data_bytes / right.last_decoded_sample; + offset = left.page_start + bytes_per_sample * (sample_number - left.last_decoded_sample); + } else { + // second probe (try to bound the other side) + double error = ((double) sample_number - mid.last_decoded_sample) * bytes_per_sample; + if (error >= 0 && error < 8000) error = 8000; + if (error < 0 && error > -8000) error = -8000; + offset += error * 2; + } + + // ensure the offset is valid + if (offset < left.page_end) + offset = left.page_end; + if (offset > right.page_start - 65536) + offset = right.page_start - 65536; + + set_file_offset(f, (unsigned int) offset); + } else { + // binary search for large ranges (offset by 32K to ensure + // we don't hit the right page) + set_file_offset(f, left.page_end + (delta / 2) - 32768); + } + + if (!vorbis_find_page(f, NULL, NULL)) goto error; + } + + for (;;) { + if (!get_seek_page_info(f, &mid)) goto error; + if (mid.last_decoded_sample != ~0U) break; + // (untested) no frames end on this page + set_file_offset(f, mid.page_end); + assert(mid.page_start < right.page_start); + } + + // if we've just found the last page again then we're in a tricky file, + // and we're close enough. + if (mid.page_start == right.page_start) + break; + + if (sample_number < mid.last_decoded_sample) + right = mid; + else + left = mid; + + ++probe; + } + + // seek back to start of the last packet + page_start = left.page_start; + set_file_offset(f, page_start); + if (!start_page(f)) return error(f, VORBIS_seek_failed); + end_pos = f->end_seg_with_known_loc; + assert(end_pos >= 0); + + for (;;) { + for (i = end_pos; i > 0; --i) + if (f->segments[i-1] != 255) + break; + + start_seg_with_known_loc = i; + + if (start_seg_with_known_loc > 0 || !(f->page_flag & PAGEFLAG_continued_packet)) + break; + + // (untested) the final packet begins on an earlier page + if (!go_to_page_before(f, page_start)) + goto error; + + page_start = stb_vorbis_get_file_offset(f); + if (!start_page(f)) goto error; + end_pos = f->segment_count - 1; + } + + // prepare to start decoding + f->current_loc_valid = FALSE; + f->last_seg = FALSE; + f->valid_bits = 0; + f->packet_bytes = 0; + f->bytes_in_seg = 0; + f->previous_length = 0; + f->next_seg = start_seg_with_known_loc; + + for (i = 0; i < start_seg_with_known_loc; i++) + skip(f, f->segments[i]); + + // start decoding (optimizable - this frame is generally discarded) + vorbis_pump_first_frame(f); + return 1; + +error: + // try to restore the file to a valid state + stb_vorbis_seek_start(f); + return error(f, VORBIS_seek_failed); +} + +// the same as vorbis_decode_initial, but without advancing +static int peek_decode_initial(vorb *f, int *p_left_start, int *p_left_end, int *p_right_start, int *p_right_end, int *mode) +{ + int bits_read, bytes_read; + + if (!vorbis_decode_initial(f, p_left_start, p_left_end, p_right_start, p_right_end, mode)) + return 0; + + // either 1 or 2 bytes were read, figure out which so we can rewind + bits_read = 1 + ilog(f->mode_count-1); + if (f->mode_config[*mode].blockflag) + bits_read += 2; + bytes_read = (bits_read + 7) / 8; + + f->bytes_in_seg += bytes_read; + f->packet_bytes -= bytes_read; + skip(f, -bytes_read); + if (f->next_seg == -1) + f->next_seg = f->segment_count - 1; + else + f->next_seg--; + f->valid_bits = 0; + + return 1; +} + +int stb_vorbis_seek_frame(stb_vorbis *f, unsigned int sample_number) +{ + uint32 max_frame_samples; + + if (IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing); + + // fast page-level search + if (!seek_to_sample_coarse(f, sample_number)) + return 0; + + assert(f->current_loc_valid); + assert(f->current_loc <= sample_number); + + // linear search for the relevant packet + max_frame_samples = (f->blocksize_1*3 - f->blocksize_0) >> 2; + while (f->current_loc < sample_number) { + int left_start, left_end, right_start, right_end, mode, frame_samples; + if (!peek_decode_initial(f, &left_start, &left_end, &right_start, &right_end, &mode)) + return error(f, VORBIS_seek_failed); + // calculate the number of samples returned by the next frame + frame_samples = right_start - left_start; + if (f->current_loc + frame_samples > sample_number) { + return 1; // the next frame will contain the sample + } else if (f->current_loc + frame_samples + max_frame_samples > sample_number) { + // there's a chance the frame after this could contain the sample + vorbis_pump_first_frame(f); + } else { + // this frame is too early to be relevant + f->current_loc += frame_samples; + f->previous_length = 0; + maybe_start_packet(f); + flush_packet(f); + } + } + // the next frame will start with the sample + assert(f->current_loc == sample_number); + return 1; +} + +int stb_vorbis_seek(stb_vorbis *f, unsigned int sample_number) +{ + if (!stb_vorbis_seek_frame(f, sample_number)) + return 0; + + if (sample_number != f->current_loc) { + int n; + uint32 frame_start = f->current_loc; + stb_vorbis_get_frame_float(f, &n, NULL); + assert(sample_number > frame_start); + assert(f->channel_buffer_start + (int) (sample_number-frame_start) <= f->channel_buffer_end); + f->channel_buffer_start += (sample_number - frame_start); + } + + return 1; +} + +void stb_vorbis_seek_start(stb_vorbis *f) +{ + if (IS_PUSH_MODE(f)) { error(f, VORBIS_invalid_api_mixing); return; } + set_file_offset(f, f->first_audio_page_offset); + f->previous_length = 0; + f->first_decode = TRUE; + f->next_seg = -1; + vorbis_pump_first_frame(f); +} + +unsigned int stb_vorbis_stream_length_in_samples(stb_vorbis *f) +{ + unsigned int restore_offset, previous_safe; + unsigned int end, last_page_loc; + + if (IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing); + if (!f->total_samples) { + unsigned int last; + uint32 lo,hi; + char header[6]; + + // first, store the current decode position so we can restore it + restore_offset = stb_vorbis_get_file_offset(f); + + // now we want to seek back 64K from the end (the last page must + // be at most a little less than 64K, but let's allow a little slop) + if (f->stream_len >= 65536 && f->stream_len-65536 >= f->first_audio_page_offset) + previous_safe = f->stream_len - 65536; + else + previous_safe = f->first_audio_page_offset; + + set_file_offset(f, previous_safe); + // previous_safe is now our candidate 'earliest known place that seeking + // to will lead to the final page' + + if (!vorbis_find_page(f, &end, &last)) { + // if we can't find a page, we're hosed! + f->error = VORBIS_cant_find_last_page; + f->total_samples = 0xffffffff; + goto done; + } + + // check if there are more pages + last_page_loc = stb_vorbis_get_file_offset(f); + + // stop when the last_page flag is set, not when we reach eof; + // this allows us to stop short of a 'file_section' end without + // explicitly checking the length of the section + while (!last) { + set_file_offset(f, end); + if (!vorbis_find_page(f, &end, &last)) { + // the last page we found didn't have the 'last page' flag + // set. whoops! + break; + } + previous_safe = last_page_loc+1; + last_page_loc = stb_vorbis_get_file_offset(f); + } + + set_file_offset(f, last_page_loc); + + // parse the header + getn(f, (unsigned char *)header, 6); + // extract the absolute granule position + lo = get32(f); + hi = get32(f); + if (lo == 0xffffffff && hi == 0xffffffff) { + f->error = VORBIS_cant_find_last_page; + f->total_samples = SAMPLE_unknown; + goto done; + } + if (hi) + lo = 0xfffffffe; // saturate + f->total_samples = lo; + + f->p_last.page_start = last_page_loc; + f->p_last.page_end = end; + f->p_last.last_decoded_sample = lo; + + done: + set_file_offset(f, restore_offset); + } + return f->total_samples == SAMPLE_unknown ? 0 : f->total_samples; +} + +float stb_vorbis_stream_length_in_seconds(stb_vorbis *f) +{ + return stb_vorbis_stream_length_in_samples(f) / (float) f->sample_rate; +} + + + +int stb_vorbis_get_frame_float(stb_vorbis *f, int *channels, float ***output) +{ + int len, right,left,i; + if (IS_PUSH_MODE(f)) return error(f, VORBIS_invalid_api_mixing); + + if (!vorbis_decode_packet(f, &len, &left, &right)) { + f->channel_buffer_start = f->channel_buffer_end = 0; + return 0; + } + + len = vorbis_finish_frame(f, len, left, right); + for (i=0; i < f->channels; ++i) + f->outputs[i] = f->channel_buffers[i] + left; + + f->channel_buffer_start = left; + f->channel_buffer_end = left+len; + + if (channels) *channels = f->channels; + if (output) *output = f->outputs; + return len; +} + +#ifndef STB_VORBIS_NO_STDIO + +stb_vorbis * stb_vorbis_open_file_section(FILE *file, int close_on_free, int *error, const stb_vorbis_alloc *alloc, unsigned int length) +{ + stb_vorbis *f, p; + vorbis_init(&p, alloc); + p.f = file; + p.f_start = (uint32) ftell(file); + p.stream_len = length; + p.close_on_free = close_on_free; + if (start_decoder(&p)) { + f = vorbis_alloc(&p); + if (f) { + *f = p; + vorbis_pump_first_frame(f); + return f; + } + } + if (error) *error = p.error; + vorbis_deinit(&p); + return NULL; +} + +stb_vorbis * stb_vorbis_open_file(FILE *file, int close_on_free, int *error, const stb_vorbis_alloc *alloc) +{ + unsigned int len, start; + start = (unsigned int) ftell(file); + fseek(file, 0, SEEK_END); + len = (unsigned int) (ftell(file) - start); + fseek(file, start, SEEK_SET); + return stb_vorbis_open_file_section(file, close_on_free, error, alloc, len); +} + +stb_vorbis * stb_vorbis_open_filename(const char *filename, int *error, const stb_vorbis_alloc *alloc) +{ + FILE *f = fopen(filename, "rb"); + if (f) + return stb_vorbis_open_file(f, TRUE, error, alloc); + if (error) *error = VORBIS_file_open_failure; + return NULL; +} +#endif // STB_VORBIS_NO_STDIO + +stb_vorbis * stb_vorbis_open_memory(const unsigned char *data, int len, int *error, const stb_vorbis_alloc *alloc) +{ + stb_vorbis *f, p; + if (data == NULL) return NULL; + vorbis_init(&p, alloc); + p.stream = (uint8 *) data; + p.stream_end = (uint8 *) data + len; + p.stream_start = (uint8 *) p.stream; + p.stream_len = len; + p.push_mode = FALSE; + if (start_decoder(&p)) { + f = vorbis_alloc(&p); + if (f) { + *f = p; + vorbis_pump_first_frame(f); + return f; + } + } + if (error) *error = p.error; + vorbis_deinit(&p); + return NULL; +} + +#ifndef STB_VORBIS_NO_INTEGER_CONVERSION +#define PLAYBACK_MONO 1 +#define PLAYBACK_LEFT 2 +#define PLAYBACK_RIGHT 4 + +#define L (PLAYBACK_LEFT | PLAYBACK_MONO) +#define C (PLAYBACK_LEFT | PLAYBACK_RIGHT | PLAYBACK_MONO) +#define R (PLAYBACK_RIGHT | PLAYBACK_MONO) + +static int8 channel_position[7][6] = +{ + { 0 }, + { C }, + { L, R }, + { L, C, R }, + { L, R, L, R }, + { L, C, R, L, R }, + { L, C, R, L, R, C }, +}; + + +#ifndef STB_VORBIS_NO_FAST_SCALED_FLOAT + typedef union { + float f; + int i; + } float_conv; + typedef char stb_vorbis_float_size_test[sizeof(float)==4 && sizeof(int) == 4]; + #define FASTDEF(x) float_conv x + // add (1<<23) to convert to int, then divide by 2^SHIFT, then add 0.5/2^SHIFT to round + #define MAGIC(SHIFT) (1.5f * (1 << (23-SHIFT)) + 0.5f/(1 << SHIFT)) + #define ADDEND(SHIFT) (((150-SHIFT) << 23) + (1 << 22)) + #define FAST_SCALED_FLOAT_TO_INT(temp,x,s) (temp.f = (x) + MAGIC(s), temp.i - ADDEND(s)) + #define check_endianness() +#else + #define FAST_SCALED_FLOAT_TO_INT(temp,x,s) ((int) ((x) * (1 << (s)))) + #define check_endianness() + #define FASTDEF(x) +#endif + +static void copy_samples(short *dest, float *src, int len) +{ + int i; + check_endianness(); + for (i=0; i < len; ++i) { + FASTDEF(temp); + int v = FAST_SCALED_FLOAT_TO_INT(temp, src[i],15); + if ((unsigned int) (v + 32768) > 65535) + v = v < 0 ? -32768 : 32767; + dest[i] = v; + } +} + +static void compute_samples(int mask, short *output, int num_c, float **data, int d_offset, int len) +{ + #define BUFFER_SIZE 32 + float buffer[BUFFER_SIZE]; + int i,j,o,n = BUFFER_SIZE; + check_endianness(); + for (o = 0; o < len; o += BUFFER_SIZE) { + memset(buffer, 0, sizeof(buffer)); + if (o + n > len) n = len - o; + for (j=0; j < num_c; ++j) { + if (channel_position[num_c][j] & mask) { + for (i=0; i < n; ++i) + buffer[i] += data[j][d_offset+o+i]; + } + } + for (i=0; i < n; ++i) { + FASTDEF(temp); + int v = FAST_SCALED_FLOAT_TO_INT(temp,buffer[i],15); + if ((unsigned int) (v + 32768) > 65535) + v = v < 0 ? -32768 : 32767; + output[o+i] = v; + } + } +} + +static void compute_stereo_samples(short *output, int num_c, float **data, int d_offset, int len) +{ + #define BUFFER_SIZE 32 + float buffer[BUFFER_SIZE]; + int i,j,o,n = BUFFER_SIZE >> 1; + // o is the offset in the source data + check_endianness(); + for (o = 0; o < len; o += BUFFER_SIZE >> 1) { + // o2 is the offset in the output data + int o2 = o << 1; + memset(buffer, 0, sizeof(buffer)); + if (o + n > len) n = len - o; + for (j=0; j < num_c; ++j) { + int m = channel_position[num_c][j] & (PLAYBACK_LEFT | PLAYBACK_RIGHT); + if (m == (PLAYBACK_LEFT | PLAYBACK_RIGHT)) { + for (i=0; i < n; ++i) { + buffer[i*2+0] += data[j][d_offset+o+i]; + buffer[i*2+1] += data[j][d_offset+o+i]; + } + } else if (m == PLAYBACK_LEFT) { + for (i=0; i < n; ++i) { + buffer[i*2+0] += data[j][d_offset+o+i]; + } + } else if (m == PLAYBACK_RIGHT) { + for (i=0; i < n; ++i) { + buffer[i*2+1] += data[j][d_offset+o+i]; + } + } + } + for (i=0; i < (n<<1); ++i) { + FASTDEF(temp); + int v = FAST_SCALED_FLOAT_TO_INT(temp,buffer[i],15); + if ((unsigned int) (v + 32768) > 65535) + v = v < 0 ? -32768 : 32767; + output[o2+i] = v; + } + } +} + +static void convert_samples_short(int buf_c, short **buffer, int b_offset, int data_c, float **data, int d_offset, int samples) +{ + int i; + if (buf_c != data_c && buf_c <= 2 && data_c <= 6) { + static int channel_selector[3][2] = { {0}, {PLAYBACK_MONO}, {PLAYBACK_LEFT, PLAYBACK_RIGHT} }; + for (i=0; i < buf_c; ++i) + compute_samples(channel_selector[buf_c][i], buffer[i]+b_offset, data_c, data, d_offset, samples); + } else { + int limit = buf_c < data_c ? buf_c : data_c; + for (i=0; i < limit; ++i) + copy_samples(buffer[i]+b_offset, data[i]+d_offset, samples); + for ( ; i < buf_c; ++i) + memset(buffer[i]+b_offset, 0, sizeof(short) * samples); + } +} + +int stb_vorbis_get_frame_short(stb_vorbis *f, int num_c, short **buffer, int num_samples) +{ + float **output; + int len = stb_vorbis_get_frame_float(f, NULL, &output); + if (len > num_samples) len = num_samples; + if (len) + convert_samples_short(num_c, buffer, 0, f->channels, output, 0, len); + return len; +} + +static void convert_channels_short_interleaved(int buf_c, short *buffer, int data_c, float **data, int d_offset, int len) +{ + int i; + check_endianness(); + if (buf_c != data_c && buf_c <= 2 && data_c <= 6) { + assert(buf_c == 2); + for (i=0; i < buf_c; ++i) + compute_stereo_samples(buffer, data_c, data, d_offset, len); + } else { + int limit = buf_c < data_c ? buf_c : data_c; + int j; + for (j=0; j < len; ++j) { + for (i=0; i < limit; ++i) { + FASTDEF(temp); + float f = data[i][d_offset+j]; + int v = FAST_SCALED_FLOAT_TO_INT(temp, f,15);//data[i][d_offset+j],15); + if ((unsigned int) (v + 32768) > 65535) + v = v < 0 ? -32768 : 32767; + *buffer++ = v; + } + for ( ; i < buf_c; ++i) + *buffer++ = 0; + } + } +} + +int stb_vorbis_get_frame_short_interleaved(stb_vorbis *f, int num_c, short *buffer, int num_shorts) +{ + float **output; + int len; + if (num_c == 1) return stb_vorbis_get_frame_short(f,num_c,&buffer, num_shorts); + len = stb_vorbis_get_frame_float(f, NULL, &output); + if (len) { + if (len*num_c > num_shorts) len = num_shorts / num_c; + convert_channels_short_interleaved(num_c, buffer, f->channels, output, 0, len); + } + return len; +} + +int stb_vorbis_get_samples_short_interleaved(stb_vorbis *f, int channels, short *buffer, int num_shorts) +{ + float **outputs; + int len = num_shorts / channels; + int n=0; + int z = f->channels; + if (z > channels) z = channels; + while (n < len) { + int k = f->channel_buffer_end - f->channel_buffer_start; + if (n+k >= len) k = len - n; + if (k) + convert_channels_short_interleaved(channels, buffer, f->channels, f->channel_buffers, f->channel_buffer_start, k); + buffer += k*channels; + n += k; + f->channel_buffer_start += k; + if (n == len) break; + if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) break; + } + return n; +} + +int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer, int len) +{ + float **outputs; + int n=0; + int z = f->channels; + if (z > channels) z = channels; + while (n < len) { + int k = f->channel_buffer_end - f->channel_buffer_start; + if (n+k >= len) k = len - n; + if (k) + convert_samples_short(channels, buffer, n, f->channels, f->channel_buffers, f->channel_buffer_start, k); + n += k; + f->channel_buffer_start += k; + if (n == len) break; + if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) break; + } + return n; +} + +#ifndef STB_VORBIS_NO_STDIO +int stb_vorbis_decode_filename(const char *filename, int *channels, int *sample_rate, short **output) +{ + int data_len, offset, total, limit, error; + short *data; + stb_vorbis *v = stb_vorbis_open_filename(filename, &error, NULL); + if (v == NULL) return -1; + limit = v->channels * 4096; + *channels = v->channels; + if (sample_rate) + *sample_rate = v->sample_rate; + offset = data_len = 0; + total = limit; + data = (short *) malloc(total * sizeof(*data)); + if (data == NULL) { + stb_vorbis_close(v); + return -2; + } + for (;;) { + int n = stb_vorbis_get_frame_short_interleaved(v, v->channels, data+offset, total-offset); + if (n == 0) break; + data_len += n; + offset += n * v->channels; + if (offset + limit > total) { + short *data2; + total *= 2; + data2 = (short *) realloc(data, total * sizeof(*data)); + if (data2 == NULL) { + free(data); + stb_vorbis_close(v); + return -2; + } + data = data2; + } + } + *output = data; + stb_vorbis_close(v); + return data_len; +} +#endif // NO_STDIO + +int stb_vorbis_decode_memory(const uint8 *mem, int len, int *channels, int *sample_rate, short **output) +{ + int data_len, offset, total, limit, error; + short *data; + stb_vorbis *v = stb_vorbis_open_memory(mem, len, &error, NULL); + if (v == NULL) return -1; + limit = v->channels * 4096; + *channels = v->channels; + if (sample_rate) + *sample_rate = v->sample_rate; + offset = data_len = 0; + total = limit; + data = (short *) malloc(total * sizeof(*data)); + if (data == NULL) { + stb_vorbis_close(v); + return -2; + } + for (;;) { + int n = stb_vorbis_get_frame_short_interleaved(v, v->channels, data+offset, total-offset); + if (n == 0) break; + data_len += n; + offset += n * v->channels; + if (offset + limit > total) { + short *data2; + total *= 2; + data2 = (short *) realloc(data, total * sizeof(*data)); + if (data2 == NULL) { + free(data); + stb_vorbis_close(v); + return -2; + } + data = data2; + } + } + *output = data; + stb_vorbis_close(v); + return data_len; +} +#endif // STB_VORBIS_NO_INTEGER_CONVERSION + +int stb_vorbis_get_samples_float_interleaved(stb_vorbis *f, int channels, float *buffer, int num_floats) +{ + float **outputs; + int len = num_floats / channels; + int n=0; + int z = f->channels; + if (z > channels) z = channels; + while (n < len) { + int i,j; + int k = f->channel_buffer_end - f->channel_buffer_start; + if (n+k >= len) k = len - n; + for (j=0; j < k; ++j) { + for (i=0; i < z; ++i) + *buffer++ = f->channel_buffers[i][f->channel_buffer_start+j]; + for ( ; i < channels; ++i) + *buffer++ = 0; + } + n += k; + f->channel_buffer_start += k; + if (n == len) + break; + if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) + break; + } + return n; +} + +int stb_vorbis_get_samples_float(stb_vorbis *f, int channels, float **buffer, int num_samples) +{ + float **outputs; + int n=0; + int z = f->channels; + if (z > channels) z = channels; + while (n < num_samples) { + int i; + int k = f->channel_buffer_end - f->channel_buffer_start; + if (n+k >= num_samples) k = num_samples - n; + if (k) { + for (i=0; i < z; ++i) + memcpy(buffer[i]+n, f->channel_buffers[i]+f->channel_buffer_start, sizeof(float)*k); + for ( ; i < channels; ++i) + memset(buffer[i]+n, 0, sizeof(float) * k); + } + n += k; + f->channel_buffer_start += k; + if (n == num_samples) + break; + if (!stb_vorbis_get_frame_float(f, NULL, &outputs)) + break; + } + return n; +} +#endif // STB_VORBIS_NO_PULLDATA_API + +/* Version history + 1.09 - 2016/04/04 - back out 'avoid discarding last frame' fix from previous version + 1.08 - 2016/04/02 - fixed multiple warnings; fix setup memory leaks; + avoid discarding last frame of audio data + 1.07 - 2015/01/16 - fixed some warnings, fix mingw, const-correct API + some more crash fixes when out of memory or with corrupt files + 1.06 - 2015/08/31 - full, correct support for seeking API (Dougall Johnson) + some crash fixes when out of memory or with corrupt files + 1.05 - 2015/04/19 - don't define __forceinline if it's redundant + 1.04 - 2014/08/27 - fix missing const-correct case in API + 1.03 - 2014/08/07 - Warning fixes + 1.02 - 2014/07/09 - Declare qsort compare function _cdecl on windows + 1.01 - 2014/06/18 - fix stb_vorbis_get_samples_float + 1.0 - 2014/05/26 - fix memory leaks; fix warnings; fix bugs in multichannel + (API change) report sample rate for decode-full-file funcs + 0.99996 - bracket #include <malloc.h> for macintosh compilation by Laurent Gomila + 0.99995 - use union instead of pointer-cast for fast-float-to-int to avoid alias-optimization problem + 0.99994 - change fast-float-to-int to work in single-precision FPU mode, remove endian-dependence + 0.99993 - remove assert that fired on legal files with empty tables + 0.99992 - rewind-to-start + 0.99991 - bugfix to stb_vorbis_get_samples_short by Bernhard Wodo + 0.9999 - (should have been 0.99990) fix no-CRT support, compiling as C++ + 0.9998 - add a full-decode function with a memory source + 0.9997 - fix a bug in the read-from-FILE case in 0.9996 addition + 0.9996 - query length of vorbis stream in samples/seconds + 0.9995 - bugfix to another optimization that only happened in certain files + 0.9994 - bugfix to one of the optimizations that caused significant (but inaudible?) errors + 0.9993 - performance improvements; runs in 99% to 104% of time of reference implementation + 0.9992 - performance improvement of IMDCT; now performs close to reference implementation + 0.9991 - performance improvement of IMDCT + 0.999 - (should have been 0.9990) performance improvement of IMDCT + 0.998 - no-CRT support from Casey Muratori + 0.997 - bugfixes for bugs found by Terje Mathisen + 0.996 - bugfix: fast-huffman decode initialized incorrectly for sparse codebooks; fixing gives 10% speedup - found by Terje Mathisen + 0.995 - bugfix: fix to 'effective' overrun detection - found by Terje Mathisen + 0.994 - bugfix: garbage decode on final VQ symbol of a non-multiple - found by Terje Mathisen + 0.993 - bugfix: pushdata API required 1 extra byte for empty page (failed to consume final page if empty) - found by Terje Mathisen + 0.992 - fixes for MinGW warning + 0.991 - turn fast-float-conversion on by default + 0.990 - fix push-mode seek recovery if you seek into the headers + 0.98b - fix to bad release of 0.98 + 0.98 - fix push-mode seek recovery; robustify float-to-int and support non-fast mode + 0.97 - builds under c++ (typecasting, don't use 'class' keyword) + 0.96 - somehow MY 0.95 was right, but the web one was wrong, so here's my 0.95 rereleased as 0.96, fixes a typo in the clamping code + 0.95 - clamping code for 16-bit functions + 0.94 - not publically released + 0.93 - fixed all-zero-floor case (was decoding garbage) + 0.92 - fixed a memory leak + 0.91 - conditional compiles to omit parts of the API and the infrastructure to support them: STB_VORBIS_NO_PULLDATA_API, STB_VORBIS_NO_PUSHDATA_API, STB_VORBIS_NO_STDIO, STB_VORBIS_NO_INTEGER_CONVERSION + 0.90 - first public release +*/ + +#endif // STB_VORBIS_HEADER_ONLY diff --git a/thirdparty/zlib/deflate.c b/thirdparty/zlib/deflate.c index 2ad890e354..1ec761448d 100644 --- a/thirdparty/zlib/deflate.c +++ b/thirdparty/zlib/deflate.c @@ -52,7 +52,7 @@ #include "deflate.h" const char deflate_copyright[] = - " deflate 1.2.10 Copyright 1995-2017 Jean-loup Gailly and Mark Adler "; + " deflate 1.2.11 Copyright 1995-2017 Jean-loup Gailly and Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -586,7 +586,8 @@ int ZEXPORT deflateParams(strm, level, strategy) } func = configuration_table[s->level].func; - if ((strategy != s->strategy || func != configuration_table[level].func)) { + if ((strategy != s->strategy || func != configuration_table[level].func) && + s->high_water) { /* Flush the last buffer: */ int err = deflate(strm, Z_BLOCK); if (err == Z_STREAM_ERROR) @@ -1671,8 +1672,6 @@ local block_state deflate_stored(s, flush) len = left + s->strm->avail_in; /* limit len to the input */ if (len > have) len = have; /* limit len to the output */ - if (left > len) - left = len; /* limit window pull to len */ /* If the stored block would be less than min_block in length, or if * unable to copy all of the available input when flushing, then try @@ -1681,13 +1680,13 @@ local block_state deflate_stored(s, flush) */ if (len < min_block && ((len == 0 && flush != Z_FINISH) || flush == Z_NO_FLUSH || - len - left != s->strm->avail_in)) + len != left + s->strm->avail_in)) break; /* Make a dummy stored block in pending to get the header bytes, * including any pending bits. This also updates the debugging counts. */ - last = flush == Z_FINISH && len - left == s->strm->avail_in ? 1 : 0; + last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0; _tr_stored_block(s, (char *)0, 0L, last); /* Replace the lengths in the dummy stored block with len. */ @@ -1699,14 +1698,16 @@ local block_state deflate_stored(s, flush) /* Write the stored block header bytes. */ flush_pending(s->strm); - /* Update debugging counts for the data about to be copied. */ #ifdef ZLIB_DEBUG + /* Update debugging counts for the data about to be copied. */ s->compressed_len += len << 3; s->bits_sent += len << 3; #endif /* Copy uncompressed bytes from the window to next_out. */ if (left) { + if (left > len) + left = len; zmemcpy(s->strm->next_out, s->window + s->block_start, left); s->strm->next_out += left; s->strm->avail_out -= left; @@ -1756,6 +1757,8 @@ local block_state deflate_stored(s, flush) s->block_start = s->strstart; s->insert += MIN(used, s->w_size - s->insert); } + if (s->high_water < s->strstart) + s->high_water = s->strstart; /* If the last block was written to next_out, then done. */ if (last) @@ -1783,6 +1786,8 @@ local block_state deflate_stored(s, flush) read_buf(s->strm, s->window + s->strstart, have); s->strstart += have; } + if (s->high_water < s->strstart) + s->high_water = s->strstart; /* There was not enough avail_out to write a complete worthy or flushed * stored block to next_out. Write a stored block to pending instead, if we diff --git a/thirdparty/zlib/gzlib.c b/thirdparty/zlib/gzlib.c index e142ffb3d7..4105e6aff9 100644 --- a/thirdparty/zlib/gzlib.c +++ b/thirdparty/zlib/gzlib.c @@ -1,5 +1,5 @@ /* gzlib.c -- zlib functions common to reading and writing gzip files - * Copyright (C) 2004, 2010, 2011, 2012, 2013, 2016 Mark Adler + * Copyright (C) 2004-2017 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/thirdparty/zlib/gzwrite.c b/thirdparty/zlib/gzwrite.c index 1ec1da4095..c7b5651d70 100644 --- a/thirdparty/zlib/gzwrite.c +++ b/thirdparty/zlib/gzwrite.c @@ -1,5 +1,5 @@ /* gzwrite.c -- zlib functions for writing gzip files - * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013, 2016 Mark Adler + * Copyright (C) 2004-2017 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/thirdparty/zlib/inffast.c b/thirdparty/zlib/inffast.c index 29eb7d8244..0dbd1dbc09 100644 --- a/thirdparty/zlib/inffast.c +++ b/thirdparty/zlib/inffast.c @@ -1,5 +1,5 @@ /* inffast.c -- fast decoding - * Copyright (C) 1995-2008, 2010, 2013, 2016 Mark Adler + * Copyright (C) 1995-2017 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/thirdparty/zlib/inftrees.c b/thirdparty/zlib/inftrees.c index 8a904ddbce..2ea08fc13e 100644 --- a/thirdparty/zlib/inftrees.c +++ b/thirdparty/zlib/inftrees.c @@ -9,7 +9,7 @@ #define MAXBITS 15 const char inflate_copyright[] = - " inflate 1.2.10 Copyright 1995-2017 Mark Adler "; + " inflate 1.2.11 Copyright 1995-2017 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -62,7 +62,7 @@ unsigned short FAR *work; 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 192, 202}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 77, 202}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, diff --git a/thirdparty/zlib/trees.c b/thirdparty/zlib/trees.c index 357f313925..50cf4b4571 100644 --- a/thirdparty/zlib/trees.c +++ b/thirdparty/zlib/trees.c @@ -1,5 +1,5 @@ /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2016 Jean-loup Gailly + * Copyright (C) 1995-2017 Jean-loup Gailly * detect_data_type() function provided freely by Cosmin Truta, 2006 * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -906,7 +906,7 @@ void ZLIB_INTERNAL _tr_align(s) /* =========================================================================== * Determine the best encoding for the current block: dynamic trees, static - * trees or store, and output the encoded block to the zip file. + * trees or store, and write out the encoded block. */ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) deflate_state *s; diff --git a/thirdparty/zlib/zlib.h b/thirdparty/zlib/zlib.h index dc90dc8d22..f09cdaf1e0 100644 --- a/thirdparty/zlib/zlib.h +++ b/thirdparty/zlib/zlib.h @@ -1,5 +1,5 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.10, January 2nd, 2017 + version 1.2.11, January 15th, 2017 Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.10" -#define ZLIB_VERNUM 0x12a0 +#define ZLIB_VERSION "1.2.11" +#define ZLIB_VERNUM 0x12b0 #define ZLIB_VER_MAJOR 1 #define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 10 +#define ZLIB_VER_REVISION 11 #define ZLIB_VER_SUBREVISION 0 /* @@ -712,10 +712,11 @@ ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, used to switch between compression and straight copy of the input data, or to switch to a different kind of input data requiring a different strategy. If the compression approach (which is a function of the level) or the - strategy is changed, then the input available so far is compressed with the - old level and strategy using deflate(strm, Z_BLOCK). There are three - approaches for the compression levels 0, 1..3, and 4..9 respectively. The - new level and strategy will take effect at the next call of deflate(). + strategy is changed, and if any input has been consumed in a previous + deflate() call, then the input available so far is compressed with the old + level and strategy using deflate(strm, Z_BLOCK). There are three approaches + for the compression levels 0, 1..3, and 4..9 respectively. The new level + and strategy will take effect at the next call of deflate(). If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does not have enough output space to complete, then the parameter change will not diff --git a/thirdparty/zlib/zutil.c b/thirdparty/zlib/zutil.c index 56534fba0f..a76c6b0c7e 100644 --- a/thirdparty/zlib/zutil.c +++ b/thirdparty/zlib/zutil.c @@ -1,5 +1,5 @@ /* zutil.c -- target dependent utility functions for the compression library - * Copyright (C) 1995-2005, 2010, 2011, 2012, 2016 Jean-loup Gailly + * Copyright (C) 1995-2017 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/tools/SCsub b/tools/SCsub deleted file mode 100644 index 43cad794d4..0000000000 --- a/tools/SCsub +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env python - -Import('env') - -env.tool_sources = [] -env.add_source_files(env.tool_sources, "*.cpp") - -Export('env') - - -def make_translations_header(target, source, env): - - dst = target[0].srcnode().abspath - - g = open(dst, "wb") - - """" - """ - - g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef _EDITOR_TRANSLATIONS_H\n") - g.write("#define _EDITOR_TRANSLATIONS_H\n") - - import zlib - import os.path - - paths = [node.srcnode().abspath for node in source] - sorted_paths = sorted(paths, key=lambda path: os.path.splitext(os.path.basename(path))[0]) - - xl_names = [] - for i in range(len(sorted_paths)): - print("Appending translation: " + sorted_paths[i]) - f = open(sorted_paths[i], "rb") - buf = f.read() - decomp_size = len(buf) - buf = zlib.compress(buf) - name = os.path.splitext(os.path.basename(sorted_paths[i]))[0] - - #g.write("static const int _translation_"+name+"_compressed_size="+str(len(buf))+";\n") - #g.write("static const int _translation_"+name+"_uncompressed_size="+str(decomp_size)+";\n") - g.write("static const unsigned char _translation_" + name + "_compressed[]={\n") - for i in range(len(buf)): - g.write(str(ord(buf[i])) + ",\n") - - g.write("};\n") - - xl_names.append([name, len(buf), str(decomp_size)]) - - g.write("struct EditorTranslationList {\n") - g.write("\tconst char* lang;\n") - g.write("\tint comp_size;\n") - g.write("\tint uncomp_size;\n") - g.write("\tconst unsigned char* data;\n") - g.write("};\n\n") - g.write("static EditorTranslationList _editor_translations[]={\n") - for x in xl_names: - g.write("\t{ \"" + x[0] + "\", " + str(x[1]) + ", " + str(x[2]) + ",_translation_" + x[0] + "_compressed},\n") - g.write("\t{NULL,0,0,NULL}\n") - g.write("};\n") - - g.write("#endif") - - -def make_fonts_header(target, source, env): - - dst = target[0].srcnode().abspath - - g = open(dst, "wb") - - """" - """ - - g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef _EDITOR_FONTS_H\n") - g.write("#define _EDITOR_FONTS_H\n") - - # saving uncompressed, since freetype will reference from memory pointer - xl_names = [] - for i in range(len(source)): - print("Appending font: " + source[i].srcnode().abspath) - f = open(source[i].srcnode().abspath, "rb") - buf = f.read() - import os.path - - name = os.path.splitext(os.path.basename(source[i].srcnode().abspath))[0] - - g.write("static const int _font_" + name + "_size=" + str(len(buf)) + ";\n") - g.write("static const unsigned char _font_" + name + "[]={\n") - for i in range(len(buf)): - g.write(str(ord(buf[i])) + ",\n") - - g.write("};\n") - - g.write("#endif") - - -if (env["tools"] != "no"): - - import glob - - dir = env.Dir('.').abspath - tlist = glob.glob(dir + "/translations/*.po") - - print("translations: ", tlist) - env.Depends('#tools/editor/translations.h', tlist) - env.Command('#tools/editor/translations.h', tlist, make_translations_header) - - flist = glob.glob(dir + "/editor_fonts/*.ttf") - flist.append(glob.glob(dir + "/editor_fonts/*.otf")) - - print("fonts: ", flist) - env.Depends('#tools/editor/builtin_fonts.h', flist) - env.Command('#tools/editor/builtin_fonts.h', flist, make_fonts_header) - - SConscript('editor/SCsub') - SConscript('collada/SCsub') - SConscript('doc/SCsub') - - lib = env.Library("tool", env.tool_sources) - - env.Prepend(LIBS=[lib]) diff --git a/tools/editor/SCsub b/tools/editor/SCsub index caf45d25be..710dac3ea7 100644 --- a/tools/editor/SCsub +++ b/tools/editor/SCsub @@ -1,9 +1,10 @@ #!/usr/bin/env python Import('env') +env.editor_sources = [] -def make_doc_header(target, source, env): +def make_certs_header(target, source, env): src = source[0].srcnode().abspath dst = target[0].srcnode().abspath @@ -15,18 +16,18 @@ def make_doc_header(target, source, env): buf = zlib.compress(buf) g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef _DOC_DATA_RAW_H\n") - g.write("#define _DOC_DATA_RAW_H\n") - g.write("static const int _doc_data_compressed_size=" + str(len(buf)) + ";\n") - g.write("static const int _doc_data_uncompressed_size=" + str(decomp_size) + ";\n") - g.write("static const unsigned char _doc_data_compressed[]={\n") + g.write("#ifndef _CERTS_RAW_H\n") + g.write("#define _CERTS_RAW_H\n") + g.write("static const int _certs_compressed_size=" + str(len(buf)) + ";\n") + g.write("static const int _certs_uncompressed_size=" + str(decomp_size) + ";\n") + g.write("static const unsigned char _certs_compressed[]={\n") for i in range(len(buf)): g.write(str(ord(buf[i])) + ",\n") g.write("};\n") g.write("#endif") -def make_certs_header(target, source, env): +def make_doc_header(target, source, env): src = source[0].srcnode().abspath dst = target[0].srcnode().abspath @@ -38,24 +39,105 @@ def make_certs_header(target, source, env): buf = zlib.compress(buf) g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") - g.write("#ifndef _CERTS_RAW_H\n") - g.write("#define _CERTS_RAW_H\n") - g.write("static const int _certs_compressed_size=" + str(len(buf)) + ";\n") - g.write("static const int _certs_uncompressed_size=" + str(decomp_size) + ";\n") - g.write("static const unsigned char _certs_compressed[]={\n") + g.write("#ifndef _DOC_DATA_RAW_H\n") + g.write("#define _DOC_DATA_RAW_H\n") + g.write("static const int _doc_data_compressed_size=" + str(len(buf)) + ";\n") + g.write("static const int _doc_data_uncompressed_size=" + str(decomp_size) + ";\n") + g.write("static const unsigned char _doc_data_compressed[]={\n") for i in range(len(buf)): g.write(str(ord(buf[i])) + ",\n") g.write("};\n") g.write("#endif") +def make_fonts_header(target, source, env): + + dst = target[0].srcnode().abspath + + g = open(dst, "wb") + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef _EDITOR_FONTS_H\n") + g.write("#define _EDITOR_FONTS_H\n") + + # saving uncompressed, since freetype will reference from memory pointer + xl_names = [] + for i in range(len(source)): + print("Appending font: " + source[i].srcnode().abspath) + f = open(source[i].srcnode().abspath, "rb") + buf = f.read() + import os.path + + name = os.path.splitext(os.path.basename(source[i].srcnode().abspath))[0] + + g.write("static const int _font_" + name + "_size=" + str(len(buf)) + ";\n") + g.write("static const unsigned char _font_" + name + "[]={\n") + for i in range(len(buf)): + g.write(str(ord(buf[i])) + ",\n") + + g.write("};\n") + + g.write("#endif") + + +def make_translations_header(target, source, env): + + dst = target[0].srcnode().abspath + + g = open(dst, "wb") + + g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") + g.write("#ifndef _EDITOR_TRANSLATIONS_H\n") + g.write("#define _EDITOR_TRANSLATIONS_H\n") + + import zlib + import os.path + + paths = [node.srcnode().abspath for node in source] + sorted_paths = sorted(paths, key=lambda path: os.path.splitext(os.path.basename(path))[0]) + + xl_names = [] + for i in range(len(sorted_paths)): + print("Appending translation: " + sorted_paths[i]) + f = open(sorted_paths[i], "rb") + buf = f.read() + decomp_size = len(buf) + buf = zlib.compress(buf) + name = os.path.splitext(os.path.basename(sorted_paths[i]))[0] + + #g.write("static const int _translation_"+name+"_compressed_size="+str(len(buf))+";\n") + #g.write("static const int _translation_"+name+"_uncompressed_size="+str(decomp_size)+";\n") + g.write("static const unsigned char _translation_" + name + "_compressed[]={\n") + for i in range(len(buf)): + g.write(str(ord(buf[i])) + ",\n") + + g.write("};\n") + + xl_names.append([name, len(buf), str(decomp_size)]) + + g.write("struct EditorTranslationList {\n") + g.write("\tconst char* lang;\n") + g.write("\tint comp_size;\n") + g.write("\tint uncomp_size;\n") + g.write("\tconst unsigned char* data;\n") + g.write("};\n\n") + g.write("static EditorTranslationList _editor_translations[]={\n") + for x in xl_names: + g.write("\t{ \"" + x[0] + "\", " + str(x[1]) + ", " + str(x[2]) + ",_translation_" + x[0] + "_compressed},\n") + g.write("\t{NULL,0,0,NULL}\n") + g.write("};\n") + + g.write("#endif") + + if (env["tools"] == "yes"): + # Register exporters reg_exporters_inc = '#include "register_exporters.h"\n' reg_exporters = 'void register_exporters() {\n' for e in env.platform_exporters: - env.tool_sources.append("#platform/" + e + "/export/export.cpp") - reg_exporters += '\tregister_' + e + '_exporter();\n' + env.editor_sources.append("#platform/" + e + "/export/export.cpp") + reg_exporters += '\t//register_' + e + '_exporter();\n' reg_exporters_inc += '#include "platform/' + e + '/export/export.h"\n' reg_exporters += '}\n' f = open("register_exporters.cpp", "wb") @@ -63,18 +145,42 @@ if (env["tools"] == "yes"): f.write(reg_exporters) f.close() + # API documentation env.Depends("#tools/editor/doc_data_compressed.h", "#doc/base/classes.xml") env.Command("#tools/editor/doc_data_compressed.h", "#doc/base/classes.xml", make_doc_header) - env.Depends("#tools/editor/certs_compressed.h", "#tools/certs/ca-certificates.crt") - env.Command("#tools/editor/certs_compressed.h", "#tools/certs/ca-certificates.crt", make_certs_header) + # Certificates + env.Depends("#tools/editor/certs_compressed.h", "#thirdparty/certs/ca-certificates.crt") + env.Command("#tools/editor/certs_compressed.h", "#thirdparty/certs/ca-certificates.crt", make_certs_header) - # make_doc_header(env.File("#tools/editor/doc_data_raw.h").srcnode().abspath,env.File("#doc/base/classes.xml").srcnode().abspath,env) + import glob + path = env.Dir('.').abspath - env.add_source_files(env.tool_sources, "*.cpp") + # Translations + tlist = glob.glob(path + "/translations/*.po") + print("translations: ", tlist) + env.Depends('#tools/editor/translations.h', tlist) + env.Command('#tools/editor/translations.h', tlist, make_translations_header) - Export('env') - SConscript('icons/SCsub') - SConscript('plugins/SCsub') + # Fonts + flist = glob.glob(path + "/../../thirdparty/fonts/*.ttf") + flist.append(glob.glob(path + "/../../thirdparty/fonts/*.otf")) + print("fonts: ", flist) + env.Depends('#tools/editor/builtin_fonts.h', flist) + env.Command('#tools/editor/builtin_fonts.h', flist, make_fonts_header) + + + env.add_source_files(env.editor_sources, "*.cpp") + + SConscript('collada/SCsub') + SConscript('doc/SCsub') SConscript('fileserver/SCsub') + SConscript('icons/SCsub') + SConscript('import/SCsub') SConscript('io_plugins/SCsub') + SConscript('plugins/SCsub') + + lib = env.Library("editor", env.editor_sources) + env.Prepend(LIBS=[lib]) + + Export('env') diff --git a/tools/editor/animation_editor.cpp b/tools/editor/animation_editor.cpp index cb95f5fb7d..f256e351ae 100644 --- a/tools/editor/animation_editor.cpp +++ b/tools/editor/animation_editor.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "animation_editor.h" + #include "editor_settings.h" #include "os/keyboard.h" #include "os/os.h" @@ -178,12 +179,12 @@ private: bool sg = val < 0; val = Math::absf(val); - val = Math::log(val)/Math::log(2); + val = Math::log(val)/Math::log((float)2.0); //logspace val+=rel*0.05; // - val = Math::pow(2,val); + val = Math::pow((float)2.0,val); if (sg) val=-val; @@ -518,7 +519,7 @@ public: case Animation::TYPE_VALUE: { if (name=="value") { - r_ret = animation->track_get_key_value(track,key);; + r_ret = animation->track_get_key_value(track,key); return true; } @@ -1054,9 +1055,9 @@ float AnimationKeyEditor::_get_zoom_scale() const { float zv = zoom->get_value(); if (zv<1) { zv = 1.0-zv; - return Math::pow(1.0+zv,8.0)*100; + return Math::pow(1.0f+zv,8.0f)*100; } else { - return 1.0/Math::pow(zv,8.0)*100; + return 1.0/Math::pow(zv,8.0f)*100; } } @@ -1486,8 +1487,8 @@ void AnimationKeyEditor::_track_editor_draw() { //draw the keys; int tt = animation->track_get_type(idx); - float key_vofs = Math::floor((h - type_icon[tt]->get_height())/2); - float key_hofs = -Math::floor(type_icon[tt]->get_height()/2); + float key_vofs = Math::floor((float)(h - type_icon[tt]->get_height())/2); + float key_hofs = -Math::floor((float)type_icon[tt]->get_height()/2); int kc=animation->track_get_key_count(idx); bool first=true; @@ -1591,8 +1592,8 @@ void AnimationKeyEditor::_track_editor_draw() { continue; int y = h+i*h+sep; - float key_vofs = Math::floor((h - type_selected->get_height())/2); - float key_hofs = -Math::floor(type_selected->get_height()/2); + float key_vofs = Math::floor((float)(h - type_selected->get_height())/2); + float key_hofs = -Math::floor((float)type_selected->get_height()/2); float time = animation->track_get_key_time(idx,E->key().key); float diff = time-from_t; @@ -1916,7 +1917,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { else _menu_track(TRACK_MENU_DUPLICATE); - accept_event();; + accept_event(); } else if (p_input.key.scancode==KEY_DELETE && p_input.key.pressed && click.click==ClickOver::CLICK_NONE) { @@ -2917,7 +2918,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent& p_input) { } break; case Animation::TYPE_VALUE: { - Variant v = animation->track_get_key_value(idx,mouse_over.over_key);; + Variant v = animation->track_get_key_value(idx,mouse_over.over_key); //text+="value: "+String(v)+"\n"; bool prop_exists=false; @@ -3706,7 +3707,7 @@ void AnimationKeyEditor::_pane_drag(const Point2& p_delta) { ecs.y-=p_delta.y; if (ecs.y<100) ecs.y=100; - ec->set_custom_minimum_size(ecs);; + ec->set_custom_minimum_size(ecs); } diff --git a/tools/editor/asset_library_editor_plugin.cpp b/tools/editor/asset_library_editor_plugin.cpp index ad17364685..6ba7a7e79b 100644 --- a/tools/editor/asset_library_editor_plugin.cpp +++ b/tools/editor/asset_library_editor_plugin.cpp @@ -27,12 +27,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "asset_library_editor_plugin.h" + #include "editor_node.h" #include "editor_settings.h" #include "io/json.h" - void EditorAssetLibraryItem::configure(const String& p_title,int p_asset_id,const String& p_category,int p_category_id,const String& p_author,int p_author_id,int p_rating,const String& p_cost) { title->set_text(p_title); @@ -789,7 +789,7 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons } } - image_queue[p_queue_id].request->queue_delete();; + image_queue[p_queue_id].request->queue_delete(); image_queue.erase(p_queue_id); _update_image_queue(); diff --git a/tools/editor/call_dialog.cpp b/tools/editor/call_dialog.cpp index f8966093f6..6dfeb87dfd 100644 --- a/tools/editor/call_dialog.cpp +++ b/tools/editor/call_dialog.cpp @@ -30,7 +30,7 @@ #if 0 #include "scene/gui/label.h" -#include "object_type_db.h" +#include "class_db.h" #include "print_string.h" diff --git a/tools/editor/code_editor.cpp b/tools/editor/code_editor.cpp index 00767fd297..0a25b43716 100644 --- a/tools/editor/code_editor.cpp +++ b/tools/editor/code_editor.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "code_editor.h" + #include "editor_settings.h" #include "scene/gui/margin_container.h" #include "scene/gui/separator.h" diff --git a/tools/doc/SCsub b/tools/editor/collada/SCsub index 4bc64ffdc2..04c9a827ef 100644 --- a/tools/doc/SCsub +++ b/tools/editor/collada/SCsub @@ -2,6 +2,6 @@ Import('env') -env.add_source_files(env.tool_sources, "*.cpp") +env.add_source_files(env.editor_sources, "*.cpp") Export('env') diff --git a/tools/collada/collada.cpp b/tools/editor/collada/collada.cpp index daf30b00d7..a23fd84aa0 100644 --- a/tools/collada/collada.cpp +++ b/tools/editor/collada/collada.cpp @@ -29,6 +29,7 @@ #ifdef TOOLS_ENABLED #include "collada.h" + #include "stdio.h" //#define DEBUG_DEFAULT_ANIMATION @@ -1295,7 +1296,7 @@ void Collada::_parse_skin_controller(XMLParser& parser,String p_id) { int stride=1; if (parser.has_attribute("stride")) - stride=parser.get_attribute_value("stride").to_int();; + stride=parser.get_attribute_value("stride").to_int(); skindata.sources[current_source].stride=stride; COLLADA_PRINT("section: "+current_source+" stride "+itos(skindata.sources[current_source].stride)); @@ -1470,7 +1471,7 @@ void Collada::_parse_morph_controller(XMLParser& parser, String p_id) { int stride=1; if (parser.has_attribute("stride")) - stride=parser.get_attribute_value("stride").to_int();; + stride=parser.get_attribute_value("stride").to_int(); morphdata.sources[current_source].stride=stride; COLLADA_PRINT("section: "+current_source+" stride "+itos(morphdata.sources[current_source].stride)); diff --git a/tools/collada/collada.h b/tools/editor/collada/collada.h index fd7ad4920d..fd7ad4920d 100644 --- a/tools/collada/collada.h +++ b/tools/editor/collada/collada.h diff --git a/tools/editor/connections_dialog.cpp b/tools/editor/connections_dialog.cpp index 92dd206030..91ba419c97 100644 --- a/tools/editor/connections_dialog.cpp +++ b/tools/editor/connections_dialog.cpp @@ -28,10 +28,7 @@ /*************************************************************************/ #include "connections_dialog.h" - #include "scene/gui/label.h" - - #include "print_string.h" #include "editor_settings.h" #include "editor_node.h" diff --git a/tools/editor/create_dialog.cpp b/tools/editor/create_dialog.cpp index b69234e704..53e968f389 100644 --- a/tools/editor/create_dialog.cpp +++ b/tools/editor/create_dialog.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "create_dialog.h" -#include "object_type_db.h" +#include "class_db.h" #include "print_string.h" #include "scene/gui/box_container.h" #include "editor_node.h" diff --git a/tools/editor/dependency_editor.cpp b/tools/editor/dependency_editor.cpp index 20e185104b..a01383a868 100644 --- a/tools/editor/dependency_editor.cpp +++ b/tools/editor/dependency_editor.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "dependency_editor.h" + #include "os/file_access.h" #include "scene/gui/margin_container.h" #include "io/resource_loader.h" diff --git a/tools/collada/SCsub b/tools/editor/doc/SCsub index 4bc64ffdc2..04c9a827ef 100644 --- a/tools/collada/SCsub +++ b/tools/editor/doc/SCsub @@ -2,6 +2,6 @@ Import('env') -env.add_source_files(env.tool_sources, "*.cpp") +env.add_source_files(env.editor_sources, "*.cpp") Export('env') diff --git a/tools/doc/doc_data.cpp b/tools/editor/doc/doc_data.cpp index f18265c541..d51dc886b2 100644 --- a/tools/doc/doc_data.cpp +++ b/tools/editor/doc/doc_data.cpp @@ -26,9 +26,9 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "version.h" #include "doc_data.h" +#include "version.h" #include "global_constants.h" #include "globals.h" #include "script_language.h" diff --git a/tools/doc/doc_data.h b/tools/editor/doc/doc_data.h index fead1da510..fead1da510 100644 --- a/tools/doc/doc_data.h +++ b/tools/editor/doc/doc_data.h diff --git a/tools/doc/doc_dump.cpp b/tools/editor/doc/doc_dump.cpp index e1ffcfbbb2..5ebba596e9 100644 --- a/tools/doc/doc_dump.cpp +++ b/tools/editor/doc/doc_dump.cpp @@ -26,8 +26,9 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "version.h" #include "doc_dump.h" + +#include "version.h" #include "os/file_access.h" #include "scene/main/node.h" diff --git a/tools/doc/doc_dump.h b/tools/editor/doc/doc_dump.h index 4577af078e..84629b89c8 100644 --- a/tools/doc/doc_dump.h +++ b/tools/editor/doc/doc_dump.h @@ -29,7 +29,7 @@ #ifndef DOC_DUMP_H #define DOC_DUMP_H -#include "object_type_db.h" +#include "class_db.h" class DocDump { public: diff --git a/tools/editor/editor_asset_installer.cpp b/tools/editor/editor_asset_installer.cpp index 9992100ff8..8af01012a4 100644 --- a/tools/editor/editor_asset_installer.cpp +++ b/tools/editor/editor_asset_installer.cpp @@ -27,10 +27,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_asset_installer.h" + #include "io/zip_io.h" #include "os/dir_access.h" #include "os/file_access.h" #include "editor_node.h" + void EditorAssetInstaller::_update_subitems(TreeItem* p_item,bool p_check,bool p_first) { diff --git a/tools/editor/editor_audio_buses.cpp b/tools/editor/editor_audio_buses.cpp new file mode 100644 index 0000000000..6ee18f08d8 --- /dev/null +++ b/tools/editor/editor_audio_buses.cpp @@ -0,0 +1,1192 @@ +#include "editor_audio_buses.h" +#include "editor_node.h" +#include "servers/audio_server.h" +#include "os/keyboard.h" +#include "io/resource_saver.h" +#include "filesystem_dock.h" + +void EditorAudioBus::_notification(int p_what) { + + if (p_what==NOTIFICATION_READY) { + + vu_l->set_under_texture(get_icon("BusVuEmpty","EditorIcons")); + vu_l->set_progress_texture(get_icon("BusVuFull","EditorIcons")); + vu_r->set_under_texture(get_icon("BusVuEmpty","EditorIcons")); + vu_r->set_progress_texture(get_icon("BusVuFull","EditorIcons")); + scale->set_texture( get_icon("BusVuDb","EditorIcons")); + + disabled_vu = get_icon("BusVuFrozen","EditorIcons"); + + prev_active=true; + update_bus(); + set_process(true); + } + + if (p_what==NOTIFICATION_DRAW) { + + if (has_focus()) { + draw_style_box(get_stylebox("focus","Button"),Rect2(Vector2(),get_size())); + } + } + + if (p_what==NOTIFICATION_PROCESS) { + + float real_peak[2]={-100,-100}; + bool activity_found=false; + + int cc; + switch(AudioServer::get_singleton()->get_speaker_mode()) { + case AudioServer::SPEAKER_MODE_STEREO: cc = 1; break; + case AudioServer::SPEAKER_SURROUND_51: cc = 4; break; + case AudioServer::SPEAKER_SURROUND_71: cc = 5; break; + } + + for(int i=0;i<cc;i++) { + if (AudioServer::get_singleton()->is_bus_channel_active(get_index(),i)) { + activity_found=true; + real_peak[0]=MAX(real_peak[0],AudioServer::get_singleton()->get_bus_peak_volume_left_db(get_index(),i)); + real_peak[1]=MAX(real_peak[1],AudioServer::get_singleton()->get_bus_peak_volume_right_db(get_index(),i)); + } + } + + + if (real_peak[0]>peak_l) { + peak_l = real_peak[0]; + } else { + peak_l-=get_process_delta_time()*60.0; + } + + if (real_peak[1]>peak_r) { + peak_r = real_peak[1]; + } else { + peak_r-=get_process_delta_time()*60.0; + + } + + vu_l->set_value(peak_l); + vu_r->set_value(peak_r); + + if (activity_found!=prev_active) { + if (activity_found) { + vu_l->set_over_texture(Ref<Texture>()); + vu_r->set_over_texture(Ref<Texture>()); + } else { + vu_l->set_over_texture(disabled_vu); + vu_r->set_over_texture(disabled_vu); + + } + + prev_active=activity_found; + } + + } + + if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { + + peak_l=-100; + peak_r=-100; + prev_active=true; + + set_process(is_visible_in_tree()); + } + +} + +void EditorAudioBus::update_send() { + + send->clear(); + if (get_index()==0) { + send->set_disabled(true); + send->set_text("Speakers"); + } else { + send->set_disabled(false); + StringName current_send = AudioServer::get_singleton()->get_bus_send(get_index()); + int current_send_index=0; //by default to master + + for(int i=0;i<get_index();i++) { + StringName send_name = AudioServer::get_singleton()->get_bus_name(i); + send->add_item(send_name); + if (send_name==current_send) { + current_send_index=i; + } + } + + send->select(current_send_index); + } +} + +void EditorAudioBus::update_bus() { + + if (updating_bus) + return; + + updating_bus=true; + + int index = get_index(); + + slider->set_value(AudioServer::get_singleton()->get_bus_volume_db(index)); + track_name->set_text(AudioServer::get_singleton()->get_bus_name(index)); + if (get_index()==0) + track_name->set_editable(false); + + solo->set_pressed( AudioServer::get_singleton()->is_bus_solo(index)); + mute->set_pressed( AudioServer::get_singleton()->is_bus_mute(index)); + bypass->set_pressed( AudioServer::get_singleton()->is_bus_bypassing_effects(index)); + // effects.. + effects->clear(); + + TreeItem *root = effects->create_item(); + for(int i=0;i<AudioServer::get_singleton()->get_bus_effect_count(index);i++) { + + Ref<AudioEffect> afx = AudioServer::get_singleton()->get_bus_effect(index,i); + + TreeItem *fx = effects->create_item(root); + fx->set_cell_mode(0,TreeItem::CELL_MODE_CHECK); + fx->set_editable(0,true); + fx->set_checked(0,AudioServer::get_singleton()->is_bus_effect_enabled(index,i)); + fx->set_text(0,afx->get_name()); + fx->set_metadata(0,i); + + } + + TreeItem *add = effects->create_item(root); + add->set_cell_mode(0,TreeItem::CELL_MODE_CUSTOM); + add->set_editable(0,true); + add->set_selectable(0,false); + add->set_text(0,"Add Effect"); + + update_send(); + + updating_bus=false; + +} + + +void EditorAudioBus::_name_changed(const String& p_new_name) { + + if (p_new_name==AudioServer::get_singleton()->get_bus_name(get_index())) + return; + + String attempt=p_new_name; + int attempts=1; + + while(true) { + + bool name_free=true; + for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) { + + if (AudioServer::get_singleton()->get_bus_name(i)==attempt) { + name_free=false; + break; + } + } + + if (name_free) { + break; + } + + attempts++; + attempt=p_new_name+" "+itos(attempts); + } + updating_bus=true; + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + + StringName current = AudioServer::get_singleton()->get_bus_name(get_index()); + ur->create_action("Rename Audio Bus"); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_name",get_index(),attempt); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_name",get_index(),current); + + for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) { + if (AudioServer::get_singleton()->get_bus_send(i)==current) { + ur->add_do_method(AudioServer::get_singleton(),"set_bus_send",i,attempt); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_send",i,current); + } + } + + ur->add_do_method(buses,"_update_bus",get_index()); + ur->add_undo_method(buses,"_update_bus",get_index()); + + + ur->add_do_method(buses,"_update_sends"); + ur->add_undo_method(buses,"_update_sends"); + ur->commit_action(); + + updating_bus=false; + +} + +void EditorAudioBus::_volume_db_changed(float p_db){ + + if (updating_bus) + return; + + updating_bus=true; + + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Audio Bus Volume",UndoRedo::MERGE_ENDS); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_volume_db",get_index(),p_db); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_volume_db",get_index(),AudioServer::get_singleton()->get_bus_volume_db(get_index())); + ur->add_do_method(buses,"_update_bus",get_index()); + ur->add_undo_method(buses,"_update_bus",get_index()); + ur->commit_action(); + + updating_bus=false; + +} +void EditorAudioBus::_solo_toggled(){ + + updating_bus=true; + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Toggle Audio Bus Solo"); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_solo",get_index(),solo->is_pressed()); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_solo",get_index(),AudioServer::get_singleton()->is_bus_solo(get_index())); + ur->add_do_method(buses,"_update_bus",get_index()); + ur->add_undo_method(buses,"_update_bus",get_index()); + ur->commit_action(); + + updating_bus=false; + +} +void EditorAudioBus::_mute_toggled(){ + + updating_bus=true; + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Toggle Audio Bus Mute"); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_mute",get_index(),mute->is_pressed()); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_mute",get_index(),AudioServer::get_singleton()->is_bus_mute(get_index())); + ur->add_do_method(buses,"_update_bus",get_index()); + ur->add_undo_method(buses,"_update_bus",get_index()); + ur->commit_action(); + + updating_bus=false; + +} +void EditorAudioBus::_bypass_toggled(){ + + updating_bus=true; + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Toggle Audio Bus Bypass Effects"); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_bypass_effects",get_index(),bypass->is_pressed()); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_bypass_effects",get_index(),AudioServer::get_singleton()->is_bus_bypassing_effects(get_index())); + ur->add_do_method(buses,"_update_bus",get_index()); + ur->add_undo_method(buses,"_update_bus",get_index()); + ur->commit_action(); + + updating_bus=false; + + +} + +void EditorAudioBus::_send_selected(int p_which) { + + updating_bus=true; + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Select Audio Bus Send"); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_send",get_index(),send->get_item_text(p_which)); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_send",get_index(),AudioServer::get_singleton()->get_bus_send(get_index())); + ur->add_do_method(buses,"_update_bus",get_index()); + ur->add_undo_method(buses,"_update_bus",get_index()); + ur->commit_action(); + + updating_bus=false; +} + +void EditorAudioBus::_effect_selected() { + + TreeItem *effect = effects->get_selected(); + if (!effect) + return; + updating_bus=true; + + if (effect->get_metadata(0)!=Variant()) { + + int index = effect->get_metadata(0); + Ref<AudioEffect> effect = AudioServer::get_singleton()->get_bus_effect(get_index(),index); + if (effect.is_valid()) { + EditorNode::get_singleton()->push_item(effect.ptr()); + } + } + + updating_bus=false; + +} + +void EditorAudioBus::_effect_edited() { + + if (updating_bus) + return; + + TreeItem *effect = effects->get_edited(); + if (!effect) + return; + + if (effect->get_metadata(0)==Variant()) { + Rect2 area = effects->get_item_rect(effect); + + effect_options->set_pos(effects->get_global_pos()+area.pos+Vector2(0,area.size.y)); + effect_options->popup(); + //add effect + } else { + int index = effect->get_metadata(0); + updating_bus=true; + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Select Audio Bus Send"); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_effect_enabled",get_index(),index,effect->is_checked(0)); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_effect_enabled",get_index(),index,AudioServer::get_singleton()->is_bus_effect_enabled(get_index(),index)); + ur->add_do_method(buses,"_update_bus",get_index()); + ur->add_undo_method(buses,"_update_bus",get_index()); + ur->commit_action(); + + updating_bus=false; + + } + +} + +void EditorAudioBus::_effect_add(int p_which) { + + if (updating_bus) + return; + + StringName name = effect_options->get_item_metadata(p_which); + + Object *fx = ClassDB::instance(name); + ERR_FAIL_COND(!fx); + AudioEffect *afx = fx->cast_to<AudioEffect>(); + ERR_FAIL_COND(!afx); + Ref<AudioEffect> afxr = Ref<AudioEffect>(afx); + + afxr->set_name(effect_options->get_item_text(p_which)); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Add Audio Bus Effect"); + ur->add_do_method(AudioServer::get_singleton(),"add_bus_effect",get_index(),afxr,-1); + ur->add_undo_method(AudioServer::get_singleton(),"remove_bus_effect",get_index(),AudioServer::get_singleton()->get_bus_effect_count(get_index())); + ur->add_do_method(buses,"_update_bus",get_index()); + ur->add_undo_method(buses,"_update_bus",get_index()); + ur->commit_action(); +} + +void EditorAudioBus::_gui_input(const InputEvent& p_event) { + + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && !p_event.key.echo) { + accept_event(); + emit_signal("delete_request"); + } + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==2 && p_event.mouse_button.pressed) { + + Vector2 pos = Vector2(p_event.mouse_button.x,p_event.mouse_button.y); + delete_popup->set_pos(get_global_pos()+pos); + delete_popup->popup(); + } +} + +void EditorAudioBus::_delete_pressed(int p_option) { + + if (p_option==1) { + emit_signal("delete_request"); + } else if (p_option==0) { + //duplicate + emit_signal("duplicate_request",get_index()); + } + +} + + +Variant EditorAudioBus::get_drag_data(const Point2& p_point) { + + if (get_index()==0) { + return Variant(); + } + + Control *c = memnew(Control); + Panel *p = memnew( Panel ); + c->add_child(p); + p->add_style_override("panel",get_stylebox("focus","Button")); + p->set_size(get_size()); + p->set_pos(-p_point); + set_drag_preview(c); + Dictionary d; + d["type"]="move_audio_bus"; + d["index"]=get_index(); + emit_signal("drop_end_request"); + return d; +} + +bool EditorAudioBus::can_drop_data(const Point2& p_point,const Variant& p_data) const { + + if (get_index()==0) + return false; + Dictionary d=p_data; + if (d.has("type") && String(d["type"])=="move_audio_bus") { + return true; + } + + return false; +} +void EditorAudioBus::drop_data(const Point2& p_point,const Variant& p_data) { + + Dictionary d=p_data; + emit_signal("dropped",d["index"],get_index()); + +} + +Variant EditorAudioBus::get_drag_data_fw(const Point2& p_point,Control* p_from) { + + print_line("drag fw"); + TreeItem *item = effects->get_item_at_pos(p_point); + if (!item) { + print_line("no item"); + return Variant(); + } + + Variant md = item->get_metadata(0); + + if (md.get_type()==Variant::INT) { + Dictionary fxd; + fxd["type"]="audio_bus_effect"; + fxd["bus"]=get_index(); + fxd["effect"]=md; + + Label *l = memnew( Label ); + l->set_text(item->get_text(0)); + effects->set_drag_preview(l); + + return fxd; + } + + return Variant(); + +} + +bool EditorAudioBus::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const{ + + Dictionary d = p_data; + if (!d.has("type") || String(d["type"])!="audio_bus_effect") + return false; + + TreeItem *item = effects->get_item_at_pos(p_point); + if (!item) + return false; + + effects->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); + + return true; +} + +void EditorAudioBus::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){ + + Dictionary d = p_data; + + TreeItem *item = effects->get_item_at_pos(p_point); + if (!item) + return; + int pos=effects->get_drop_section_at_pos(p_point); + Variant md = item->get_metadata(0); + + int paste_at; + int bus = d["bus"]; + int effect = d["effect"]; + + if (md.get_type()==Variant::INT) { + paste_at=md; + if (pos>0) + paste_at++; + + if (bus==get_index() && paste_at >effect) { + paste_at--; + } + } else { + paste_at=-1; + } + + + bool enabled = AudioServer::get_singleton()->is_bus_effect_enabled(bus,effect); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Move Bus Effect"); + ur->add_do_method(AudioServer::get_singleton(),"remove_bus_effect",bus,effect); + ur->add_do_method(AudioServer::get_singleton(),"add_bus_effect",get_index(),AudioServer::get_singleton()->get_bus_effect(bus,effect),paste_at); + + if (paste_at==-1) { + paste_at = AudioServer::get_singleton()->get_bus_effect_count(get_index()); + if (bus==get_index()) { + paste_at--; + } + } + if (!enabled) { + ur->add_do_method(AudioServer::get_singleton(),"set_bus_effect_enabled",get_index(),paste_at,false); + } + + ur->add_undo_method(AudioServer::get_singleton(),"remove_bus_effect",get_index(),paste_at); + ur->add_undo_method(AudioServer::get_singleton(),"add_bus_effect",bus,AudioServer::get_singleton()->get_bus_effect(bus,effect),effect); + if (!enabled) { + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_effect_enabled",bus,effect,false); + } + + ur->add_do_method(buses,"_update_bus",get_index()); + ur->add_undo_method(buses,"_update_bus",get_index()); + if (get_index()!=bus) { + ur->add_do_method(buses,"_update_bus",bus); + ur->add_undo_method(buses,"_update_bus",bus); + } + ur->commit_action(); + + + +} + +void EditorAudioBus::_delete_effect_pressed(int p_option) { + + TreeItem * item = effects->get_selected(); + if (!item) + return; + + if (item->get_metadata(0).get_type()!=Variant::INT) + return; + + int index = item->get_metadata(0); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Delete Bus Effect"); + ur->add_do_method(AudioServer::get_singleton(),"remove_bus_effect",get_index(),index); + ur->add_undo_method(AudioServer::get_singleton(),"add_bus_effect",get_index(),AudioServer::get_singleton()->get_bus_effect(get_index(),index),index); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_effect_enabled",get_index(),index,AudioServer::get_singleton()->is_bus_effect_enabled(get_index(),index)); + ur->add_do_method(buses,"_update_bus",get_index()); + ur->add_undo_method(buses,"_update_bus",get_index()); + ur->commit_action(); + + +} + +void EditorAudioBus::_effect_rmb(const Vector2& p_pos) { + + TreeItem * item = effects->get_selected(); + if (!item) + return; + + if (item->get_metadata(0).get_type()!=Variant::INT) + return; + + delete_effect_popup->set_pos(get_global_mouse_pos()); + delete_effect_popup->popup(); +} + +void EditorAudioBus::_bind_methods() { + + ClassDB::bind_method("update_bus",&EditorAudioBus::update_bus); + ClassDB::bind_method("update_send",&EditorAudioBus::update_send); + ClassDB::bind_method("_name_changed",&EditorAudioBus::_name_changed); + ClassDB::bind_method("_volume_db_changed",&EditorAudioBus::_volume_db_changed); + ClassDB::bind_method("_solo_toggled",&EditorAudioBus::_solo_toggled); + ClassDB::bind_method("_mute_toggled",&EditorAudioBus::_mute_toggled); + ClassDB::bind_method("_bypass_toggled",&EditorAudioBus::_bypass_toggled); + ClassDB::bind_method("_name_focus_exit",&EditorAudioBus::_name_focus_exit); + ClassDB::bind_method("_send_selected",&EditorAudioBus::_send_selected); + ClassDB::bind_method("_effect_edited",&EditorAudioBus::_effect_edited); + ClassDB::bind_method("_effect_selected",&EditorAudioBus::_effect_selected); + ClassDB::bind_method("_effect_add",&EditorAudioBus::_effect_add); + ClassDB::bind_method("_gui_input",&EditorAudioBus::_gui_input); + ClassDB::bind_method("_delete_pressed",&EditorAudioBus::_delete_pressed); + ClassDB::bind_method("get_drag_data_fw",&EditorAudioBus::get_drag_data_fw); + ClassDB::bind_method("can_drop_data_fw",&EditorAudioBus::can_drop_data_fw); + ClassDB::bind_method("drop_data_fw",&EditorAudioBus::drop_data_fw); + ClassDB::bind_method("_delete_effect_pressed",&EditorAudioBus::_delete_effect_pressed); + ClassDB::bind_method("_effect_rmb",&EditorAudioBus::_effect_rmb); + + + + ADD_SIGNAL(MethodInfo("duplicate_request")); + ADD_SIGNAL(MethodInfo("delete_request")); + ADD_SIGNAL(MethodInfo("drop_end_request")); + ADD_SIGNAL(MethodInfo("dropped")); + +} + +EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses) { + + buses=p_buses; + updating_bus=false; + + VBoxContainer *vb = memnew( VBoxContainer ); + add_child(vb); + + set_v_size_flags(SIZE_EXPAND_FILL); + + track_name = memnew( LineEdit ); + vb->add_child(track_name); + track_name->connect("text_entered",this,"_name_changed"); + track_name->connect("focus_exited",this,"_name_focus_exit"); + + HBoxContainer *hbc = memnew( HBoxContainer); + vb->add_child(hbc); + hbc->add_spacer(); + solo = memnew( ToolButton ); + solo->set_text("S"); + solo->set_toggle_mode(true); + solo->set_modulate(Color(0.8,1.2,0.8)); + solo->set_focus_mode(FOCUS_NONE); + solo->connect("pressed",this,"_solo_toggled"); + hbc->add_child(solo); + mute = memnew( ToolButton ); + mute->set_text("M"); + mute->set_toggle_mode(true); + mute->set_modulate(Color(1.2,0.8,0.8)); + mute->set_focus_mode(FOCUS_NONE); + mute->connect("pressed",this,"_mute_toggled"); + hbc->add_child(mute); + bypass = memnew( ToolButton ); + bypass->set_text("B"); + bypass->set_toggle_mode(true); + bypass->set_modulate(Color(1.1,1.1,0.8)); + bypass->set_focus_mode(FOCUS_NONE); + bypass->connect("pressed",this,"_bypass_toggled"); + hbc->add_child(bypass); + hbc->add_spacer(); + + HBoxContainer *hb = memnew( HBoxContainer ); + vb->add_child(hb); + slider = memnew( VSlider ); + slider->set_min(-80); + slider->set_max(24); + slider->set_step(0.1); + + slider->connect("value_changed",this,"_volume_db_changed"); + hb->add_child(slider); + vu_l = memnew( TextureProgress ); + vu_l->set_fill_mode(TextureProgress::FILL_BOTTOM_TO_TOP); + hb->add_child(vu_l); + vu_l->set_min(-80); + vu_l->set_max(24); + vu_l->set_step(0.1); + + vu_r = memnew( TextureProgress ); + vu_r->set_fill_mode(TextureProgress::FILL_BOTTOM_TO_TOP); + hb->add_child(vu_r); + vu_r->set_min(-80); + vu_r->set_max(24); + vu_r->set_step(0.1); + + scale = memnew( TextureRect ); + hb->add_child(scale); + + //add_child(hb); + + effects = memnew( Tree ); + effects->set_hide_root(true); + effects->set_custom_minimum_size(Size2(0,90)*EDSCALE); + effects->set_hide_folding(true); + vb->add_child(effects); + effects->connect("item_edited",this,"_effect_edited"); + effects->connect("cell_selected",this,"_effect_selected"); + effects->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true); + effects->set_drag_forwarding(this); + effects->connect("item_rmb_selected",this,"_effect_rmb"); + effects->set_allow_rmb_select(true); + + send = memnew( OptionButton ); + send->set_clip_text(true); + send->connect("item_selected",this,"_send_selected"); + vb->add_child(send); + + set_focus_mode(FOCUS_CLICK); + + effect_options = memnew( PopupMenu ); + effect_options->connect("index_pressed",this,"_effect_add"); + add_child(effect_options); + List<StringName> effects; + ClassDB::get_inheriters_from_class("AudioEffect",&effects); + effects.sort_custom<StringName::AlphCompare>(); + for (List<StringName>::Element *E=effects.front();E;E=E->next()) { + if (!ClassDB::can_instance(E->get())) + continue; + + Ref<Texture> icon; + if (has_icon(E->get(),"EditorIcons")) { + icon = get_icon(E->get(),"EditorIcons"); + } + String name = E->get().operator String().replace("AudioEffect",""); + effect_options->add_item(name); + effect_options->set_item_metadata(effect_options->get_item_count()-1,E->get()); + effect_options->set_item_icon(effect_options->get_item_count()-1,icon); + } + + delete_popup = memnew( PopupMenu ); + delete_popup->add_item("Duplicate"); + delete_popup->add_item("Delete"); + add_child(delete_popup); + delete_popup->connect("index_pressed",this,"_delete_pressed"); + + delete_effect_popup = memnew( PopupMenu ); + delete_effect_popup->add_item("Delete Effect"); + add_child(delete_effect_popup); + delete_effect_popup->connect("index_pressed",this,"_delete_effect_pressed"); + +} + + + +bool EditorAudioBusDrop::can_drop_data(const Point2& p_point,const Variant& p_data) const { + + Dictionary d=p_data; + if (d.has("type") && String(d["type"])=="move_audio_bus") { + return true; + } + + return false; +} +void EditorAudioBusDrop::drop_data(const Point2& p_point,const Variant& p_data){ + + Dictionary d=p_data; + emit_signal("dropped",d["index"],-1); + +} + +void EditorAudioBusDrop::_bind_methods() { + + ADD_SIGNAL(MethodInfo("dropped")); +} + +EditorAudioBusDrop::EditorAudioBusDrop() { + + +} + + +void EditorAudioBuses::_update_buses() { + + while(bus_hb->get_child_count()>0) { + memdelete(bus_hb->get_child(0)); + } + + drop_end=NULL; + + for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) { + + EditorAudioBus *audio_bus = memnew( EditorAudioBus(this) ); + if (i==0) { + audio_bus->set_self_modulate(Color(1,0.9,0.9)); + } + bus_hb->add_child(audio_bus); + audio_bus->connect("delete_request",this,"_delete_bus",varray(audio_bus),CONNECT_DEFERRED); + audio_bus->connect("duplicate_request",this,"_duplicate_bus",varray(),CONNECT_DEFERRED); + audio_bus->connect("drop_end_request",this,"_request_drop_end"); + audio_bus->connect("dropped",this,"_drop_at_index",varray(),CONNECT_DEFERRED); + + + + } +} + +EditorAudioBuses *EditorAudioBuses::register_editor() { + + EditorAudioBuses * audio_buses = memnew( EditorAudioBuses ); + EditorNode::get_singleton()->add_bottom_panel_item("Audio",audio_buses); + return audio_buses; +} + +void EditorAudioBuses::_notification(int p_what) { + + if (p_what==NOTIFICATION_READY) { + _update_buses(); + } + + if (p_what==NOTIFICATION_DRAG_END) { + if (drop_end) { + drop_end->queue_delete(); + drop_end=NULL; + } + } + + if (p_what==NOTIFICATION_PROCESS) { + + //check if anything was edited + bool edited = AudioServer::get_singleton()->is_edited(); + for(int i=0;i<AudioServer::get_singleton()->get_bus_count();i++) { + for(int j=0;j<AudioServer::get_singleton()->get_bus_effect_count(i);j++) { + Ref<AudioEffect> effect = AudioServer::get_singleton()->get_bus_effect(i,j); + if (effect->is_edited()) { + edited=true; + effect->set_edited(false); + } + } + } + + AudioServer::get_singleton()->set_edited(false); + + if (edited) { + + save_timer->start(); + } + } + +} + + +void EditorAudioBuses::_add_bus() { + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + + //need to simulate new name, so we can undi :( + ur->create_action("Add Audio Bus"); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_count",AudioServer::get_singleton()->get_bus_count()+1); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_count",AudioServer::get_singleton()->get_bus_count()); + ur->add_do_method(this,"_update_buses"); + ur->add_undo_method(this,"_update_buses"); + ur->commit_action(); + +} + +void EditorAudioBuses::_update_bus(int p_index) { + + if (p_index>=bus_hb->get_child_count()) + return; + + bus_hb->get_child(p_index)->call("update_bus"); +} + +void EditorAudioBuses::_update_sends() { + + for(int i=0;i<bus_hb->get_child_count();i++) { + bus_hb->get_child(i)->call("update_send"); + } +} + +void EditorAudioBuses::_delete_bus(Object* p_which) { + + EditorAudioBus *bus = p_which->cast_to<EditorAudioBus>(); + int index = bus->get_index(); + if (index==0) { + EditorNode::get_singleton()->show_warning("Master bus can't be deleted!"); + return; + } + + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + + ur->create_action("Delete Audio Bus"); + ur->add_do_method(AudioServer::get_singleton(),"remove_bus",index); + ur->add_undo_method(AudioServer::get_singleton(),"add_bus",index); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_name",index,AudioServer::get_singleton()->get_bus_name(index)); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_volume_db",index,AudioServer::get_singleton()->get_bus_volume_db(index)); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_send",index,AudioServer::get_singleton()->get_bus_send(index)); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_solo",index,AudioServer::get_singleton()->is_bus_solo(index)); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_mute",index,AudioServer::get_singleton()->is_bus_mute(index)); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_bypass_effects",index,AudioServer::get_singleton()->is_bus_bypassing_effects(index)); + for(int i=0;i<AudioServer::get_singleton()->get_bus_effect_count(index);i++) { + + ur->add_undo_method(AudioServer::get_singleton(),"add_bus_effect",index,AudioServer::get_singleton()->get_bus_effect(index,i)); + ur->add_undo_method(AudioServer::get_singleton(),"set_bus_effect_enabled",index,i,AudioServer::get_singleton()->is_bus_effect_enabled(index,i)); + } + ur->add_do_method(this,"_update_buses"); + ur->add_undo_method(this,"_update_buses"); + ur->commit_action(); + +} + + +void EditorAudioBuses::_duplicate_bus(int p_which) { + + int add_at_pos = p_which+1; + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Duplicate Audio Bus"); + ur->add_do_method(AudioServer::get_singleton(),"add_bus",add_at_pos); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_name",add_at_pos,AudioServer::get_singleton()->get_bus_name(p_which)+" Copy"); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_volume_db",add_at_pos,AudioServer::get_singleton()->get_bus_volume_db(p_which)); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_send",add_at_pos,AudioServer::get_singleton()->get_bus_send(p_which)); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_solo",add_at_pos,AudioServer::get_singleton()->is_bus_solo(p_which)); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_mute",add_at_pos,AudioServer::get_singleton()->is_bus_mute(p_which)); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_bypass_effects",add_at_pos,AudioServer::get_singleton()->is_bus_bypassing_effects(p_which)); + for(int i=0;i<AudioServer::get_singleton()->get_bus_effect_count(p_which);i++) { + + ur->add_do_method(AudioServer::get_singleton(),"add_bus_effect",add_at_pos,AudioServer::get_singleton()->get_bus_effect(p_which,i)); + ur->add_do_method(AudioServer::get_singleton(),"set_bus_effect_enabled",add_at_pos,i,AudioServer::get_singleton()->is_bus_effect_enabled(p_which,i)); + } + ur->add_undo_method(AudioServer::get_singleton(),"remove_bus",add_at_pos); + ur->add_do_method(this,"_update_buses"); + ur->add_undo_method(this,"_update_buses"); + ur->commit_action(); + +} + +void EditorAudioBuses::_request_drop_end() { + + if (!drop_end && bus_hb->get_child_count()) { + drop_end = memnew( EditorAudioBusDrop ); + + bus_hb->add_child(drop_end); + drop_end->set_custom_minimum_size(bus_hb->get_child(0)->cast_to<Control>()->get_size()); + drop_end->connect("dropped",this,"_drop_at_index",varray(),CONNECT_DEFERRED); + } +} + +void EditorAudioBuses::_drop_at_index(int p_bus,int p_index) { + + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + + //need to simulate new name, so we can undi :( + ur->create_action("Move Audio Bus"); + ur->add_do_method(AudioServer::get_singleton(),"move_bus",p_bus,p_index); + int final_pos; + if (p_index==p_bus) { + final_pos=p_bus; + } else if (p_index==-1) { + final_pos = AudioServer::get_singleton()->get_bus_count()-1; + } else if (p_index<p_bus) { + final_pos = p_index; + } else { + final_pos = p_index -1; + } + ur->add_undo_method(AudioServer::get_singleton(),"move_bus",final_pos,p_bus); + + ur->add_do_method(this,"_update_buses"); + ur->add_undo_method(this,"_update_buses"); + ur->commit_action(); +} + +void EditorAudioBuses::_server_save() { + + Ref<AudioBusLayout> state = AudioServer::get_singleton()->generate_bus_layout(); + ResourceSaver::save(edited_path,state); + +} + +void EditorAudioBuses::_select_layout() { + + EditorNode::get_singleton()->get_filesystem_dock()->select_file(edited_path); +} + +void EditorAudioBuses::_save_as_layout() { + + file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); + file_dialog->set_title(TTR("Save Audio Bus Layout As..")); + file_dialog->set_current_path(edited_path); + file_dialog->popup_centered_ratio(); + new_layout=false; +} + + +void EditorAudioBuses::_new_layout() { + + file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); + file_dialog->set_title(TTR("Location for New Layout..")); + file_dialog->set_current_path(edited_path); + file_dialog->popup_centered_ratio(); + new_layout=true; +} + +void EditorAudioBuses::_load_layout() { + + file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); + file_dialog->set_title(TTR("Open Audio Bus Layout")); + file_dialog->set_current_path(edited_path); + file_dialog->popup_centered_ratio(); + new_layout=false; +} + + +void EditorAudioBuses::_load_default_layout() { + + + Ref<AudioBusLayout> state = ResourceLoader::load("res://default_bus_layout.tres"); + if (state.is_null()) { + EditorNode::get_singleton()->show_warning("There is no 'res://default_bus_layout.tres' file."); + return; + } + + edited_path="res://default_bus_layout.tres"; + file->set_text(edited_path.get_file()); + AudioServer::get_singleton()->set_bus_layout(state); + _update_buses(); + EditorNode::get_singleton()->get_undo_redo()->clear_history(); + call_deferred("_select_layout"); +} + +void EditorAudioBuses::_file_dialog_callback(const String& p_string) { + + if (file_dialog->get_mode()==EditorFileDialog::MODE_OPEN_FILE) { + Ref<AudioBusLayout> state = ResourceLoader::load(p_string); + if (state.is_null()) { + EditorNode::get_singleton()->show_warning("Invalid file, not an audio bus layout."); + return; + } + + edited_path=p_string; + file->set_text(p_string.get_file()); + AudioServer::get_singleton()->set_bus_layout(state); + _update_buses(); + EditorNode::get_singleton()->get_undo_redo()->clear_history(); + call_deferred("_select_layout"); + + } else if (file_dialog->get_mode()==EditorFileDialog::MODE_SAVE_FILE) { + + if (new_layout) { + Ref<AudioBusLayout> empty_state; + empty_state.instance(); + AudioServer::get_singleton()->set_bus_layout(empty_state); + } + + Error err = ResourceSaver::save(p_string,AudioServer::get_singleton()->generate_bus_layout()); + + if (err!=OK) { + EditorNode::get_singleton()->show_warning("Error saving file: "+p_string); + return; + } + + edited_path=p_string; + file->set_text(p_string.get_file()); + _update_buses(); + EditorNode::get_singleton()->get_undo_redo()->clear_history(); + call_deferred("_select_layout"); + } + +} + +void EditorAudioBuses::_bind_methods() { + + ClassDB::bind_method("_add_bus",&EditorAudioBuses::_add_bus); + ClassDB::bind_method("_update_buses",&EditorAudioBuses::_update_buses); + ClassDB::bind_method("_update_bus",&EditorAudioBuses::_update_bus); + ClassDB::bind_method("_update_sends",&EditorAudioBuses::_update_sends); + ClassDB::bind_method("_delete_bus",&EditorAudioBuses::_delete_bus); + ClassDB::bind_method("_request_drop_end",&EditorAudioBuses::_request_drop_end); + ClassDB::bind_method("_drop_at_index",&EditorAudioBuses::_drop_at_index); + ClassDB::bind_method("_server_save",&EditorAudioBuses::_server_save); + ClassDB::bind_method("_select_layout",&EditorAudioBuses::_select_layout); + ClassDB::bind_method("_save_as_layout",&EditorAudioBuses::_save_as_layout); + ClassDB::bind_method("_load_layout",&EditorAudioBuses::_load_layout); + ClassDB::bind_method("_load_default_layout",&EditorAudioBuses::_load_default_layout); + ClassDB::bind_method("_new_layout",&EditorAudioBuses::_new_layout); + ClassDB::bind_method("_duplicate_bus",&EditorAudioBuses::_duplicate_bus); + + ClassDB::bind_method("_file_dialog_callback",&EditorAudioBuses::_file_dialog_callback); +} + +EditorAudioBuses::EditorAudioBuses() +{ + + drop_end = NULL; + top_hb = memnew( HBoxContainer ); + add_child(top_hb); + + add = memnew( Button ); + top_hb->add_child(add);; + add->set_text(TTR("Add Bus")); + + add->connect("pressed",this,"_add_bus"); + + + + top_hb->add_spacer(); + + file = memnew( ToolButton ); + file->set_text("default_bus_layout.tres"); + top_hb->add_child(file); + file->connect("pressed",this,"_select_layout"); + + load = memnew( Button ); + load->set_text(TTR("Load")); + top_hb->add_child(load); + load->connect("pressed",this,"_load_layout"); + + save_as = memnew( Button ); + save_as->set_text(TTR("Save As")); + top_hb->add_child(save_as); + save_as->connect("pressed",this,"_save_as_layout"); + + _default = memnew( Button ); + _default->set_text(TTR("Default")); + top_hb->add_child(_default); + _default->connect("pressed",this,"_load_default_layout"); + + _new = memnew( Button ); + _new->set_text(TTR("Create")); + top_hb->add_child(_new); + _new->connect("pressed",this,"_new_layout"); + + bus_scroll = memnew( ScrollContainer ); + bus_scroll->set_v_size_flags(SIZE_EXPAND_FILL); + bus_scroll->set_enable_h_scroll(true); + bus_scroll->set_enable_v_scroll(false); + add_child(bus_scroll); + bus_hb = memnew( HBoxContainer ); + bus_scroll->add_child(bus_hb); + + save_timer=memnew(Timer); + save_timer->set_wait_time(0.8); + save_timer->set_one_shot(true); + add_child(save_timer); + save_timer->connect("timeout",this,"_server_save"); + + set_v_size_flags(SIZE_EXPAND_FILL); + + + edited_path = "res://default_bus_layout.tres"; + + file_dialog = memnew( EditorFileDialog ); + List<String> ext; + ResourceLoader::get_recognized_extensions_for_type("AudioServerState",&ext); + for (List<String>::Element *E=ext.front();E;E=E->next()) { + file_dialog->add_filter("*."+E->get()+"; Audio Bus State"); + } + add_child(file_dialog); + file_dialog->connect("file_selected",this,"_file_dialog_callback"); + + set_process(true); + +} +void EditorAudioBuses::open_layout(const String& p_path) { + + EditorNode::get_singleton()->make_bottom_panel_item_visible(this); + + Ref<AudioBusLayout> state = ResourceLoader::load(p_path); + if (state.is_null()) { + EditorNode::get_singleton()->show_warning("Invalid file, not an audio bus layout."); + return; + } + + edited_path=p_path; + file->set_text(p_path.get_file()); + AudioServer::get_singleton()->set_bus_layout(state); + _update_buses(); + EditorNode::get_singleton()->get_undo_redo()->clear_history(); + call_deferred("_select_layout"); +} + +void AudioBusesEditorPlugin::edit(Object *p_node) { + + if (p_node->cast_to<AudioBusLayout>()) { + + String path = p_node->cast_to<AudioBusLayout>()->get_path(); + if (path.is_resource_file()) { + audio_bus_editor->open_layout(path); + } + } +} + +bool AudioBusesEditorPlugin::handles(Object *p_node) const { + + return (p_node->cast_to<AudioBusLayout>()!=NULL); +} + +void AudioBusesEditorPlugin::make_visible(bool p_visible){ + + +} + +AudioBusesEditorPlugin::AudioBusesEditorPlugin(EditorAudioBuses *p_node) { + + audio_bus_editor=p_node; +} + +AudioBusesEditorPlugin::~AudioBusesEditorPlugin() { + +} diff --git a/tools/editor/editor_audio_buses.h b/tools/editor/editor_audio_buses.h new file mode 100644 index 0000000000..e44f8cd579 --- /dev/null +++ b/tools/editor/editor_audio_buses.h @@ -0,0 +1,186 @@ +#ifndef EDITORAUDIOBUSES_H +#define EDITORAUDIOBUSES_H + + +#include "scene/gui/box_container.h" +#include "scene/gui/button.h" +#include "scene/gui/tool_button.h" +#include "scene/gui/scroll_container.h" +#include "scene/gui/panel_container.h" +#include "scene/gui/slider.h" +#include "scene/gui/texture_progress.h" +#include "scene/gui/texture_rect.h" +#include "scene/gui/line_edit.h" +#include "scene/gui/tree.h" +#include "scene/gui/option_button.h" +#include "scene/gui/panel.h" +#include "tools/editor/editor_file_dialog.h" +#include "editor_plugin.h" + +class EditorAudioBuses; + +class EditorAudioBus : public PanelContainer { + + GDCLASS( EditorAudioBus, PanelContainer ) + + bool prev_active; + float peak_l; + float peak_r; + + Ref<Texture> disabled_vu; + LineEdit *track_name; + VSlider *slider; + TextureProgress *vu_l; + TextureProgress *vu_r; + TextureRect *scale; + OptionButton *send; + + PopupMenu *effect_options; + PopupMenu *delete_popup; + PopupMenu *delete_effect_popup; + + Button *solo; + Button *mute; + Button *bypass; + + Tree *effects; + + bool updating_bus; + + void _gui_input(const InputEvent& p_event); + void _delete_pressed(int p_option); + + void _name_changed(const String& p_new_name); + void _name_focus_exit() { _name_changed(track_name->get_text()); } + void _volume_db_changed(float p_db); + void _solo_toggled(); + void _mute_toggled(); + void _bypass_toggled(); + void _send_selected(int p_which); + void _effect_edited(); + void _effect_add(int p_which); + void _effect_selected(); + void _delete_effect_pressed(int p_option); + void _effect_rmb(const Vector2& p_pos); + + + virtual Variant get_drag_data(const Point2& p_point); + virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const; + virtual void drop_data(const Point2& p_point,const Variant& p_data); + + + Variant get_drag_data_fw(const Point2& p_point,Control* p_from); + bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const; + void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from); + +friend class EditorAudioBuses; + + EditorAudioBuses *buses; + +protected: + + static void _bind_methods(); + void _notification(int p_what); +public: + + void update_bus(); + void update_send(); + + EditorAudioBus(EditorAudioBuses *p_buses=NULL); +}; + + +class EditorAudioBusDrop : public Panel { + + GDCLASS(EditorAudioBusDrop,Panel); + + virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const; + virtual void drop_data(const Point2& p_point,const Variant& p_data); +protected: + + static void _bind_methods(); +public: + + EditorAudioBusDrop(); +}; + +class EditorAudioBuses : public VBoxContainer { + + GDCLASS(EditorAudioBuses,VBoxContainer) + + HBoxContainer *top_hb; + + Button *add; + ScrollContainer *bus_scroll; + HBoxContainer *bus_hb; + + EditorAudioBusDrop *drop_end; + + Button *file; + Button *load; + Button *save_as; + Button *_default; + Button *_new; + + Timer *save_timer; + String edited_path; + + void _add_bus(); + void _update_buses(); + void _update_bus(int p_index); + void _update_sends(); + + void _delete_bus(Object* p_which); + void _duplicate_bus(int p_which); + + + void _request_drop_end(); + void _drop_at_index(int p_bus,int p_index); + + void _server_save(); + + void _select_layout(); + void _load_layout(); + void _save_as_layout(); + void _load_default_layout(); + void _new_layout(); + + EditorFileDialog *file_dialog; + bool new_layout; + + void _file_dialog_callback(const String& p_string); + +protected: + + static void _bind_methods(); + void _notification(int p_what); +public: + + void open_layout(const String& p_path); + + static EditorAudioBuses* register_editor(); + + EditorAudioBuses(); +}; + + + +class AudioBusesEditorPlugin : public EditorPlugin { + + GDCLASS( AudioBusesEditorPlugin, EditorPlugin ); + + EditorAudioBuses *audio_bus_editor; +public: + + virtual String get_name() const { return "SampleLibrary"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_node); + virtual bool handles(Object *p_node) const; + virtual void make_visible(bool p_visible); + + AudioBusesEditorPlugin(EditorAudioBuses *p_node); + ~AudioBusesEditorPlugin(); + +}; + +#endif // EDITORAUDIOBUSES_H diff --git a/tools/editor/editor_autoload_settings.cpp b/tools/editor/editor_autoload_settings.cpp index 087bf1a3b7..0038ab48d5 100644 --- a/tools/editor/editor_autoload_settings.cpp +++ b/tools/editor/editor_autoload_settings.cpp @@ -26,12 +26,10 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ - #include "editor_autoload_settings.h" #include "globals.h" #include "global_constants.h" - #include "editor_node.h" #define PREVIEW_LIST_MAX_SIZE 10 diff --git a/tools/editor/editor_data.cpp b/tools/editor/editor_data.cpp index 08b03ae65f..ef839d7e74 100644 --- a/tools/editor/editor_data.cpp +++ b/tools/editor/editor_data.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_data.h" + #include "globals.h" #include "editor_settings.h" #include "os/dir_access.h" @@ -768,26 +769,6 @@ Dictionary EditorData::restore_edited_scene_state(EditorSelection *p_selection, } -void EditorData::set_edited_scene_import_metadata(Ref<ResourceImportMetadata> p_mdata) { - - ERR_FAIL_INDEX(current_edited_scene,edited_scene.size()); - edited_scene[current_edited_scene].medatata=p_mdata; - -} - -Ref<ResourceImportMetadata> EditorData::get_edited_scene_import_metadata(int idx) const{ - - ERR_FAIL_INDEX_V(current_edited_scene,edited_scene.size(),Ref<ResourceImportMetadata>()); - if(idx<0) { - return edited_scene[current_edited_scene].medatata; - } else { - ERR_FAIL_INDEX_V(idx,edited_scene.size(),Ref<ResourceImportMetadata>()); - return edited_scene[idx].medatata; - } -} - - - void EditorData::clear_edited_scenes() { for(int i=0;i<edited_scene.size();i++) { diff --git a/tools/editor/editor_data.h b/tools/editor/editor_data.h index f0bc5983a2..fce606f722 100644 --- a/tools/editor/editor_data.h +++ b/tools/editor/editor_data.h @@ -129,7 +129,6 @@ private: struct EditedScene { Node* root; Dictionary editor_states; - Ref<ResourceImportMetadata> medatata; List<Node*> selection; Vector<EditorHistory::History> history_stored; int history_current; @@ -184,8 +183,6 @@ public: void remove_scene(int p_idx); void set_edited_scene(int p_idx); void set_edited_scene_root(Node* p_root); - void set_edited_scene_import_metadata(Ref<ResourceImportMetadata> p_mdata); - Ref<ResourceImportMetadata> get_edited_scene_import_metadata(int p_idx = -1) const; int get_edited_scene() const; Node* get_edited_scene_root(int p_idx = -1); int get_edited_scene_count() const; diff --git a/tools/editor/editor_dir_dialog.cpp b/tools/editor/editor_dir_dialog.cpp index e2b7d475b0..bb9ddc2aef 100644 --- a/tools/editor/editor_dir_dialog.cpp +++ b/tools/editor/editor_dir_dialog.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_dir_dialog.h" + #include "os/os.h" #include "os/keyboard.h" #include "tools/editor/editor_settings.h" diff --git a/tools/editor/editor_file_dialog.cpp b/tools/editor/editor_file_dialog.cpp index d4ca515493..e23e2419d8 100644 --- a/tools/editor/editor_file_dialog.cpp +++ b/tools/editor/editor_file_dialog.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_file_dialog.h" + #include "scene/gui/label.h" #include "scene/gui/center_container.h" #include "print_string.h" @@ -36,6 +37,7 @@ #include "scene/gui/margin_container.h" #include "os/file_access.h" #include "editor_scale.h" + EditorFileDialog::GetIconFunc EditorFileDialog::get_icon_func=NULL; EditorFileDialog::GetIconFunc EditorFileDialog::get_large_icon_func=NULL; @@ -1150,7 +1152,7 @@ void EditorFileDialog::set_display_mode(DisplayMode p_mode) { mode_list->set_pressed(true); } display_mode=p_mode; - invalidate();; + invalidate(); } EditorFileDialog::DisplayMode EditorFileDialog::get_display_mode() const{ diff --git a/tools/editor/editor_file_system.cpp b/tools/editor/editor_file_system.cpp index 1d32415be9..c7b50a3c09 100644 --- a/tools/editor/editor_file_system.cpp +++ b/tools/editor/editor_file_system.cpp @@ -27,14 +27,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_file_system.h" + #include "globals.h" #include "io/resource_loader.h" #include "os/os.h" #include "os/file_access.h" #include "editor_node.h" #include "io/resource_saver.h" +#include "io/resource_import.h" #include "editor_settings.h" #include "editor_resource_preview.h" +#include "variant_parser.h" EditorFileSystem *EditorFileSystem::singleton=NULL; @@ -114,74 +117,12 @@ String EditorFileSystemDirectory::get_file_path(int p_idx) const { return "res://"+file; } -bool EditorFileSystemDirectory::get_file_meta(int p_idx) const { - - ERR_FAIL_INDEX_V(p_idx,files.size(),""); - return files[p_idx]->meta.enabled; -} Vector<String> EditorFileSystemDirectory::get_file_deps(int p_idx) const { ERR_FAIL_INDEX_V(p_idx,files.size(),Vector<String>()); - return files[p_idx]->meta.deps; - -} -Vector<String> EditorFileSystemDirectory::get_missing_sources(int p_idx) const { - - ERR_FAIL_INDEX_V(p_idx,files.size(),Vector<String>()); - Vector<String> missing; - for(int i=0;i<files[p_idx]->meta.sources.size();i++) { - if (files[p_idx]->meta.sources[i].missing) - missing.push_back(files[p_idx]->meta.sources[i].path); - } - - return missing; - - -} -bool EditorFileSystemDirectory::is_missing_sources(int p_idx) const { - - ERR_FAIL_INDEX_V(p_idx,files.size(),false); - for(int i=0;i<files[p_idx]->meta.sources.size();i++) { - if (files[p_idx]->meta.sources[i].missing) - return true; - } - - return false; -} - -bool EditorFileSystemDirectory::have_sources_changed(int p_idx) const { - - ERR_FAIL_INDEX_V(p_idx,files.size(),false); - return files[p_idx]->meta.sources_changed; - -} - -int EditorFileSystemDirectory::get_source_count(int p_idx) const { - - ERR_FAIL_INDEX_V(p_idx,files.size(),0); - if (!files[p_idx]->meta.enabled) - return 0; - return files[p_idx]->meta.sources.size(); -} -String EditorFileSystemDirectory::get_source_file(int p_idx,int p_source) const { + return files[p_idx]->deps; - ERR_FAIL_INDEX_V(p_idx,files.size(),String()); - ERR_FAIL_INDEX_V(p_source,files[p_idx]->meta.sources.size(),String()); - if (!files[p_idx]->meta.enabled) - return String(); - - return files[p_idx]->meta.sources[p_source].path; - -} -bool EditorFileSystemDirectory::is_source_file_missing(int p_idx,int p_source) const { - - ERR_FAIL_INDEX_V(p_idx,files.size(),false); - ERR_FAIL_INDEX_V(p_source,files[p_idx]->meta.sources.size(),false); - if (!files[p_idx]->meta.enabled) - return false; - - return files[p_idx]->meta.sources[p_source].missing; } @@ -209,7 +150,6 @@ void EditorFileSystemDirectory::_bind_methods() { ClassDB::bind_method(_MD("get_file","idx"),&EditorFileSystemDirectory::get_file); ClassDB::bind_method(_MD("get_file_path","idx"),&EditorFileSystemDirectory::get_file_path); ClassDB::bind_method(_MD("get_file_type","idx"),&EditorFileSystemDirectory::get_file_type); - ClassDB::bind_method(_MD("is_missing_sources","idx"),&EditorFileSystemDirectory::is_missing_sources); ClassDB::bind_method(_MD("get_name"),&EditorFileSystemDirectory::get_name); ClassDB::bind_method(_MD("get_path"),&EditorFileSystemDirectory::get_path); ClassDB::bind_method(_MD("get_parent:EditorFileSystemDirectory"),&EditorFileSystemDirectory::get_parent); @@ -243,39 +183,6 @@ EditorFileSystemDirectory::~EditorFileSystemDirectory() { - -EditorFileSystemDirectory::ImportMeta EditorFileSystem::_get_meta(const String& p_path) { - - Ref<ResourceImportMetadata> imd = ResourceLoader::load_import_metadata(p_path); - EditorFileSystemDirectory::ImportMeta m; - if (imd.is_null()) { - m.enabled=false; - m.sources_changed=false; - } else { - m.enabled=true; - m.sources_changed=false; - - for(int i=0;i<imd->get_source_count();i++) { - EditorFileSystemDirectory::ImportMeta::Source s; - s.path=imd->get_source_path(i); - s.md5=imd->get_source_md5(i); - s.modified_time=0; - s.missing=false; - m.sources.push_back(s); - } - m.import_editor=imd->get_editor(); - } - - List<String> deps; - ResourceLoader::get_dependencies(p_path,&deps); - for(List<String>::Element *E=deps.front();E;E=E->next()) { - m.deps.push_back(E->get()); - } - - return m; -} - - void EditorFileSystem::_scan_filesystem() { ERR_FAIL_COND(!scanning || new_filesystem); @@ -288,7 +195,7 @@ void EditorFileSystem::_scan_filesystem() { String project=GlobalConfig::get_singleton()->get_resource_path(); - String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache"); + String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache2"); FileAccess *f =FileAccess::open(fscache,FileAccess::READ); if (f) { @@ -318,30 +225,14 @@ void EditorFileSystem::_scan_filesystem() { FileCache fc; fc.type=split[1]; fc.modification_time=split[2].to_int64(); - String meta = split[3].strip_edges(); - fc.meta.enabled=false; - if (meta.find("<>")!=-1){ - Vector<String> spl = meta.split("<>"); - int sc = spl.size()-1; - if (sc%3==0){ - fc.meta.enabled=true; - fc.meta.import_editor=spl[0]; - fc.meta.sources.resize(sc/3); - for(int i=0;i<fc.meta.sources.size();i++) { - fc.meta.sources[i].path=spl[1+i*3+0]; - fc.meta.sources[i].md5=spl[1+i*3+1]; - fc.meta.sources[i].modified_time=spl[1+i*3+2].to_int64(); - } - - } + fc.import_modification_time = split[3].to_int64(); - } String deps = split[4].strip_edges(); if (deps.length()) { Vector<String> dp = deps.split("<>"); for(int i=0;i<dp.size();i++) { String path=dp[i]; - fc.meta.deps.push_back(path); + fc.deps.push_back(path); } } @@ -389,7 +280,14 @@ void EditorFileSystem::_scan_filesystem() { } +void EditorFileSystem::_save_filesystem_cache() { + String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache2"); + FileAccess *f=FileAccess::open(fscache,FileAccess::WRITE); + _save_filesystem_cache(filesystem,f); + f->close(); + memdelete(f); +} void EditorFileSystem::_thread_func(void *_userdata) { @@ -404,6 +302,8 @@ bool EditorFileSystem::_update_scan_actions() { bool fs_changed=false; + Vector<String> reimports; + for (List<ItemAction>::Element *E=scan_actions.front();E;E=E->next()) { ItemAction&ia = E->get(); @@ -468,18 +368,25 @@ bool EditorFileSystem::_update_scan_actions() { //print_line("*ACTION REMOVE FILE: "+ia.file); } break; - case ItemAction::ACTION_FILE_SOURCES_CHANGED: { + case ItemAction::ACTION_FILE_REIMPORT: { + int idx = ia.dir->find_file_index(ia.file); ERR_CONTINUE(idx==-1); String full_path = ia.dir->get_file_path(idx); - sources_changed.push_back(full_path); + reimports.push_back(full_path); + fs_changed=true; } break; } } + + if (reimports.size()) { + reimport_files(reimports); + + } scan_actions.clear(); return fs_changed; @@ -491,9 +398,10 @@ void EditorFileSystem::scan() { if (false /*&& bool(Globals::get_singleton()->get("debug/disable_scan"))*/) return; - if (scanning || scanning_sources|| thread) + if (scanning || scanning_changes|| thread) return; + _update_extensions(); abort_scan=false; if (!use_threads) { @@ -528,42 +436,6 @@ void EditorFileSystem::scan() { } -bool EditorFileSystem::_check_meta_sources(EditorFileSystemDirectory::ImportMeta & p_meta) { - - if (p_meta.enabled) { - - for(int j=0;j<p_meta.sources.size();j++) { - - - String src = EditorImportPlugin::expand_source_path(p_meta.sources[j].path); - - if (!FileAccess::exists(src)) { - p_meta.sources[j].missing=true; - continue; - } - - p_meta.sources[j].missing=false; - - uint64_t mt = FileAccess::get_modified_time(src); - - if (mt!=p_meta.sources[j].modified_time) { - //scan - String md5 = FileAccess::get_md5(src); - //print_line("checking: "+src); - //print_line("md5: "+md5); - //print_line("vs: "+p_meta.sources[j].md5); - if (md5!=p_meta.sources[j].md5) { - //really changed - return true; - } - p_meta.sources[j].modified_time=mt; - } - } - } - - return false; -} - void EditorFileSystem::ScanProgress::update(int p_current,int p_total) const { float ratio = low + ((hi-low)/p_total)*p_current; @@ -579,9 +451,75 @@ EditorFileSystem::ScanProgress EditorFileSystem::ScanProgress::get_sub(int p_cur sp.hi=slice; return sp; - } +bool EditorFileSystem::_check_missing_imported_files(const String& p_path) { + + if (!reimport_on_missing_imported_files) + return true; + + Error err; + FileAccess *f= FileAccess::open(p_path+".import",FileAccess::READ,&err); + + if (!f) { + print_line("could not open import for "+p_path); + return false; + } + + VariantParser::StreamFile stream; + stream.f=f; + + String assign; + Variant value; + VariantParser::Tag next_tag; + + int lines=0; + String error_text; + + List<String> to_check; + + while(true) { + + assign=Variant(); + next_tag.fields.clear(); + next_tag.name=String(); + + err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL,true); + if (err==ERR_FILE_EOF) { + memdelete(f); + return OK; + } + else if (err!=OK) { + ERR_PRINTS("ResourceFormatImporter::load - "+p_path+".import:"+itos(lines)+" error: "+error_text); + memdelete(f); + return false; + } + + if (assign!=String()) { + if (assign.begins_with("path")) { + to_check.push_back(value); + } else if (assign=="files") { + Array fa = value; + for(int i=0;i<fa.size();i++) { + to_check.push_back(fa[i]); + } + } + + } else if (next_tag.name!="remap" && next_tag.name!="deps") { + break; + } + } + + memdelete(f); + + for (List<String>::Element *E=to_check.front();E;E=E->next()) { + if (!FileAccess::exists(E->get())) { + print_line("missing "+E->get()+", reimport" ); + return false; + } + } + return true; +} void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess *da,const ScanProgress& p_progress) { @@ -606,7 +544,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess if (f.begins_with(".")) //ignore hidden and . / .. continue; - if (FileAccess::exists(cd.plus_file(f).plus_file("engine.cfg"))) // skip if another project inside this + if (FileAccess::exists(cd.plus_file(f).plus_file("godot.cfg"))) // skip if another project inside this continue; dirs.push_back(f); @@ -670,9 +608,11 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess for (List<String>::Element*E=files.front();E;E=E->next(),idx++) { + String ext = E->get().get_extension().to_lower(); - if (!valid_extensions.has(ext)) + if (!valid_extensions.has(ext)) { continue; //invalid + } EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo ); fi->file=E->get(); @@ -682,32 +622,59 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess FileCache *fc = file_cache.getptr(path); uint64_t mt = FileAccess::get_modified_time(path); - if (fc && fc->modification_time == mt) { + if (import_extensions.has(ext)) { - fi->meta=fc->meta; - fi->type=fc->type; - fi->modified_time=fc->modification_time; - } else { - fi->meta=_get_meta(path); - fi->type=ResourceLoader::get_resource_type(path); - fi->modified_time=mt; + //is imported + uint64_t import_mt=0; + if (FileAccess::exists(path+".import")) { + import_mt=FileAccess::get_modified_time(path+".import"); + } + + + if (fc && fc->modification_time==mt && fc->import_modification_time==import_mt && _check_missing_imported_files(path)) { + + fi->type=fc->type; + fi->modified_time=fc->modification_time; + fi->import_modified_time=fc->import_modification_time; + + } else { + + if (!fc) { + print_line("REIMPORT BECAUSE: not previously found"); + } else if (fc->modification_time!=mt) { + print_line("REIMPORT BECAUSE: modified resource time "+itos(fc->modification_time)+" vs "+itos(mt)); + + } else if (fc->import_modification_time!=import_mt) { + print_line("REIMPORT BECAUSE: modified .import time"+itos(fc->import_modification_time)+" vs "+itos(import_mt)); + + } else { + + print_line("REIMPORT BECAUSE: missing imported files"); + } - } - if (fi->meta.enabled) { - if (_check_meta_sources(fi->meta)) { + fi->type=ResourceFormatImporter::get_singleton()->get_resource_type(path); + fi->modified_time=0; + fi->import_modified_time=0; + ItemAction ia; - ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED; + ia.action=ItemAction::ACTION_FILE_REIMPORT; ia.dir=p_dir; ia.file=E->get(); scan_actions.push_back(ia); - fi->meta.sources_changed=true; - } else { - fi->meta.sources_changed=false; } - } else { - fi->meta.sources_changed=true; + //not imported, so just update type if changed + if (fc && fc->modification_time == mt) { + + fi->type=fc->type; + fi->modified_time=fc->modification_time; + fi->import_modified_time=0; + } else { + fi->type=ResourceLoader::get_resource_type(path); + fi->modified_time=mt; + fi->import_modified_time=0; + } } p_dir->files.push_back(fi); @@ -717,11 +684,13 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess } + void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const ScanProgress& p_progress) { uint64_t current_mtime = FileAccess::get_modified_time(p_dir->get_path()); bool updated_dir=false; + String cd = p_dir->get_path(); //print_line("dir: "+p_dir->get_path()+" MODTIME: "+itos(p_dir->modified_time)+" CTIME: "+itos(current_mtime)); @@ -746,7 +715,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S //then scan files and directories and check what's different DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); - String cd = p_dir->get_path(); + da->change_dir(cd); da->list_dir_begin(); while (true) { @@ -764,7 +733,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S int idx = p_dir->find_dir_index(f); if (idx==-1) { - if (FileAccess::exists(cd.plus_file(f).plus_file("engine.cfg"))) // skip if another project inside this + if (FileAccess::exists(cd.plus_file(f).plus_file("godot.cfg"))) // skip if another project inside this continue; EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory ); @@ -802,7 +771,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S String path = cd.plus_file(fi->file); fi->modified_time=FileAccess::get_modified_time(path); - fi->meta=_get_meta(path); + fi->import_modified_time=0; fi->type=ResourceLoader::get_resource_type(path); { @@ -812,19 +781,22 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S ia.file=f; ia.new_file=fi; scan_actions.push_back(ia); - } - //take the chance and scan sources - if (_check_meta_sources(fi->meta)) { + } + + if (import_extensions.has(ext)) { + //if it can be imported, and it was added, it needs to be reimported + print_line("REIMPORT: file was not found before, reimport"); + print_line("at dir: "+p_dir->get_path()+" file: "+f); + for(int i=0;i<p_dir->files.size();i++) { + print_line(itos(i)+": "+p_dir->files[i]->file); + } ItemAction ia; - ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED; + ia.action=ItemAction::ACTION_FILE_REIMPORT; ia.dir=p_dir; ia.file=f; scan_actions.push_back(ia); - fi->meta.sources_changed=true; - } else { - fi->meta.sources_changed=false; } } else { @@ -854,15 +826,43 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const S } - if (_check_meta_sources(p_dir->files[i]->meta)) { - ItemAction ia; - ia.action=ItemAction::ACTION_FILE_SOURCES_CHANGED; - ia.dir=p_dir; - ia.file=p_dir->files[i]->file; - scan_actions.push_back(ia); - p_dir->files[i]->meta.sources_changed=true; - } else { - p_dir->files[i]->meta.sources_changed=false; + if (import_extensions.has(p_dir->files[i]->file.get_extension().to_lower())) { + //check here if file must be imported or not + + String path = cd.plus_file(p_dir->files[i]->file); + + uint64_t mt = FileAccess::get_modified_time(path); + + bool reimport=false; + + if (mt!=p_dir->files[i]->modified_time) { + print_line("REIMPORT: modified time changed, reimport"); + reimport=true; //it was modified, must be reimported. + } else if (!FileAccess::exists(path+".import")) { + print_line("REIMPORT: no .import exists, reimport"); + reimport=true; //no .import file, obviously reimport + } else { + + uint64_t import_mt=FileAccess::get_modified_time(path+".import"); + print_line(itos(import_mt)+" vs "+itos(p_dir->files[i]->import_modified_time)); + if (import_mt!=p_dir->files[i]->import_modified_time) { + print_line("REIMPORT: import modified changed, reimport"); + reimport=true; + } else if (!_check_missing_imported_files(path)) { + print_line("REIMPORT: imported files removed"); + reimport=true; + } + } + + if (reimport) { + + ItemAction ia; + ia.action=ItemAction::ACTION_FILE_REIMPORT; + ia.dir=p_dir; + ia.file=p_dir->files[i]->file; + scan_actions.push_back(ia); + } + } EditorResourcePreview::get_singleton()->check_for_invalidation(p_dir->get_file_path(i)); @@ -895,7 +895,7 @@ void EditorFileSystem::_thread_func_sources(void *_userdata) { sp.low=0; efs->_scan_fs_changes(efs->filesystem,sp); } - efs->scanning_sources_done=true; + efs->scanning_changes_done=true; } void EditorFileSystem::get_changed_sources(List<String> *r_changed) { @@ -903,14 +903,15 @@ void EditorFileSystem::get_changed_sources(List<String> *r_changed) { *r_changed=sources_changed; } -void EditorFileSystem::scan_sources() { +void EditorFileSystem::scan_changes() { - if (scanning || scanning_sources|| thread) + if (scanning || scanning_changes|| thread) return; + _update_extensions(); sources_changed.clear(); - scanning_sources=true; - scanning_sources_done=false; + scanning_changes=true; + scanning_changes_done=false; abort_scan=false; @@ -926,8 +927,8 @@ void EditorFileSystem::scan_sources() { if (_update_scan_actions()) emit_signal("filesystem_changed"); } - scanning_sources=false; - scanning_sources_done=true; + scanning_changes=false; + scanning_changes_done=true; emit_signal("sources_changed",sources_changed.size()>0); } else { @@ -982,11 +983,11 @@ void EditorFileSystem::_notification(int p_what) { if (use_threads) { - if (scanning_sources) { + if (scanning_changes) { - if (scanning_sources_done) { + if (scanning_changes_done) { - scanning_sources=false; + scanning_changes=false; set_process(false); @@ -1027,7 +1028,7 @@ void EditorFileSystem::_notification(int p_what) { bool EditorFileSystem::is_scanning() const { - return scanning; + return scanning || scanning_changes; } float EditorFileSystem::get_scanning_progress() const { @@ -1048,22 +1049,13 @@ void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory*p_dir,Fi for(int i=0;i<p_dir->files.size();i++) { - String s=p_dir->files[i]->file+"::"+p_dir->files[i]->type+"::"+String::num(p_dir->files[i]->modified_time)+"::"; - if (p_dir->files[i]->meta.enabled) { - s+=p_dir->files[i]->meta.import_editor; - for(int j=0;j<p_dir->files[i]->meta.sources.size();j++){ - s+="<>"+p_dir->files[i]->meta.sources[j].path; - s+="<>"+p_dir->files[i]->meta.sources[j].md5; - s+="<>"+String::num(p_dir->files[i]->meta.sources[j].modified_time); - - } - } + String s=p_dir->files[i]->file+"::"+p_dir->files[i]->type+"::"+itos(p_dir->files[i]->modified_time)+"::"+itos(p_dir->files[i]->import_modified_time); s+="::"; - for(int j=0;j<p_dir->files[i]->meta.deps.size();j++) { + for(int j=0;j<p_dir->files[i]->deps.size();j++) { if (j>0) s+="<>"; - s+=p_dir->files[i]->meta.deps[j]; + s+=p_dir->files[i]->deps[j]; } p_file->store_line(s); @@ -1106,6 +1098,8 @@ bool EditorFileSystem::_find_file(const String& p_file,EditorFileSystemDirectory for(int i=0;i<path.size();i++) { + if (path[i].begins_with(".")) + return false; int idx=-1; for(int j=0;j<fs->get_subdir_count();j++) { @@ -1256,34 +1250,8 @@ void EditorFileSystem::_resource_saved(const String& p_path){ } -String EditorFileSystem::_find_first_from_source(EditorFileSystemDirectory* p_dir,const String &p_src) const { - - for(int i=0;i<p_dir->files.size();i++) { - for(int j=0;j<p_dir->files[i]->meta.sources.size();j++) { - - if (p_dir->files[i]->meta.sources[j].path==p_src) - return p_dir->get_file_path(i); - } - } - - for(int i=0;i<p_dir->subdirs.size();i++) { - - String ret = _find_first_from_source(p_dir->subdirs[i],p_src); - if (ret.length()>0) - return ret; - } - - return String(); -} - - -String EditorFileSystem::find_resource_from_source(const String& p_path) const { - if (filesystem) - return _find_first_from_source(filesystem,p_path); - return String(); -} void EditorFileSystem::update_file(const String& p_file) { @@ -1319,6 +1287,7 @@ void EditorFileSystem::update_file(const String& p_file) { EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo ); fi->file=p_file.get_file(); + fi->import_modified_time=0; if (idx==fs->files.size()) { fs->files.push_back(fi); @@ -1334,7 +1303,9 @@ void EditorFileSystem::update_file(const String& p_file) { //print_line("UPDATING: "+p_file); fs->files[cpos]->type=type; fs->files[cpos]->modified_time=FileAccess::get_modified_time(p_file); - fs->files[cpos]->meta=_get_meta(p_file); + //if (FileAccess::exists(p_file+".import")) { + // fs->files[cpos]->import_modified_time=FileAccess::get_modified_time(p_file+".import"); + //} EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation",p_file); call_deferred("emit_signal","filesystem_changed"); //update later @@ -1342,6 +1313,173 @@ void EditorFileSystem::update_file(const String& p_file) { } +void EditorFileSystem::_reimport_file(const String& p_file) { + + print_line("REIMPORTING: "+p_file); + + EditorFileSystemDirectory *fs=NULL; + int cpos=-1; + bool found = _find_file(p_file,&fs,cpos); + ERR_FAIL_COND(!found); + + //try to obtain existing params + + Map<StringName,Variant> params; + String importer_name; + + if (FileAccess::exists(p_file+".import")) { + + Ref<ConfigFile> cf; + cf.instance(); + Error err = cf->load(p_file+".import"); + if (err==OK) { + List<String> sk; + cf->get_section_keys("params",&sk); + for(List<String>::Element *E=sk.front();E;E=E->next()) { + params[E->get()]=cf->get_value("params",E->get()); + } + importer_name = cf->get_value("remap","importer"); + } + } + + Ref<ResourceImporter> importer; + //find the importer + if (importer_name!="") { + importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name); + } + + if (importer.is_null()) { + //not found by name, find by extension + importer = ResourceFormatImporter::get_singleton()->get_importer_by_extension(p_file.get_extension()); + if (importer.is_null()) { + ERR_PRINT("BUG: File queued for import, but can't be imported!"); + ERR_FAIL(); + + } + } + + //mix with default params, in case a parameter is missing + + List<ResourceImporter::ImportOption> opts; + importer->get_import_options(&opts); + for (List<ResourceImporter::ImportOption>::Element *E=opts.front();E;E=E->next()) { + if (!params.has(E->get().option.name)) { //this one is not present + params[E->get().option.name]=E->get().default_value; + } + } + + //finally, perform import!! + String base_path = ResourceFormatImporter::get_singleton()->get_import_base_path(p_file); + + List<String> import_variants; + List<String> gen_files; + + Error err = importer->import(p_file,base_path,params,&import_variants,&gen_files); + + if (err!=OK) { + ERR_PRINTS("Error importing: "+p_file); + } + + //as import is complete, save the .import file + + FileAccess *f = FileAccess::open(p_file+".import",FileAccess::WRITE); + ERR_FAIL_COND(!f); + + //write manually, as order matters ([remap] has to go first for performance). + f->store_line("[remap]"); + f->store_line(""); + f->store_line("importer=\""+importer->get_importer_name()+"\""); + if (importer->get_resource_type()!="") { + f->store_line("type=\""+importer->get_resource_type()+"\""); + } + + + if (importer->get_save_extension()=="") { + //no path + } else if (import_variants.size()) { + //import with variants + for(List<String>::Element *E=import_variants.front();E;E=E->next()) { + + + String path = base_path.c_escape()+"."+E->get()+"."+importer->get_save_extension(); + + f->store_line("path."+E->get()+"=\""+path+"\""); + + } + } else { + + f->store_line("path=\""+base_path+"."+importer->get_save_extension()+"\""); + } + + f->store_line(""); + if (gen_files.size()) { + f->store_line("[gen]"); + Array genf; + for (List<String>::Element *E=gen_files.front();E;E=E->next()) { + genf.push_back(E->get()); + } + + String value; + VariantWriter::write_to_string(genf,value); + f->store_line("files="+value); + f->store_line(""); + } + + + f->store_line("[params]"); + f->store_line(""); + + //store options in provided order, to avoid file changing + + + for (List<ResourceImporter::ImportOption>::Element *E=opts.front();E;E=E->next()) { + + String base = E->get().option.name; + String value; + VariantWriter::write_to_string(params[base],value); + f->store_line(base+"="+value); + + + } + + f->close(); + memdelete(f); + + //update modified times, to avoid reimport + fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file); + fs->files[cpos]->import_modified_time = FileAccess::get_modified_time(p_file+".import"); + + //if file is currently up, maybe the source it was loaded from changed, so import math must be updated for it + //to reload properly + if (ResourceCache::has(p_file)) { + + Resource *r = ResourceCache::get(p_file); + + if (r->get_import_path()!=String()) { + + String dst_path = ResourceFormatImporter::get_singleton()->get_internal_resource_path(p_file); + r->set_import_path(dst_path); + r->set_import_last_modified_time(0); + } + } +} + +void EditorFileSystem::reimport_files(const Vector<String>& p_files) { + + importing=true; + EditorProgress pr("reimport",TTR("(Re)Importing Assets"),p_files.size()); + for(int i=0;i<p_files.size();i++) { + pr.step(p_files[i].get_file(),i); + + _reimport_file(p_files[i]); + } + + _save_filesystem_cache(); + importing=false; + if (!is_scanning()) { + emit_signal("filesystem_changed"); + } +} void EditorFileSystem::_bind_methods() { @@ -1350,7 +1488,7 @@ void EditorFileSystem::_bind_methods() { ClassDB::bind_method(_MD("is_scanning"),&EditorFileSystem::is_scanning); ClassDB::bind_method(_MD("get_scanning_progress"),&EditorFileSystem::get_scanning_progress); ClassDB::bind_method(_MD("scan"),&EditorFileSystem::scan); - ClassDB::bind_method(_MD("scan_sources"),&EditorFileSystem::scan_sources); + ClassDB::bind_method(_MD("scan_sources"),&EditorFileSystem::scan_changes); ClassDB::bind_method(_MD("update_file","path"),&EditorFileSystem::update_file); ClassDB::bind_method(_MD("get_filesystem_path:EditorFileSystemDirectory","path"),&EditorFileSystem::get_filesystem_path); ClassDB::bind_method(_MD("get_file_type","path"),&EditorFileSystem::get_file_type); @@ -1360,30 +1498,48 @@ void EditorFileSystem::_bind_methods() { } +void EditorFileSystem::_update_extensions() { + valid_extensions.clear(); + import_extensions.clear(); + + List<String> extensionsl; + ResourceLoader::get_recognized_extensions_for_type("",&extensionsl); + for(List<String>::Element *E = extensionsl.front();E;E=E->next()) { + + valid_extensions.insert(E->get()); + } + + extensionsl.clear(); + ResourceFormatImporter::get_singleton()->get_recognized_extensions(&extensionsl); + for(List<String>::Element *E = extensionsl.front();E;E=E->next()) { + + import_extensions.insert(E->get()); + } +} EditorFileSystem::EditorFileSystem() { + reimport_on_missing_imported_files = GLOBAL_DEF("editor/reimport_missing_imported_files",true); singleton=this; filesystem=memnew( EditorFileSystemDirectory ); //like, empty thread = NULL; scanning=false; + importing=false; use_threads=true; thread_sources=NULL; new_filesystem=NULL; - scanning_sources=false; + scanning_changes=false; ResourceSaver::set_save_callback(_resource_saved); - List<String> extensionsl; - ResourceLoader::get_recognized_extensions_for_type("",&extensionsl); - for(List<String>::Element *E = extensionsl.front();E;E=E->next()) { - - valid_extensions.insert(E->get()); + DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + if (da->change_dir("res://.import")!=OK) { + da->make_dir("res://.import"); } - + memdelete(da); scan_total=0; } diff --git a/tools/editor/editor_file_system.h b/tools/editor/editor_file_system.h index 3a26f46aa9..10d9b919fc 100644 --- a/tools/editor/editor_file_system.h +++ b/tools/editor/editor_file_system.h @@ -48,30 +48,13 @@ class EditorFileSystemDirectory : public Object { EditorFileSystemDirectory *parent; Vector<EditorFileSystemDirectory*> subdirs; - struct ImportMeta { - - struct Source { - - String path; - String md5; - uint64_t modified_time; - bool missing; - - }; - - Vector<Source> sources; - String import_editor; - Vector<String> deps; - bool enabled; - bool sources_changed; - - }; struct FileInfo { String file; StringName type; uint64_t modified_time; - ImportMeta meta; + uint64_t import_modified_time; + Vector<String> deps; bool verified; //used for checking changes }; @@ -101,14 +84,7 @@ public: String get_file(int p_idx) const; String get_file_path(int p_idx) const; StringName get_file_type(int p_idx) const; - bool get_file_meta(int p_idx) const; - bool is_missing_sources(int p_idx) const; - bool have_sources_changed(int p_idx) const; - Vector<String> get_missing_sources(int p_idx) const; Vector<String> get_file_deps(int p_idx) const; - int get_source_count(int p_idx) const; - String get_source_file(int p_idx,int p_source) const; - bool is_source_file_missing(int p_idx,int p_source) const; EditorFileSystemDirectory *get_parent(); @@ -136,7 +112,7 @@ class EditorFileSystem : public Node { ACTION_DIR_REMOVE, ACTION_FILE_ADD, ACTION_FILE_REMOVE, - ACTION_FILE_SOURCES_CHANGED + ACTION_FILE_REIMPORT }; Action action; @@ -157,6 +133,7 @@ class EditorFileSystem : public Node { bool abort_scan; bool scanning; + bool importing; float scan_total; @@ -171,7 +148,7 @@ class EditorFileSystem : public Node { String type; uint64_t modification_time; - EditorFileSystemDirectory::ImportMeta meta; + uint64_t import_modification_time; Vector<String> deps; }; @@ -186,25 +163,25 @@ class EditorFileSystem : public Node { ScanProgress get_sub(int p_current,int p_total) const; }; - static EditorFileSystemDirectory::ImportMeta _get_meta(const String& p_path); - - bool _check_meta_sources(EditorFileSystemDirectory::ImportMeta & p_meta); + void _save_filesystem_cache(); void _save_filesystem_cache(EditorFileSystemDirectory *p_dir,FileAccess *p_file); bool _find_file(const String& p_file,EditorFileSystemDirectory ** r_d, int &r_file_pos) const; void _scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress); + int md_count; Set<String> valid_extensions; + Set<String> import_extensions; void _scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess *da,const ScanProgress& p_progress); Thread *thread_sources; - bool scanning_sources; - bool scanning_sources_done; + bool scanning_changes; + bool scanning_changes_done; static void _thread_func_sources(void *_userdata); @@ -214,7 +191,14 @@ class EditorFileSystem : public Node { bool _update_scan_actions(); static void _resource_saved(const String& p_path); - String _find_first_from_source(EditorFileSystemDirectory* p_dir,const String &p_src) const; + + void _update_extensions(); + + void _reimport_file(const String &p_file); + + bool _check_missing_imported_files(const String& p_path); + + bool reimport_on_missing_imported_files; protected: @@ -227,16 +211,19 @@ public: EditorFileSystemDirectory *get_filesystem(); bool is_scanning() const; + bool is_importing() const { return importing; } float get_scanning_progress() const; void scan(); - void scan_sources(); + void scan_changes(); void get_changed_sources(List<String> *r_changed); void update_file(const String& p_file); - String find_resource_from_source(const String& p_path) const; + EditorFileSystemDirectory *get_filesystem_path(const String& p_path); String get_file_type(const String& p_file) const; EditorFileSystemDirectory* find_file(const String& p_file,int* r_index) const; + void reimport_files(const Vector<String>& p_files); + EditorFileSystem(); ~EditorFileSystem(); }; diff --git a/tools/editor/editor_fonts.cpp b/tools/editor/editor_fonts.cpp index 3c846fc538..3652a59978 100644 --- a/tools/editor/editor_fonts.cpp +++ b/tools/editor/editor_fonts.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_fonts.h" + #include "doc_font.h" #include "doc_title_font.h" #include "doc_code_font.h" diff --git a/tools/editor/editor_help.cpp b/tools/editor/editor_help.cpp index f96a02bc52..03e631cbc3 100644 --- a/tools/editor/editor_help.cpp +++ b/tools/editor/editor_help.cpp @@ -27,15 +27,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_help.h" + #include "editor_node.h" #include "editor_settings.h" #include "os/keyboard.h" #include "doc_data_compressed.h" #include "tools/editor/plugins/script_editor_plugin.h" - -#include "os/keyboard.h" - void EditorHelpSearch::popup() { popup_centered_ratio(0.6); if (search_box->get_text()!="") { diff --git a/tools/editor/editor_help.h b/tools/editor/editor_help.h index 85bac27705..3c4ba1f43e 100644 --- a/tools/editor/editor_help.h +++ b/tools/editor/editor_help.h @@ -40,7 +40,7 @@ #include "scene/main/timer.h" #include "tools/editor/code_editor.h" -#include "tools/doc/doc_data.h" +#include "tools/editor/doc/doc_data.h" class EditorNode; diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp index cf83052ee0..69a004fc08 100644 --- a/tools/editor/editor_import_export.cpp +++ b/tools/editor/editor_import_export.cpp @@ -26,8 +26,10 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "version.h" #include "editor_import_export.h" + +#if 0 +#include "version.h" #include "script_language.h" #include "globals.h" #include "os/file_access.h" @@ -388,8 +390,8 @@ Vector<StringName> EditorExportPlatform::get_dependencies(bool p_bundles) const Set<StringName> exported; - if (FileAccess::exists("res://engine.cfg")) - exported.insert("res://engine.cfg"); + if (FileAccess::exists("res://godot.cfg")) + exported.insert("res://godot.cfg"); if (EditorImportExport::get_singleton()->get_export_filter()!=EditorImportExport::EXPORT_SELECTED) { @@ -985,7 +987,7 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func } - StringName engine_cfg="res://engine.cfg"; + StringName engine_cfg="res://godot.cfg"; StringName boot_splash; { String splash=GlobalConfig::get_singleton()->get("application/boot_splash"); //avoid splash from being converted @@ -1039,7 +1041,7 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func { - //make binary engine.cfg config + //make binary godot.cfg config Map<String,Variant> custom; @@ -1083,7 +1085,7 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func } - String remap_file="engine.cfb"; + String remap_file="godot.cfb"; String engine_cfb =EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmp"+remap_file; GlobalConfig::get_singleton()->save_custom(engine_cfb,custom); Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb); @@ -1174,7 +1176,7 @@ Error EditorExportPlatform::save_pack_file(void *p_userdata,const String& p_path pd->f->store_32(cs.length()); pd->f->store_buffer((uint8_t*)cs.get_data(),cs.length()); TempData td; - td.pos=pd->f->get_pos();; + td.pos=pd->f->get_pos(); td.ofs=pd->ftmp->get_pos(); td.size=p_data.size(); pd->file_ofs.push_back(td); @@ -2093,13 +2095,21 @@ void EditorImportExport::save_config() { if (image_groups.size() && image_group_files.size()){ - Vector<String> igfsave; - igfsave.resize(image_group_files.size()*2); + Vector<String> igfkeys; + igfkeys.resize(image_group_files.size()); int idx=0; for (Map<StringName,StringName>::Element *E=image_group_files.front();E;E=E->next()) { + igfkeys[idx++]=E->key(); + } + igfkeys.sort(); + + Vector<String> igfsave; + igfsave.resize(image_group_files.size()*2); + idx=0; + for (int i=0;i<igfkeys.size();++i) { - igfsave[idx++]=E->key(); - igfsave[idx++]=E->get(); + igfsave[idx++]=igfkeys[i]; + igfsave[idx++]=image_group_files[igfkeys[i]]; } cf->set_value("image_group_files","files",igfsave); } @@ -2293,3 +2303,4 @@ EditorImportExport::~EditorImportExport() { } +#endif diff --git a/tools/editor/editor_import_export.h b/tools/editor/editor_import_export.h index fb75373f17..2654a4ea33 100644 --- a/tools/editor/editor_import_export.h +++ b/tools/editor/editor_import_export.h @@ -29,6 +29,8 @@ #ifndef EDITOR_IMPORT_EXPORT_H #define EDITOR_IMPORT_EXPORT_H +#if 0 + #include "resource.h" #include "scene/main/node.h" #include "scene/resources/texture.h" @@ -419,4 +421,5 @@ VARIANT_ENUM_CAST(EditorImportExport::ImageAction); VARIANT_ENUM_CAST(EditorImportExport::ScriptAction); VARIANT_ENUM_CAST(EditorImportExport::SampleAction); +#endif #endif // EDITOR_IMPORT_EXPORT_H diff --git a/tools/editor/editor_initialize_ssl.cpp b/tools/editor/editor_initialize_ssl.cpp index 9ac4f90e9f..c08dcc6656 100644 --- a/tools/editor/editor_initialize_ssl.cpp +++ b/tools/editor/editor_initialize_ssl.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_initialize_ssl.h" + #include "certs_compressed.h" #include "io/stream_peer_ssl.h" #include "io/compression.h" diff --git a/tools/editor/editor_log.cpp b/tools/editor/editor_log.cpp index fd2da2e4c0..6b6a1b9988 100644 --- a/tools/editor/editor_log.cpp +++ b/tools/editor/editor_log.cpp @@ -26,8 +26,9 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "version.h" #include "editor_log.h" + +#include "version.h" #include "scene/gui/center_container.h" #include "editor_node.h" diff --git a/tools/editor/editor_name_dialog.cpp b/tools/editor/editor_name_dialog.cpp index e7dcea4d40..da9f25f1e3 100644 --- a/tools/editor/editor_name_dialog.cpp +++ b/tools/editor/editor_name_dialog.cpp @@ -26,9 +26,9 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ - #include "editor_name_dialog.h" -#include "object_type_db.h" + +#include "class_db.h" #include "os/keyboard.h" void EditorNameDialog::_line_gui_input(const InputEvent& p_event) { diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 979f54dabb..9fac8dfbeb 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -26,22 +26,20 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "version.h" #include "editor_node.h" + +#include "version.h" #include "print_string.h" #include "editor_themes.h" - #include "editor_help.h" #include "core/io/resource_saver.h" #include "core/io/resource_loader.h" #include "servers/physics_2d_server.h" #include "scene/resources/packed_scene.h" #include "editor_settings.h" -#include "io_plugins/editor_import_collada.h" -#include "io_plugins/editor_scene_importer_fbxconv.h" #include "globals.h" #include <stdio.h> -#include "object_type_db.h" +#include "class_db.h" #include "os/keyboard.h" #include "os/os.h" #include "os/file_access.h" @@ -56,6 +54,8 @@ #include "io/config_file.h" #include "animation_editor.h" #include "io/stream_peer_ssl.h" +#include "main/input_default.h" +#include "os/input.h" // plugins #include "plugins/sprite_frames_editor_plugin.h" #include "plugins/texture_region_editor_plugin.h" @@ -76,7 +76,6 @@ #include "plugins/mesh_instance_editor_plugin.h" #include "plugins/mesh_editor_plugin.h" #include "plugins/theme_editor_plugin.h" - #include "plugins/tile_map_editor_plugin.h" #include "plugins/cube_grid_theme_editor_plugin.h" #include "plugins/shader_editor_plugin.h" @@ -101,20 +100,27 @@ #include "plugins/color_ramp_editor_plugin.h" #include "plugins/collision_shape_2d_editor_plugin.h" #include "plugins/gi_probe_editor_plugin.h" -#include "main/input_default.h" +#include "import/resource_importer_texture.h" +#include "import/resource_importer_csv_translation.h" +#include "import/resource_importer_wav.h" +#include "import/resource_importer_obj.h" +#include "import/resource_importer_scene.h" // end -#include "tools/editor/editor_settings.h" -#include "tools/editor/io_plugins/editor_texture_import_plugin.h" -#include "tools/editor/io_plugins/editor_scene_import_plugin.h" -#include "tools/editor/io_plugins/editor_font_import_plugin.h" -#include "tools/editor/io_plugins/editor_sample_import_plugin.h" -#include "tools/editor/io_plugins/editor_translation_import_plugin.h" -#include "tools/editor/io_plugins/editor_bitmask_import_plugin.h" -#include "tools/editor/io_plugins/editor_mesh_import_plugin.h" -#include "tools/editor/io_plugins/editor_export_scene.h" +#include "editor_settings.h" +#include "io_plugins/editor_texture_import_plugin.h" +#include "io_plugins/editor_scene_import_plugin.h" +#include "io_plugins/editor_font_import_plugin.h" +#include "io_plugins/editor_sample_import_plugin.h" +#include "io_plugins/editor_translation_import_plugin.h" +#include "io_plugins/editor_bitmask_import_plugin.h" +#include "io_plugins/editor_mesh_import_plugin.h" +#include "io_plugins/editor_export_scene.h" +#include "import/editor_import_collada.h" +#include "io_plugins/editor_scene_importer_fbxconv.h" #include "plugins/editor_preview_plugins.h" #include "editor_initialize_ssl.h" +#include "editor_audio_buses.h" #include "script_editor_debugger.h" EditorNode *EditorNode::singleton=NULL; @@ -189,6 +195,9 @@ void EditorNode::_unhandled_input(const InputEvent& p_event) { next_tab = next_tab >= 0 ? next_tab : editor_data.get_edited_scene_count() - 1; _scene_tab_changed(next_tab); } + if (ED_IS_SHORTCUT("editor/filter_files", p_event)) { + filesystem_dock->focus_on_filter(); + } switch(p_event.key.scancode) { @@ -280,7 +289,7 @@ void EditorNode::_notification(int p_what) { editor_selection->update(); { - uint32_t p32 = AudioServer::get_singleton()->read_output_peak()>>8; + uint32_t p32 = 0;//AudioServer::get_singleton()->read_output_peak()>>8; float peak = p32==0? -80 : Math::linear2db(p32 / 65535.0); @@ -300,6 +309,8 @@ void EditorNode::_notification(int p_what) { } + ResourceImporterTexture::get_singleton()->update_imports(); + } if (p_what==NOTIFICATION_ENTER_TREE) { @@ -328,21 +339,7 @@ void EditorNode::_notification(int p_what) { VisualServer::get_singleton()->viewport_set_disable_environment(get_viewport()->get_viewport_rid(),true); _editor_select(EDITOR_3D); - - if (defer_load_scene!="") { - - load_scene(defer_load_scene); - defer_load_scene=""; - } - - if (defer_translatable!="") { - - Error ok = save_translatable_strings(defer_translatable); - if (ok!=OK) - OS::get_singleton()->set_exit_code(255); - defer_translatable=""; - get_tree()->quit(); - } + _update_debug_options(); /* if (defer_optimize!="") { @@ -366,40 +363,7 @@ void EditorNode::_notification(int p_what) { if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) { - /* - List<Ref<Resource> > cached; - ResourceCache::get_cached_resources(&cached); - - bool changes=false; - for(List<Ref<Resource> >::Element *E=cached.front();E;E=E->next()) { - - if (!E->get()->can_reload_from_file()) - continue; - if (E->get()->get_path().find("::")!=-1) - continue; - uint64_t mt = FileAccess::get_modified_time(E->get()->get_path()); - if (mt!=E->get()->get_last_modified_time()) { - changes=true; - break; - } - } - - - - sources_button->get_popup()->set_item_disabled(sources_button->get_popup()->get_item_index(DEPENDENCY_UPDATE_LOCAL),!changes); - if (changes && sources_button->get_popup()->is_item_disabled(sources_button->get_popup()->get_item_index(DEPENDENCY_UPDATE_IMPORTED))) { - sources_button->set_icon(gui_base->get_icon("DependencyLocalChanged","EditorIcons")); - } -*/ - - if (bool(EDITOR_DEF("filesystem/resources/auto_reload_modified_images",true))) { - - _menu_option_confirm(DEPENDENCY_LOAD_CHANGED_IMAGES,true); - } - - waiting_for_sources_changed=true; - EditorFileSystem::get_singleton()->scan_sources(); - + EditorFileSystem::get_singleton()->scan_changes(); } if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) { @@ -427,63 +391,75 @@ void EditorNode::_fs_changed() { if (export_defer.platform!="") { - project_export_settings->export_platform(export_defer.platform,export_defer.path,export_defer.debug,export_defer.password,true); + //project_export_settings->export_platform(export_defer.platform,export_defer.path,export_defer.debug,export_defer.password,true); export_defer.platform=""; } -} - -void EditorNode::_sources_changed(bool p_exist) { + { - if (p_exist && bool(EditorSettings::get_singleton()->get("filesystem/import/automatic_reimport_on_sources_changed"))) { - p_exist=false; + //reload changed resources + List<Ref<Resource> > changed; - List<String> changed_sources; - EditorFileSystem::get_singleton()->get_changed_sources(&changed_sources); + List<Ref<Resource> > cached; + ResourceCache::get_cached_resources(&cached); + //this should probably be done in a thread.. + for(List<Ref<Resource> >::Element *E=cached.front();E;E=E->next()) { + if (!E->get()->editor_can_reload_from_file()) + continue; + if (!E->get()->get_path().is_resource_file() && !E->get()->get_path().is_abs_path()) + continue; + if (!FileAccess::exists(E->get()->get_path())) + continue; - EditorProgress ep("reimport",TTR("Re-Importing"),changed_sources.size()); - int step_idx=0; + if (E->get()->get_import_path()!=String()) { + //imported resource + uint64_t mt = FileAccess::get_modified_time(E->get()->get_import_path()); + print_line("testing modified: "+E->get()->get_import_path()+" "+itos(mt)+" vs "+itos(E->get()->get_import_last_modified_time())); - for(List<String>::Element *E=changed_sources.front();E;E=E->next()) { + if (mt!=E->get()->get_import_last_modified_time()) { + print_line("success"); + changed.push_back(E->get()); + } - ep.step(TTR("Importing:")+" "+E->get(),step_idx++); + } else { + uint64_t mt = FileAccess::get_modified_time(E->get()->get_path()); - Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(E->get()); - ERR_CONTINUE(rimd.is_null()); - String editor = rimd->get_editor(); - if (editor.begins_with("texture_")) { - editor="texture"; //compatibility fix for old versions - } - Ref<EditorImportPlugin> eip = EditorImportExport::get_singleton()->get_import_plugin_by_name(editor); - ERR_CONTINUE(eip.is_null()); - Error err = eip->import(E->get(),rimd); - if (err!=OK) { - EditorNode::add_io_error("Error Re Importing:\n "+E->get()); + if (mt!=E->get()->get_last_modified_time()) { + changed.push_back(E->get()); + } } + } + if (changed.size()) { + //EditorProgress ep("reload_res","Reload Modified Resources",changed.size()); + int idx=0; + for(List<Ref<Resource> >::Element *E=changed.front();E;E=E->next()) { + + //ep.step(E->get()->get_path(),idx++); + E->get()->reload_from_file(); + } } - EditorFileSystem::get_singleton()->scan_sources(); - waiting_for_sources_changed=false; - return; } +} - if (p_exist) { +void EditorNode::_sources_changed(bool p_exist) { - sources_button->set_icon(gui_base->get_icon("DependencyChanged","EditorIcons")); - sources_button->set_disabled(false); + if (waiting_for_first_scan) { - } else { + if (defer_load_scene!="") { - sources_button->set_icon(gui_base->get_icon("DependencyOk","EditorIcons")); - sources_button->set_disabled(true); + print_line("loading scene DEFERED"); + load_scene(defer_load_scene); + defer_load_scene=""; + } + waiting_for_first_scan=false; } - waiting_for_sources_changed=false; } @@ -498,9 +474,11 @@ void EditorNode::_rebuild_import_menu() p->clear(); //p->add_item(TTR("Node From Scene"), FILE_IMPORT_SUBSCENE); //p->add_separator(); +#if 0 for (int i = 0; i < editor_import_export->get_import_plugin_count(); i++) { p->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(), IMPORT_PLUGIN_BASE + i); } +#endif } void EditorNode::_node_renamed() { @@ -831,7 +809,7 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj,Map<RES,bool>& p case Variant::DICTIONARY: { - Dictionary d=obj->get(E->get().name);; + Dictionary d=obj->get(E->get().name); List<Variant> keys; d.get_key_list(&keys); for(List<Variant>::Element *E=keys.front();E;E=E->next()) { @@ -917,7 +895,7 @@ void EditorNode::_save_scene_with_preview(String p_file) { save.step(TTR("Creating Thumbnail"),3); #if 0 Image img = VS::get_singleton()->viewport_texture(scree_capture(viewport); - int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");; + int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); preview_size*=EDSCALE; int width,height; if (img.get_width() > preview_size && img.get_width() >= img.get_height()) { @@ -1004,7 +982,6 @@ void EditorNode::_save_scene(String p_file, int idx) { return; } - sdata->set_import_metadata(editor_data.get_edited_scene_import_metadata(idx)); int flg=0; if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) flg|=ResourceSaver::FLAG_COMPRESS; @@ -1056,7 +1033,7 @@ void EditorNode::_import_action(const String& p_action) { //accept->get_cancel()->hide(); accept->get_ok()->set_text("Ugh"); accept->set_text("Error importing scene."); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); return; } @@ -1072,7 +1049,7 @@ void EditorNode::_import_action(const String& p_action) { //accept->get_cancel()->hide(); accept->get_ok()->set_text("Ugh"); accept->set_text("Error load scene to update."); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); return; } @@ -1113,7 +1090,7 @@ void EditorNode::_import(const String &p_file) { //accept->get_cancel()->hide(); accept->get_ok()->set_text("Ugh"); accept->set_text("Error importing scene."); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); return; } @@ -1201,12 +1178,6 @@ void EditorNode::_dialog_action(String p_file) { get_undo_redo()->clear_history(); } break; - case FILE_DUMP_STRINGS: { - - save_translatable_strings(p_file); - - } break; - case FILE_SAVE_SCENE: case FILE_SAVE_AS_SCENE: { @@ -1924,17 +1895,17 @@ void EditorNode::_run(bool p_current,const String& p_custom) { editor_data.save_editor_external_data(); } - if (bool(EDITOR_DEF("run/always_clear_output_on_play", true))) { + if (bool(EDITOR_DEF("run/output/always_clear_output_on_play", true))) { log->clear(); } - if (bool(EDITOR_DEF("run/always_open_output_on_play", true))) { + if (bool(EDITOR_DEF("run/output/always_open_output_on_play", true))) { make_bottom_panel_item_visible(log); } List<String> breakpoints; editor_data.get_editor_breakpoints(&breakpoints); - + args = GlobalConfig::get_singleton()->get("editor/main_run_args"); Error error = editor_run.run(run_filename,args,breakpoints,current_filename); @@ -2075,14 +2046,6 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { quick_open->set_title(TTR("Quick Open Script..")); } break; - case FILE_QUICK_OPEN_FILE: { - - - //quick_open->popup("Resource", false, true); - //quick_open->set_title("Quick Search File.."); - scenes_dock->focus_on_filter(); - - } break; case FILE_RUN_SCRIPT: { file_script->popup_centered_ratio(); @@ -2206,46 +2169,6 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { _menu_option_confirm(FILE_SAVE_AND_RUN, true); } break; - case FILE_DUMP_STRINGS: { - - Node *scene = editor_data.get_edited_scene_root(); - - if (!scene) { - - current_option=-1; - //confirmation->get_cancel()->hide(); - accept->get_ok()->set_text(TTR("I see..")); - accept->set_text("This operation can't be done without a tree root."); - accept->popup_centered_minsize(); - break; - } - - String cpath; - if (scene->get_filename()!="") { - cpath = scene->get_filename(); - - String fn = cpath.substr(0,cpath.length() - cpath.get_extension().size()); - String ext=cpath.get_extension(); - cpath=fn+".pot"; - - - } else { - current_option=-1; - //confirmation->get_cancel()->hide(); - accept->get_ok()->set_text(TTR("I see..")); - accept->set_text(TTR("Please save the scene first.")); - accept->popup_centered_minsize(); - break; - - } - - file->set_mode(EditorFileDialog::MODE_SAVE_FILE); - - file->set_current_path(cpath); - file->set_title(TTR("Save Translatable Strings")); - file->popup_centered_ratio(); - - } break; case FILE_SAVE_OPTIMIZED: { #if 0 Node *scene = editor_data.get_edited_scene_root(); @@ -2255,7 +2178,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done without a tree root."); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); break; } @@ -2277,7 +2200,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("Please save the scene first."); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); break; } @@ -2286,13 +2209,13 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { case FILE_EXPORT_PROJECT: { - project_export_settings->popup_export(); + //project_export_settings->popup_export(); /* String target = export_db->get_current_platform(); Ref<EditorExporter> exporter = export_db->get_exporter(target); if (exporter.is_null()) { accept->set_text("No exporter for platform '"+target+"' yet."); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); return; } @@ -2409,8 +2332,12 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { case EDIT_UNDO: { - if (OS::get_singleton()->get_mouse_button_state()) + + + if (Input::get_singleton()->get_mouse_button_mask()&0x7) { + print_line("no because state"); break; // can't undo while mouse buttons are pressed + } String action = editor_data.get_undo_redo().get_current_action_name(); if (action!="") @@ -2420,7 +2347,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case EDIT_REDO: { - if (OS::get_singleton()->get_mouse_button_state()) + if (Input::get_singleton()->get_mouse_button_mask()&0x7) break; // can't redo while mouse buttons are pressed editor_data.get_undo_redo().redo(); @@ -2475,7 +2402,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { //accept->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done without a selected node."); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); break; } @@ -2487,7 +2414,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done without a selected node."); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); break; } @@ -2499,7 +2426,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { //accept->get_cancel()->hide(); accept->get_ok()->set_text("Ugh"); accept->set_text("Error loading scene from "+external_file); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); return; } @@ -2594,20 +2521,20 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case OBJECT_COPY_PARAMS: { - editor_data.apply_changes_in_editors();; + editor_data.apply_changes_in_editors(); if (current) editor_data.copy_object_params(current); } break; case OBJECT_PASTE_PARAMS: { - editor_data.apply_changes_in_editors();; + editor_data.apply_changes_in_editors(); if (current) editor_data.paste_object_params(current); editor_data.get_undo_redo().clear_history(); } break; case OBJECT_UNIQUE_RESOURCES: { - editor_data.apply_changes_in_editors();; + editor_data.apply_changes_in_editors(); if (current) { List<PropertyInfo> props; current->get_property_list(&props); @@ -2678,6 +2605,14 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { play_custom_scene_button->set_pressed(false); play_custom_scene_button->set_icon(gui_base->get_icon("PlayCustom","EditorIcons")); //pause_button->set_pressed(false); + if (bool(EDITOR_DEF("run/output/always_close_output_on_stop", true))) { + for(int i=0;i<bottom_panel_items.size();i++) { + if (bottom_panel_items[i].control==log) { + _bottom_panel_switch(false,i); + break; + } + } + } emit_signal("stop_pressed"); } break; @@ -2749,7 +2684,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } debug_button->get_popup()->set_item_checked( debug_button->get_popup()->get_item_index(RUN_FILE_SERVER),!ischecked); - + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_file_server", !ischecked); } break; case RUN_LIVE_DEBUG: { @@ -2757,6 +2692,8 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { debug_button->get_popup()->set_item_checked( debug_button->get_popup()->get_item_index(RUN_LIVE_DEBUG),!ischecked); ScriptEditor::get_singleton()->get_debugger()->set_live_debugging(!ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_live_debug", !ischecked); + } break; /*case RUN_DEPLOY_DUMB_CLIENTS: { @@ -2771,6 +2708,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { bool ischecked = debug_button->get_popup()->is_item_checked( debug_button->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG)); debug_button->get_popup()->set_item_checked( debug_button->get_popup()->get_item_index(RUN_DEPLOY_REMOTE_DEBUG),!ischecked); run_native->set_deploy_debug_remote(!ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_deploy_remote_debug", !ischecked); } break; case RUN_DEBUG_COLLISONS: { @@ -2779,6 +2717,8 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { debug_button->get_popup()->set_item_checked( debug_button->get_popup()->get_item_index(RUN_DEBUG_COLLISONS),!ischecked); run_native->set_debug_collisions(!ischecked); editor_run.set_debug_collisions(!ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_collisons", !ischecked); + } break; case RUN_DEBUG_NAVIGATION: { @@ -2786,6 +2726,8 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { debug_button->get_popup()->set_item_checked( debug_button->get_popup()->get_item_index(RUN_DEBUG_NAVIGATION),!ischecked); run_native->set_debug_navigation(!ischecked); editor_run.set_debug_navigation(!ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_navigation", !ischecked); + } break; case RUN_RELOAD_SCRIPTS: { @@ -2794,6 +2736,8 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { debug_button->get_popup()->set_item_checked( debug_button->get_popup()->get_item_index(RUN_RELOAD_SCRIPTS),!ischecked); ScriptEditor::get_singleton()->set_live_auto_reload_running_scripts(!ischecked); + EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_reload_scripts", !ischecked); + } break; case SETTINGS_UPDATE_ALWAYS: { @@ -2807,10 +2751,10 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { update_menu->get_popup()->set_item_checked(1,true); OS::get_singleton()->set_low_processor_usage_mode(true); } break; - case SETTINGS_UPDATE_SPINNER_HIDE: { + case SETTINGS_UPDATE_SPINNER_HIDE: { update_menu->set_icon(gui_base->get_icon("Collapse","EditorIcons")); - update_menu->get_popup()->toggle_item_checked(3); - } break; + update_menu->get_popup()->toggle_item_checked(3); + } break; case SETTINGS_PREFERENCES: { settings_config_dialog->popup_edit_settings(); @@ -2861,29 +2805,11 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case SOURCES_REIMPORT: { - reimport_dialog->popup_reimport(); + //reimport_dialog->popup_reimport(); } break; case DEPENDENCY_LOAD_CHANGED_IMAGES: { - List<Ref<Resource> > cached; - ResourceCache::get_cached_resources(&cached); - //this should probably be done in a thread.. - for(List<Ref<Resource> >::Element *E=cached.front();E;E=E->next()) { - - if (!E->get()->editor_can_reload_from_file()) - continue; - if (!E->get()->get_path().is_resource_file() && !E->get()->get_path().is_abs_path()) - continue; - if (!FileAccess::exists(E->get()->get_path())) - continue; - uint64_t mt = FileAccess::get_modified_time(E->get()->get_path()); - if (mt!=E->get()->get_last_modified_time()) { - E->get()->reload_from_file(); - } - - } - } break; case DEPENDENCY_UPDATE_IMPORTED: { @@ -2915,7 +2841,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { //accept->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("Can't import if edited scene was not saved."); //i dont think this code will ever run - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); break; } @@ -2951,16 +2877,29 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { current->call(name); } else if (p_option>=IMPORT_PLUGIN_BASE) { - Ref<EditorImportPlugin> p = editor_import_export->get_import_plugin(p_option-IMPORT_PLUGIN_BASE); - if (p.is_valid()) { - p->import_dialog(); - } } } } } +void EditorNode::_update_debug_options() { + + bool check_deploy_remote = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_deploy_remote_debug", false); + bool check_file_server = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_file_server", false); + bool check_debug_collisons = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisons", false); + bool check_debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false); + bool check_live_debug = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_live_debug", false); + bool check_reload_scripts = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_reload_scripts", false); + + if (check_deploy_remote) _menu_option_confirm(RUN_DEPLOY_REMOTE_DEBUG, true); + if (check_file_server) _menu_option_confirm(RUN_FILE_SERVER, true); + if (check_debug_collisons) _menu_option_confirm(RUN_DEBUG_COLLISONS, true); + if (check_debug_navigation) _menu_option_confirm(RUN_DEBUG_NAVIGATION, true); + if (check_live_debug) _menu_option_confirm(RUN_LIVE_DEBUG, true); + if (check_reload_scripts) _menu_option_confirm(RUN_RELOAD_SCRIPTS, true); + +} Control* EditorNode::get_viewport() { @@ -3055,20 +2994,6 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor) { } -void EditorNode::add_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) { - - ERR_FAIL_COND( p_editor_import.is_null() ); - editor_import_export->add_import_plugin(p_editor_import); - _rebuild_import_menu(); -} - -void EditorNode::remove_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) { - ERR_FAIL_COND( p_editor_import.is_null() ); - - editor_import_export->remove_import_plugin(p_editor_import); - _rebuild_import_menu(); -} - void EditorNode::_update_addon_config() { @@ -3228,232 +3153,6 @@ void EditorNode::set_edited_scene(Node *p_scene) { } -void EditorNode::_fetch_translatable_strings(const Object *p_object,Set<StringName>& strings) { - - - List<String> tstrings; - p_object->get_translatable_strings(&tstrings); - for(List<String>::Element *E=tstrings.front();E;E=E->next()) - strings.insert(E->get()); - - - - const Node * node = p_object->cast_to<Node>(); - - if (!node) - return; - - Ref<Script> script = node->get_script(); - if (script.is_valid()) - _fetch_translatable_strings(script.ptr(),strings); - - for(int i=0;i<node->get_child_count();i++) { - - Node *c=node->get_child(i); - if (c->get_owner()!=get_edited_scene()) - continue; - - _fetch_translatable_strings(c,strings); - } - -} - - -Error EditorNode::save_translatable_strings(const String& p_to_file) { - - if (!is_inside_tree()) { - defer_translatable=p_to_file; - return OK; - } - - ERR_FAIL_COND_V(!get_edited_scene(),ERR_INVALID_DATA); - - Set<StringName> strings; - _fetch_translatable_strings(get_edited_scene(),strings); - - Error err; - FileAccess *f = FileAccess::open(p_to_file,FileAccess::WRITE,&err); - ERR_FAIL_COND_V(err,err); - - OS::Date date = OS::get_singleton()->get_date(); - OS::Time time = OS::get_singleton()->get_time(); - f->store_line("# Translation Strings Dump."); - f->store_line("# Created By."); - f->store_line("# \t" VERSION_FULL_NAME " (c) 2008-2017 Juan Linietsky, Ariel Manzur."); - f->store_line("# From Scene: "); - f->store_line("# \t"+get_edited_scene()->get_filename()); - f->store_line(""); - f->store_line("msgid \"\""); - f->store_line("msgstr \"\""); - f->store_line("\"Report-Msgid-Bugs-To: <define>\\n\""); - f->store_line("\"POT-Creation-Date: "+itos(date.year)+"-"+itos(date.month)+"-"+itos(date.day)+" "+itos(time.hour)+":"+itos(time.min)+"0000\\n\""); - //f->store_line("\"PO-Revision-Date: 2006-08-30 13:56-0700\\n\""); - //f->store_line("\"Last-Translator: Rubén C. Díaz Alonso <outime@gmail.com>\\n\""); - f->store_line("\"Language-Team: <define>\\n\""); - f->store_line("\"MIME-Version: 1.0\\n\""); - f->store_line("\"Content-Type: text/plain; charset=UTF-8\\n\""); - f->store_line("\"Content-Transfer-Encoding: 8bit\\n\""); - f->store_line(""); - - for(Set<StringName>::Element *E=strings.front();E;E=E->next()) { - - String s = E->get(); - if (s=="" || s.strip_edges()=="") - continue; - Vector<String> substr = s.split("\n"); - ERR_CONTINUE(substr.size()==0); - - f->store_line(""); - - if (substr.size()==1) { - - f->store_line("msgid \""+substr[0].c_escape()+"\""); - } else { - - f->store_line("msgid \"\""); - for(int i=0;i<substr.size();i++) { - - String s = substr[i]; - if (i!=substr.size()-1) - s+="\n"; - f->store_line("\""+s.c_escape()+"\""); - } - } - - f->store_line("msgstr \"\""); - - } - - - f->close(); - memdelete(f); - - return OK; - -} - -Error EditorNode::save_optimized_copy(const String& p_scene,const String& p_preset) { - -#if 0 - - if (!is_inside_scene()) { - defer_optimize=p_scene; - defer_optimize_preset=p_preset; - return OK; - } - - - if (!get_edited_scene()) { - - get_scene()->quit(); - ERR_EXPLAIN("No scene to optimize (loading failed?)"); - ERR_FAIL_V(ERR_FILE_NOT_FOUND); - } - - - String src_scene=GlobalConfig::get_singleton()->localize_path(get_edited_scene()->get_filename()); - - - String path=p_scene; - print_line("p_path: "+p_scene); - print_line("src_scene: "+p_scene); - - if (path.is_rel_path()) { - print_line("rel path!?"); - path=src_scene.get_base_dir()+"/"+path; - } - path = GlobalConfig::get_singleton()->localize_path(path); - - print_line("path: "+path); - - - String preset = "optimizer_presets/"+p_preset; - if (!GlobalConfig::get_singleton()->has(preset)) { - - //accept->"()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("Optimizer preset not found: "+p_preset); - accept->popup_centered(Size2(300,70));; - ERR_EXPLAIN("Optimizer preset not found: "+p_preset); - ERR_FAIL_V(ERR_INVALID_PARAMETER); - - } - - Dictionary d = GlobalConfig::get_singleton()->get(preset); - - ERR_FAIL_COND_V(!d.has("__type__"),ERR_INVALID_DATA); - String type=d["__type__"]; - - Ref<EditorOptimizedSaver> saver; - - for(int i=0;i<editor_data.get_optimized_saver_count();i++) { - - print_line(type+" vs "+editor_data.get_optimized_saver(i)->get_target_name()); - if (editor_data.get_optimized_saver(i)->get_target_name()==type) { - saver=editor_data.get_optimized_saver(i); - } - } - - ERR_EXPLAIN("Preset '"+p_preset+"' references nonexistent saver: "+type); - ERR_FAIL_COND_V(saver.is_null(),ERR_INVALID_DATA); - - List<Variant> keys; - d.get_key_list(&keys); - - saver->clear(); - - for(List<Variant>::Element *E=keys.front();E;E=E->next()) { - - saver->set(E->get(),d[E->get()]); - } - - uint32_t flags=0; - - /* - if (saver->is_bundle_scenes_enabled()) - flags|=ResourceSaver::FLAG_BUNDLE_INSTANCED_SCENES; - */ - if (saver->is_bundle_resources_enabled()) - flags|=ResourceSaver::FLAG_BUNDLE_RESOURCES; - if (saver->is_remove_editor_data_enabled()) - flags|=ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES; - if (saver->is_big_endian_data_enabled()) - flags|=ResourceSaver::FLAG_SAVE_BIG_ENDIAN; - - String platform=saver->get_target_platform(); - if (platform=="") - platform="all"; - - Ref<PackedScene> sdata = memnew( PackedScene ); - Error err = sdata->pack(get_edited_scene()); - - if (err) { - - current_option=-1; - //accept->get_cancel()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("Couldn't save scene. Likely dependencies (instances) couldn't be satisfied."); - accept->popup_centered(Size2(300,70));; - return ERR_INVALID_DATA; - - } - err = ResourceSaver::save(path,sdata,flags); //todo, saverSceneSaver::save(path,get_edited_scene(),flags,saver); - - if (err) { - - //accept->"()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("Error saving optimized scene: "+path); - accept->popup_centered(Size2(300,70));; - - ERR_FAIL_COND_V(err,err); - - } - - project_settings->add_remapped_path(src_scene,path,platform); -#endif - return OK; -} int EditorNode::_get_current_main_editor() { @@ -3645,7 +3344,10 @@ void EditorNode::fix_dependencies(const String& p_for_file) { dependency_fixer->edit(p_for_file); } -Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bool p_set_inherited,bool p_clear_errors) { + + + +Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps, bool p_set_inherited, bool p_clear_errors, bool p_force_open_imported) { if (!is_inside_tree()) { defer_load_scene = p_scene; @@ -3654,6 +3356,8 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo if(!p_set_inherited) { + + for(int i=0;i<editor_data.get_edited_scene_count();i++) { if (editor_data.get_scene_path(i)==p_scene) { @@ -3661,9 +3365,19 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo return OK; } } + + if (!p_force_open_imported && FileAccess::exists(p_scene+".import")) { + open_imported->set_text(vformat(TTR("Scene '%s' was automatically imported, so it can't be modified.\nTo make changes to it, a new inherited scene can be created."),p_scene.get_file())); + open_imported->popup_centered_minsize(); + new_inherited_button->grab_focus(); + open_import_request=p_scene; + return OK; + } + } + if (p_clear_errors) load_errors->clear(); @@ -3812,7 +3526,6 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo property_editor->edit(new_scene); editor_data.set_edited_scene_root(new_scene); */ - editor_data.set_edited_scene_import_metadata( sdata->get_import_metadata() ); //editor_data.get_undo_redo().clear_history(); saved_version=editor_data.get_undo_redo().get_version(); @@ -3852,9 +3565,13 @@ void EditorNode::request_instance_scenes(const Vector<String>& p_files) { scene_tree_dock->instance_scenes(p_files); } -FileSystemDock *EditorNode::get_scenes_dock() { +ImportDock *EditorNode::get_import_dock() { + return import_dock; +} + +FileSystemDock *EditorNode::get_filesystem_dock() { - return scenes_dock; + return filesystem_dock; } SceneTreeDock *EditorNode::get_scene_tree_dock() { @@ -4029,7 +3746,7 @@ void EditorNode::_save_optimized() { //accept->"()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("Error saving optimized scene: "+path); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); return; } @@ -4155,9 +3872,9 @@ bool EditorNode::is_scene_in_use(const String& p_path) { void EditorNode::register_editor_types() { ClassDB::register_class<EditorPlugin>(); - ClassDB::register_class<EditorImportPlugin>(); - ClassDB::register_class<EditorExportPlugin>(); - ClassDB::register_class<EditorScenePostImport>(); +// ClassDB::register_class<EditorImportPlugin>(); +// ClassDB::register_class<EditorExportPlugin>(); +// ClassDB::register_class<EditorScenePostImport>(); ClassDB::register_class<EditorScript>(); ClassDB::register_class<EditorSelection>(); ClassDB::register_class<EditorFileDialog>(); @@ -4514,6 +4231,8 @@ void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String& p } } + p_layout->set_value(p_section,"dock_filesystem_split",filesystem_dock->get_split_offset()); + VSplitContainer*splits[DOCK_SLOT_MAX/2]={ left_l_vsplit, left_r_vsplit, @@ -4690,6 +4409,12 @@ void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String& } } + int fs_split_ofs = 0; + if (p_layout->has_section_key(p_section,"dock_filesystem_split")) { + fs_split_ofs = p_layout->get_value(p_section,"dock_filesystem_split"); + } + filesystem_dock->set_split_offset(fs_split_ofs); + VSplitContainer*splits[DOCK_SLOT_MAX/2]={ left_l_vsplit, left_r_vsplit, @@ -5073,7 +4798,6 @@ Variant EditorNode::drag_resource(const Ref<Resource>& p_res,Control* p_from) { TextureRect *drag_preview = memnew( TextureRect ); Label* label=memnew( Label ); - waiting_for_sources_changed=true; // Ref<Texture> preview; { @@ -5178,10 +4902,10 @@ Variant EditorNode::drag_files_and_dirs(const Vector<String>& p_files, Control * void EditorNode::_dropped_files(const Vector<String>& p_files,int p_screen) { - String cur_path = scenes_dock->get_current_path(); - for(int i=0;i<EditorImportExport::get_singleton()->get_import_plugin_count();i++) { - EditorImportExport::get_singleton()->get_import_plugin(i)->import_from_drop(p_files,cur_path); - } + String cur_path = filesystem_dock->get_current_path(); +// for(int i=0;i<EditorImportExport::get_singleton()->get_import_plugin_count();i++) { +// EditorImportExport::get_singleton()->get_import_plugin(i)->import_from_drop(p_files,cur_path); +// } } void EditorNode::_file_access_close_error_notify(const String& p_str) { @@ -5289,6 +5013,19 @@ void EditorNode::_call_build() { } } + +void EditorNode::_inherit_imported(const String& p_action) { + + open_imported->hide(); + load_scene(open_import_request,true,true); + +} + +void EditorNode::_open_imported() { + + load_scene(open_import_request,true,false,true,true); +} + void EditorNode::_bind_methods() { @@ -5361,11 +5098,13 @@ void EditorNode::_bind_methods() { - ClassDB::bind_method(_MD("add_editor_import_plugin", "plugin"), &EditorNode::add_editor_import_plugin); - ClassDB::bind_method(_MD("remove_editor_import_plugin", "plugin"), &EditorNode::remove_editor_import_plugin); +// ClassDB::bind_method(_MD("add_editor_import_plugin", "plugin"), &EditorNode::add_editor_import_plugin); + //ClassDB::bind_method(_MD("remove_editor_import_plugin", "plugin"), &EditorNode::remove_editor_import_plugin); ClassDB::bind_method(_MD("get_gui_base"), &EditorNode::get_gui_base); ClassDB::bind_method(_MD("_bottom_panel_switch"), &EditorNode::_bottom_panel_switch); + ClassDB::bind_method(_MD("_open_imported"), &EditorNode::_open_imported); + ClassDB::bind_method(_MD("_inherit_imported"), &EditorNode::_inherit_imported); ADD_SIGNAL( MethodInfo("play_pressed") ); ADD_SIGNAL( MethodInfo("pause_pressed") ); @@ -5415,7 +5154,6 @@ EditorNode::EditorNode() { FileAccess::set_backup_save(true); - PathRemap::get_singleton()->clear_remaps();; //editor uses no remaps TranslationServer::get_singleton()->set_enabled(false); // load settings if (!EditorSettings::get_singleton()) @@ -5451,6 +5189,37 @@ EditorNode::EditorNode() { ResourceLoader::set_timestamp_on_load(true); ResourceSaver::set_timestamp_on_save(true); + + { //register importers at the begining, so dialogs are created with the right extensions + Ref<ResourceImporterTexture> import_texture; + import_texture.instance(); + ResourceFormatImporter::get_singleton()->add_importer(import_texture); + + Ref<ResourceImporterCSVTranslation> import_csv_translation; + import_csv_translation.instance(); + ResourceFormatImporter::get_singleton()->add_importer(import_csv_translation); + + Ref<ResourceImporterWAV> import_wav; + import_wav.instance(); + ResourceFormatImporter::get_singleton()->add_importer(import_wav); + + + Ref<ResourceImporterOBJ> import_obj; + import_obj.instance(); + ResourceFormatImporter::get_singleton()->add_importer(import_obj); + + Ref<ResourceImporterScene> import_scene; + import_scene.instance(); + ResourceFormatImporter::get_singleton()->add_importer(import_scene); + + { + Ref<EditorSceneImporterCollada> import_collada; + import_collada.instance(); + import_scene->add_importer(import_collada); + } + + } + _pvrtc_register_compressors(); editor_selection = memnew( EditorSelection ); @@ -5468,13 +5237,8 @@ EditorNode::EditorNode() { EditorFileDialog::unregister_func=_editor_file_dialog_unregister; - editor_import_export = memnew( EditorImportExport ); - add_child(editor_import_export); - register_exporters(); - editor_import_export->load_config(); - GLOBAL_DEF("editor/main_run_args","$scene"); ClassDB::set_class_enabled("CollisionShape",true); @@ -5510,7 +5274,7 @@ EditorNode::EditorNode() { #if 0 PanelContainer *top_dark_panel = memnew( PanelContainer ); Ref<StyleBoxTexture> top_dark_sb; - top_dark_sb.instance();; + top_dark_sb.instance(); top_dark_sb->set_texture(theme->get_icon("PanelTop","EditorIcons")); for(int i=0;i<4;i++) { top_dark_sb->set_margin_size(Margin(i),3); @@ -5755,6 +5519,7 @@ EditorNode::EditorNode() { ED_SHORTCUT("editor/next_tab", TTR("Next tab"), KEY_MASK_CMD+KEY_TAB); ED_SHORTCUT("editor/prev_tab", TTR("Previous tab"), KEY_MASK_CMD+KEY_MASK_SHIFT+KEY_TAB); + ED_SHORTCUT("editor/filter_files", TTR("Filter Files.."), KEY_MASK_ALT+KEY_MASK_CMD+KEY_P); file_menu->set_tooltip(TTR("Operations with scene files.")); @@ -5774,14 +5539,12 @@ EditorNode::EditorNode() { p->add_separator(); p->add_shortcut(ED_SHORTCUT("editor/quick_open_scene",TTR("Quick Open Scene.."),KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_O),FILE_QUICK_OPEN_SCENE); p->add_shortcut(ED_SHORTCUT("editor/quick_open_script",TTR("Quick Open Script.."),KEY_MASK_ALT+KEY_MASK_CMD+KEY_O),FILE_QUICK_OPEN_SCRIPT); - p->add_shortcut(ED_SHORTCUT("editor/quick_filter_files",TTR("Quick Filter Files.."),KEY_MASK_ALT+KEY_MASK_CMD+KEY_P),FILE_QUICK_OPEN_FILE); p->add_separator(); PopupMenu *pm_export = memnew(PopupMenu ); pm_export->set_name("Export"); p->add_child(pm_export); p->add_submenu_item(TTR("Convert To.."),"Export"); - pm_export->add_item(TTR("Translatable Strings.."),FILE_DUMP_STRINGS); pm_export->add_separator(); pm_export->add_shortcut(ED_SHORTCUT("editor/convert_to_MeshLibrary", TTR("MeshLibrary..")), FILE_EXPORT_MESH_LIBRARY); pm_export->add_shortcut(ED_SHORTCUT("editor/convert_to_TileSet", TTR("TileSet..")), FILE_EXPORT_TILESET); @@ -5832,7 +5595,7 @@ EditorNode::EditorNode() { #if 0 node_menu = memnew( MenuButton ); node_menu->set_text("Node"); - node_menu->set_pos( Point2( 50,0) );; + node_menu->set_pos( Point2( 50,0) ); menu_panel->add_child( node_menu ); p=node_menu->get_popup(); @@ -6264,6 +6027,11 @@ EditorNode::EditorNode() { property_editor->set_undo_redo(&editor_data.get_undo_redo()); + import_dock = memnew( ImportDock ); + dock_slot[DOCK_SLOT_RIGHT_UL]->add_child(import_dock); + import_dock->set_name(TTR("Import")); + + node_dock = memnew( NodeDock ); //node_dock->set_undoredo(&editor_data.get_undo_redo()); if (use_single_dock_column) { @@ -6272,21 +6040,21 @@ EditorNode::EditorNode() { dock_slot[DOCK_SLOT_RIGHT_BL]->add_child(node_dock); } - scenes_dock = memnew( FileSystemDock(this) ); - scenes_dock->set_name(TTR("FileSystem")); - scenes_dock->set_display_mode(int(EditorSettings::get_singleton()->get("docks/filesystem/display_mode"))); + filesystem_dock = memnew( FileSystemDock(this) ); + filesystem_dock->set_name(TTR("FileSystem")); + filesystem_dock->set_display_mode(int(EditorSettings::get_singleton()->get("docks/filesystem/display_mode"))); if (use_single_dock_column) { - dock_slot[DOCK_SLOT_RIGHT_BL]->add_child(scenes_dock); + dock_slot[DOCK_SLOT_RIGHT_BL]->add_child(filesystem_dock); left_r_vsplit->hide(); dock_slot[DOCK_SLOT_LEFT_UR]->hide(); dock_slot[DOCK_SLOT_LEFT_BR]->hide(); } else { - dock_slot[DOCK_SLOT_LEFT_UR]->add_child(scenes_dock); + dock_slot[DOCK_SLOT_LEFT_UR]->add_child(filesystem_dock); } - //prop_pallete->add_child(scenes_dock); - scenes_dock->connect("open",this,"open_request"); - scenes_dock->connect("instance",this,"_instance_request"); + //prop_pallete->add_child(filesystem_dock); + filesystem_dock->connect("open",this,"open_request"); + filesystem_dock->connect("instance",this,"_instance_request"); const String docks_section = "docks"; @@ -6351,7 +6119,7 @@ EditorNode::EditorNode() { animation_menu->set_focus_mode(Control::FOCUS_NONE); menu_panel->add_child(animation_menu); animation_menu->set_icon(gui_base->get_icon("Animation","EditorIcons")); - animation_menu->connect("pressed",this,"_animation_visibility_toggle");; + animation_menu->connect("pressed",this,"_animation_visibility_toggle"); */ @@ -6388,11 +6156,11 @@ EditorNode::EditorNode() { //gui_base->add_child(optimized_save); //optimized_save->connect("confirmed",this,"_save_optimized"); - project_export = memnew( ProjectExport(&editor_data) ); - gui_base->add_child(project_export); + //project_export = memnew( ProjectExport(&editor_data) ); + //gui_base->add_child(project_export); - project_export_settings = memnew( ProjectExportDialog(this) ); - gui_base->add_child(project_export_settings); + //project_export_settings = memnew( ProjectExportDialog(this) ); + //gui_base->add_child(project_export_settings); //optimized_presets = memnew( OptimizedPresetsDialog(&editor_data) ); //gui_base->add_child(optimized_presets); @@ -6506,8 +6274,8 @@ EditorNode::EditorNode() { gui_base->add_child(file_script); file_script->connect("file_selected",this,"_dialog_action"); - reimport_dialog = memnew( EditorReImportDialog ); - gui_base->add_child(reimport_dialog); + //reimport_dialog = memnew( EditorReImportDialog ); + //gui_base->add_child(reimport_dialog); @@ -6533,32 +6301,15 @@ EditorNode::EditorNode() { file_server = memnew( EditorFileServer ); - editor_import_export->add_import_plugin( Ref<EditorTextureImportPlugin>( memnew(EditorTextureImportPlugin(this) ))); - Ref<EditorSceneImportPlugin> _scene_import = memnew(EditorSceneImportPlugin(this) ); - Ref<EditorSceneImporterCollada> _collada_import = memnew( EditorSceneImporterCollada); - _scene_import->add_importer(_collada_import); - //Ref<EditorSceneImporterFBXConv> _fbxconv_import = memnew( EditorSceneImporterFBXConv); - //_scene_import->add_importer(_fbxconv_import); - editor_import_export->add_import_plugin( _scene_import); - // TODO: This plugin has no code, it should be either implemented or dropped (GH-3667) - // editor_import_export->add_import_plugin( Ref<EditorSceneAnimationImportPlugin>( memnew(EditorSceneAnimationImportPlugin(this)))); - editor_import_export->add_import_plugin( Ref<EditorMeshImportPlugin>( memnew(EditorMeshImportPlugin(this)))); - editor_import_export->add_import_plugin( Ref<EditorFontImportPlugin>( memnew(EditorFontImportPlugin(this)))); - editor_import_export->add_import_plugin( Ref<EditorSampleImportPlugin>( memnew(EditorSampleImportPlugin(this)))); - editor_import_export->add_import_plugin( Ref<EditorTranslationImportPlugin>( memnew(EditorTranslationImportPlugin(this)))); - editor_import_export->add_import_plugin( Ref<EditorBitMaskImportPlugin>( memnew(EditorBitMaskImportPlugin(this)))); - - - editor_import_export->add_export_plugin( Ref<EditorTextureExportPlugin>( memnew(EditorTextureExportPlugin))); - editor_import_export->add_export_plugin( Ref<EditorSampleExportPlugin>( memnew(EditorSampleExportPlugin))); - editor_import_export->add_export_plugin( Ref<EditorSceneExportPlugin>( memnew(EditorSceneExportPlugin))); - add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) ); add_editor_plugin( memnew( CanvasItemEditorPlugin(this) ) ); add_editor_plugin( memnew( SpatialEditorPlugin(this) ) ); add_editor_plugin( memnew( ScriptEditorPlugin(this) ) ); + + EditorAudioBuses *audio_bus_editor = EditorAudioBuses::register_editor(); + ScriptTextEditor::register_editor(); //register one for text scripts if (StreamPeerSSL::is_available()) { @@ -6575,8 +6326,8 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( ShaderEditorPlugin(this,false) ) );*/ add_editor_plugin( memnew( CameraEditorPlugin(this) ) ); - add_editor_plugin( memnew( SampleEditorPlugin(this) ) ); - add_editor_plugin( memnew( SampleLibraryEditorPlugin(this) ) ); +// add_editor_plugin( memnew( SampleEditorPlugin(this) ) ); +// add_editor_plugin( memnew( SampleLibraryEditorPlugin(this) ) ); add_editor_plugin( memnew( ThemeEditorPlugin(this) ) ); add_editor_plugin( memnew( MultiMeshEditorPlugin(this) ) ); add_editor_plugin( memnew( MeshInstanceEditorPlugin(this) ) ); @@ -6607,6 +6358,7 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( ColorRampEditorPlugin(this) ) ); add_editor_plugin( memnew( CollisionShape2DEditorPlugin(this) ) ); add_editor_plugin( memnew( TextureEditorPlugin(this) ) ); + add_editor_plugin( memnew( AudioBusesEditorPlugin(audio_bus_editor) ) ); //add_editor_plugin( memnew( MaterialEditorPlugin(this) ) ); //add_editor_plugin( memnew( MeshEditorPlugin(this) ) ); @@ -6617,6 +6369,9 @@ EditorNode::EditorNode() { plugin_init_callbacks[i](); } + + + /*resource_preview->add_preview_generator( Ref<EditorTexturePreviewPlugin>( memnew(EditorTexturePreviewPlugin ))); resource_preview->add_preview_generator( Ref<EditorPackedScenePreviewPlugin>( memnew(EditorPackedScenePreviewPlugin ))); resource_preview->add_preview_generator( Ref<EditorMaterialPreviewPlugin>( memnew(EditorMaterialPreviewPlugin ))); @@ -6673,6 +6428,14 @@ EditorNode::EditorNode() { } } + open_imported = memnew( ConfirmationDialog ); + open_imported->get_ok()->set_text(TTR("Open Anyway")); + new_inherited_button=open_imported->add_button("New Inherited",!OS::get_singleton()->get_swap_ok_cancel(),"inherit"); + open_imported->connect("confirmed",this,"_open_imported"); + open_imported->connect("custom_action",this,"_inherit_imported"); + gui_base->add_child(open_imported); + + //edited_scene=NULL; saved_version=1; @@ -6763,6 +6526,7 @@ EditorNode::EditorNode() { FileAccess::set_file_close_fail_notify_callback(_file_access_close_error_notify); + waiting_for_first_scan=true; } diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index dd5ff1e175..7ac2760a5c 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -50,6 +50,7 @@ #include "tools/editor/reparent_dialog.h" #include "tools/editor/connections_dialog.h" #include "tools/editor/node_dock.h" +#include "tools/editor/import_dock.h" #include "tools/editor/settings_config_dialog.h" #include "tools/editor/groups_editor.h" #include "tools/editor/editor_data.h" @@ -134,12 +135,10 @@ private: FILE_EXPORT_MESH_LIBRARY, FILE_EXPORT_TILESET, FILE_SAVE_OPTIMIZED, - FILE_DUMP_STRINGS, FILE_OPEN_RECENT, FILE_OPEN_OLD_SCENE, FILE_QUICK_OPEN_SCENE, FILE_QUICK_OPEN_SCRIPT, - FILE_QUICK_OPEN_FILE, FILE_RUN_SCRIPT, FILE_OPEN_PREV, FILE_CLOSE, @@ -197,7 +196,9 @@ private: IMPORT_PLUGIN_BASE=100, - OBJECT_METHOD_BASE=500 + OBJECT_METHOD_BASE=500, + + TOOL_MENU_BASE=1000 }; @@ -277,8 +278,9 @@ private: //ResourcesDock *resources_dock; PropertyEditor *property_editor; NodeDock *node_dock; + ImportDock *import_dock; VBoxContainer *prop_editor_vb; - FileSystemDock *scenes_dock; + FileSystemDock *filesystem_dock; EditorRunNative *run_native; HBoxContainer *search_bar; @@ -317,9 +319,6 @@ private: //TabContainer *prop_pallete; //TabContainer *top_pallete; String defer_load_scene; - String defer_translatable; - String defer_optimize; - String defer_optimize_preset; String defer_export; String defer_export_platform; bool defer_export_debug; @@ -339,7 +338,7 @@ private: Vector<ToolButton*> main_editor_buttons; Vector<EditorPlugin*> editor_table; - EditorReImportDialog *reimport_dialog; +// EditorReImportDialog *reimport_dialog; ProgressDialog *progress_dialog; BackgroundProgress *progress_hb; @@ -347,6 +346,10 @@ private: DependencyErrorDialog *dependency_error; DependencyEditor *dependency_fixer; OrphanResourcesDialog *orphan_resources; + ConfirmationDialog *open_imported; + Button *new_inherited_button; + String open_import_request; + TabContainer *dock_slot[DOCK_SLOT_MAX]; Rect2 dock_select_rect[DOCK_SLOT_MAX]; @@ -375,6 +378,7 @@ private: bool unsaved_cache; String open_navigate; bool changing_scene; + bool waiting_for_first_scan; bool waiting_for_sources_changed; @@ -390,8 +394,8 @@ private: EditorData editor_data; EditorRun editor_run; EditorSelection *editor_selection; - ProjectExport *project_export; - ProjectExportDialog *project_export_settings; +// ProjectExport *project_export; +// ProjectExportDialog *project_export_settings; EditorResourcePreview *resource_preview; EditorFileServer *file_server; @@ -428,6 +432,7 @@ private: void _menu_option(int p_option); void _menu_confirm_current(); void _menu_option_confirm(int p_option,bool p_confirmed); + void _update_debug_options(); void _property_editor_forward(); void _property_editor_back(); @@ -487,7 +492,6 @@ private: static void _load_error_notify(void* p_ud,const String& p_text); bool has_main_screen() const { return true; } - void _fetch_translatable_strings(const Object *p_object,Set<StringName>& strings); bool _find_editing_changed_scene(Node *p_from); @@ -585,6 +589,8 @@ private: MAX_BUILD_CALLBACKS=128 }; + void _inherit_imported(const String &p_action); + void _open_imported(); static int plugin_init_callback_count; @@ -593,6 +599,22 @@ private: void _call_build(); static int build_callback_count; static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS]; + + bool _initializing_tool_menu; + + struct ToolMenuItem { + String name; + String submenu; + Variant ud; + ObjectID handler; + String callback; + }; + + Vector<ToolMenuItem> tool_menu_items; + + void _tool_menu_insert_item(const ToolMenuItem& p_item); + void _rebuild_tool_menu() const; + protected: void _notification(int p_what); static void _bind_methods(); @@ -630,9 +652,6 @@ public: void add_control_to_dock(DockSlot p_slot,Control* p_control); void remove_control_from_dock(Control* p_control); - void add_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import); - void remove_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import); - void set_addon_plugin_enabled(const String& p_addon,bool p_enabled); bool is_addon_plugin_enabled(const String &p_addon) const; @@ -669,11 +688,10 @@ public: Node *get_edited_scene() { return editor_data.get_edited_scene_root(); } Viewport *get_scene_root() { return scene_root; } //root of the scene being edited - Error save_optimized_copy(const String& p_scene,const String& p_preset); void fix_dependencies(const String& p_for_file); void clear_scene() { _cleanup_scene(); } - Error load_scene(const String& p_scene, bool p_ignore_broken_deps=false, bool p_set_inherited=false, bool p_clear_errors=true); + Error load_scene(const String& p_scene, bool p_ignore_broken_deps=false, bool p_set_inherited=false, bool p_clear_errors=true,bool p_force_open_imported=false); Error load_resource(const String& p_scene); bool is_scene_open(const String& p_path); @@ -688,14 +706,13 @@ public: void request_instance_scene(const String &p_path); void request_instance_scenes(const Vector<String>& p_files); - FileSystemDock *get_scenes_dock(); + FileSystemDock *get_filesystem_dock(); + ImportDock *get_import_dock(); SceneTreeDock *get_scene_tree_dock(); static UndoRedo* get_undo_redo() { return &singleton->editor_data.get_undo_redo(); } EditorSelection *get_editor_selection() { return editor_selection; } - Error save_translatable_strings(const String& p_to_file); - void set_convert_old_scene(bool p_old) { convert_old=p_old; } void notify_child_process_exited(); @@ -755,6 +772,9 @@ public: Variant drag_files(const Vector<String>& p_files,Control* p_from); Variant drag_files_and_dirs(const Vector<String>& p_files,Control* p_from); + void add_tool_menu_item(const String& p_name, Object *p_handler, const String& p_callback, const Variant& p_ud = Variant()); + void add_tool_submenu_item(const String& p_name, PopupMenu *p_submenu); + void remove_tool_menu_item(const String& p_name); EditorNode(); ~EditorNode(); @@ -767,7 +787,6 @@ public: }; - struct EditorProgress { String task; diff --git a/tools/editor/editor_path.cpp b/tools/editor/editor_path.cpp index b359522e4f..8cd31c4bcc 100644 --- a/tools/editor/editor_path.cpp +++ b/tools/editor/editor_path.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_path.h" + #include "editor_scale.h" #include "editor_node.h" diff --git a/tools/editor/editor_plugin.cpp b/tools/editor/editor_plugin.cpp index 8769fe2cd8..2f44b5558c 100644 --- a/tools/editor/editor_plugin.cpp +++ b/tools/editor/editor_plugin.cpp @@ -27,6 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_plugin.h" + +#include "scene/gui/popup_menu.h" #include "scene/3d/camera.h" #include "plugins/canvas_item_editor_plugin.h" #include "plugins/spatial_editor_plugin.h" @@ -132,6 +134,24 @@ void EditorPlugin::add_control_to_container(CustomControlContainer p_location,Co } } +void EditorPlugin::add_tool_menu_item(const String& p_name, Object *p_handler, const String& p_callback, const Variant& p_ud) { + + //EditorNode::get_singleton()->add_tool_menu_item(p_name, p_handler, p_callback, p_ud); +} + +void EditorPlugin::add_tool_submenu_item(const String& p_name, Object *p_submenu) { + + ERR_FAIL_NULL(p_submenu); + PopupMenu *submenu = p_submenu->cast_to<PopupMenu>(); + ERR_FAIL_NULL(submenu); + //EditorNode::get_singleton()->add_tool_submenu_item(p_name, submenu); +} + +void EditorPlugin::remove_tool_menu_item(const String& p_name) { + + //EditorNode::get_singleton()->remove_tool_menu_item(p_name); +} + Ref<SpatialEditorGizmo> EditorPlugin::create_spatial_gizmo(Spatial* p_spatial) { //?? if (get_script_instance() && get_script_instance()->has_method("create_spatial_gizmo")) { @@ -299,27 +319,6 @@ EditorResourcePreview *EditorPlugin::get_resource_previewer() { return EditorResourcePreview::get_singleton(); } -void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) { - - EditorNode::get_singleton()->add_editor_import_plugin(p_editor_import); -} - -void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin>& p_editor_import){ - - EditorNode::get_singleton()->remove_editor_import_plugin(p_editor_import); - -} - -void EditorPlugin::add_export_plugin(const Ref<EditorExportPlugin>& p_editor_export){ - - EditorImportExport::get_singleton()->add_export_plugin(p_editor_export); -} -void EditorPlugin::remove_export_plugin(const Ref<EditorExportPlugin>& p_editor_export){ - - EditorImportExport::get_singleton()->remove_export_plugin(p_editor_export); - -} - Control *EditorPlugin::get_base_control() { return EditorNode::get_singleton()->get_gui_base(); @@ -351,16 +350,13 @@ void EditorPlugin::_bind_methods() { ClassDB::bind_method(_MD("add_control_to_dock","slot","control:Control"),&EditorPlugin::add_control_to_dock); ClassDB::bind_method(_MD("remove_control_from_docks","control:Control"),&EditorPlugin::remove_control_from_docks); ClassDB::bind_method(_MD("remove_control_from_bottom_panel","control:Control"),&EditorPlugin::remove_control_from_bottom_panel); + //ClassDB::bind_method(_MD("add_tool_menu_item", "name", "handler", "callback", "ud"),&EditorPlugin::add_tool_menu_item,DEFVAL(Variant())); + ClassDB::bind_method(_MD("add_tool_submenu_item", "name", "submenu:PopupMenu"),&EditorPlugin::add_tool_submenu_item); + //ClassDB::bind_method(_MD("remove_tool_menu_item", "name"),&EditorPlugin::remove_tool_menu_item); ClassDB::bind_method(_MD("add_custom_type","type","base","script:Script","icon:Texture"),&EditorPlugin::add_custom_type); ClassDB::bind_method(_MD("remove_custom_type","type"),&EditorPlugin::remove_custom_type); ClassDB::bind_method(_MD("get_editor_viewport:Control"), &EditorPlugin::get_editor_viewport); - ClassDB::bind_method(_MD("add_import_plugin","plugin:EditorImportPlugin"),&EditorPlugin::add_import_plugin); - ClassDB::bind_method(_MD("remove_import_plugin","plugin:EditorImportPlugin"),&EditorPlugin::remove_import_plugin); - - ClassDB::bind_method(_MD("add_export_plugin","plugin:EditorExportPlugin"),&EditorPlugin::add_export_plugin); - ClassDB::bind_method(_MD("remove_export_plugin","plugin:EditorExportPlugin"),&EditorPlugin::remove_export_plugin); - ClassDB::bind_method(_MD("get_resource_previewer:EditorResourcePreview"),&EditorPlugin::get_resource_previewer); ClassDB::bind_method(_MD("get_resource_filesystem:EditorFileSystem"),&EditorPlugin::get_resource_file_system); diff --git a/tools/editor/editor_plugin.h b/tools/editor/editor_plugin.h index 9943e94d98..cf998dd55b 100644 --- a/tools/editor/editor_plugin.h +++ b/tools/editor/editor_plugin.h @@ -103,6 +103,10 @@ public: Control* get_editor_viewport(); void edit_resource(const Ref<Resource>& p_resource); + void add_tool_menu_item(const String& p_name, Object *p_handler, const String& p_callback, const Variant& p_ud = Variant()); + void add_tool_submenu_item(const String& p_name, Object *p_submenu); + void remove_tool_menu_item(const String& p_name); + virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial* p_spatial); virtual bool forward_canvas_gui_input(const Transform2D& p_canvas_xform, const InputEvent& p_event); virtual void forward_draw_over_canvas(const Transform2D& p_canvas_xform,Control *p_canvas); @@ -135,12 +139,6 @@ public: void make_bottom_panel_item_visible(Control *p_item); void hide_bottom_panel(); - void add_import_plugin(const Ref<EditorImportPlugin>& p_editor_import); - void remove_import_plugin(const Ref<EditorImportPlugin>& p_editor_import); - - void add_export_plugin(const Ref<EditorExportPlugin>& p_editor_export); - void remove_export_plugin(const Ref<EditorExportPlugin>& p_editor_export); - EditorSelection* get_selection(); //EditorImportExport *get_import_export(); EditorSettings *get_editor_settings(); diff --git a/tools/editor/editor_plugin_settings.cpp b/tools/editor/editor_plugin_settings.cpp index 208e576a8a..2b6828e82f 100644 --- a/tools/editor/editor_plugin_settings.cpp +++ b/tools/editor/editor_plugin_settings.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_plugin_settings.h" + #include "scene/gui/margin_container.h" #include "io/config_file.h" #include "os/file_access.h" diff --git a/tools/editor/editor_profiler.cpp b/tools/editor/editor_profiler.cpp index 5279711b0f..94ec059ea7 100644 --- a/tools/editor/editor_profiler.cpp +++ b/tools/editor/editor_profiler.cpp @@ -1,4 +1,33 @@ +/*************************************************************************/ +/* editor_profiler.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #include "editor_profiler.h" + #include "editor_settings.h" #include "os/os.h" @@ -349,7 +378,7 @@ void EditorProfiler::_update_plot() { } - graph_texture->set_data(img);; + graph_texture->set_data(img); graph->set_texture(graph_texture); diff --git a/tools/editor/editor_profiler.h b/tools/editor/editor_profiler.h index 52b38cdae8..bf89e3939c 100644 --- a/tools/editor/editor_profiler.h +++ b/tools/editor/editor_profiler.h @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* editor_profiler.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #ifndef EDITORPROFILER_H #define EDITORPROFILER_H diff --git a/tools/editor/editor_reimport_dialog.cpp b/tools/editor/editor_reimport_dialog.cpp index c6a8f13dc7..5904070230 100644 --- a/tools/editor/editor_reimport_dialog.cpp +++ b/tools/editor/editor_reimport_dialog.cpp @@ -27,8 +27,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_reimport_dialog.h" + #include "editor_file_system.h" #include "editor_node.h" + +#if 0 void EditorReImportDialog::popup_reimport() { if (EditorFileSystem::get_singleton()->is_scanning()) { @@ -142,3 +145,4 @@ EditorReImportDialog::EditorReImportDialog() { scene_must_save=false; } +#endif diff --git a/tools/editor/editor_reimport_dialog.h b/tools/editor/editor_reimport_dialog.h index 68e1ca0597..7379c70c5e 100644 --- a/tools/editor/editor_reimport_dialog.h +++ b/tools/editor/editor_reimport_dialog.h @@ -29,6 +29,7 @@ #ifndef EDITOR_REIMPORT_DIALOG_H #define EDITOR_REIMPORT_DIALOG_H +#if 0 #include "scene/gui/dialogs.h" #include "scene/gui/tree.h" @@ -49,3 +50,4 @@ public: }; #endif // EDITOR_REIMPORT_DIALOG_H +#endif diff --git a/tools/editor/editor_resource_preview.cpp b/tools/editor/editor_resource_preview.cpp index 76ae53d821..b4c459a493 100644 --- a/tools/editor/editor_resource_preview.cpp +++ b/tools/editor/editor_resource_preview.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_resource_preview.h" + #include "editor_settings.h" #include "os/file_access.h" #include "io/resource_loader.h" diff --git a/tools/editor/editor_run.cpp b/tools/editor/editor_run.cpp index 7d79412b3b..813a8ee5b7 100644 --- a/tools/editor/editor_run.cpp +++ b/tools/editor/editor_run.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_run.h" + #include "globals.h" #include "editor_settings.h" diff --git a/tools/editor/editor_run_native.cpp b/tools/editor/editor_run_native.cpp index caa1bf5db7..25cb41befc 100644 --- a/tools/editor/editor_run_native.cpp +++ b/tools/editor/editor_run_native.cpp @@ -27,12 +27,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_run_native.h" -#include "editor_import_export.h" +#include "editor_import_export.h" void EditorRunNative::_notification(int p_what) { - +#if 0 if (p_what==NOTIFICATION_ENTER_TREE) { List<StringName> ep; @@ -97,11 +97,12 @@ void EditorRunNative::_notification(int p_what) { first=false; } } - +#endif } void EditorRunNative::_run_native(int p_idx,const String& p_platform) { +#if 0 Ref<EditorExportPlatform> eep = EditorImportExport::get_singleton()->get_export_platform(p_platform); ERR_FAIL_COND(eep.is_null()); if (p_idx == -1) { @@ -125,6 +126,8 @@ void EditorRunNative::_run_native(int p_idx,const String& p_platform) { flags|=EditorExportPlatform::EXPORT_VIEW_NAVIGATION; eep->run(p_idx,flags); + +#endif } void EditorRunNative::_bind_methods() { diff --git a/tools/editor/editor_run_script.cpp b/tools/editor/editor_run_script.cpp index 4a3cbfbccb..6a980019e4 100644 --- a/tools/editor/editor_run_script.cpp +++ b/tools/editor/editor_run_script.cpp @@ -27,11 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_run_script.h" -#include "editor_node.h" - - - +#include "editor_node.h" void EditorScript::add_root_node(Node *p_node) { diff --git a/tools/editor/editor_scale.cpp b/tools/editor/editor_scale.cpp index 8575e1c30a..5687f97b22 100644 --- a/tools/editor/editor_scale.cpp +++ b/tools/editor/editor_scale.cpp @@ -1,4 +1,33 @@ +/*************************************************************************/ +/* editor_scale.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #include "editor_scale.h" + #include "os/os.h" static float scale = 1.0; diff --git a/tools/editor/editor_scale.h b/tools/editor/editor_scale.h index 90e575f771..035a5056c1 100644 --- a/tools/editor/editor_scale.h +++ b/tools/editor/editor_scale.h @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* editor_scale.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #ifndef EDITOR_SCALE_H #define EDITOR_SCALE_H diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp index 807183ae46..6d9f1bd979 100644 --- a/tools/editor/editor_settings.cpp +++ b/tools/editor/editor_settings.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http:/www.godotengine.org */ +/* http:/www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ @@ -27,13 +27,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_settings.h" + #include "os/os.h" #include "os/dir_access.h" #include "os/file_access.h" - #include "version.h" #include "scene/main/scene_main_loop.h" -#include "os/os.h" #include "scene/main/node.h" #include "io/resource_loader.h" #include "io/resource_saver.h" @@ -127,7 +126,7 @@ bool EditorSettings::_get(const StringName& p_name,Variant &r_ret) const { const VariantContainer *v=props.getptr(p_name); if (!v) { - //print_line("WARNING NOT FOUND: "+String(p_name)); + print_line("EditorSettings::_get - Warning, not found: "+String(p_name)); return false; } r_ret = v->variant; @@ -243,13 +242,20 @@ void EditorSettings::create() { String exe_path = OS::get_singleton()->get_executable_path().get_base_dir(); DirAccess* d = DirAccess::create_for_path(exe_path); + bool self_contained = false; if (d->file_exists(exe_path + "/._sc_")) { + self_contained = true; + extra_config->load(exe_path + "/._sc_"); + } else if (d->file_exists(exe_path + "/_sc_")) { + self_contained = true; + extra_config->load(exe_path + "/_sc_"); + } + if (self_contained) { // editor is self contained config_path = exe_path; config_dir = "editor_data"; - extra_config->load(exe_path + "/._sc_"); } else { if (OS::get_singleton()->has_environment("APPDATA")) { @@ -654,6 +660,9 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("run/auto_save/save_before_running",true); + set("run/output/always_clear_output_on_play",true); + set("run/output/always_open_output_on_play",true); + set("run/output/always_close_output_on_stop",false); set("filesystem/resources/save_compressed_resources",true); set("filesystem/resources/auto_reload_modified_images",true); @@ -714,6 +723,7 @@ void EditorSettings::_load_default_text_editor_theme() { set("text_editor/highlighting/selection_color",Color::html("7b5dbe")); set("text_editor/highlighting/brace_mismatch_color",Color(1,0.2,0.2)); set("text_editor/highlighting/current_line_color",Color(0.3,0.5,0.8,0.15)); + set("text_editor/highlighting/line_length_guideline_color",Color(0.3,0.5,0.8,0.1)); set("text_editor/highlighting/mark_color", Color(1.0,0.4,0.4,0.4)); set("text_editor/highlighting/breakpoint_color", Color(0.8,0.8,0.4,0.2)); set("text_editor/highlighting/word_highlighted_color",Color(0.8,0.9,0.9,0.15)); @@ -971,6 +981,7 @@ bool EditorSettings::_save_text_editor_theme(String p_file) { cf->set_value(theme_section, "selection_color", ((Color)get("text_editor/highlighting/selection_color")).to_html()); cf->set_value(theme_section, "brace_mismatch_color", ((Color)get("text_editor/highlighting/brace_mismatch_color")).to_html()); cf->set_value(theme_section, "current_line_color", ((Color)get("text_editor/highlighting/current_line_color")).to_html()); + cf->set_value(theme_section, "line_length_guideline_color", ((Color)get("text_editor/highlighting/line_length_guideline_color")).to_html()); cf->set_value(theme_section, "mark_color", ((Color)get("text_editor/highlighting/mark_color")).to_html()); cf->set_value(theme_section, "breakpoint_color", ((Color)get("text_editor/highlighting/breakpoint_color")).to_html()); cf->set_value(theme_section, "word_highlighted_color", ((Color)get("text_editor/highlighting/word_highlighted_color")).to_html()); @@ -1026,26 +1037,22 @@ void EditorSettings::set_optimize_save(bool p_optimize) { optimize_save=p_optimize; } -String EditorSettings::get_last_selected_language() -{ +Variant EditorSettings::get_project_metadata(const String& p_section, const String& p_key, Variant p_default) { Ref<ConfigFile> cf = memnew( ConfigFile ); String path = get_project_settings_path().plus_file("project_metadata.cfg"); Error err = cf->load(path); if (err != OK) { - return ""; + return p_default; } - Variant last_selected_language = cf->get_value("script_setup", "last_selected_language"); - if (last_selected_language.get_type() != Variant::STRING) - return ""; - return static_cast<String>(last_selected_language); + return cf->get_value(p_section, p_key, p_default); } -void EditorSettings::set_last_selected_language(String p_language) +void EditorSettings::set_project_metadata(const String& p_section, const String& p_key, Variant p_data) { Ref<ConfigFile> cf = memnew( ConfigFile ); String path = get_project_settings_path().plus_file("project_metadata.cfg"); cf->load(path); - cf->set_value("script_setup", "last_selected_language", p_language); + cf->set_value(p_section, p_key, p_data); cf->save(path); } diff --git a/tools/editor/editor_settings.h b/tools/editor/editor_settings.h index c11feef667..809389eb40 100644 --- a/tools/editor/editor_settings.h +++ b/tools/editor/editor_settings.h @@ -160,8 +160,8 @@ public: void set_optimize_save(bool p_optimize); - String get_last_selected_language(); - void set_last_selected_language(String p_language); + Variant get_project_metadata(const String& p_section, const String& p_key, Variant p_default); + void set_project_metadata(const String& p_section, const String& p_key, Variant p_data); EditorSettings(); ~EditorSettings(); diff --git a/tools/editor/editor_sub_scene.cpp b/tools/editor/editor_sub_scene.cpp index 34c3d47006..094cf049b3 100644 --- a/tools/editor/editor_sub_scene.cpp +++ b/tools/editor/editor_sub_scene.cpp @@ -27,10 +27,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_sub_scene.h" + #include "scene/gui/margin_container.h" #include "scene/resources/packed_scene.h" -void EditorSubScene::_path_selected(const String& p_path) { +void EditorSubScene::_path_selected(const String& p_path) { path->set_text(p_path); _path_changed(p_path); diff --git a/tools/editor/editor_themes.cpp b/tools/editor/editor_themes.cpp index 56654cad7a..7657996b81 100644 --- a/tools/editor/editor_themes.cpp +++ b/tools/editor/editor_themes.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* editor_themes.cpp */ +/* editor_themes.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -26,8 +26,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ - #include "editor_themes.h" + #include "editor_icons.h" #include "editor_fonts.h" #include "editor_settings.h" diff --git a/tools/editor/editor_themes.h b/tools/editor/editor_themes.h index 83e7dde78a..bf15420917 100644 --- a/tools/editor/editor_themes.h +++ b/tools/editor/editor_themes.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* editor_themes.h */ +/* editor_themes.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ diff --git a/tools/editor/file_type_cache.cpp b/tools/editor/file_type_cache.cpp index 176205a7df..aff99fbc05 100644 --- a/tools/editor/file_type_cache.cpp +++ b/tools/editor/file_type_cache.cpp @@ -27,10 +27,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "file_type_cache.h" + #include "globals.h" #include "os/file_access.h" - FileTypeCache* FileTypeCache::singleton=NULL; bool FileTypeCache::has_file(const String& p_path) const { diff --git a/tools/editor/fileserver/SCsub b/tools/editor/fileserver/SCsub index 4bf55189cc..f1fa50148f 100644 --- a/tools/editor/fileserver/SCsub +++ b/tools/editor/fileserver/SCsub @@ -2,4 +2,4 @@ Import('env') Export('env') -env.add_source_files(env.tool_sources, "*.cpp") +env.add_source_files(env.editor_sources, "*.cpp") diff --git a/tools/editor/fileserver/editor_file_server.cpp b/tools/editor/fileserver/editor_file_server.cpp index 6330b06d3e..2e5dbf6248 100644 --- a/tools/editor/fileserver/editor_file_server.cpp +++ b/tools/editor/fileserver/editor_file_server.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_file_server.h" + #include "io/marshalls.h" #include "io/marshalls.h" #include "../editor_settings.h" diff --git a/tools/editor/filesystem_dock.cpp b/tools/editor/filesystem_dock.cpp index 792eb54dd4..08b8307eb4 100644 --- a/tools/editor/filesystem_dock.cpp +++ b/tools/editor/filesystem_dock.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* scenes_dock.cpp */ +/* filesystem_dock.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,14 +27,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "filesystem_dock.h" + #include "os/dir_access.h" #include "os/file_access.h" #include "globals.h" - #include "io/resource_loader.h" #include "os/os.h" #include "editor_node.h" - #include "editor_settings.h" #include "scene/main/viewport.h" @@ -171,7 +170,7 @@ void FileSystemDock::_notification(int p_what) { _update_tree(); //maybe it finished already if (EditorFileSystem::get_singleton()->is_scanning()) { - _set_scannig_mode(); + _set_scanning_mode(); } } break; @@ -351,25 +350,9 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path,List<FileInfo>* m FileInfo fi; fi.name=file; fi.type=p_path->get_file_type(i); - fi.path=p_path->get_file_path(i); - if (p_path->get_file_meta(i)) { - if (p_path->is_missing_sources(i)) { - fi.import_status=3; - } else if (p_path->have_sources_changed(i)) { - fi.import_status=2; - } else { - fi.import_status=1; - } - } else { - fi.import_status=0; - } - for(int j=0;j<p_path->get_source_count(i);j++) { - String s = EditorImportPlugin::expand_source_path(p_path->get_source_file(i,j)); - if (p_path->is_source_file_missing(i,j)) { - s+=" (Missing)"; - } - fi.sources.push_back(s); - } + fi.path=p_path->get_file_path(i); + fi.import_status=0; + matches->push_back(fi); if (matches->size()>p_max_items) @@ -501,25 +484,7 @@ void FileSystemDock::_update_files(bool p_keep_selection) { fi.name=efd->get_file(i); fi.path=path.plus_file(fi.name); fi.type=efd->get_file_type(i); - if (efd->get_file_meta(i)) { - if (efd->is_missing_sources(i)) { - fi.import_status=3; - } else if (efd->have_sources_changed(i)) { - fi.import_status=2; - } else { - fi.import_status=1; - } - - for(int j=0;j<efd->get_source_count(i);j++) { - String s = EditorImportPlugin::expand_source_path(efd->get_source_file(i,j)); - if (efd->is_source_file_missing(i,j)) { - s+=" (Missing)"; - } - fi.sources.push_back(s); - } - } else { - fi.import_status=0; - } + fi.import_status=0; @@ -663,7 +628,7 @@ void FileSystemDock::_fs_changed() { set_process(false); } -void FileSystemDock::_set_scannig_mode() { +void FileSystemDock::_set_scanning_mode() { split_box->hide(); button_hist_prev->set_disabled(true); @@ -990,7 +955,7 @@ void FileSystemDock::_file_option(int p_option) { } break; case FILE_MOVE: { - move_dirs.clear();; + move_dirs.clear(); move_files.clear(); for(int i=0;i<files->get_item_count();i++) { @@ -1069,7 +1034,7 @@ void FileSystemDock::_file_option(int p_option) { } ERR_FAIL_COND(reimport.size()==0); - +/* Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(reimport[0]); ERR_FAIL_COND(!rimd.is_valid()); String editor=rimd->get_editor(); @@ -1087,6 +1052,7 @@ void FileSystemDock::_file_option(int p_option) { rimp->reimport_multiple_files(reimport); } + */ } break; case FILE_COPY_PATH: @@ -1175,7 +1141,7 @@ void FileSystemDock::_search_changed(const String& p_text) { void FileSystemDock::_rescan() { - _set_scannig_mode(); + _set_scanning_mode(); EditorFileSystem::get_singleton()->scan(); } @@ -1187,6 +1153,14 @@ void FileSystemDock::fix_dependencies(const String& p_for_file) { void FileSystemDock::focus_on_filter() { + if (!search_box->is_visible_in_tree()) { + // Tree mode, switch to files list with search box + tree->hide(); + file_list_vb->show(); + button_favorite->hide(); + } + + search_box->grab_focus(); } void FileSystemDock::set_display_mode(int p_mode) { @@ -1530,25 +1504,6 @@ void FileSystemDock::_files_list_rmb_select(int p_item,const Vector2& p_pos) { if (efsd) { - if (!efsd->get_file_meta(pos)) { - all_can_reimport=false; - - - } else { - Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(path); - if (rimd.is_valid()) { - - String editor=rimd->get_editor(); - if (editor.begins_with("texture_")) { //compatibility fix for old texture format - editor="texture"; - } - types.insert(editor); - - } else { - all_can_reimport=false; - - } - } } else { all_can_reimport=false; @@ -1596,7 +1551,7 @@ void FileSystemDock::_files_list_rmb_select(int p_item,const Vector2& p_pos) { if (all_can_reimport && types.size()==1) { //all can reimport and are of the same type - +/* bool valid=true; Ref<EditorImportPlugin> rimp = EditorImportExport::get_singleton()->get_import_plugin_by_name(types.front()->get()); if (rimp.is_valid()) { @@ -1612,6 +1567,7 @@ void FileSystemDock::_files_list_rmb_select(int p_item,const Vector2& p_pos) { file_options->add_separator(); file_options->add_item(TTR("Re-Import.."),FILE_REIMPORT); } + */ } file_options->set_pos(files->get_global_pos() + p_pos); @@ -1619,6 +1575,70 @@ void FileSystemDock::_files_list_rmb_select(int p_item,const Vector2& p_pos) { } +void FileSystemDock::select_file(const String& p_file) { + + _go_to_dir(p_file.get_base_dir()); + for(int i=0;i<files->get_item_count();i++) { + if (files->get_item_metadata(i)==p_file) { + files->select(i); + files->ensure_current_is_visible(); + break; + } + } + +} + +void FileSystemDock::_file_multi_selected(int p_index,bool p_selected) { + + + _file_selected(); +} + +void FileSystemDock::_file_selected() { + + //check import + Vector<String> imports; + String import_type; + + for(int i=0;i<files->get_item_count();i++) { + if (!files->is_selected(i)) + continue; + + String p = files->get_item_metadata(i); + if (!FileAccess::exists(p+".import")) { + imports.clear(); + break; + } + Ref<ConfigFile> cf; + cf.instance(); + Error err = cf->load(p+".import"); + if (err!=OK) { + imports.clear(); + break; + } + + String type = cf->get_value("remap","type"); + if (import_type=="") { + import_type=type; + } else if (import_type!=type) { + //all should be the same type + imports.clear(); + break; + } + imports.push_back(p); + } + + + if (imports.size()==0) { + EditorNode::get_singleton()->get_import_dock()->clear(); + } else if (imports.size()==1) { + EditorNode::get_singleton()->get_import_dock()->set_edit_path(imports[0]); + } else { + EditorNode::get_singleton()->get_import_dock()->set_edit_multiple_paths(imports); + } +} + + void FileSystemDock::_bind_methods() { ClassDB::bind_method(_MD("_update_tree"),&FileSystemDock::_update_tree); @@ -1650,6 +1670,8 @@ void FileSystemDock::_bind_methods() { ClassDB::bind_method(_MD("_files_list_rmb_select"),&FileSystemDock::_files_list_rmb_select); ClassDB::bind_method(_MD("_preview_invalidated"),&FileSystemDock::_preview_invalidated); + ClassDB::bind_method(_MD("_file_selected"),&FileSystemDock::_file_selected); + ClassDB::bind_method(_MD("_file_multi_selected"),&FileSystemDock::_file_multi_selected); ADD_SIGNAL(MethodInfo("instance", PropertyInfo(Variant::POOL_STRING_ARRAY, "files"))); @@ -1754,6 +1776,8 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { files->set_select_mode(ItemList::SELECT_MULTI); files->set_drag_forwarding(this); files->connect("item_rmb_selected",this,"_files_list_rmb_select"); + files->connect("item_selected",this,"_file_selected"); + files->connect("multi_selected",this,"_file_multi_selected"); files->set_allow_rmb_select(true); file_list_vb = memnew( VBoxContainer ); diff --git a/tools/editor/filesystem_dock.h b/tools/editor/filesystem_dock.h index 0b0a73b9a2..224efe0f28 100644 --- a/tools/editor/filesystem_dock.h +++ b/tools/editor/filesystem_dock.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* scenes_dock.h */ +/* filesystem_dock.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -126,6 +126,11 @@ private: Tree * tree; //directories ItemList *files; + + void _file_multi_selected(int p_index, bool p_selected); + void _file_selected(); + + void _go_to_tree(); void _go_to_dir(const String& p_dir); void _select_file(int p_idx); @@ -153,7 +158,7 @@ private: void _dir_selected(); void _update_tree(); void _rescan(); - void _set_scannig_mode(); + void _set_scanning_mode(); void _favorites_pressed(); @@ -199,6 +204,10 @@ public: void set_display_mode(int p_mode); + int get_split_offset() { return split_box->get_split_offset(); } + void set_split_offset(int p_offset) { split_box->set_split_offset(p_offset); } + void select_file(const String& p_file); + FileSystemDock(EditorNode *p_editor); ~FileSystemDock(); }; diff --git a/tools/editor/groups_editor.cpp b/tools/editor/groups_editor.cpp index 07b2bca385..90f0bab6dd 100644 --- a/tools/editor/groups_editor.cpp +++ b/tools/editor/groups_editor.cpp @@ -32,6 +32,7 @@ #include "scene/gui/label.h" #include "editor_node.h" #include "scene/resources/packed_scene.h" + void GroupsEditor::_add_group(const String& p_group) { if (!node) diff --git a/tools/editor/icons/2x/icon_anchor.png b/tools/editor/icons/2x/icon_anchor.png Binary files differindex db964fd910..7e9e259c13 100644 --- a/tools/editor/icons/2x/icon_anchor.png +++ b/tools/editor/icons/2x/icon_anchor.png diff --git a/tools/editor/icons/2x/icon_animation.png b/tools/editor/icons/2x/icon_animation.png Binary files differindex 5b21e99e43..ef18959a74 100644 --- a/tools/editor/icons/2x/icon_animation.png +++ b/tools/editor/icons/2x/icon_animation.png diff --git a/tools/editor/icons/2x/icon_area.png b/tools/editor/icons/2x/icon_area.png Binary files differindex ff332bf748..d9cefe8fc4 100644 --- a/tools/editor/icons/2x/icon_area.png +++ b/tools/editor/icons/2x/icon_area.png diff --git a/tools/editor/icons/2x/icon_auto_play.png b/tools/editor/icons/2x/icon_auto_play.png Binary files differindex 9a50d1c030..ec31dee958 100644 --- a/tools/editor/icons/2x/icon_auto_play.png +++ b/tools/editor/icons/2x/icon_auto_play.png diff --git a/tools/editor/icons/2x/icon_bitmap_font.png b/tools/editor/icons/2x/icon_bitmap_font.png Binary files differindex df6d2a5081..c533b5f40e 100644 --- a/tools/editor/icons/2x/icon_bitmap_font.png +++ b/tools/editor/icons/2x/icon_bitmap_font.png diff --git a/tools/editor/icons/2x/icon_canvas_layer.png b/tools/editor/icons/2x/icon_canvas_layer.png Binary files differindex 9861d3ef45..8a4b31cd7d 100644 --- a/tools/editor/icons/2x/icon_canvas_layer.png +++ b/tools/editor/icons/2x/icon_canvas_layer.png diff --git a/tools/editor/icons/2x/icon_canvas_modulate.png b/tools/editor/icons/2x/icon_canvas_modulate.png Binary files differindex 07ee8a0570..6cc15e2655 100644 --- a/tools/editor/icons/2x/icon_canvas_modulate.png +++ b/tools/editor/icons/2x/icon_canvas_modulate.png diff --git a/tools/editor/icons/2x/icon_color_rect.png b/tools/editor/icons/2x/icon_color_rect.png Binary files differnew file mode 100644 index 0000000000..153029ac20 --- /dev/null +++ b/tools/editor/icons/2x/icon_color_rect.png diff --git a/tools/editor/icons/2x/icon_copy_node_path.png b/tools/editor/icons/2x/icon_copy_node_path.png Binary files differnew file mode 100644 index 0000000000..056748d20b --- /dev/null +++ b/tools/editor/icons/2x/icon_copy_node_path.png diff --git a/tools/editor/icons/2x/icon_create_new_scene_from.png b/tools/editor/icons/2x/icon_create_new_scene_from.png Binary files differindex 15b2c89dc5..cc3be48033 100644 --- a/tools/editor/icons/2x/icon_create_new_scene_from.png +++ b/tools/editor/icons/2x/icon_create_new_scene_from.png diff --git a/tools/editor/icons/2x/icon_dynamic_font_data.png b/tools/editor/icons/2x/icon_dynamic_font_data.png Binary files differindex 397a849b4f..6d76303c81 100644 --- a/tools/editor/icons/2x/icon_dynamic_font_data.png +++ b/tools/editor/icons/2x/icon_dynamic_font_data.png diff --git a/tools/editor/icons/2x/icon_error.png b/tools/editor/icons/2x/icon_error.png Binary files differindex b577182044..a6d79ab41b 100644 --- a/tools/editor/icons/2x/icon_error.png +++ b/tools/editor/icons/2x/icon_error.png diff --git a/tools/editor/icons/2x/icon_fixed_spatial_material.png b/tools/editor/icons/2x/icon_fixed_spatial_material.png Binary files differindex b95e78d6cc..65509a590e 100644 --- a/tools/editor/icons/2x/icon_fixed_spatial_material.png +++ b/tools/editor/icons/2x/icon_fixed_spatial_material.png diff --git a/tools/editor/icons/2x/icon_key_next.png b/tools/editor/icons/2x/icon_key_next.png Binary files differindex cb2c4eae4b..d35b52d3c7 100644 --- a/tools/editor/icons/2x/icon_key_next.png +++ b/tools/editor/icons/2x/icon_key_next.png diff --git a/tools/editor/icons/2x/icon_material_shader.png b/tools/editor/icons/2x/icon_material_shader.png Binary files differindex 65509a590e..f8c2e15fcb 100644 --- a/tools/editor/icons/2x/icon_material_shader.png +++ b/tools/editor/icons/2x/icon_material_shader.png diff --git a/tools/editor/icons/2x/icon_nine_patch_rect.png b/tools/editor/icons/2x/icon_nine_patch_rect.png Binary files differnew file mode 100644 index 0000000000..5762a0392e --- /dev/null +++ b/tools/editor/icons/2x/icon_nine_patch_rect.png diff --git a/tools/editor/icons/2x/icon_reparent.png b/tools/editor/icons/2x/icon_reparent.png Binary files differindex 2473a3b362..3063da4b43 100644 --- a/tools/editor/icons/2x/icon_reparent.png +++ b/tools/editor/icons/2x/icon_reparent.png diff --git a/tools/editor/icons/2x/icon_script_remove.png b/tools/editor/icons/2x/icon_script_remove.png Binary files differnew file mode 100644 index 0000000000..f9a1bb19a4 --- /dev/null +++ b/tools/editor/icons/2x/icon_script_remove.png diff --git a/tools/editor/icons/2x/icon_shader.png b/tools/editor/icons/2x/icon_shader.png Binary files differindex 65509a590e..f8c2e15fcb 100644 --- a/tools/editor/icons/2x/icon_shader.png +++ b/tools/editor/icons/2x/icon_shader.png diff --git a/tools/editor/icons/2x/icon_shader_material.png b/tools/editor/icons/2x/icon_shader_material.png Binary files differindex 65509a590e..f8c2e15fcb 100644 --- a/tools/editor/icons/2x/icon_shader_material.png +++ b/tools/editor/icons/2x/icon_shader_material.png diff --git a/tools/editor/icons/2x/icon_spot_light.png b/tools/editor/icons/2x/icon_spot_light.png Binary files differindex e50c7b6135..e7aa35cbbf 100644 --- a/tools/editor/icons/2x/icon_spot_light.png +++ b/tools/editor/icons/2x/icon_spot_light.png diff --git a/tools/editor/icons/2x/icon_tab_container.png b/tools/editor/icons/2x/icon_tab_container.png Binary files differindex 086be0c5ba..93b7161a69 100644 --- a/tools/editor/icons/2x/icon_tab_container.png +++ b/tools/editor/icons/2x/icon_tab_container.png diff --git a/tools/editor/icons/2x/icon_tabs.png b/tools/editor/icons/2x/icon_tabs.png Binary files differindex ade8071b7f..6c317010c8 100644 --- a/tools/editor/icons/2x/icon_tabs.png +++ b/tools/editor/icons/2x/icon_tabs.png diff --git a/tools/editor/icons/2x/icon_track_add_key.png b/tools/editor/icons/2x/icon_track_add_key.png Binary files differindex 9cf0314270..9b7bd14fb4 100644 --- a/tools/editor/icons/2x/icon_track_add_key.png +++ b/tools/editor/icons/2x/icon_track_add_key.png diff --git a/tools/editor/icons/2x/icon_track_add_key_hl.png b/tools/editor/icons/2x/icon_track_add_key_hl.png Binary files differindex 7d170725f6..0763836c3a 100644 --- a/tools/editor/icons/2x/icon_track_add_key_hl.png +++ b/tools/editor/icons/2x/icon_track_add_key_hl.png diff --git a/tools/editor/icons/2x/icon_transparent.png b/tools/editor/icons/2x/icon_transparent.png Binary files differnew file mode 100644 index 0000000000..627607039b --- /dev/null +++ b/tools/editor/icons/2x/icon_transparent.png diff --git a/tools/editor/icons/2x/icon_viewport_container.png b/tools/editor/icons/2x/icon_viewport_container.png Binary files differnew file mode 100644 index 0000000000..c43e53c34e --- /dev/null +++ b/tools/editor/icons/2x/icon_viewport_container.png diff --git a/tools/editor/icons/2x/icon_warning.png b/tools/editor/icons/2x/icon_warning.png Binary files differindex 7359a798ee..5d807065e7 100644 --- a/tools/editor/icons/2x/icon_warning.png +++ b/tools/editor/icons/2x/icon_warning.png diff --git a/tools/editor/icons/SCsub b/tools/editor/icons/SCsub index f86ae2b10d..4af481d1f6 100644 --- a/tools/editor/icons/SCsub +++ b/tools/editor/icons/SCsub @@ -92,5 +92,5 @@ make_editor_icons_builder = Builder(action=make_editor_icons_action, env['BUILDERS']['MakeEditorIconsBuilder'] = make_editor_icons_builder env.Alias('editor_icons', [env.MakeEditorIconsBuilder('#tools/editor/editor_icons.cpp', Glob("*.png"))]) -env.tool_sources.append("#tools/editor/editor_icons.cpp") +env.editor_sources.append("#tools/editor/editor_icons.cpp") Export('env') diff --git a/tools/editor/icons/icon_accept_dialog.png b/tools/editor/icons/icon_accept_dialog.png Binary files differindex 1ba2ce8db3..7530127f82 100644 --- a/tools/editor/icons/icon_accept_dialog.png +++ b/tools/editor/icons/icon_accept_dialog.png diff --git a/tools/editor/icons/icon_anchor.png b/tools/editor/icons/icon_anchor.png Binary files differindex 9c20808bdc..7b02eb448e 100644 --- a/tools/editor/icons/icon_anchor.png +++ b/tools/editor/icons/icon_anchor.png diff --git a/tools/editor/icons/icon_animation.png b/tools/editor/icons/icon_animation.png Binary files differindex 2bc13f0b4c..b333f82711 100644 --- a/tools/editor/icons/icon_animation.png +++ b/tools/editor/icons/icon_animation.png diff --git a/tools/editor/icons/icon_area.png b/tools/editor/icons/icon_area.png Binary files differindex ea7af5f9ac..31b4473d17 100644 --- a/tools/editor/icons/icon_area.png +++ b/tools/editor/icons/icon_area.png diff --git a/tools/editor/icons/icon_audio_effect_amplify.png b/tools/editor/icons/icon_audio_effect_amplify.png Binary files differnew file mode 100644 index 0000000000..9af3227d40 --- /dev/null +++ b/tools/editor/icons/icon_audio_effect_amplify.png diff --git a/tools/editor/icons/icon_auto_play.png b/tools/editor/icons/icon_auto_play.png Binary files differindex fcd3bedcda..a6be64a1d1 100644 --- a/tools/editor/icons/icon_auto_play.png +++ b/tools/editor/icons/icon_auto_play.png diff --git a/tools/editor/icons/icon_bitmap_font.png b/tools/editor/icons/icon_bitmap_font.png Binary files differindex 2739248796..5334c335dc 100644 --- a/tools/editor/icons/icon_bitmap_font.png +++ b/tools/editor/icons/icon_bitmap_font.png diff --git a/tools/editor/icons/icon_bus_vu_db.png b/tools/editor/icons/icon_bus_vu_db.png Binary files differnew file mode 100644 index 0000000000..52507cae52 --- /dev/null +++ b/tools/editor/icons/icon_bus_vu_db.png diff --git a/tools/editor/icons/icon_bus_vu_empty.png b/tools/editor/icons/icon_bus_vu_empty.png Binary files differnew file mode 100644 index 0000000000..6fc3143a55 --- /dev/null +++ b/tools/editor/icons/icon_bus_vu_empty.png diff --git a/tools/editor/icons/icon_bus_vu_frozen.png b/tools/editor/icons/icon_bus_vu_frozen.png Binary files differnew file mode 100644 index 0000000000..cf128afa91 --- /dev/null +++ b/tools/editor/icons/icon_bus_vu_frozen.png diff --git a/tools/editor/icons/icon_bus_vu_full.png b/tools/editor/icons/icon_bus_vu_full.png Binary files differnew file mode 100644 index 0000000000..9e3d7a93e3 --- /dev/null +++ b/tools/editor/icons/icon_bus_vu_full.png diff --git a/tools/editor/icons/icon_canvas_layer.png b/tools/editor/icons/icon_canvas_layer.png Binary files differindex cae31fe3bc..bb32d6d3ad 100644 --- a/tools/editor/icons/icon_canvas_layer.png +++ b/tools/editor/icons/icon_canvas_layer.png diff --git a/tools/editor/icons/icon_canvas_modulate.png b/tools/editor/icons/icon_canvas_modulate.png Binary files differindex 711ebbae5f..b76e532268 100644 --- a/tools/editor/icons/icon_canvas_modulate.png +++ b/tools/editor/icons/icon_canvas_modulate.png diff --git a/tools/editor/icons/icon_color_frame.png b/tools/editor/icons/icon_color_frame.png Binary files differdeleted file mode 100644 index a82eefc10a..0000000000 --- a/tools/editor/icons/icon_color_frame.png +++ /dev/null diff --git a/tools/editor/icons/icon_color_rect.png b/tools/editor/icons/icon_color_rect.png Binary files differnew file mode 100644 index 0000000000..40b9dab605 --- /dev/null +++ b/tools/editor/icons/icon_color_rect.png diff --git a/tools/editor/icons/icon_copy_node_path.png b/tools/editor/icons/icon_copy_node_path.png Binary files differnew file mode 100644 index 0000000000..d777f132d8 --- /dev/null +++ b/tools/editor/icons/icon_copy_node_path.png diff --git a/tools/editor/icons/icon_create_new_scene_from.png b/tools/editor/icons/icon_create_new_scene_from.png Binary files differindex 908c82626c..45df9b1e25 100644 --- a/tools/editor/icons/icon_create_new_scene_from.png +++ b/tools/editor/icons/icon_create_new_scene_from.png diff --git a/tools/editor/icons/icon_dynamic_font_data.png b/tools/editor/icons/icon_dynamic_font_data.png Binary files differindex 8f36106b61..5cff86c40c 100644 --- a/tools/editor/icons/icon_dynamic_font_data.png +++ b/tools/editor/icons/icon_dynamic_font_data.png diff --git a/tools/editor/icons/icon_error.png b/tools/editor/icons/icon_error.png Binary files differindex 0fdf5facbf..7a9bed43aa 100644 --- a/tools/editor/icons/icon_error.png +++ b/tools/editor/icons/icon_error.png diff --git a/tools/editor/icons/icon_fixed_spatial_material.png b/tools/editor/icons/icon_fixed_spatial_material.png Binary files differindex 2e52c45a46..f26ac3be37 100644 --- a/tools/editor/icons/icon_fixed_spatial_material.png +++ b/tools/editor/icons/icon_fixed_spatial_material.png diff --git a/tools/editor/icons/icon_key_next.png b/tools/editor/icons/icon_key_next.png Binary files differindex ed7a20637f..288161d245 100644 --- a/tools/editor/icons/icon_key_next.png +++ b/tools/editor/icons/icon_key_next.png diff --git a/tools/editor/icons/icon_material_shader.png b/tools/editor/icons/icon_material_shader.png Binary files differindex f26ac3be37..568a45d938 100644 --- a/tools/editor/icons/icon_material_shader.png +++ b/tools/editor/icons/icon_material_shader.png diff --git a/tools/editor/icons/icon_nine_patch_rect.png b/tools/editor/icons/icon_nine_patch_rect.png Binary files differnew file mode 100644 index 0000000000..bdd1467144 --- /dev/null +++ b/tools/editor/icons/icon_nine_patch_rect.png diff --git a/tools/editor/icons/icon_reparent.png b/tools/editor/icons/icon_reparent.png Binary files differindex b3235e60c5..135ccee4ad 100644 --- a/tools/editor/icons/icon_reparent.png +++ b/tools/editor/icons/icon_reparent.png diff --git a/tools/editor/icons/icon_script_remove.png b/tools/editor/icons/icon_script_remove.png Binary files differnew file mode 100644 index 0000000000..c200b01690 --- /dev/null +++ b/tools/editor/icons/icon_script_remove.png diff --git a/tools/editor/icons/icon_shader.png b/tools/editor/icons/icon_shader.png Binary files differindex f26ac3be37..568a45d938 100644 --- a/tools/editor/icons/icon_shader.png +++ b/tools/editor/icons/icon_shader.png diff --git a/tools/editor/icons/icon_shader_material.png b/tools/editor/icons/icon_shader_material.png Binary files differindex f26ac3be37..568a45d938 100644 --- a/tools/editor/icons/icon_shader_material.png +++ b/tools/editor/icons/icon_shader_material.png diff --git a/tools/editor/icons/icon_spot_light.png b/tools/editor/icons/icon_spot_light.png Binary files differindex 89b0b28aa3..f52570a5cd 100644 --- a/tools/editor/icons/icon_spot_light.png +++ b/tools/editor/icons/icon_spot_light.png diff --git a/tools/editor/icons/icon_tab_container.png b/tools/editor/icons/icon_tab_container.png Binary files differindex dd661c5ab6..7ff3081ec1 100644 --- a/tools/editor/icons/icon_tab_container.png +++ b/tools/editor/icons/icon_tab_container.png diff --git a/tools/editor/icons/icon_tabs.png b/tools/editor/icons/icon_tabs.png Binary files differindex cc7e08a835..bef0f60660 100644 --- a/tools/editor/icons/icon_tabs.png +++ b/tools/editor/icons/icon_tabs.png diff --git a/tools/editor/icons/icon_track_add_key.png b/tools/editor/icons/icon_track_add_key.png Binary files differindex fb86b37963..02d92439a3 100644 --- a/tools/editor/icons/icon_track_add_key.png +++ b/tools/editor/icons/icon_track_add_key.png diff --git a/tools/editor/icons/icon_track_add_key_hl.png b/tools/editor/icons/icon_track_add_key_hl.png Binary files differindex c1bfee736a..0e857f5fe2 100644 --- a/tools/editor/icons/icon_track_add_key_hl.png +++ b/tools/editor/icons/icon_track_add_key_hl.png diff --git a/tools/editor/icons/icon_transparent.png b/tools/editor/icons/icon_transparent.png Binary files differnew file mode 100644 index 0000000000..07e9b52b5c --- /dev/null +++ b/tools/editor/icons/icon_transparent.png diff --git a/tools/editor/icons/icon_viewport_container.png b/tools/editor/icons/icon_viewport_container.png Binary files differnew file mode 100644 index 0000000000..c70dee3698 --- /dev/null +++ b/tools/editor/icons/icon_viewport_container.png diff --git a/tools/editor/icons/icon_vu_db.png b/tools/editor/icons/icon_vu_db.png Binary files differnew file mode 100644 index 0000000000..405a929e2a --- /dev/null +++ b/tools/editor/icons/icon_vu_db.png diff --git a/tools/editor/icons/icon_warning.png b/tools/editor/icons/icon_warning.png Binary files differindex 0928062938..451beba820 100644 --- a/tools/editor/icons/icon_warning.png +++ b/tools/editor/icons/icon_warning.png diff --git a/tools/editor/icons/source/icon_accept_dialog.svg b/tools/editor/icons/source/icon_accept_dialog.svg index 8d2c307691..9f82b30c94 100644 --- a/tools/editor/icons/source/icon_accept_dialog.svg +++ b/tools/editor/icons/source/icon_accept_dialog.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="32" - inkscape:cx="6.0807642" - inkscape:cy="9.1331382" + inkscape:zoom="45.254834" + inkscape:cx="8.3712909" + inkscape:cy="7.2310094" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -59,7 +59,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -70,8 +70,10 @@ transform="translate(0,-1036.3622)"> <path style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 3 1 C 1.89543 1 1 1.8954 1 3 L 1 4 L 15 4 L 15 3 C 15 1.8954 14.104569 1 13 1 L 3 1 z M 12 2 L 13 2 L 13 3 L 12 3 L 12 2 z M 1 5 L 1 13 C 1 14.1046 1.89543 15 3 15 L 13 15 C 14.104569 15 15 14.1046 15 13 L 15 5 L 1 5 z M 10.474609 6.6367188 L 11.888672 8.0507812 L 8.3535156 11.585938 L 6.9394531 13 L 5.5253906 11.585938 L 4.1113281 10.171875 L 5.5253906 8.7578125 L 6.9394531 10.171875 L 10.474609 6.6367188 z " + d="M 3,1 C 1.89543,1 1,1.8954 1,3 L 1,4 15,4 15,3 C 15,1.8954 14.104569,1 13,1 Z m 9,1 1,0 0,1 -1,0 z M 1,5 1,13 c 0,1.1046 0.89543,2 2,2 l 10,0 c 1.104569,0 2,-0.8954 2,-2 L 15,5 Z M 10.474609,6.6367188 11.888672,8.0507812 6.9394531,13 4.1113281,10.171875 5.5253906,8.7578125 6.9394531,10.171875 Z" transform="translate(0,1036.3622)" - id="rect4140" /> + id="rect4140" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ssccsssccccccssssccccccccc" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_add_track.svg b/tools/editor/icons/source/icon_add_track.svg index 916199d29e..d19448efb0 100644 --- a/tools/editor/icons/source/icon_add_track.svg +++ b/tools/editor/icons/source/icon_add_track.svg @@ -18,7 +18,7 @@ inkscape:export-filename="/home/djrm/Projects/godot/tools/editor/icons/icon_add_track.png" inkscape:export-xdpi="45" inkscape:export-ydpi="45" - sodipodi:docname="icon_add_track (copy).svg"> + sodipodi:docname="icon_add_track.svg"> <defs id="defs4" /> <sodipodi:namedview @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="32.000001" - inkscape:cx="4.2247291" - inkscape:cy="8.9595523" + inkscape:zoom="45.254835" + inkscape:cx="6.9909025" + inkscape:cy="7.4569962" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -59,7 +59,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -68,20 +68,10 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <rect + <path style="fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" - id="rect4137" - width="14" - height="1.9999478" - x="1" - y="1043.3622" /> - <rect - y="-9" - x="1037.3622" - height="2.0000017" - width="13.999966" - id="rect4158" - style="fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" - transform="matrix(0,1,-1,0,0,0)" /> + d="M 7 1 L 7 7 L 1 7 L 1 9 L 7 9 L 7 15 L 9 15 L 9 9 L 15 9 L 15 7 L 9 7 L 9 1 L 7 1 z " + transform="translate(0,1036.3622)" + id="rect4137" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_anchor.svg b/tools/editor/icons/source/icon_anchor.svg index ff43271224..6b10be040b 100644 --- a/tools/editor/icons/source/icon_anchor.svg +++ b/tools/editor/icons/source/icon_anchor.svg @@ -18,7 +18,7 @@ inkscape:export-filename="/home/djrm/Projects/godot/tools/editor/icons/icon_anchor.png" inkscape:export-xdpi="90" inkscape:export-ydpi="90" - sodipodi:docname="icon_anchor (copy).svg"> + sodipodi:docname="icon_anchor.svg"> <defs id="defs4" /> <sodipodi:namedview @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="32" - inkscape:cx="5.8188721" - inkscape:cy="10.181863" + inkscape:cx="12.991456" + inkscape:cy="8.2347656" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -70,27 +70,8 @@ transform="translate(0,-1036.3622)"> <path style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 8 1 A 3 3.0000043 0 0 0 5 4 A 3 3.0000043 0 0 0 8 7 A 3 3.0000043 0 0 0 11 4 A 3 3.0000043 0 0 0 8 1 z M 8 3 A 1.000016 1.0000174 0 0 1 9 4 A 1.000016 1.0000174 0 0 1 8 5 A 1.000016 1.0000174 0 0 1 7 4 A 1.000016 1.0000174 0 0 1 8 3 z " + d="M 8 1 A 3 3.0000043 0 0 0 5 4 A 3 3.0000043 0 0 0 7 6.8261719 L 7 7 L 5 7 L 5 9 L 7 9 L 7 12.898438 A 5.0000172 5.0000172 0 0 1 3.171875 9.2949219 L 1.2382812 9.8125 A 7 7 0 0 0 8 15 A 7 7 0 0 0 14.761719 9.8125 L 12.824219 9.2929688 A 5.0000172 5.0000172 0 0 1 9 12.896484 L 9 9 L 11 9 L 11 7 L 9 7 L 9 6.8242188 A 3 3.0000043 0 0 0 11 4 A 3 3.0000043 0 0 0 8 1 z M 8 3 A 1.000016 1.0000174 0 0 1 9 4 A 1.000016 1.0000174 0 0 1 8 5 A 1.000016 1.0000174 0 0 1 7 4 A 1.000016 1.0000174 0 0 1 8 3 z " transform="translate(0,1036.3622)" id="path4142" /> - <rect - y="1042.3622" - x="7" - height="7.0000172" - width="2" - id="rect4148" - style="fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> - <path - style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 12.824219 9.2929688 A 5.0000172 5.0000172 0 0 1 8 13 A 5.0000172 5.0000172 0 0 1 3.171875 9.2949219 L 1.2382812 9.8125 A 7 7 0 0 0 8 15 A 7 7 0 0 0 14.761719 9.8125 L 12.824219 9.2929688 z " - transform="translate(0,1036.3622)" - id="path4150" /> - <rect - style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4155" - width="6" - height="2" - x="5" - y="1043.3622" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_animation.svg b/tools/editor/icons/source/icon_animation.svg index 38d73cf5bb..371979345f 100644 --- a/tools/editor/icons/source/icon_animation.svg +++ b/tools/editor/icons/source/icon_animation.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="64" - inkscape:cx="10.327464" - inkscape:cy="2.5689331" + inkscape:zoom="22.627417" + inkscape:cx="9.2543315" + inkscape:cy="5.9550306" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -70,49 +70,8 @@ transform="translate(0,-1036.3622)"> <path style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 8 2 A 6 6 0 0 0 2 8 A 6 6 0 0 0 8 14 A 6 6 0 0 0 14 8 A 6 6 0 0 0 8 2 z M 8 3 A 1 1 0 0 1 9 4 A 1 1 0 0 1 8 5 A 1 1 0 0 1 7 4 A 1 1 0 0 1 8 3 z M 11.441406 5 A 1 1 0 0 1 12.330078 5.5 A 1 1 0 0 1 11.964844 6.8652344 A 1 1 0 0 1 10.597656 6.5 A 1 1 0 0 1 10.964844 5.1347656 A 1 1 0 0 1 11.441406 5 z M 4.4882812 5.0019531 A 1 1 0 0 1 5.0351562 5.1347656 A 1 1 0 0 1 5.4023438 6.5 A 1 1 0 0 1 4.0351562 6.8652344 A 1 1 0 0 1 3.6699219 5.5 A 1 1 0 0 1 4.4882812 5.0019531 z M 4.5117188 9 A 1 1 0 0 1 5.4023438 9.5 A 1 1 0 0 1 5.0351562 10.865234 A 1 1 0 0 1 3.6699219 10.5 A 1 1 0 0 1 4.0351562 9.1347656 A 1 1 0 0 1 4.5117188 9 z M 11.416016 9.0019531 A 1 1 0 0 1 11.964844 9.1347656 A 1 1 0 0 1 12.330078 10.5 A 1 1 0 0 1 10.964844 10.865234 A 1 1 0 0 1 10.597656 9.5 A 1 1 0 0 1 11.416016 9.0019531 z M 8 11 A 1 1 0 0 1 9 12 A 1 1 0 0 1 8 13 A 1 1 0 0 1 7 12 A 1 1 0 0 1 8 11 z " - transform="translate(0,1036.3622)" - id="path4140" /> - <path - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 13 8 L 13 14 A 1 1 0 0 0 14 15 L 15 15 L 15 14 L 14 14 L 14 13 L 14 8 L 13 8 z " - transform="translate(0,1036.3622)" - id="rect4202" /> - <path - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 14 13.5 L 14 14 L 14.5 14 A 0.5 0.4999913 0 0 1 14 13.5 z " - transform="translate(0,1036.3622)" - id="rect4215" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4137" - width="1" - height="3.0000174" - x="12" - y="1047.3622" /> - <path - id="path4139" - transform="translate(0,1036.3622)" - d="M 13 8 L 13 14 A 1 1 0 0 0 14 15 L 15 15 L 15 14 L 14 14 L 14 13 L 14 8 L 13 8 z " - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - y="1050.3622" - x="14" - height="2" - width="1" - id="rect4141" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> - <path - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="path4145" - sodipodi:type="arc" - sodipodi:cx="14" - sodipodi:cy="1050.3622" - sodipodi:rx="2" - sodipodi:ry="2" - sodipodi:start="1.5707963" - sodipodi:end="4.712389" - d="m 14,1052.3622 a 2,2 0 0 1 -1.732051,-1 2,2 0 0 1 0,-2 2,2 0 0 1 1.732051,-1" - sodipodi:open="true" /> + d="M 8 2 A 6 6 0 0 0 2 8 A 6 6 0 0 0 8 14 A 6 6 0 0 0 12 12.464844 L 12 14 L 12.001953 14 A 2 2 0 0 0 12.267578 15 A 2 2 0 0 0 14 16 L 15 16 L 15 15 L 15 14 L 14.5 14 A 0.5 0.4999913 0 0 1 14 13.5 L 14 13 L 14 8 A 6 6 0 0 0 8 2 z M 8 3 A 1 1 0 0 1 9 4 A 1 1 0 0 1 8 5 A 1 1 0 0 1 7 4 A 1 1 0 0 1 8 3 z M 11.441406 5 A 1 1 0 0 1 12.330078 5.5 A 1 1 0 0 1 11.964844 6.8652344 A 1 1 0 0 1 10.597656 6.5 A 1 1 0 0 1 10.964844 5.1347656 A 1 1 0 0 1 11.441406 5 z M 4.4882812 5.0019531 A 1 1 0 0 1 5.0351562 5.1347656 A 1 1 0 0 1 5.4023438 6.5 A 1 1 0 0 1 4.0351562 6.8652344 A 1 1 0 0 1 3.6699219 5.5 A 1 1 0 0 1 4.4882812 5.0019531 z M 4.5117188 9 A 1 1 0 0 1 5.4023438 9.5 A 1 1 0 0 1 5.0351562 10.865234 A 1 1 0 0 1 3.6699219 10.5 A 1 1 0 0 1 4.0351562 9.1347656 A 1 1 0 0 1 4.5117188 9 z M 11.416016 9.0019531 A 1 1 0 0 1 11.964844 9.1347656 A 1 1 0 0 1 12.330078 10.5 A 1 1 0 0 1 10.964844 10.865234 A 1 1 0 0 1 10.597656 9.5 A 1 1 0 0 1 11.416016 9.0019531 z M 8 11 A 1 1 0 0 1 9 12 A 1 1 0 0 1 8 13 A 1 1 0 0 1 7 12 A 1 1 0 0 1 8 11 z " + id="path4140" + transform="translate(0,1036.3622)" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_area.svg b/tools/editor/icons/source/icon_area.svg index d56043cf3b..d16ad26e23 100644 --- a/tools/editor/icons/source/icon_area.svg +++ b/tools/editor/icons/source/icon_area.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" - inkscape:cx="5.5000497" - inkscape:cy="8.7464605" + inkscape:cx="-2.7642608" + inkscape:cy="8.6580722" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -68,97 +68,10 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <rect + <path style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4148" - width="2" - height="4" - x="1" - y="1047.3622" /> - <rect - y="1049.3622" - x="1" - height="1.9999304" - width="4" - id="rect4150" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - y="1040.3622" - x="4" - height="8.0000172" - width="2" - id="rect4152" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - y="-1041.3622" - x="1" - height="4" - width="2" - id="rect4154" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - transform="scale(1,-1)" /> - <rect - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4156" - width="4" - height="1.9999304" - x="1" - y="-1039.3622" - transform="scale(1,-1)" /> - <rect - transform="scale(-1,-1)" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4158" - width="2" - height="4" - x="-15" - y="-1041.3622" /> - <rect - transform="scale(-1,-1)" - y="-1039.3622" - x="-15" - height="1.9999304" - width="4" - id="rect4160" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - y="1047.3623" - x="-15" - height="4" - width="2" - id="rect4162" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - transform="scale(-1,1)" /> - <rect - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4164" - width="4" - height="1.9999304" - x="-15" - y="1049.3623" - transform="scale(-1,1)" /> - <rect - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4168" - width="8" - height="1.9999998" - x="4" - y="1046.3622" /> - <rect - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4170" - width="2" - height="8.0000172" - x="-12" - y="-1048.3622" - transform="scale(-1,-1)" /> - <rect - y="-1042.3622" - x="-12" - height="1.9999998" - width="8" - id="rect4172" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - transform="scale(-1,-1)" /> + d="M 1 1 L 1 3 L 1 5 L 3 5 L 3 3 L 5 3 L 5 1 L 1 1 z M 11 1 L 11 3 L 13 3 L 13 5 L 15 5 L 15 1 L 11 1 z M 4 4 L 4 6 L 4 10 L 4 12 L 12 12 L 12 10 L 12 4 L 4 4 z M 6 6 L 10 6 L 10 10 L 6 10 L 6 6 z M 1 11 L 1 13 L 1 15 L 3 15 L 5 15 L 5 13 L 3 13 L 3 11 L 1 11 z M 13 11 L 13 13 L 11 13 L 11 15 L 15 15 L 15 13 L 15 11 L 13 11 z " + transform="translate(0,1036.3622)" + id="rect4148" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_area_2d.svg b/tools/editor/icons/source/icon_area_2d.svg index 1373d9f0e4..ef7b16dd06 100644 --- a/tools/editor/icons/source/icon_area_2d.svg +++ b/tools/editor/icons/source/icon_area_2d.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="11.313709" - inkscape:cx="14.936968" - inkscape:cy="11.331549" + inkscape:cx="-1.5916523" + inkscape:cy="11.154772" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -68,97 +68,10 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <rect + <path style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4148" - width="2" - height="4" - x="1" - y="1047.3622" /> - <rect - y="1049.3622" - x="1" - height="1.9999304" - width="4" - id="rect4150" - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - y="1040.3622" - x="4" - height="8.0000172" - width="2" - id="rect4152" - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - y="-1041.3622" - x="1" - height="4" - width="2" - id="rect4154" - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - transform="scale(1,-1)" /> - <rect - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4156" - width="4" - height="1.9999304" - x="1" - y="-1039.3622" - transform="scale(1,-1)" /> - <rect - transform="scale(-1,-1)" - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4158" - width="2" - height="4" - x="-15" - y="-1041.3622" /> - <rect - transform="scale(-1,-1)" - y="-1039.3622" - x="-15" - height="1.9999304" - width="4" - id="rect4160" - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - y="1047.3623" - x="-15" - height="4" - width="2" - id="rect4162" - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - transform="scale(-1,1)" /> - <rect - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4164" - width="4" - height="1.9999304" - x="-15" - y="1049.3623" - transform="scale(-1,1)" /> - <rect - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4168" - width="8" - height="1.9999998" - x="4" - y="1046.3622" /> - <rect - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4170" - width="2" - height="8.0000172" - x="-12" - y="-1048.3622" - transform="scale(-1,-1)" /> - <rect - y="-1042.3622" - x="-12" - height="1.9999998" - width="8" - id="rect4172" - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - transform="scale(-1,-1)" /> + d="M 1 1 L 1 3 L 1 5 L 3 5 L 3 3 L 5 3 L 5 1 L 1 1 z M 11 1 L 11 3 L 13 3 L 13 5 L 15 5 L 15 1 L 11 1 z M 4 4 L 4 6 L 4 10 L 4 12 L 12 12 L 12 10 L 12 4 L 4 4 z M 6 6 L 10 6 L 10 10 L 6 10 L 6 6 z M 1 11 L 1 13 L 1 15 L 3 15 L 5 15 L 5 13 L 3 13 L 3 11 L 1 11 z M 13 11 L 13 13 L 11 13 L 11 15 L 15 15 L 15 13 L 15 11 L 13 11 z " + transform="translate(0,1036.3622)" + id="rect4148" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_arrow_left.svg b/tools/editor/icons/source/icon_arrow_left.svg index 7af9be05d8..75a9ef0d68 100644 --- a/tools/editor/icons/source/icon_arrow_left.svg +++ b/tools/editor/icons/source/icon_arrow_left.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="32" - inkscape:cx="5.5903114" - inkscape:cy="9.1977698" + inkscape:cx="-0.2534386" + inkscape:cy="9.1352698" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -68,30 +68,10 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <rect - style="fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" - id="rect4352" - width="9" - height="2.0000174" - x="6" - y="1043.3622" /> <path - transform="matrix(0,1.2810265,0.92450034,0,964.29952,1037.9571)" - inkscape:transform-center-y="-9.6789057e-05" - d="m 8.122499,-1036.5594 -3.122499,0 -3.122499,0 1.5612495,-2.7042 L 5,-1041.9677 l 1.5612495,2.7041 z" - inkscape:randomized="0" - inkscape:rounded="0" - inkscape:flatsided="false" - sodipodi:arg2="1.5707963" - sodipodi:arg1="0.52359878" - sodipodi:r2="1.8027756" - sodipodi:r1="3.6055512" - sodipodi:cy="-1038.3622" - sodipodi:cx="5" - sodipodi:sides="3" - id="path4435" - style="fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-linecap:round;stroke-opacity:1" - sodipodi:type="star" - inkscape:transform-center-x="1.1667546" /> + style="fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 6 4 L 3.5 6 L 1 8 L 3.5 10 L 6 12 L 6 9 L 15 9 L 15 7 L 6 7 L 6 4 z " + transform="translate(0,1036.3622)" + id="rect4352" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_arrow_right.svg b/tools/editor/icons/source/icon_arrow_right.svg index 860a6f1481..a7600699f7 100644 --- a/tools/editor/icons/source/icon_arrow_right.svg +++ b/tools/editor/icons/source/icon_arrow_right.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="32" - inkscape:cx="6.7465614" - inkscape:cy="9.3227698" + inkscape:cx="0.9028114" + inkscape:cy="9.2602698" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -59,7 +59,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -70,8 +70,9 @@ transform="translate(0,-1036.3622)"> <path style="fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" - d="m 10,1048.3622 2.5,-2 2.5,-2 -2.5,-2 -2.5,-2 0,3 -9,0 0,2 9,0 0,3 z" + d="m 10,1048.3622 5,-4 -5,-4 0,3 -9,0 0,2 9,0 z" id="rect4352" - inkscape:connector-curvature="0" /> + inkscape:connector-curvature="0" + sodipodi:nodetypes="cccccccc" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_auto_play.svg b/tools/editor/icons/source/icon_auto_play.svg index 00bc96aac5..d4e1068ebf 100644 --- a/tools/editor/icons/source/icon_auto_play.svg +++ b/tools/editor/icons/source/icon_auto_play.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="64" - inkscape:cx="6.4431479" - inkscape:cy="7.7277865" + inkscape:zoom="32" + inkscape:cx="9.592521" + inkscape:cy="9.4268437" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -60,7 +60,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -70,40 +70,9 @@ id="layer1" transform="translate(0,-1036.3622)"> <path - style="fill:none;fill-rule:evenodd;stroke:#e0e0e0;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" - d="m 2,1049.3622 0,-10 8,0 4,5 -4,5 z" - id="path4164" - inkscape:connector-curvature="0" /> - <rect - y="1043.3622" - x="4" - height="3.9999824" - width="1" - id="rect4162" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <path - style="fill:#e0e0e0;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1" - d="m 11,1044.3622 -2,-2 0,4 z" - id="path4166" - inkscape:connector-curvature="0" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4168" - width="1" - height="3.9999824" - x="7" - y="1043.3622" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4170" - width="2" - height="0.99994755" - x="5" - y="1044.3622" /> - <path - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 6 5 C 4.8954305 5 4 5.8954 4 7 L 5 7 A 1 1 0 0 1 6 6 A 1 1 0 0 1 7 7 L 8 7 C 8 5.8954 7.1045695 5 6 5 z " + style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;baseline-shift:baseline;text-anchor:start;white-space:normal;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#e0e0e0;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" + d="M 2 2 A 1.0001 1.0001 0 0 0 1 3 L 1 13 A 1.0001 1.0001 0 0 0 2 14 L 10 14 A 1.0001 1.0001 0 0 0 10.78125 13.625 L 14.78125 8.625 A 1.0001 1.0001 0 0 0 14.78125 7.3769531 L 10.78125 2.3769531 A 1.0001 1.0001 0 0 0 10 2 L 2 2 z M 3 4 L 9.5195312 4 L 12.71875 8 L 9.5195312 12 L 3 12 L 3 4 z M 6 5 C 4.8954305 5 4 5.8954 4 7 L 4 11 L 5 11 L 5 9 L 7 9 L 7 11 L 8 11 L 8 7 C 8 5.8954 7.1045695 5 6 5 z M 6 6 A 1 1 0 0 1 7 7 L 7 8 L 5 8 L 5 7 A 1 1 0 0 1 6 6 z M 9 6 L 9 10 L 11 8 L 9 6 z " transform="translate(0,1036.3622)" - id="path4172" /> + id="path4164" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_back_buffer_copy.svg b/tools/editor/icons/source/icon_back_buffer_copy.svg index 150421d7dd..17d83ed73f 100644 --- a/tools/editor/icons/source/icon_back_buffer_copy.svg +++ b/tools/editor/icons/source/icon_back_buffer_copy.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" - inkscape:cx="12.102474" - inkscape:cy="8.4888344" + inkscape:cx="3.8381635" + inkscape:cy="8.4004461" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -59,7 +59,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -68,57 +68,10 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <rect + <path style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4146" - width="2" - height="9" - x="1" - y="1037.3622" /> - <rect - y="1037.3622" - x="1" - height="2.0000174" - width="8" - id="rect4148" - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - y="-1051.3622" - x="-15" - height="9" - width="2" - id="rect4150" - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - transform="scale(-1,-1)" /> - <rect - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4152" - width="7" - height="2.0000174" - x="-15" - y="-1051.3622" - transform="scale(-1,-1)" /> - <rect - transform="scale(-1,-1)" - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4154" - width="2" - height="9" - x="-9" - y="-1051.3622" /> - <rect - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4156" - width="8" - height="2.0000174" - x="7" - y="1040.3622" /> - <rect - style="opacity:1;fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4158" - width="5" - height="2.0000174" - x="1" - y="1046.3622" /> + d="M 1 1 L 1 3 L 1 10 L 1 12 L 6 12 L 6 10 L 3 10 L 3 3 L 9 3 L 9 1 L 3 1 L 1 1 z M 7 4 L 7 6 L 7 15 L 9 15 L 15 15 L 15 13 L 15 6 L 15 4 L 7 4 z M 9 6 L 13 6 L 13 13 L 9 13 L 9 6 z " + transform="translate(0,1036.3622)" + id="rect4146" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_bake.svg b/tools/editor/icons/source/icon_bake.svg index 7f1e9b4ae8..ca07bca379 100644 --- a/tools/editor/icons/source/icon_bake.svg +++ b/tools/editor/icons/source/icon_bake.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" - inkscape:cx="4.5449307" - inkscape:cy="12.981869" + inkscape:cx="-3.7193798" + inkscape:cy="12.893481" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -60,7 +60,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -71,22 +71,8 @@ transform="translate(0,-1036.3622)"> <path style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 1 4 L 1 13 A 2 2.0000174 0 0 0 3 15 L 13 15 A 2 2.0000174 0 0 0 15 13 L 15 4 L 1 4 z M 3 5 L 4 5 L 4 6 L 3 6 L 3 5 z M 6 5 L 7 5 L 7 6 L 6 6 L 6 5 z M 9 5 L 10 5 L 10 6 L 9 6 L 9 5 z M 12 5 L 13 5 L 13 6 L 12 6 L 12 5 z M 3 7 L 13 7 L 13 13 L 3 13 L 3 7 z " + d="M 2 1 L 2 3 L 14 3 L 14 1 L 2 1 z M 1 4 L 1 13 A 2 2.0000174 0 0 0 3 15 L 13 15 A 2 2.0000174 0 0 0 15 13 L 15 4 L 1 4 z M 3 5 L 4 5 L 4 6 L 3 6 L 3 5 z M 6 5 L 7 5 L 7 6 L 6 6 L 6 5 z M 9 5 L 10 5 L 10 6 L 9 6 L 9 5 z M 12 5 L 13 5 L 13 6 L 12 6 L 12 5 z M 3 7 L 13 7 L 13 13 L 3 13 L 3 7 z M 6 8 L 6 9 L 10 9 L 10 8 L 6 8 z " transform="translate(0,1036.3622)" id="rect4155" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4173" - width="12" - height="2.0000174" - x="2" - y="1037.3622" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4159" - width="4" - height="1.0000174" - x="6" - y="1044.3622" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_baked_light.svg b/tools/editor/icons/source/icon_baked_light.svg index 7f1e9b4ae8..98dc3135f6 100644 --- a/tools/editor/icons/source/icon_baked_light.svg +++ b/tools/editor/icons/source/icon_baked_light.svg @@ -18,7 +18,7 @@ inkscape:export-filename="/home/djrm/Projects/godot/tools/editor/icons/icon_bone.png" inkscape:export-xdpi="90" inkscape:export-ydpi="90" - sodipodi:docname="icon_bake.svg"> + sodipodi:docname="icon_baked_light.svg"> <defs id="defs4" /> <sodipodi:namedview @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" - inkscape:cx="4.5449307" - inkscape:cy="12.981869" + inkscape:cx="6.1801151" + inkscape:cy="10.551189" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -60,7 +60,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -71,22 +71,8 @@ transform="translate(0,-1036.3622)"> <path style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 1 4 L 1 13 A 2 2.0000174 0 0 0 3 15 L 13 15 A 2 2.0000174 0 0 0 15 13 L 15 4 L 1 4 z M 3 5 L 4 5 L 4 6 L 3 6 L 3 5 z M 6 5 L 7 5 L 7 6 L 6 6 L 6 5 z M 9 5 L 10 5 L 10 6 L 9 6 L 9 5 z M 12 5 L 13 5 L 13 6 L 12 6 L 12 5 z M 3 7 L 13 7 L 13 13 L 3 13 L 3 7 z " + d="M 2 1 L 2 3 L 14 3 L 14 1 L 2 1 z M 1 4 L 1 13 A 2 2.0000174 0 0 0 3 15 L 13 15 A 2 2.0000174 0 0 0 15 13 L 15 4 L 1 4 z M 3 5 L 4 5 L 4 6 L 3 6 L 3 5 z M 6 5 L 7 5 L 7 6 L 6 6 L 6 5 z M 9 5 L 10 5 L 10 6 L 9 6 L 9 5 z M 12 5 L 13 5 L 13 6 L 12 6 L 12 5 z M 3 7 L 13 7 L 13 13 L 3 13 L 3 7 z M 6 8 L 6 9 L 10 9 L 10 8 L 6 8 z " transform="translate(0,1036.3622)" id="rect4155" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4173" - width="12" - height="2.0000174" - x="2" - y="1037.3622" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4159" - width="4" - height="1.0000174" - x="6" - y="1044.3622" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_baked_light_instance.svg b/tools/editor/icons/source/icon_baked_light_instance.svg index 434bf0f6fc..d854378f12 100644 --- a/tools/editor/icons/source/icon_baked_light_instance.svg +++ b/tools/editor/icons/source/icon_baked_light_instance.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" - inkscape:cx="-3.1006614" - inkscape:cy="12.893481" + inkscape:cx="10.864698" + inkscape:cy="11.302491" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -71,22 +71,8 @@ transform="translate(0,-1036.3622)"> <path style="opacity:1;fill:#fc9c9c;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 1 4 L 1 13 A 2 2.0000174 0 0 0 3 15 L 13 15 A 2 2.0000174 0 0 0 15 13 L 15 4 L 1 4 z M 3 5 L 4 5 L 4 6 L 3 6 L 3 5 z M 6 5 L 7 5 L 7 6 L 6 6 L 6 5 z M 9 5 L 10 5 L 10 6 L 9 6 L 9 5 z M 12 5 L 13 5 L 13 6 L 12 6 L 12 5 z M 3 7 L 13 7 L 13 13 L 3 13 L 3 7 z " + d="M 2 1 L 2 3 L 14 3 L 14 1 L 2 1 z M 1 4 L 1 13 A 2 2.0000174 0 0 0 3 15 L 13 15 A 2 2.0000174 0 0 0 15 13 L 15 4 L 1 4 z M 3 5 L 4 5 L 4 6 L 3 6 L 3 5 z M 6 5 L 7 5 L 7 6 L 6 6 L 6 5 z M 9 5 L 10 5 L 10 6 L 9 6 L 9 5 z M 12 5 L 13 5 L 13 6 L 12 6 L 12 5 z M 3 7 L 13 7 L 13 13 L 3 13 L 3 7 z M 6 8 L 6 9 L 10 9 L 10 8 L 6 8 z " transform="translate(0,1036.3622)" id="rect4155" /> - <rect - style="opacity:1;fill:#fc9c9c;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4173" - width="12" - height="2.0000174" - x="2" - y="1037.3622" /> - <rect - style="opacity:1;fill:#fc9c9c;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4159" - width="4" - height="1.0000174" - x="6" - y="1044.3622" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_baked_light_sampler.svg b/tools/editor/icons/source/icon_baked_light_sampler.svg index aa6e6e26d0..2dc7c39621 100644 --- a/tools/editor/icons/source/icon_baked_light_sampler.svg +++ b/tools/editor/icons/source/icon_baked_light_sampler.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="32" - inkscape:cx="3.5600026" - inkscape:cy="5.9708001" + inkscape:cx="9.2162526" + inkscape:cy="7.9395501" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -71,20 +71,8 @@ transform="translate(0,-1036.3622)"> <path style="opacity:1;fill:#fc9c9c;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 1 4 L 1 13 A 2 2.0000174 0 0 0 3 15 L 7 15 L 7 13 L 3 13 L 3 7 L 7 7 L 13 7 L 15 7 L 15 4 L 1 4 z M 3 5 L 4 5 L 4 6 L 3 6 L 3 5 z M 6 5 L 7 5 L 7 6 L 6 6 L 6 5 z M 9 5 L 10 5 L 10 6 L 9 6 L 9 5 z M 12 5 L 13 5 L 13 6 L 12 6 L 12 5 z M 6 8 L 6 9 L 7 9 L 7 8 L 6 8 z " + d="M 2 1 L 2 3 L 14 3 L 14 1 L 2 1 z M 1 4 L 1 13 A 2 2.0000174 0 0 0 3 15 L 7 15 L 7 13 L 3 13 L 3 7 L 7 7 L 13 7 L 15 7 L 15 4 L 1 4 z M 3 5 L 4 5 L 4 6 L 3 6 L 3 5 z M 6 5 L 7 5 L 7 6 L 6 6 L 6 5 z M 9 5 L 10 5 L 10 6 L 9 6 L 9 5 z M 12 5 L 13 5 L 13 6 L 12 6 L 12 5 z M 6 8 L 6 9 L 7 9 L 7 8 L 6 8 z M 10 9 A 1 1 0 0 0 9 10 L 9 14 A 1 1 0 0 0 10 15 L 14 15 A 1 1 0 0 0 15 14 L 15 10 A 1 1 0 0 0 14 9 L 10 9 z M 13 10 A 1 1 0 0 1 14 11 A 1 1 0 0 1 13 12 A 1 1 0 0 1 12 11 A 1 1 0 0 1 13 10 z M 11 12 A 1 1 0 0 1 12 13 A 1 1 0 0 1 11 14 A 1 1 0 0 1 10 13 A 1 1 0 0 1 11 12 z " transform="translate(0,1036.3622)" id="rect4155" /> - <rect - style="opacity:1;fill:#fc9c9c;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4173" - width="12" - height="2.0000174" - x="2" - y="1037.3622" /> - <path - style="opacity:1;fill:#fc9c9c;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 10 9 A 1 1 0 0 0 9 10 L 9 14 A 1 1 0 0 0 10 15 L 14 15 A 1 1 0 0 0 15 14 L 15 10 A 1 1 0 0 0 14 9 L 10 9 z M 13 10 A 1 1 0 0 1 14 11 A 1 1 0 0 1 13 12 A 1 1 0 0 1 12 11 A 1 1 0 0 1 13 10 z M 11 12 A 1 1 0 0 1 12 13 A 1 1 0 0 1 11 14 A 1 1 0 0 1 10 13 A 1 1 0 0 1 11 12 z " - transform="translate(0,1036.3622)" - id="rect4156" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_bitmap_font.svg b/tools/editor/icons/source/icon_bitmap_font.svg index fa9fdaf5c5..70749923d5 100644 --- a/tools/editor/icons/source/icon_bitmap_font.svg +++ b/tools/editor/icons/source/icon_bitmap_font.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="32" - inkscape:cx="10.302728" - inkscape:cy="7.9861624" + inkscape:cx="5.619442" + inkscape:cy="6.940754" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -60,7 +60,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -69,62 +69,10 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4212" - width="14" - height="2" - x="1" - y="1037.3622" /> - <rect - y="1037.3622" - x="7" - height="14.000017" - width="2" - id="rect4214" - style="opacity:1;fill:#fcef9c;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> - <rect - style="opacity:1;fill:#fcef9c;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4216" - width="6" - height="0.99999976" - x="5" - y="1050.3622" /> - <path - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - d="M 1 1 L 1 3 L 1 5 L 2 5 L 2 4 L 3 4 L 3 3 L 4 3 L 4 1 L 2 1 L 1 1 z " - transform="translate(0,1036.3622)" - id="rect4218" /> <path - style="opacity:1;fill:#be9cfc;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - d="M 12 1 L 12 3 L 13 3 L 13 4 L 14 4 L 14 5 L 15 5 L 15 3 L 15 1 L 14 1 L 12 1 z " - transform="translate(0,1036.3622)" - id="rect4220" /> - <rect - style="opacity:1;fill:#fcef9c;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4259" - width="1" - height="1" - x="9" - y="1049.3622" /> - <rect - y="1049.3622" - x="6" - height="1" - width="1" - id="rect4261" - style="opacity:1;fill:#fcef9c;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> - <path - style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - d="M 4 1 L 4 3 L 7 3 L 7 6 L 9 6 L 9 3 L 12 3 L 12 1 L 4 1 z " - transform="translate(0,1036.3622)" - id="rect4276" /> - <rect - style="opacity:1;fill:#a5b7f8;fill-opacity:0.98823529;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4307" - width="2" - height="5" - x="7" - y="1042.3622" /> + style="opacity:1;fill:#84c2ff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" + d="m 1,1037.3622 0,2 0,2 1,0 0,-1 1,0 0,-1 4,0 0,3 0,5 0,2 -1,0 0,1 -1,0 0,1 6,0 0,-1 -1,0 0,-1 -1,0 0,-10 4,0 0,1 1,0 0,1 1,0 0,-2 0,-2 -13,0 -1,0 z" + id="rect4212" + inkscape:connector-curvature="0" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_canvas_layer.svg b/tools/editor/icons/source/icon_canvas_layer.svg index a26edd7d6d..794d832eea 100644 --- a/tools/editor/icons/source/icon_canvas_layer.svg +++ b/tools/editor/icons/source/icon_canvas_layer.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" - inkscape:cx="-3.1074492" - inkscape:cy="10.973033" + inkscape:cx="-2.2677599" + inkscape:cy="10.08915" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -64,7 +64,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -74,35 +74,9 @@ id="layer1" transform="translate(0,-1036.3622)"> <path - sodipodi:nodetypes="cscsccccsssc" - inkscape:connector-curvature="0" - id="path4146" - d="m 2.920797,1046.3957 c -0.2637264,0.3 -0.4203983,0.7296 -0.4203983,1.2383 0,1.6277 -3.13814186,-0.1781 -0.337569,2.6703 0.8838207,0.899 2.6543881,0.6701 3.538224,-0.2288 0.8838352,-0.899 0.8838163,-2.3565 0,-3.2554 -1.1002211,-1.1191 -2.200058,-1.0845 -2.7802567,-0.4244 z m 2.3801743,-1.6103 2.4004918,2.4416 6.8013899,-6.9177 c 0.662863,-0.6742 0.662863,-1.7673 0,-2.4415 -0.662877,-0.6741 -1.737613,-0.6741 -2.400491,0 z" - style="fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> - <path - style="opacity:1;fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 3 1 A 2 2 0 0 0 1 3 L 2 3 A 1.0000174 1.0000174 0 0 1 3 2 L 3 1 z " + style="fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 3 1 A 2 2 0 0 0 1 3 L 1 9 L 2 9 L 2 3 A 1.0000174 1.0000174 0 0 1 3 2 L 9 2 L 9 1 L 3 1 z M 13.302734 1 C 12.868331 1 12.433001 1.1688094 12.101562 1.5058594 L 5.3007812 8.4238281 L 7.7011719 10.865234 L 14.501953 3.9472656 C 15.164816 3.2730656 15.164816 2.1800594 14.501953 1.5058594 C 14.170515 1.1688094 13.737138 1 13.302734 1 z M 14 7 L 14 13 A 1.0000174 1.0000174 0 0 1 13 14 L 7 14 L 7 15 L 13 15 A 2 2 0 0 0 15 13 L 15 7 L 14 7 z M 4.1152344 9.578125 C 3.6302227 9.5294 3.2100212 9.7031531 2.9199219 10.033203 C 2.6561955 10.333203 2.5 10.762784 2.5 11.271484 C 2.5 12.899184 -0.63846349 11.093006 2.1621094 13.941406 C 3.0459301 14.840406 4.817336 14.611791 5.7011719 13.712891 C 6.5850071 12.813891 6.5849882 11.355931 5.7011719 10.457031 C 5.1510613 9.8974813 4.6002461 9.62685 4.1152344 9.578125 z " transform="translate(0,1036.3622)" - id="path4160" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4164" - width="6" - height="1" - x="3" - y="1037.3622" /> - <rect - y="-2" - x="1039.3622" - height="1" - width="6" - id="rect4166" - style="opacity:1;fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - transform="matrix(0,1,-1,0,0,0)" /> - <path - style="opacity:1;fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="m 13,1051.3622 a 2,2 0 0 0 2,-2 l 0,-6 -1,0 0,6 a 1.0000174,1.0000174 0 0 1 -1,1 l -6,0 0,1 6,0 z" - id="path4169" - inkscape:connector-curvature="0" /> + id="path4146" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_canvas_modulate.svg b/tools/editor/icons/source/icon_canvas_modulate.svg index 450823e005..8f8bd55f82 100644 --- a/tools/editor/icons/source/icon_canvas_modulate.svg +++ b/tools/editor/icons/source/icon_canvas_modulate.svg @@ -20,7 +20,44 @@ inkscape:export-ydpi="90" sodipodi:docname="icon_canvas_modulate.svg"> <defs - id="defs4" /> + id="defs4"> + <clipPath + id="clipPath4253" + clipPathUnits="userSpaceOnUse"> + <path + inkscape:connector-curvature="0" + id="path4255" + d="m 16.458984,1024.37 a 12.000027,12.000027 0 0 0 -3.564453,0.4004 12.000027,12.000027 0 0 0 -8.4863279,14.6973 12.000027,12.000027 0 0 0 14.6972659,8.4863 12.000027,12.000027 0 0 0 8.486328,-14.6973 12.000027,12.000027 0 0 0 -11.132813,-8.8867 z M 16.25,1029.8212 a 6.5451717,6.5451717 0 0 1 6.072266,4.8476 6.5451717,6.5451717 0 0 1 -4.628907,8.0157 6.5451717,6.5451717 0 0 1 -8.0156246,-4.6289 6.5451717,6.5451717 0 0 1 4.6289066,-8.0157 6.5451717,6.5451717 0 0 1 1.943359,-0.2187 z" + style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </clipPath> + <clipPath + id="clipPath4199" + clipPathUnits="userSpaceOnUse"> + <path + style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + d="m 16.5,1025.8622 a 11.8125,10.499999 0 0 0 -11.8125001,10.5 11.8125,10.499999 0 0 0 11.8125001,10.5 11.8125,10.499999 0 0 0 11.8125,-10.5 11.8125,10.499999 0 0 0 -11.8125,-10.5 z m -3.375,3 a 3.375,2.9999997 0 0 1 3.375,3 3.375,2.9999997 0 0 1 -3.375,3 3.375,2.9999997 0 0 1 -3.3750001,-3 3.375,2.9999997 0 0 1 3.3750001,-3 z" + id="path4201" + inkscape:connector-curvature="0" /> + </clipPath> + <clipPath + clipPathUnits="userSpaceOnUse" + id="clipPath4392"> + <path + style="fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m 8.072266,1041.3622 a 5,5 0 0 0 -3.607422,1.4648 5,5 0 0 0 0,7.0704 5,5 0 0 0 7.070312,0 l -1.416015,-1.4161 A 3,3 0 0 1 8,1049.3622 a 3,3 0 0 1 -3,-3 3,3 0 0 1 3,-3 3,3 0 0 1 2.119141,0.8809 l 1.416015,-1.4161 a 5,5 0 0 0 -3.46289,-1.4648 z" + id="path4394" + inkscape:connector-curvature="0" /> + </clipPath> + <clipPath + id="clipPath4196" + clipPathUnits="userSpaceOnUse"> + <path + inkscape:connector-curvature="0" + id="path4198" + d="m 8.0624999,1025.8622 a 3.375,2.9999997 0 0 0 -3.375,3 3.375,2.9999997 0 0 0 1.6875,2.5957 l 0,9.8115 a 3.375,2.9999997 0 0 0 -1.6875,2.5928 3.375,2.9999997 0 0 0 3.375,3 3.375,2.9999997 0 0 0 3.3750001,-3 3.375,2.9999997 0 0 0 -1.6875001,-2.5957 l 0,-8.7832 11.9311511,10.6054 a 3.375,2.9999997 0 0 0 -0.118651,0.7735 3.375,2.9999997 0 0 0 3.375,3 3.375,2.9999997 0 0 0 3.375,-3 3.375,2.9999997 0 0 0 -3.375,-3 3.375,2.9999997 0 0 0 -0.873413,0.1025 l -11.927857,-10.6025 9.884399,0 a 3.375,2.9999997 0 0 0 2.916871,1.5 3.375,2.9999997 0 0 0 3.375,-3 3.375,2.9999997 0 0 0 -3.375,-3 3.375,2.9999997 0 0 0 -2.920166,1.5 l -11.037964,0 a 3.375,2.9999997 0 0 0 -2.9168701,-1.5 z" + style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + </clipPath> + </defs> <sodipodi:namedview id="base" pagecolor="#ffffff" @@ -28,9 +65,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="16" - inkscape:cx="7.3785882" - inkscape:cy="11.139886" + inkscape:zoom="45.254834" + inkscape:cx="10.091501" + inkscape:cy="9.4358129" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -46,7 +83,10 @@ inkscape:window-height="1016" inkscape:window-x="0" inkscape:window-y="27" - inkscape:window-maximized="1"> + inkscape:window-maximized="1" + inkscape:snap-midpoints="true" + inkscape:snap-smooth-nodes="true" + inkscape:object-nodes="true"> <inkscape:grid type="xygrid" id="grid3336" @@ -60,7 +100,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -69,39 +109,29 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <rect - style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" - id="rect4159" - width="10" - height="10.000017" - x="3" - y="1039.3622" /> <path style="fill:#a5b7f1;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" - d="m 1,1037.3622 0,2 0,12 2,0 12,0 0,-2 0,-12 -2,0 -10,0 z m 2,2 10,0 0,10 -10,0 z" + d="m 1,1037.3622 0,14 14,0 0,-14 z m 2,2 10,0 0,10 -10,0 z" id="rect4280" inkscape:connector-curvature="0" - sodipodi:nodetypes="ccccccccccccccc" /> - <ellipse - style="fill:#ff0000;fill-opacity:0.78431373;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" - id="path4153" - cx="6.5" - cy="1045.8622" - rx="2.5" - ry="2.4999871" /> - <ellipse - style="fill:#0000ff;fill-opacity:0.78431373;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" - id="ellipse4157" - cx="8" - cy="1042.8622" - rx="2.5" - ry="2.4999938" /> - <ellipse - ry="2.4999936" - rx="2.5" - cy="1045.8622" - cx="9.5" - id="ellipse4155" - style="fill:#00ff00;fill-opacity:0.78431373;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + sodipodi:nodetypes="cccccccccc" /> + <path + inkscape:connector-curvature="0" + id="path4183" + d="m 12,1048.3622 -5,0 5,-5 z" + style="fill:#70bfff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + sodipodi:nodetypes="cccc" /> + <path + style="fill:#ff7070;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="m 4,1040.3622 5,0 -5,5 z" + id="path4185" + inkscape:connector-curvature="0" + sodipodi:nodetypes="cccc" /> + <path + sodipodi:nodetypes="ccccccc" + inkscape:connector-curvature="0" + id="path4187" + d="m 4,1048.3622 0,-3 5,-5 3,0 0,3 -5,5 z" + style="fill:#7aff70;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_color_rect.svg b/tools/editor/icons/source/icon_color_rect.svg new file mode 100644 index 0000000000..76bf6596a9 --- /dev/null +++ b/tools/editor/icons/source/icon_color_rect.svg @@ -0,0 +1,156 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="16" + height="16" + viewBox="0 0 16 16" + id="svg2" + version="1.1" + inkscape:version="0.91 r13725" + inkscape:export-filename="/home/djrm/Projects/godot/tools/editor/icons/icon_center_container.png" + inkscape:export-xdpi="90" + inkscape:export-ydpi="90" + sodipodi:docname="icon_color_rect.svg"> + <defs + id="defs4"> + <clipPath + clipPathUnits="userSpaceOnUse" + id="clipPath4253"> + <path + style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m 16.458984,1024.37 a 12.000027,12.000027 0 0 0 -3.564453,0.4004 12.000027,12.000027 0 0 0 -8.4863279,14.6973 12.000027,12.000027 0 0 0 14.6972659,8.4863 12.000027,12.000027 0 0 0 8.486328,-14.6973 12.000027,12.000027 0 0 0 -11.132813,-8.8867 z M 16.25,1029.8212 a 6.5451717,6.5451717 0 0 1 6.072266,4.8476 6.5451717,6.5451717 0 0 1 -4.628907,8.0157 6.5451717,6.5451717 0 0 1 -8.0156246,-4.6289 6.5451717,6.5451717 0 0 1 4.6289066,-8.0157 6.5451717,6.5451717 0 0 1 1.943359,-0.2187 z" + id="path4255" + inkscape:connector-curvature="0" /> + </clipPath> + <clipPath + clipPathUnits="userSpaceOnUse" + id="clipPath4199"> + <path + inkscape:connector-curvature="0" + id="path4201" + d="m 16.5,1025.8622 a 11.8125,10.499999 0 0 0 -11.8125001,10.5 11.8125,10.499999 0 0 0 11.8125001,10.5 11.8125,10.499999 0 0 0 11.8125,-10.5 11.8125,10.499999 0 0 0 -11.8125,-10.5 z m -3.375,3 a 3.375,2.9999997 0 0 1 3.375,3 3.375,2.9999997 0 0 1 -3.375,3 3.375,2.9999997 0 0 1 -3.3750001,-3 3.375,2.9999997 0 0 1 3.3750001,-3 z" + style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + </clipPath> + <clipPath + id="clipPath4392" + clipPathUnits="userSpaceOnUse"> + <path + inkscape:connector-curvature="0" + id="path4394" + d="m 8.072266,1041.3622 a 5,5 0 0 0 -3.607422,1.4648 5,5 0 0 0 0,7.0704 5,5 0 0 0 7.070312,0 l -1.416015,-1.4161 A 3,3 0 0 1 8,1049.3622 a 3,3 0 0 1 -3,-3 3,3 0 0 1 3,-3 3,3 0 0 1 2.119141,0.8809 l 1.416015,-1.4161 a 5,5 0 0 0 -3.46289,-1.4648 z" + style="fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </clipPath> + <clipPath + clipPathUnits="userSpaceOnUse" + id="clipPath4196"> + <path + style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + d="m 8.0624999,1025.8622 a 3.375,2.9999997 0 0 0 -3.375,3 3.375,2.9999997 0 0 0 1.6875,2.5957 l 0,9.8115 a 3.375,2.9999997 0 0 0 -1.6875,2.5928 3.375,2.9999997 0 0 0 3.375,3 3.375,2.9999997 0 0 0 3.3750001,-3 3.375,2.9999997 0 0 0 -1.6875001,-2.5957 l 0,-8.7832 11.9311511,10.6054 a 3.375,2.9999997 0 0 0 -0.118651,0.7735 3.375,2.9999997 0 0 0 3.375,3 3.375,2.9999997 0 0 0 3.375,-3 3.375,2.9999997 0 0 0 -3.375,-3 3.375,2.9999997 0 0 0 -0.873413,0.1025 l -11.927857,-10.6025 9.884399,0 a 3.375,2.9999997 0 0 0 2.916871,1.5 3.375,2.9999997 0 0 0 3.375,-3 3.375,2.9999997 0 0 0 -3.375,-3 3.375,2.9999997 0 0 0 -2.920166,1.5 l -11.037964,0 a 3.375,2.9999997 0 0 0 -2.9168701,-1.5 z" + id="path4198" + inkscape:connector-curvature="0" /> + </clipPath> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="32" + inkscape:cx="9.9050022" + inkscape:cy="11.383887" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="true" + units="px" + inkscape:snap-bbox="true" + inkscape:bbox-paths="true" + inkscape:bbox-nodes="true" + inkscape:snap-bbox-edge-midpoints="true" + inkscape:snap-bbox-midpoints="true" + inkscape:snap-object-midpoints="true" + inkscape:snap-center="true" + inkscape:window-width="1920" + inkscape:window-height="1016" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:snap-smooth-nodes="true" + inkscape:snap-midpoints="true" + inkscape:object-nodes="true"> + <inkscape:grid + type="xygrid" + id="grid3336" /> + </sodipodi:namedview> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(0,-1036.3622)"> + <rect + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect4154" + width="1" + height="14" + x="1" + y="1037.3622" /> + <rect + y="1050.3622" + x="1" + height="0.9999826" + width="14" + id="rect4156" + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + <rect + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect4158" + width="14" + height="0.9999826" + x="1" + y="1037.3622" /> + <rect + y="1037.3622" + x="14" + height="14" + width="1" + id="rect4160" + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + <path + style="fill:#70bfff;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1" + d="m 13,1049.3622 -6,0 6,-6 z" + id="path4168" + inkscape:connector-curvature="0" /> + <path + inkscape:connector-curvature="0" + id="path4170" + d="m 3,1039.3622 6,0 -6,6 z" + style="fill:#ff7070;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> + <path + style="fill:#7aff70;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="m 3,1049.3622 0,-4 6,-6 4,0 0,4 -6,6 z" + id="path4172" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ccccccc" /> + </g> +</svg> diff --git a/tools/editor/icons/source/icon_connect.svg b/tools/editor/icons/source/icon_connect.svg index 2261765bdf..745d3cc436 100644 --- a/tools/editor/icons/source/icon_connect.svg +++ b/tools/editor/icons/source/icon_connect.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627418" - inkscape:cx="9.0509434" - inkscape:cy="11.261328" + inkscape:cx="0.78663326" + inkscape:cy="12.940707" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -59,7 +59,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -68,52 +68,10 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <rect - y="1043.3622" - x="1" - height="1.9999478" - width="5" - id="rect4155" - style="fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4157" - width="4" - height="12" - x="7" - y="1038.3622" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4159" - width="3" - height="2" - x="11" - y="1040.3622" /> - <rect - y="1046.3622" - x="11" - height="2" - width="3" - id="rect4161" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <circle - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="path4163" - cx="7" - cy="1040.3622" - r="2" /> - <rect - y="1040.3622" - x="5" - height="8.0000172" - width="4" - id="rect4165" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <circle - r="2" - cy="1048.3622" - cx="7" - id="circle4167" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + <path + style="fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 7 2 A 2 2 0 0 0 5 4 L 5 7 L 1 7 L 1 9 L 5 9 L 5 12 A 2 2 0 0 0 7 14 L 11 14 L 11 12 L 14 12 L 14 10 L 11 10 L 11 6 L 14 6 L 14 4 L 11 4 L 11 2 L 7 2 z " + transform="translate(0,1036.3622)" + id="rect4155" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_connection_and_groups.svg b/tools/editor/icons/source/icon_connection_and_groups.svg index 97f615d9bc..5468312b4b 100644 --- a/tools/editor/icons/source/icon_connection_and_groups.svg +++ b/tools/editor/icons/source/icon_connection_and_groups.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627418" - inkscape:cx="4.8878469" - inkscape:cy="12.667351" + inkscape:cx="-3.3764632" + inkscape:cy="12.578963" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -68,97 +68,10 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <rect - y="1048.3622" - x="2" - height="0.99993038" - width="6" - id="rect4155" - style="fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4157" - width="2" - height="6.9999485" - x="10" - y="1045.3622" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4159" - width="2" - height="0.9999826" - x="12" - y="1046.3622" /> - <rect - y="1050.3622" - x="12" - height="0.9999826" - width="2" - id="rect4161" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <ellipse - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="path4163" - cx="10" - cy="1047.3622" - rx="2" - ry="1.9999913" /> - <circle - r="2" - cy="1050.3622" - cx="10" - id="circle4167" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - y="1047.3623" - x="8" - height="2.9998953" - width="2" - id="rect4201" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4203" - width="12" - height="1" - x="2" - y="1036.3622" /> - <rect - y="1042.3622" - x="2" - height="1" - width="12" - id="rect4205" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <rect - y="-3" - x="1036.3622" - height="1" - width="6.0000348" - id="rect4207" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - transform="matrix(0,1,-1,0,0,0)" /> - <rect - transform="matrix(0,1,-1,0,0,0)" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4209" - width="6.0000348" - height="1" - x="1036.3622" - y="-14" /> - <ellipse - ry="1.5000032" - rx="1.5" - cy="1039.8622" - cx="5.5" - id="ellipse4214" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <ellipse - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="ellipse4216" - cx="10.5" - cy="1039.8622" - rx="1.5" - ry="1.5000032" /> + <path + style="fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 2 0 L 2 1 L 2 6 L 2 7 L 14 7 L 14 6 L 14 0 L 3 0 L 2 0 z M 3 1 L 13 1 L 13 6 L 3 6 L 3 1 z M 5.5 2 A 1.5 1.5000032 0 0 0 4 3.5 A 1.5 1.5000032 0 0 0 5.5 5 A 1.5 1.5000032 0 0 0 7 3.5 A 1.5 1.5000032 0 0 0 5.5 2 z M 10.5 2 A 1.5 1.5000032 0 0 0 9 3.5 A 1.5 1.5000032 0 0 0 10.5 5 A 1.5 1.5000032 0 0 0 12 3.5 A 1.5 1.5000032 0 0 0 10.5 2 z M 10 9 A 2 1.9999913 0 0 0 8 11 L 8 12 L 2 12 L 2 13 L 8 13 L 8 14 A 2 2 0 0 0 10 16 L 12 16 L 12 15 L 14 15 L 14 14 L 12 14 L 12 11 L 14 11 L 14 10 L 12 10 L 12 9 L 10 9 z " + transform="translate(0,1036.3622)" + id="rect4155" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_copy_node_path.svg b/tools/editor/icons/source/icon_copy_node_path.svg new file mode 100644 index 0000000000..9f33c5e54d --- /dev/null +++ b/tools/editor/icons/source/icon_copy_node_path.svg @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="16" + height="16" + viewBox="0 0 16 16" + id="svg2" + version="1.1" + inkscape:version="0.91 r13725" + inkscape:export-filename="/home/godotengine/godot/tools/editor/icons/con_script_create.png" + inkscape:export-xdpi="90" + inkscape:export-ydpi="90" + sodipodi:docname="icon_copy_node_path.svg"> + <defs + id="defs4"> + <clipPath + id="clipPath4253" + clipPathUnits="userSpaceOnUse"> + <path + inkscape:connector-curvature="0" + id="path4255" + d="m 16.458984,1024.37 a 12.000027,12.000027 0 0 0 -3.564453,0.4004 12.000027,12.000027 0 0 0 -8.4863279,14.6973 12.000027,12.000027 0 0 0 14.6972659,8.4863 12.000027,12.000027 0 0 0 8.486328,-14.6973 12.000027,12.000027 0 0 0 -11.132813,-8.8867 z M 16.25,1029.8212 a 6.5451717,6.5451717 0 0 1 6.072266,4.8476 6.5451717,6.5451717 0 0 1 -4.628907,8.0157 6.5451717,6.5451717 0 0 1 -8.0156246,-4.6289 6.5451717,6.5451717 0 0 1 4.6289066,-8.0157 6.5451717,6.5451717 0 0 1 1.943359,-0.2187 z" + style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </clipPath> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="21.189633" + inkscape:cx="12.640765" + inkscape:cy="9.6848443" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="true" + units="px" + inkscape:snap-bbox="true" + inkscape:bbox-paths="true" + inkscape:bbox-nodes="true" + inkscape:snap-bbox-edge-midpoints="true" + inkscape:snap-bbox-midpoints="true" + inkscape:snap-object-midpoints="true" + inkscape:snap-center="true" + inkscape:window-width="1920" + inkscape:window-height="1016" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + showguides="false" + inkscape:snap-smooth-nodes="true" + inkscape:object-nodes="true"> + <inkscape:grid + type="xygrid" + id="grid3336" + empspacing="4" /> + </sodipodi:namedview> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(0,-1036.3622)"> + <circle + cy="1048.3622" + cx="3" + id="ellipse4234" + style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" + ry="1.0000174" + rx="1" /> + <path + style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="M 2 1 C 1.4477381 1.0001 1.0000552 1.4477 1 2 L 1 14 C 1.0000552 14.5523 1.4477381 14.9999 2 15 L 14 15 C 14.552262 14.9999 14.999945 14.5523 15 14 L 15 6 L 10 1 L 2 1 z M 3 3 L 9 3 L 9 6 C 9 6.554 9.4459905 7 10 7 L 13 7 L 13 13 L 3 13 L 3 3 z M 6 8 L 4 12 L 6 12 L 8 8 L 6 8 z M 10 8 L 8 12 L 10 12 L 12 8 L 10 8 z " + transform="translate(0,1036.3622)" + id="rect4178" /> + </g> +</svg> diff --git a/tools/editor/icons/source/icon_create_new_scene_from.svg b/tools/editor/icons/source/icon_create_new_scene_from.svg index f5a456773c..529553bbd3 100644 --- a/tools/editor/icons/source/icon_create_new_scene_from.svg +++ b/tools/editor/icons/source/icon_create_new_scene_from.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" - inkscape:cx="4.1061535" - inkscape:cy="9.360052" + inkscape:cx="-3.7255471" + inkscape:cy="8.1847434" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -46,7 +46,10 @@ inkscape:window-height="1016" inkscape:window-x="0" inkscape:window-y="27" - inkscape:window-maximized="1"> + inkscape:window-maximized="1" + inkscape:snap-midpoints="true" + inkscape:snap-smooth-nodes="true" + inkscape:object-nodes="true"> <inkscape:grid type="xygrid" id="grid3336" /> @@ -59,7 +62,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -70,9 +73,11 @@ transform="translate(0,-1036.3622)"> <path style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 1 7 L 1 13 A 2 2 0 0 0 3 15 L 15 15 L 15 7 L 1 7 z M 4 9 L 5 9 L 5 11 L 7 11 L 7 12 L 5 12 L 5 14 L 4 14 L 4 12 L 2 12 L 2 11 L 4 11 L 4 9 z " + d="m 1,7 0,6 c 0,1.104569 0.8954305,2 2,2 l 7,0 0,-1 -2,0 0,-4 2,0 0,-2 4,0 0,2 1,0 0,-3 z" transform="translate(0,1036.3622)" - id="rect4136" /> + id="rect4136" + inkscape:connector-curvature="0" + sodipodi:nodetypes="cssccccccccccc" /> <path style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" d="M 0.7112932,1040.3831 1,1042.3622 l 2.2438279,-0.3273 -0.8182578,-1.9018 -1.7142769,0.25 z m 3.6933293,-0.5387 0.8182578,1.9018 1.9790524,-0.2887 -0.8182579,-1.9018 -1.9790523,0.2887 z m 3.9581047,-0.5775 0.8182579,1.9018 1.9790519,-0.2887 -0.818257,-1.9018 -1.9790528,0.2887 z m 3.9581048,-0.5774 0.818258,1.9018 1.714277,-0.25 -0.288707,-1.9791 -2.243828,0.3273 z" @@ -80,5 +85,17 @@ inkscape:connector-curvature="0" inkscape:transform-center-x="-6.7823301" inkscape:transform-center-y="-2" /> + <circle + r="0" + cy="1047.3622" + cx="-14" + id="ellipse4234" + style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> + <path + sodipodi:nodetypes="ccccccccccccc" + inkscape:connector-curvature="0" + id="path4155" + d="m 13,1049.3622 2,0 0,-2 -2,0 0,-2 -2,0 0,2 -2,0 0,2 2,0 0,2 2,0 z" + style="fill:#84ffb1;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_dynamic_font_data.svg b/tools/editor/icons/source/icon_dynamic_font_data.svg index 468b472d7e..9f06172fef 100644 --- a/tools/editor/icons/source/icon_dynamic_font_data.svg +++ b/tools/editor/icons/source/icon_dynamic_font_data.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="32" - inkscape:cx="1.442498" - inkscape:cy="7.5824259" + inkscape:cx="6.4667889" + inkscape:cy="8.2902868" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -69,10 +69,10 @@ id="layer1" transform="translate(0,-1036.3622)"> <path - id="path4246" - d="m 1,1037.3622 0,2 0,1 1,0 a 1,1 0 0 1 1,-1 l 2,0 0,6 a 1,1 0 0 1 -1,1 l 0,1 1,0 2,0 1,0 0,-1 a 1,1 0 0 1 -1,-1 l 0,-6 2,0 a 1,1 0 0 1 1,1 l 1,0 0,-1 0,-2 -4,0 -2,0 -4,0 z" style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - inkscape:connector-curvature="0" /> + d="M 1 1 L 1 3 L 1 4 L 2 4 A 1 1 0 0 1 3 3 L 5 3 L 5 9 A 1 1 0 0 1 4 10 L 4 11 L 5 11 L 7 11 L 8 11 L 8 10 A 1 1 0 0 1 7 9 L 7 3 L 9 3 A 1 1 0 0 1 10 4 L 11 4 L 11 3 L 11 1 L 7 1 L 5 1 L 1 1 z M 1 6 L 1 8 L 3 8 L 3 6 L 1 6 z M 1 9 L 1 11 L 3 11 L 3 9 L 1 9 z M 1 12 L 1 14 L 3 14 L 3 12 L 1 12 z M 4 12 L 4 14 L 6 14 L 6 12 L 4 12 z " + transform="translate(0,1036.3622)" + id="path4246" /> <path style="opacity:1;fill:#ff8484;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" d="M 4 5 L 4 7 L 4 8 L 5 8 A 1 1 0 0 1 6 7 L 8 7 L 8 13 A 1 1 0 0 1 7 14 L 7 15 L 8 15 L 10 15 L 11 15 L 11 14 A 1 1 0 0 1 10 13 L 10 7 L 12 7 A 1 1 0 0 1 13 8 L 14 8 L 14 7 L 14 5 L 10 5 L 8 5 L 4 5 z " diff --git a/tools/editor/icons/source/icon_error.svg b/tools/editor/icons/source/icon_error.svg index 831bac859a..a0b04a98cb 100644 --- a/tools/editor/icons/source/icon_error.svg +++ b/tools/editor/icons/source/icon_error.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627416" - inkscape:cx="-12.047246" - inkscape:cy="6.3485985" + inkscape:cx="5.542036" + inkscape:cy="14.568715" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -75,6 +75,7 @@ width="8" height="8" x="2.220446e-16" - y="1044.3622" /> + y="1044.3622" + ry="1.0000174" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_fixed_spatial_material.svg b/tools/editor/icons/source/icon_fixed_spatial_material.svg index 575b0d06c6..7ae0f93ffc 100644 --- a/tools/editor/icons/source/icon_fixed_spatial_material.svg +++ b/tools/editor/icons/source/icon_fixed_spatial_material.svg @@ -7,7 +7,6 @@ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="16" @@ -22,38 +21,6 @@ sodipodi:docname="icon_fixed_spatial_material.svg"> <defs id="defs4"> - <linearGradient - inkscape:collect="always" - id="linearGradient4257"> - <stop - style="stop-color:#ff70ac;stop-opacity:1" - offset="0" - id="stop4259" /> - <stop - id="stop4273" - offset="0.17862372" - style="stop-color:#9f70ff;stop-opacity:1" /> - <stop - id="stop4271" - offset="0.3572498" - style="stop-color:#70deff;stop-opacity:1" /> - <stop - id="stop4269" - offset="0.53587586" - style="stop-color:#70ffb9;stop-opacity:1" /> - <stop - id="stop4267" - offset="0.71450192" - style="stop-color:#9dff70;stop-opacity:1" /> - <stop - id="stop4265" - offset="0.89312798" - style="stop-color:#ffeb70;stop-opacity:1" /> - <stop - style="stop-color:#ff7070;stop-opacity:1" - offset="1" - id="stop4261" /> - </linearGradient> <clipPath id="clipPath4189" clipPathUnits="userSpaceOnUse"> @@ -63,17 +30,33 @@ d="m 6.3750001,1025.8622 a 1.6876688,1.5001498 0 0 0 -1.6875,1.5 l 0,18 a 1.6876688,1.5001498 0 0 0 1.6875,1.5 l 10.1217039,0 c -0.747392,-0.8796 -1.304338,-1.8888 -1.562256,-3 l -6.8719479,0 0,-15 16.8749999,0 0,3.3486 a 3.4281247,3.0472216 0 0 1 1.282105,1.1279 c 0.537834,0.828 1.294284,1.677 2.092895,2.5723 l 0,-8.5488 a 1.6876688,1.5001498 0 0 0 -1.6875,-1.5 l -20.2499999,0 z m 11.8124999,4.5 0,1.5 -1.6875,0 0,1.5 -3.375,0 0,1.5 -1.6875,0 0,1.5 -1.6874999,0 0,1.5 3.3749999,0 3.375,0 0.02637,0 c 0.246127,-0.317 0.496441,-0.6239 0.738282,-0.9053 1.145331,-1.3327 2.270672,-2.4711 3.015746,-3.6182 a 3.4281247,3.0472216 0 0 1 1.282105,-1.1279 l 0,-0.3486 -1.6875,0 0,-1.5 -1.6875,0 z m 5.0625,4.5 c -1.948558,3 -5.0625,5.0146 -5.0625,7.5 0,2.4853 2.266559,4.5 5.0625,4.5 2.795941,0 5.0625,-2.0147 5.0625,-4.5 0,-2.4854 -3.113942,-4.5 -5.0625,-7.5 z" style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;baseline-shift:baseline;text-anchor:start;white-space:normal;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" /> </clipPath> - <radialGradient - inkscape:collect="always" - xlink:href="#linearGradient4257" - id="radialGradient4263" - cx="13.333239" - cy="1043.3622" - fx="13.333239" - fy="1043.3622" - r="7" - gradientUnits="userSpaceOnUse" - gradientTransform="matrix(-0.93305925,0.79975529,-0.85714494,-0.99999821,914.75331,2076.0592)" /> + <clipPath + id="clipPath4253" + clipPathUnits="userSpaceOnUse"> + <path + inkscape:connector-curvature="0" + id="path4255" + d="m 16.458984,1024.37 a 12.000027,12.000027 0 0 0 -3.564453,0.4004 12.000027,12.000027 0 0 0 -8.4863279,14.6973 12.000027,12.000027 0 0 0 14.6972659,8.4863 12.000027,12.000027 0 0 0 8.486328,-14.6973 12.000027,12.000027 0 0 0 -11.132813,-8.8867 z M 16.25,1029.8212 a 6.5451717,6.5451717 0 0 1 6.072266,4.8476 6.5451717,6.5451717 0 0 1 -4.628907,8.0157 6.5451717,6.5451717 0 0 1 -8.0156246,-4.6289 6.5451717,6.5451717 0 0 1 4.6289066,-8.0157 6.5451717,6.5451717 0 0 1 1.943359,-0.2187 z" + style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + </clipPath> + <clipPath + clipPathUnits="userSpaceOnUse" + id="clipPath4208"> + <path + style="fill:none;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="m 4.6875001,1042.3622 11.8124999,4.5 11.8125,-4.5 0,-12 -11.8125,-4.5 -11.8124999,4.5 z" + id="path4210" + inkscape:connector-curvature="0" /> + </clipPath> + <clipPath + clipPathUnits="userSpaceOnUse" + id="clipPath4199"> + <path + inkscape:connector-curvature="0" + id="path4201" + d="m 16.5,1025.8622 a 11.8125,10.499999 0 0 0 -11.8125001,10.5 11.8125,10.499999 0 0 0 11.8125001,10.5 11.8125,10.499999 0 0 0 11.8125,-10.5 11.8125,10.499999 0 0 0 -11.8125,-10.5 z m -3.375,3 a 3.375,2.9999997 0 0 1 3.375,3 3.375,2.9999997 0 0 1 -3.375,3 3.375,2.9999997 0 0 1 -3.3750001,-3 3.375,2.9999997 0 0 1 3.3750001,-3 z" + style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + </clipPath> </defs> <sodipodi:namedview id="base" @@ -83,8 +66,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" - inkscape:cx="12.314693" - inkscape:cy="10.250946" + inkscape:cx="11.899872" + inkscape:cy="11.262807" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -118,7 +101,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -127,21 +110,60 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <path - inkscape:connector-curvature="0" - style="fill:url(#radialGradient4263);fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" - d="m 8,1037.3622 -7,3 0,8 7,3 7,-3 0,-8 -7,-3 z" - id="path4151" /> - <path - style="fill:#ffffff;fill-opacity:0.72222221;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" - d="m 1,1040.3622 7,3 7,-3 -7,-3 z" - id="path4149" - inkscape:connector-curvature="0" /> - <path - inkscape:connector-curvature="0" - id="path4145" - d="m 8,1051.3622 7,-3 0,-8 -7,3 z" - style="fill:#000000;fill-opacity:0.46969697;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" - sodipodi:nodetypes="ccccc" /> + <g + id="g4181" + mask="none" + clip-path="url(#clipPath4199)" + transform="matrix(0.59259259,0,0,0.66666674,-1.7777777,353.454)"> + <rect + y="1025.8622" + x="3" + height="3.0000043" + width="27" + id="rect4159" + style="fill:#ff7070;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + style="fill:#ffeb70;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect4161" + width="27" + height="3.0000041" + x="3" + y="1028.8622" /> + <rect + style="fill:#9dff70;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect4163" + width="27" + height="2.9999995" + x="3" + y="1031.8622" /> + <rect + y="1034.8622" + x="3" + height="3.0000031" + width="27" + id="rect4165" + style="fill:#70ffb9;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + y="1037.8622" + x="3" + height="3.0000029" + width="27" + id="rect4167" + style="fill:#70deff;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <rect + style="fill:#ff70ac;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect4169" + width="27" + height="2.9999976" + x="3" + y="1043.8622" /> + <rect + style="fill:#9f70ff;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect4146" + width="27" + height="3.0000029" + x="3" + y="1040.8622" /> + </g> </g> </svg> diff --git a/tools/editor/icons/source/icon_key_next.svg b/tools/editor/icons/source/icon_key_next.svg index 4155255434..942245305c 100644 --- a/tools/editor/icons/source/icon_key_next.svg +++ b/tools/editor/icons/source/icon_key_next.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="32" - inkscape:cx="3.6318496" - inkscape:cy="7.8283625" + inkscape:zoom="45.254834" + inkscape:cx="8.9672408" + inkscape:cy="7.1977527" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -59,7 +59,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -69,23 +69,14 @@ id="layer1" transform="translate(0,-1036.3622)"> <path + style="opacity:1;fill:#84ffb1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + d="M 11 9 L 11 11 L 9 11 L 9 13 L 11 13 L 11 15 L 13 15 L 13 13 L 15 13 L 15 11 L 13 11 L 13 9 L 11 9 z " + transform="translate(0,1036.3622)" + id="rect4156" /> + <path style="opacity:1;fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 11 1 A 4 4.0000024 0 0 0 7.1308594 4 L 1 4 L 1 6 L 2 6 L 2 8 L 5 8 L 5 6 L 7.1328125 6 A 4 4.0000024 0 0 0 9 8.4589844 L 9 7 L 11 7 A 2.0000174 2.0000174 0 0 1 9 5 A 2.0000174 2.0000174 0 0 1 11 3 A 2.0000174 2.0000174 0 0 1 13 5 A 2.0000174 2.0000174 0 0 1 11 7 L 14.458984 7 A 4 4.0000024 0 0 0 15 5 A 4 4.0000024 0 0 0 11 1 z " + d="M 11 1 A 4 4.0000024 0 0 0 7.1308594 4 L 1 4 L 1 6 L 2 6 L 2 8 L 5 8 L 5 6 L 7.1328125 6 A 4 4.0000024 0 0 0 10 8.8691406 L 10 8 L 13.638672 8 A 4 4.0000024 0 0 0 15 5 A 4 4.0000024 0 0 0 11 1 z M 11 3 A 2.0000174 2.0000174 0 0 1 13 5 A 2.0000174 2.0000174 0 0 1 11 7 A 2.0000174 2.0000174 0 0 1 9 5 A 2.0000174 2.0000174 0 0 1 11 3 z " transform="translate(0,1036.3622)" - id="path4137" /> - <rect - style="opacity:1;fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4156" - width="2" - height="5.9999828" - x="11" - y="1045.3622" /> - <rect - y="1047.3622" - x="9" - height="2.0000174" - width="6" - id="rect4158" - style="opacity:1;fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + id="path4137-6" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_nine_patch_rect.svg b/tools/editor/icons/source/icon_nine_patch_rect.svg new file mode 100644 index 0000000000..f12789c19e --- /dev/null +++ b/tools/editor/icons/source/icon_nine_patch_rect.svg @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="16" + height="16" + viewBox="0 0 16 16" + id="svg2" + version="1.1" + inkscape:version="0.91 r13725" + inkscape:export-filename="/home/djrm/Projects/godot/tools/editor/icons/icon_center_container.png" + inkscape:export-xdpi="90" + inkscape:export-ydpi="90" + sodipodi:docname="icon_patch_9_frame.svg"> + <defs + id="defs4" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="32" + inkscape:cx="10.35114" + inkscape:cy="9.1140348" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="true" + units="px" + inkscape:snap-bbox="true" + inkscape:bbox-paths="true" + inkscape:bbox-nodes="true" + inkscape:snap-bbox-edge-midpoints="true" + inkscape:snap-bbox-midpoints="true" + inkscape:snap-object-midpoints="true" + inkscape:snap-center="true" + inkscape:window-width="1920" + inkscape:window-height="1016" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1"> + <inkscape:grid + type="xygrid" + id="grid3336" /> + </sodipodi:namedview> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(0,-1036.3622)"> + <rect + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect4154" + width="1" + height="14" + x="1" + y="1037.3622" /> + <rect + y="1050.3622" + x="1" + height="0.9999826" + width="14" + id="rect4156" + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + <rect + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect4158" + width="14" + height="0.9999826" + x="1" + y="1037.3622" /> + <rect + y="1037.3622" + x="14" + height="14" + width="1" + id="rect4160" + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + <rect + y="1040.3622" + x="1" + height="0.9999826" + width="14" + id="rect4162" + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + <rect + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect4164" + width="14" + height="0.9999826" + x="1" + y="1047.3622" /> + <rect + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect4166" + width="14" + height="0.9999826" + x="1037.3622" + y="-5" + transform="matrix(0,1,-1,0,0,0)" /> + <rect + transform="matrix(0,1,-1,0,0,0)" + y="-12" + x="1037.3622" + height="0.9999826" + width="14" + id="rect4168" + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + </g> +</svg> diff --git a/tools/editor/icons/source/icon_reparent.svg b/tools/editor/icons/source/icon_reparent.svg index 65f101c8f7..79543fe066 100644 --- a/tools/editor/icons/source/icon_reparent.svg +++ b/tools/editor/icons/source/icon_reparent.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="11.313708" - inkscape:cx="-1.4011549" - inkscape:cy="8.7567876" + inkscape:zoom="22.627416" + inkscape:cx="11.980115" + inkscape:cy="8.5519429" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -46,7 +46,10 @@ inkscape:window-height="1016" inkscape:window-x="0" inkscape:window-y="27" - inkscape:window-maximized="1"> + inkscape:window-maximized="1" + inkscape:snap-midpoints="true" + inkscape:snap-smooth-nodes="true" + inkscape:object-nodes="true"> <inkscape:grid type="xygrid" id="grid3336" /> @@ -59,7 +62,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -68,45 +71,15 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <circle - r="2" - cy="1049.3622" - cx="3" - id="circle4277" - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> - <circle - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="circle4279" - cx="3" - cy="1039.3622" - r="2" /> - <circle - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="circle4281" - cx="13" - cy="1049.3622" - r="2" /> <path - style="fill:none;fill-rule:evenodd;stroke:#e0e0e0;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" - d="m 3,1039.3622 0,10 10,0" - id="path4287" - inkscape:connector-curvature="0" /> - <path - style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="m 9,1038.3622 0,2 a 3,3 0 0 1 3,3 l 2,0 a 5.0000172,5.0000172 0 0 0 -5,-5 z" - id="path4289" - inkscape:connector-curvature="0" /> - <rect style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4294" - width="2" - height="2" - x="12" - y="1043.3622" /> + d="M 3 2 A 2 2 0 0 0 1 4 A 2 2 0 0 0 2 5.7304688 L 2 11.271484 A 2 2 0 0 0 1 13 A 2 2 0 0 0 3 15 A 2 2 0 0 0 4.7304688 14 L 11.271484 14 A 2 2 0 0 0 13 15 A 2 2 0 0 0 15 13 A 2 2 0 0 0 13 11 A 2 2 0 0 0 11.269531 12 L 4.7285156 12 A 2 2 0 0 0 4 11.269531 L 4 5.7285156 A 2 2 0 0 0 5 4 A 2 2 0 0 0 3 2 z " + transform="translate(0,1036.3622)" + id="circle4277" /> <path - style="fill:#e0e0e0;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1" - d="m 9,1037.3622 0,4 -3,-2 z" - id="path4296" - inkscape:connector-curvature="0" /> + style="opacity:1;fill:#84ffb1;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + d="M 9 1 L 5 4 L 9 7 L 9 5 A 3 3 0 0 1 12 8 L 12 10 L 14 10 L 14 8 A 5.0000172 5.0000172 0 0 0 9 3 L 9 1 z " + transform="translate(0,1036.3622)" + id="path4289" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_script_remove.svg b/tools/editor/icons/source/icon_script_remove.svg new file mode 100644 index 0000000000..1a0a0eebe3 --- /dev/null +++ b/tools/editor/icons/source/icon_script_remove.svg @@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="16" + height="16" + viewBox="0 0 16 16" + id="svg2" + version="1.1" + inkscape:version="0.91 r13725" + inkscape:export-filename="/home/godotengine/godot/tools/editor/icons/con_script_create.png" + inkscape:export-xdpi="90" + inkscape:export-ydpi="90" + sodipodi:docname="icon_script_remove.svg"> + <defs + id="defs4" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="42.379266" + inkscape:cx="6.774667" + inkscape:cy="6.9870579" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="true" + units="px" + inkscape:snap-bbox="true" + inkscape:bbox-paths="true" + inkscape:bbox-nodes="true" + inkscape:snap-bbox-edge-midpoints="true" + inkscape:snap-bbox-midpoints="true" + inkscape:snap-object-midpoints="true" + inkscape:snap-center="true" + inkscape:window-width="1920" + inkscape:window-height="1016" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + showguides="false" + inkscape:snap-smooth-nodes="true" + inkscape:object-nodes="true"> + <inkscape:grid + type="xygrid" + id="grid3336" + empspacing="4" /> + </sodipodi:namedview> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(0,-1036.3622)"> + <path + style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" + d="M 6 1 L 6 2 C 5.4477153 2 5 2.4477153 5 3 L 5 13 L 4 13 L 4 11 L 2 11 L 2 13 C 2.0002826 13.356983 2.1908437 13.686743 2.5 13.865234 C 2.6519425 13.953279 2.8243914 13.999759 3 14 L 3 15 L 8.6347656 15 L 7.0507812 13.416016 L 8.4648438 12.001953 L 7.0507812 10.585938 L 10.585938 7.0507812 L 12 8.4648438 L 12 8 L 12 5 L 15 5 L 15 3 C 15 1.8954305 14.104569 1 13 1 L 6 1 z " + transform="translate(0,1036.3622)" + id="rect4255" /> + <path + style="opacity:1;fill:#b4b4b4;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" + d="M 6 1 C 4.8954305 1 4 1.8954305 4 3 L 4 10 L 2 10 L 1 10 L 1 11 L 1 13 C 1 14.104569 1.8954305 15 3 15 C 4.1045695 15 5 14.104569 5 13 L 5 3 C 5 2.4477153 5.4477153 2 6 2 C 6.5522847 2 7 2.4477153 7 3 L 7 4 L 7 5 L 7 6 L 8 6 L 12 6 L 12 5 L 8 5 L 8 4 L 8 3 C 8 1.8954305 7.1045695 1 6 1 z M 2 11 L 4 11 L 4 13 C 4 13.552285 3.5522847 14 3 14 C 2.4477153 14 2 13.552285 2 13 L 2 11 z " + id="path4265" + transform="translate(0,1036.3622)" /> + <circle + cy="1048.3622" + cx="3" + id="ellipse4234" + style="opacity:1;fill:#e0e0e0;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" + ry="1.0000174" + rx="1" /> + <path + style="fill:#ff8484;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="m 13.414214,1048.3622 1.414213,-1.4142 -1.414213,-1.4142 L 12,1046.948 l -1.414214,-1.4142 -1.4142131,1.4142 1.4142131,1.4142 -1.4142131,1.4142 1.4142131,1.4142 1.414214,-1.4142 1.414214,1.4142 1.414213,-1.4142 z" + id="path8069" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ccccccccccccc" /> + </g> +</svg> diff --git a/tools/editor/icons/source/icon_shader.svg b/tools/editor/icons/source/icon_shader.svg index ba12b007ad..1a2393fec2 100644 --- a/tools/editor/icons/source/icon_shader.svg +++ b/tools/editor/icons/source/icon_shader.svg @@ -32,12 +32,13 @@ </clipPath> <clipPath clipPathUnits="userSpaceOnUse" - id="clipPath4199"> + id="clipPath4207"> <path + style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;baseline-shift:baseline;text-anchor:start;white-space:normal;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" + d="m 6.3749999,1025.8622 c -0.931942,10e-5 -1.6874069,0.6715 -1.6875,1.5 l 0,18 c 9.31e-5,0.8284 0.755558,1.4998 1.6875,1.5 l 20.2500001,0 c 0.931942,-2e-4 1.687407,-0.6716 1.6875,-1.5 l 0,-12 -8.4375,-7.5 z m 1.6875,3 10.1250001,0 0,4.5 c 0,0.831 0.752609,1.5 1.6875,1.5 l 5.0625,0 0,9 -16.8750001,0 z" + id="path4209" inkscape:connector-curvature="0" - id="path4201" - d="m 16.5,1025.8622 a 11.8125,10.499999 0 0 0 -11.8125001,10.5 11.8125,10.499999 0 0 0 11.8125001,10.5 11.8125,10.499999 0 0 0 11.8125,-10.5 11.8125,10.499999 0 0 0 -11.8125,-10.5 z m -3.375,3 a 3.375,2.9999997 0 0 1 3.375,3 3.375,2.9999997 0 0 1 -3.375,3 3.375,2.9999997 0 0 1 -3.3750001,-3 3.375,2.9999997 0 0 1 3.3750001,-3 z" - style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> + sodipodi:nodetypes="ccccccccccccccccc" /> </clipPath> </defs> <sodipodi:namedview @@ -48,8 +49,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="31.999999" - inkscape:cx="6.7591143" - inkscape:cy="9.6862321" + inkscape:cx="20.042938" + inkscape:cy="7.6712905" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -95,7 +96,7 @@ <g id="g4181" mask="none" - clip-path="url(#clipPath4199)" + clip-path="url(#clipPath4207)" transform="matrix(0.59259259,0,0,0.66666674,-1.7777777,353.454)"> <rect y="1025.8622" diff --git a/tools/editor/icons/source/icon_spot_light.svg b/tools/editor/icons/source/icon_spot_light.svg index b9130eff37..04f5b42f4d 100644 --- a/tools/editor/icons/source/icon_spot_light.svg +++ b/tools/editor/icons/source/icon_spot_light.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="31.999999" - inkscape:cx="5.5818635" - inkscape:cy="8.6161108" + inkscape:cx="-0.26188668" + inkscape:cy="8.5536108" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -60,7 +60,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -71,48 +71,8 @@ transform="translate(0,-1036.3622)"> <path style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - d="m 14,1046.3622 -12,0 c 0,-2.7614 2.6862915,-5 6,-5 3.313708,0 6,2.2386 6,5 z" - id="path4155" - inkscape:connector-curvature="0" - sodipodi:nodetypes="ccsc" /> - <path - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - d="M 6 1 A 1 1 0 0 0 5 2 L 5 7 L 11 7 L 11 2 A 1 1 0 0 0 10 1 L 6 1 z " + d="M 6 1 A 1 1 0 0 0 5 2 L 5 5.6933594 C 3.2138662 6.5594405 2 8.153847 2 10 L 6 10 A 2 2 0 0 0 8 12 A 2 2 0 0 0 10 10 L 14 10 C 14 8.153847 12.786134 6.5594405 11 5.6933594 L 11 2 A 1 1 0 0 0 10 1 L 6 1 z M 4.9023438 10.634766 L 3.1699219 11.634766 L 4.1699219 13.365234 L 5.9023438 12.365234 L 4.9023438 10.634766 z M 11.097656 10.634766 L 10.097656 12.365234 L 11.830078 13.365234 L 12.830078 11.634766 L 11.097656 10.634766 z M 7 13 L 7 15 L 9 15 L 9 13 L 7 13 z " transform="translate(0,1036.3622)" - id="rect4158" /> - <circle - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="path4160" - cx="8" - cy="1046.3622" - r="2" /> - <rect - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4162" - width="2" - height="2" - x="7" - y="1049.3622" - inkscape:transform-center-y="3.9999826" /> - <rect - inkscape:transform-center-y="2.0000217" - y="533.10931" - x="-903.17627" - height="2" - width="2" - id="rect4164" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - transform="matrix(0.5,-0.8660254,0.8660254,0.5,0,0)" - inkscape:transform-center-x="-3.4640975" /> - <rect - inkscape:transform-center-x="3.4641473" - transform="matrix(0.5,0.8660254,-0.8660254,0.5,0,0)" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4166" - width="2" - height="2" - x="909.17621" - y="519.25293" - inkscape:transform-center-y="1.9999799" /> + id="path4155" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_static_body.svg b/tools/editor/icons/source/icon_static_body.svg index af1ebc8900..fcaa2b7d3e 100644 --- a/tools/editor/icons/source/icon_static_body.svg +++ b/tools/editor/icons/source/icon_static_body.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="22.627417" - inkscape:cx="7.2543819" - inkscape:cy="7.4903504" + inkscape:zoom="11.313709" + inkscape:cx="10.872202" + inkscape:cy="6.7990901" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -72,67 +72,9 @@ id="layer1" transform="translate(0,-1036.3622)"> <path - style="fill:#a5b7f5;fill-opacity:0.98823529;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" - d="M 25 3 C 22 3 21 6 21 6 C 20.879708 6.3608765 20.803605 6.6663233 20.707031 7 L 21 7 A 1 1 0 0 0 22 8 A 1 1 0 0 0 23 7 L 24 7 A 1 1 0 0 0 25 8 A 1 1 0 0 0 26 7 L 27 7 A 1 1 0 0 0 28 8 A 1 1 0 0 0 29 7 L 29.292969 7 C 29.196395 6.6663233 29.120292 6.3608765 29 6 C 29 6 28 3 25 3 z M 20.369141 8.1542969 C 19.864457 10.037394 19.478832 11.521168 18 13 L 32 13 C 30.521168 11.521168 30.135543 10.037394 29.630859 8.1542969 A 2 2 0 0 1 29 8.7324219 A 2 2 0 0 1 27 8.7324219 A 2 2 0 0 1 26.5 8.3203125 A 2 2 0 0 1 26 8.7324219 A 2 2 0 0 1 24 8.7324219 A 2 2 0 0 1 23.5 8.3203125 A 2 2 0 0 1 23 8.7324219 A 2 2 0 0 1 21 8.7324219 A 2 2 0 0 1 20.369141 8.1542969 z " - transform="translate(0,1036.3622)" - id="path4161" /> - <rect - style="opacity:1;fill:#fefeff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4175" - width="1" - height="1" - x="20" - y="1042.3622" /> - <rect - y="1042.3622" - x="29" - height="1" - width="1" - id="rect4177" - style="opacity:1;fill:#fefeff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> - <path style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - d="M 3 1 A 2 2 0 0 0 1.5859375 1.5859375 A 2 2 0 0 0 1 3 L 1 13 A 2 2 0 0 0 1.5859375 14.414062 A 2 2 0 0 0 3 15 L 13 15 A 2 2 0 0 0 15 13 L 15 3 A 2 2 0 0 0 13 1 L 3 1 z M 3 2 L 13 2 A 1.0000174 1.0000174 0 0 1 14 3 L 14 13 A 1.0000174 1.0000174 0 0 1 13 14 L 3 14 A 1.0000174 1.0000174 0 0 1 2 13 L 2 3 A 1.0000174 1.0000174 0 0 1 3 2 z " + d="M 3 1 A 2 2 0 0 0 1.5859375 1.5859375 A 2 2 0 0 0 1 3 L 1 13 A 2 2 0 0 0 1.5859375 14.414062 A 2 2 0 0 0 3 15 L 13 15 A 2 2 0 0 0 15 13 L 15 3 A 2 2 0 0 0 13 1 L 3 1 z M 3 2 L 13 2 A 1.0000174 1.0000174 0 0 1 14 3 L 14 13 A 1.0000174 1.0000174 0 0 1 13 14 L 3 14 A 1.0000174 1.0000174 0 0 1 2 13 L 2 3 A 1.0000174 1.0000174 0 0 1 3 2 z M 3 3 L 3 5 L 5 5 L 5 3 L 3 3 z M 11 3 L 11 5 L 13 5 L 13 3 L 11 3 z M 3 11 L 3 13 L 5 13 L 5 11 L 3 11 z M 11 11 L 11 13 L 13 13 L 13 11 L 11 11 z " transform="translate(0,1036.3622)" id="rect4179" /> - <rect - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4195" - width="2" - height="2" - x="3" - y="1039.3622" /> - <rect - y="1047.3622" - x="3" - height="2" - width="2" - id="rect4197" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> - <rect - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4199" - width="2" - height="2" - x="11" - y="1047.3622" /> - <rect - y="1039.3622" - x="11" - height="2" - width="2" - id="rect4201" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> - <g - id="layer1-1" - inkscape:label="Layer 1" - transform="translate(-23.644738,-1.9878833)"> - <path - id="path4139" - transform="translate(0,1036.3622)" - d="M 8,1 A 7,7 0 0 0 1,8 7,7 0 0 0 8,15 7,7 0 0 0 15,8 7,7 0 0 0 8,1 Z M 4,6 A 1,1 0 0 1 5,7 1,1 0 0 1 4,8 1,1 0 0 1 3,7 1,1 0 0 1 4,6 Z m 8,0 a 1,1 0 0 1 1,1 1,1 0 0 1 -1,1 1,1 0 0 1 -1,-1 1,1 0 0 1 1,-1 z m -7,3 6,0 a 3,3 0 0 1 -1.5,2.597656 3,3 0 0 1 -3,0 A 3,3 0 0 1 5,9 Z" - style="opacity:1;fill:#fc9c9c;fill-opacity:0.99607843;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - inkscape:connector-curvature="0" /> - </g> </g> </svg> diff --git a/tools/editor/icons/source/icon_static_body_2d.svg b/tools/editor/icons/source/icon_static_body_2d.svg index d47e924e37..0ed3ef7cf0 100644 --- a/tools/editor/icons/source/icon_static_body_2d.svg +++ b/tools/editor/icons/source/icon_static_body_2d.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" - inkscape:cx="7.2543819" - inkscape:cy="7.4903504" + inkscape:cx="-1.0099286" + inkscape:cy="7.4019621" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -62,7 +62,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -72,13 +72,6 @@ id="layer1" transform="translate(0,-1036.3622)"> <rect - style="opacity:1;fill:#fefeff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4175" - width="1" - height="1" - x="20" - y="1042.3622" /> - <rect y="1042.3622" x="29" height="1" @@ -87,36 +80,8 @@ style="opacity:1;fill:#fefeff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> <path style="opacity:1;fill:#a5b7f6;fill-opacity:0.98823529;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - d="M 3 1 A 2 2 0 0 0 1.5859375 1.5859375 A 2 2 0 0 0 1 3 L 1 13 A 2 2 0 0 0 1.5859375 14.414062 A 2 2 0 0 0 3 15 L 13 15 A 2 2 0 0 0 15 13 L 15 3 A 2 2 0 0 0 13 1 L 3 1 z M 3 2 L 13 2 A 1.0000174 1.0000174 0 0 1 14 3 L 14 13 A 1.0000174 1.0000174 0 0 1 13 14 L 3 14 A 1.0000174 1.0000174 0 0 1 2 13 L 2 3 A 1.0000174 1.0000174 0 0 1 3 2 z " + d="M 3 1 A 2 2 0 0 0 1.5859375 1.5859375 A 2 2 0 0 0 1 3 L 1 13 A 2 2 0 0 0 1.5859375 14.414062 A 2 2 0 0 0 3 15 L 13 15 A 2 2 0 0 0 15 13 L 15 3 A 2 2 0 0 0 13 1 L 3 1 z M 3 2 L 13 2 A 1.0000174 1.0000174 0 0 1 14 3 L 14 13 A 1.0000174 1.0000174 0 0 1 13 14 L 3 14 A 1.0000174 1.0000174 0 0 1 2 13 L 2 3 A 1.0000174 1.0000174 0 0 1 3 2 z M 3 3 L 3 5 L 5 5 L 5 3 L 3 3 z M 11 3 L 11 5 L 13 5 L 13 3 L 11 3 z M 3 11 L 3 13 L 5 13 L 5 11 L 3 11 z M 11 11 L 11 13 L 13 13 L 13 11 L 11 11 z " transform="translate(0,1036.3622)" id="rect4179" /> - <rect - style="opacity:1;fill:#a5b7f6;fill-opacity:0.98823529;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4195" - width="2" - height="2" - x="3" - y="1039.3622" /> - <rect - y="1047.3622" - x="3" - height="2" - width="2" - id="rect4197" - style="opacity:1;fill:#a5b7f6;fill-opacity:0.98823529;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> - <rect - style="opacity:1;fill:#a5b7f6;fill-opacity:0.98823529;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4199" - width="2" - height="2" - x="11" - y="1047.3622" /> - <rect - y="1039.3622" - x="11" - height="2" - width="2" - id="rect4201" - style="opacity:1;fill:#a5b7f6;fill-opacity:0.98823529;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_tab_container.svg b/tools/editor/icons/source/icon_tab_container.svg index b53747bf1c..6c197a86f6 100644 --- a/tools/editor/icons/source/icon_tab_container.svg +++ b/tools/editor/icons/source/icon_tab_container.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="32" - inkscape:cx="4.8125618" - inkscape:cy="8.9338072" + inkscape:zoom="45.254834" + inkscape:cx="3.8596634" + inkscape:cy="10.446251" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -62,7 +62,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -73,24 +73,8 @@ transform="translate(0,-1036.3622)"> <path style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="M 3,1 C 1.8954305,1 1,1.8954305 1,3 l 0,10 c 0,1.104569 0.8954305,2 2,2 l 10,0 c 1.104569,0 2,-0.895431 2,-2 L 15,3 C 15,1.8954305 14.104569,1 13,1 Z m 0,2 10,0 0,10 -10,0 z" + d="M 3 1 C 1.8954305 1 1 1.8954305 1 3 L 1 13 C 1 14.104569 1.8954305 15 3 15 L 13 15 C 14.104569 15 15 14.104569 15 13 L 15 3 C 15 1.8954305 14.104569 1 13 1 L 3 1 z M 3 3 L 8 3 L 8 5 L 8 7 L 13 7 L 13 13 L 3 13 L 3 3 z M 10 3 L 13 3 L 13 5 L 10 5 L 10 3 z " transform="translate(0,1036.3622)" - id="rect4140" - inkscape:connector-curvature="0" - sodipodi:nodetypes="sssssssssccccc" /> - <rect - style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4158" - width="10" - height="2" - x="3" - y="1041.3622" /> - <rect - y="1039.3622" - x="8" - height="2" - width="5" - id="rect4170" - style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> + id="rect4140" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_tabs.svg b/tools/editor/icons/source/icon_tabs.svg index 1b389fc30c..79ed1e5910 100644 --- a/tools/editor/icons/source/icon_tabs.svg +++ b/tools/editor/icons/source/icon_tabs.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="32" - inkscape:cx="3.2506704" - inkscape:cy="11.363584" + inkscape:zoom="22.627417" + inkscape:cx="11.687421" + inkscape:cy="9.3335226" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -75,21 +75,21 @@ style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="rect4156" width="1" - height="4.9999828" + height="9.0000172" x="1" - y="1042.3622" /> + y="1040.3622" /> <rect y="-8" - x="1041.3622" + x="1039.3622" height="6" width="1" id="rect4159" style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" transform="matrix(0,1,-1,0,0,0)" /> <rect - y="1042.3622" - x="8" - height="4.9999828" + y="1040.3622" + x="7" + height="3.0000174" width="1" id="rect4161" style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" /> @@ -98,38 +98,26 @@ id="path4163" sodipodi:type="arc" sodipodi:cx="2" - sodipodi:cy="1042.3622" + sodipodi:cy="1040.3622" sodipodi:rx="1" sodipodi:ry="1" sodipodi:start="1.5707963" sodipodi:end="0" - d="m 2,1043.3622 a 1,1 0 0 1 -0.9238795,-0.6173 1,1 0 0 1 0.2167727,-1.0898 1,1 0 0 1 1.0897902,-0.2168 A 1,1 0 0 1 3,1042.3622 l -1,0 z" /> - <path - d="m -8,1043.3622 a 1,1 0 0 1 -0.9238795,-0.6173 1,1 0 0 1 0.2167727,-1.0898 1,1 0 0 1 1.0897902,-0.2168 A 1,1 0 0 1 -7,1042.3622 l -1,0 z" - sodipodi:end="0" - sodipodi:start="1.5707963" - sodipodi:ry="1" - sodipodi:rx="1" - sodipodi:cy="1042.3622" - sodipodi:cx="-8" - sodipodi:type="arc" - id="path4165" - style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - transform="scale(-1,1)" /> + d="m 2,1041.3622 a 1,1 0 0 1 -0.9238795,-0.6173 1,1 0 0 1 0.2167727,-1.0898 1,1 0 0 1 1.0897902,-0.2168 A 1,1 0 0 1 3,1040.3622 l -1,0 z" /> <rect style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="rect4167" width="1" - height="4.9999828" + height="9.0000172" x="14" - y="1042.3622" /> + y="1040.3622" /> <rect transform="matrix(0,1,-1,0,0,0)" style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="rect4169" width="1" height="6" - x="1041.3622" + x="1039.3622" y="-14" /> <path transform="scale(-1,1)" @@ -137,19 +125,19 @@ id="path4171" sodipodi:type="arc" sodipodi:cx="-14" - sodipodi:cy="1042.3622" + sodipodi:cy="1040.3622" sodipodi:rx="1" sodipodi:ry="1" sodipodi:start="1.5707963" sodipodi:end="0" - d="m -14,1043.3622 a 1,1 0 0 1 -0.92388,-0.6173 1,1 0 0 1 0.216773,-1.0898 1,1 0 0 1 1.08979,-0.2168 1,1 0 0 1 0.617317,0.9239 l -1,0 z" /> + d="m -14,1041.3622 a 1,1 0 0 1 -0.92388,-0.6173 1,1 0 0 1 0.216773,-1.0898 1,1 0 0 1 1.08979,-0.2168 1,1 0 0 1 0.617317,0.9239 l -1,0 z" /> <rect transform="matrix(0,1,-1,0,0,0)" style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="rect4173" width="1" height="13" - x="1046.3622" + x="1042.3622" y="-15" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_text_edit.svg b/tools/editor/icons/source/icon_text_edit.svg index 1daf1ac75a..4d08e9e3b2 100644 --- a/tools/editor/icons/source/icon_text_edit.svg +++ b/tools/editor/icons/source/icon_text_edit.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="22.627417" - inkscape:cx="13.881612" - inkscape:cy="11.594783" + inkscape:cx="5.6173015" + inkscape:cy="11.506395" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -72,31 +72,16 @@ id="layer1" transform="translate(0,-1036.3622)"> <rect - style="opacity:1;fill:#fefeff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4175" - width="1" - height="1" - x="20" - y="1042.3622" /> - <rect y="1042.3622" x="29" height="1" width="1" id="rect4177" style="opacity:1;fill:#fefeff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> - <rect - style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4173" - width="1" - height="4" - x="4" - y="1040.3622" /> <path - style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - d="m 3,1037.3622 c -1.1045695,0 -2,0.8954 -2,2 l 0,10 c 0,1.1046 0.8954305,2 2,2 l 10,0 c 1.104569,0 2,-0.8954 2,-2 l 0,-10 c 0,-1.1046 -0.895431,-2 -2,-2 z m 0,2 10,0 0,10 -10,0 z" - id="rect4140" - inkscape:connector-curvature="0" - sodipodi:nodetypes="sssssssssccccc" /> + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" + d="M 3 1 C 1.8954305 1 1 1.8954 1 3 L 1 13 C 1 14.1046 1.8954305 15 3 15 L 13 15 C 14.104569 15 15 14.1046 15 13 L 15 3 C 15 1.8954 14.104569 1 13 1 L 3 1 z M 3 3 L 13 3 L 13 13 L 3 13 L 3 3 z M 4 4 L 4 8 L 5 8 L 5 4 L 4 4 z " + transform="translate(0,1036.3622)" + id="rect4173" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_track_add_key.svg b/tools/editor/icons/source/icon_track_add_key.svg index 96761526a8..f550f922bb 100644 --- a/tools/editor/icons/source/icon_track_add_key.svg +++ b/tools/editor/icons/source/icon_track_add_key.svg @@ -29,8 +29,8 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="45.254834" - inkscape:cx="6.0361164" - inkscape:cy="4.9218153" + inkscape:cx="10.389243" + inkscape:cy="3.816961" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -69,7 +69,7 @@ id="layer1" transform="translate(0,-1044.3622)"> <path - style="fill:#a9e100;fill-opacity:0.99607843;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + style="fill:#84ffb1;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="M 3 0 L 3 3 L 0 3 L 0 5 L 3 5 L 3 8 L 5 8 L 5 5 L 8 5 L 8 3 L 5 3 L 5 0 L 3 0 z " transform="translate(0,1044.3622)" id="rect4137" /> diff --git a/tools/editor/icons/source/icon_track_add_key_hl.svg b/tools/editor/icons/source/icon_track_add_key_hl.svg index 79e566dde6..1b45cf8c4a 100644 --- a/tools/editor/icons/source/icon_track_add_key_hl.svg +++ b/tools/editor/icons/source/icon_track_add_key_hl.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="45.254834" - inkscape:cx="5.3806528" - inkscape:cy="6.0126016" + inkscape:zoom="32" + inkscape:cx="-4.0417082" + inkscape:cy="5.5439904" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -69,9 +69,14 @@ id="layer1" transform="translate(0,-1044.3622)"> <path - style="fill:#e3fe03;fill-opacity:0.98823529;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + style="fill:#84ffb1;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="M 3 0 L 3 3 L 0 3 L 0 5 L 3 5 L 3 8 L 5 8 L 5 5 L 8 5 L 8 3 L 5 3 L 5 0 L 3 0 z " + id="rect4137" + transform="translate(0,1044.3622)" /> + <path transform="translate(0,1044.3622)" - id="rect4137" /> + id="path4143" + d="M 3 0 L 3 3 L 0 3 L 0 5 L 3 5 L 3 8 L 5 8 L 5 5 L 8 5 L 8 3 L 5 3 L 5 0 L 3 0 z " + style="fill:#ffffff;fill-opacity:0.42424244;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> </g> </svg> diff --git a/tools/editor/icons/source/icon_viewport.svg b/tools/editor/icons/source/icon_viewport.svg index fcbe094fca..631260ab33 100644 --- a/tools/editor/icons/source/icon_viewport.svg +++ b/tools/editor/icons/source/icon_viewport.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="45.254834" - inkscape:cx="7.693363" - inkscape:cy="8.1399132" + inkscape:zoom="11.313709" + inkscape:cx="14.11111" + inkscape:cy="8.6614747" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -62,7 +62,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -71,20 +71,6 @@ inkscape:groupmode="layer" id="layer1" transform="translate(0,-1036.3622)"> - <rect - style="opacity:1;fill:#fefeff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" - id="rect4175" - width="1" - height="1" - x="20" - y="1042.3622" /> - <rect - y="1042.3622" - x="29" - height="1" - width="1" - id="rect4177" - style="opacity:1;fill:#fefeff;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" /> <path style="opacity:1;fill:#e0e0e0;fill-opacity:0.99607843;stroke:none;stroke-width:2;stroke-linecap:butt;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.99607843" d="M 3,2 C 2.4695977,2.0000801 1.9609485,2.2108464 1.5859375,2.5859375 1.2108464,2.9609485 1.0000801,3.4695977 1,4 l 0,8 c 8.03e-5,0.530402 0.2108465,1.039051 0.5859375,1.414062 C 1.9609484,13.789153 2.4695976,13.99992 3,14 l 10,0 c 1.104569,0 2,-0.895431 2,-2 L 15,4 C 15,2.8954305 14.104569,2 13,2 Z m 0,1 10,0 c 0.552281,9.6e-6 0.99999,0.4477192 1,1 l 0,8 c -10e-6,0.552281 -0.447719,0.99999 -1,1 L 3,13 C 2.4477192,12.99999 2.0000096,12.552281 2,12 L 2,4 c 9.6e-6,-0.5522808 0.4477192,-0.9999904 1,-1 z" diff --git a/tools/editor/icons/source/icon_viewport_container.svg b/tools/editor/icons/source/icon_viewport_container.svg new file mode 100644 index 0000000000..300b8390c4 --- /dev/null +++ b/tools/editor/icons/source/icon_viewport_container.svg @@ -0,0 +1,82 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="16" + height="16" + viewBox="0 0 16 16" + id="svg2" + version="1.1" + inkscape:version="0.91 r13725" + inkscape:export-filename="/home/djrm/Projects/godot/tools/editor/icons/icon_center_container.png" + inkscape:export-xdpi="90" + inkscape:export-ydpi="90" + sodipodi:docname="icon_viewport_container.svg"> + <defs + id="defs4" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="32" + inkscape:cx="13.216634" + inkscape:cy="7.7987238" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="true" + units="px" + inkscape:snap-bbox="true" + inkscape:bbox-paths="true" + inkscape:bbox-nodes="true" + inkscape:snap-bbox-edge-midpoints="true" + inkscape:snap-bbox-midpoints="true" + inkscape:snap-object-midpoints="true" + inkscape:snap-center="true" + inkscape:window-width="1920" + inkscape:window-height="1016" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:snap-smooth-nodes="true" + inkscape:object-nodes="true" + inkscape:snap-midpoints="true"> + <inkscape:grid + type="xygrid" + id="grid3336" /> + </sodipodi:namedview> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(0,-1036.3622)"> + <path + style="opacity:1;fill:#a5efac;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + d="M 3,1 C 1.8954305,1 1,1.8954305 1,3 l 0,10 c 0,1.104569 0.8954305,2 2,2 l 10,0 c 1.104569,0 2,-0.895431 2,-2 L 15,3 C 15,1.8954305 14.104569,1 13,1 Z M 3,3 13,3 13,13 3,13 Z M 6,4 C 5.469598,4.0001 4.9609495,4.2108375 4.5859375,4.5859375 4.2108465,4.9609375 4.00008,5.4696 4,6 l 0,4 c 8e-5,0.5304 0.2108475,1.039063 0.5859375,1.414062 C 4.9609485,11.789162 5.469598,11.9999 6,12 l 4,0 c 1.104569,0 2,-0.8954 2,-2 L 12,6 C 12,4.8954 11.104569,4 10,4 Z m 0,1 4,0 c 0.552281,0 0.99999,0.4477 1,1 l 0,4 c -10e-6,0.5523 -0.447719,1 -1,1 L 6,11 C 5.447719,11 5.00001,10.5523 5,10 L 5,6 C 5.00001,5.4477 5.447719,5 6,5 Z" + transform="translate(0,1036.3622)" + id="rect4140" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ccccccccccccccccccccsssscssccssccs" /> + </g> +</svg> diff --git a/tools/editor/icons/source/icon_warning.svg b/tools/editor/icons/source/icon_warning.svg index ee89f3ec99..4d39141a58 100644 --- a/tools/editor/icons/source/icon_warning.svg +++ b/tools/editor/icons/source/icon_warning.svg @@ -28,9 +28,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="22.627416" - inkscape:cx="1.5203658" - inkscape:cy="5.6414917" + inkscape:zoom="45.254832" + inkscape:cx="2.2320862" + inkscape:cy="6.41947" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -60,7 +60,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata> @@ -70,11 +70,12 @@ id="layer1" transform="translate(0,-1044.3622)"> <rect - style="opacity:1;fill:#ffd684;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" - id="rect4154" + style="opacity:1;fill:#ffd684;fill-opacity:1;stroke:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="rect4142" width="8" height="8" - x="2.220446e-16" - y="1044.3622" /> + x="0" + y="1044.3622" + ry="1" /> </g> </svg> diff --git a/tools/editor/import/SCsub b/tools/editor/import/SCsub new file mode 100644 index 0000000000..f1fa50148f --- /dev/null +++ b/tools/editor/import/SCsub @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +Import('env') +Export('env') +env.add_source_files(env.editor_sources, "*.cpp") diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/import/editor_import_collada.cpp index 1cbb594a51..a901de1faf 100644 --- a/tools/editor/io_plugins/editor_import_collada.cpp +++ b/tools/editor/import/editor_import_collada.cpp @@ -27,7 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_import_collada.h" -#include "collada/collada.h" + + #include "scene/3d/spatial.h" #include "scene/3d/skeleton.h" #include "scene/3d/path.h" @@ -38,6 +39,7 @@ #include "scene/resources/animation.h" #include "scene/resources/packed_scene.h" #include "os/os.h" +#include "tools/editor/collada/collada.h" #include "tools/editor/editor_node.h" #include <iostream> @@ -63,6 +65,7 @@ struct ColladaImport { bool found_directional; bool force_make_tangents; bool apply_mesh_xform_to_vertices; + bool use_mesh_builtin_materials; float bake_fps; @@ -85,7 +88,7 @@ struct ColladaImport { Error _create_scene(Collada::Node *p_node, Spatial *p_parent); Error _create_resources(Collada::Node *p_node); Error _create_material(const String& p_material); - Error _create_mesh_surfaces(bool p_optimize, Ref<Mesh>& p_mesh, const Map<String,Collada::NodeGeometry::Material>& p_material_map, const Collada::MeshData &meshdata, const Transform& p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_data, const Collada::MorphControllerData *p_morph_data, Vector<Ref<Mesh> > p_morph_meshes=Vector<Ref<Mesh> >(), bool p_for_morph=false); + Error _create_mesh_surfaces(bool p_optimize, Ref<Mesh>& p_mesh, const Map<String,Collada::NodeGeometry::Material>& p_material_map, const Collada::MeshData &meshdata, const Transform& p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_data, const Collada::MorphControllerData *p_morph_data, Vector<Ref<Mesh> > p_morph_meshes=Vector<Ref<Mesh> >(), bool p_for_morph=false, bool p_use_mesh_material=false); Error load(const String& p_path, int p_flags, bool p_force_make_tangents=false); void _fix_param_animation_tracks(); void create_animation(int p_clip,bool p_make_tracks_in_all_bones, bool p_import_value_tracks); @@ -427,9 +430,10 @@ Error ColladaImport::_create_material(const String& p_target) { } } else { - //material->set_parameter(FixedSpatialMaterial::PARAM_SPECULAR,effect.specular.color); + material->set_metalness(effect.specular.color.get_v()); } + // EMISSION if (effect.emission.texture!="") { @@ -440,17 +444,21 @@ Error ColladaImport::_create_material(const String& p_target) { Ref<Texture> texture = ResourceLoader::load(texfile,"Texture"); if (texture.is_valid()) { + material->set_feature(FixedSpatialMaterial::FEATURE_EMISSION,true); material->set_texture(FixedSpatialMaterial::TEXTURE_EMISSION,texture); material->set_emission(Color(1,1,1,1)); //material->set_parameter(FixedSpatialMaterial::PARAM_EMISSION,Color(1,1,1,1)); }else { - //missing_textures.push_back(texfile.get_file()); + missing_textures.push_back(texfile.get_file()); } } } else { - //material->set_parameter(FixedSpatialMaterial::PARAM_EMISSION,effect.emission.color); + if (effect.emission.color!=Color()) { + material->set_feature(FixedSpatialMaterial::FEATURE_EMISSION,true); + material->set_emission(effect.emission.color); + } } // NORMAL @@ -462,6 +470,7 @@ Error ColladaImport::_create_material(const String& p_target) { Ref<Texture> texture = ResourceLoader::load(texfile,"Texture"); if (texture.is_valid()) { + material->set_feature(FixedSpatialMaterial::FEATURE_NORMAL_MAPPING,true); material->set_texture(FixedSpatialMaterial::TEXTURE_NORMAL,texture); //material->set_emission(Color(1,1,1,1)); @@ -474,7 +483,9 @@ Error ColladaImport::_create_material(const String& p_target) { } - //material->set_parameter(FixedSpatialMaterial::PARAM_SPECULAR_EXP,effect.shininess); + float roughness = Math::sqrt(1.0-((Math::log(effect.shininess)/Math::log(2.0))/8.0)); //not very right.. + material->set_roughness(roughness); + if (effect.double_sided) { material->set_cull_mode(FixedSpatialMaterial::CULL_DISABLED); } @@ -608,7 +619,7 @@ static void _generate_tangents_and_binormals(const PoolVector<int>& p_indices,co } } -Error ColladaImport::_create_mesh_surfaces(bool p_optimize,Ref<Mesh>& p_mesh,const Map<String,Collada::NodeGeometry::Material>& p_material_map,const Collada::MeshData &meshdata,const Transform& p_local_xform,const Vector<int> &bone_remap, const Collada::SkinControllerData *skin_controller, const Collada::MorphControllerData *p_morph_data,Vector<Ref<Mesh> > p_morph_meshes,bool p_for_morph) { +Error ColladaImport::_create_mesh_surfaces(bool p_optimize,Ref<Mesh>& p_mesh,const Map<String,Collada::NodeGeometry::Material>& p_material_map,const Collada::MeshData &meshdata,const Transform& p_local_xform,const Vector<int> &bone_remap, const Collada::SkinControllerData *skin_controller, const Collada::MorphControllerData *p_morph_data,Vector<Ref<Mesh> > p_morph_meshes,bool p_for_morph,bool p_use_mesh_material) { bool local_xform_mirror=p_local_xform.basis.determinant() < 0; @@ -1492,7 +1503,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize,Ref<Mesh>& p_mesh,con p_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES,d,mr,p_for_morph?0:Mesh::ARRAY_COMPRESS_DEFAULT); if (material.is_valid()) { - p_mesh->surface_set_material(surface, material); + if (p_use_mesh_material) { + p_mesh->surface_set_material(surface, material); + } p_mesh->surface_set_name(surface, material->get_name()); } } @@ -1751,7 +1764,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { mesh=Ref<Mesh>(memnew( Mesh )); const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid]; mesh->set_name( meshdata.name ); - Error err = _create_mesh_surfaces(morphs.size()==0,mesh,ng->material_map,meshdata,apply_xform,bone_remap,skin,morph,morphs); + Error err = _create_mesh_surfaces(morphs.size()==0,mesh,ng->material_map,meshdata,apply_xform,bone_remap,skin,morph,morphs,false,use_mesh_builtin_materials); ERR_FAIL_COND_V(err,err); mesh_cache[meshid]=mesh; @@ -1762,7 +1775,33 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { } if (!mesh.is_null()) { + mi->set_mesh(mesh); + if (!use_mesh_builtin_materials) { + const Collada::MeshData &meshdata = collada.state.mesh_data_map[meshid]; + + for(int i=0;i<meshdata.primitives.size();i++) { + + String matname=meshdata.primitives[i].material; + + if (ng->material_map.has(matname)) { + String target=ng->material_map[matname].target; + + Ref<Material> material; + if (!material_cache.has(target)) { + Error err = _create_material(target); + if (!err) + material=material_cache[target]; + } else + material=material_cache[target]; + + mi->set_surface_material(i,material); + } else if (matname!=""){ + print_line("Warning, unreferenced material in geometry instance: "+matname); + } + + } + } } } } @@ -2373,6 +2412,7 @@ Node* EditorSceneImporterCollada::import_scene(const String& p_path, uint32_t p_ if (p_flags&IMPORT_ANIMATION) flags|=Collada::IMPORT_FLAG_ANIMATION; + state.use_mesh_builtin_materials=!(p_flags&IMPORT_MATERIALS_IN_INSTANCES); state.bake_fps=p_bake_fps; Error err = state.load(p_path,flags,p_flags&EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS); @@ -2433,6 +2473,8 @@ Ref<Animation> EditorSceneImporterCollada::import_animation(const String& p_path ColladaImport state; + state.use_mesh_builtin_materials=false; + Error err = state.load(p_path,Collada::IMPORT_FLAG_ANIMATION,p_flags&EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS); ERR_FAIL_COND_V(err!=OK,RES()); @@ -2463,3 +2505,4 @@ EditorSceneImporterCollada::EditorSceneImporterCollada() { } + diff --git a/tools/editor/io_plugins/editor_import_collada.h b/tools/editor/import/editor_import_collada.h index f6642778ed..cd3614bb40 100644 --- a/tools/editor/io_plugins/editor_import_collada.h +++ b/tools/editor/import/editor_import_collada.h @@ -29,7 +29,7 @@ #ifndef EDITOR_IMPORT_COLLADA_H #define EDITOR_IMPORT_COLLADA_H -#include "tools/editor/io_plugins/editor_scene_import_plugin.h" +#include "tools/editor/import/resource_importer_scene.h" diff --git a/tools/editor/import/resource_importer_csv_translation.cpp b/tools/editor/import/resource_importer_csv_translation.cpp new file mode 100644 index 0000000000..f14c10fb99 --- /dev/null +++ b/tools/editor/import/resource_importer_csv_translation.cpp @@ -0,0 +1,126 @@ + +#include "resource_importer_csv_translation.h" +#include "os/file_access.h" +#include "translation.h" +#include "io/resource_saver.h" +#include "compressed_translation.h" + +String ResourceImporterCSVTranslation::get_importer_name() const { + + return "csv_translation"; +} + +String ResourceImporterCSVTranslation::get_visible_name() const{ + + return "CSV Translation"; +} +void ResourceImporterCSVTranslation::get_recognized_extensions(List<String> *p_extensions) const{ + + p_extensions->push_back("csv"); +} + +String ResourceImporterCSVTranslation::get_save_extension() const { + return ""; //does not save a single resoure +} + +String ResourceImporterCSVTranslation::get_resource_type() const{ + + return "StreamCSVTranslation"; +} + +bool ResourceImporterCSVTranslation::get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const { + + return true; +} + +int ResourceImporterCSVTranslation::get_preset_count() const { + return 0; +} +String ResourceImporterCSVTranslation::get_preset_name(int p_idx) const { + + return ""; +} + + +void ResourceImporterCSVTranslation::get_import_options(List<ImportOption> *r_options,int p_preset) const { + + + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"compress"),true)); + +} + + + +Error ResourceImporterCSVTranslation::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 compress = p_options["compress"]; + FileAccessRef f = FileAccess::open(p_source_file,FileAccess::READ); + + ERR_FAIL_COND_V( !f, ERR_INVALID_PARAMETER ); + + Vector<String> line = f->get_csv_line(); + if (line.size()<=1) { + return ERR_PARSE_ERROR; + } + + Vector<String> locales; + Vector<Ref<Translation> > translations; + + for(int i=1;i<line.size();i++) { + + String locale = line[i]; + if (!TranslationServer::is_locale_valid(locale)) { + return ERR_PARSE_ERROR; + } + + locales.push_back(locale); + Ref<Translation> translation; + translation.instance(); + translation->set_locale(locale); + translations.push_back(translation); + } + + line = f->get_csv_line(); + + while(line.size()==locales.size()+1) { + + String key = line[0]; + if (key!="") { + + for(int i=1;i<line.size();i++) { + translations[i-1]->add_message(key,line[i]); + } + } + + line = f->get_csv_line(); + } + + + for(int i=0;i<translations.size();i++) { + Ref<Translation> xlt = translations[i]; + + if (compress) { + Ref<PHashTranslation> cxl = memnew( PHashTranslation ); + cxl->generate( xlt ); + xlt=cxl; + } + + String save_path = p_source_file.get_basename()+"."+translations[i]->get_locale()+".xl"; + + ResourceSaver::save(save_path,xlt); + if (r_gen_files) { + r_gen_files->push_back(save_path); + } + } + + + + return OK; + +} + +ResourceImporterCSVTranslation::ResourceImporterCSVTranslation() +{ + +} diff --git a/tools/editor/import/resource_importer_csv_translation.h b/tools/editor/import/resource_importer_csv_translation.h new file mode 100644 index 0000000000..d08218e7d9 --- /dev/null +++ b/tools/editor/import/resource_importer_csv_translation.h @@ -0,0 +1,27 @@ +#ifndef RESOURCEIMPORTERCSVTRANSLATION_H +#define RESOURCEIMPORTERCSVTRANSLATION_H + +#include "io/resource_import.h" + + +class ResourceImporterCSVTranslation : public ResourceImporter { + GDCLASS(ResourceImporterCSVTranslation,ResourceImporter) +public: + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const; + virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const; + + virtual Error 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=NULL); + + ResourceImporterCSVTranslation(); +}; + +#endif // RESOURCEIMPORTERCSVTRANSLATION_H diff --git a/tools/editor/import/resource_importer_obj.cpp b/tools/editor/import/resource_importer_obj.cpp new file mode 100644 index 0000000000..e6e23366f6 --- /dev/null +++ b/tools/editor/import/resource_importer_obj.cpp @@ -0,0 +1,231 @@ +#include "resource_importer_obj.h" + +#include "io/resource_saver.h" +#include "scene/resources/mesh.h" +#include "scene/resources/surface_tool.h" +#include "scene/resources/surface_tool.h" +#include "os/file_access.h" + +String ResourceImporterOBJ::get_importer_name() const { + + return "obj_mesh"; +} + +String ResourceImporterOBJ::get_visible_name() const{ + + return "OBJ As Mesh"; +} +void ResourceImporterOBJ::get_recognized_extensions(List<String> *p_extensions) const{ + + p_extensions->push_back("obj"); +} +String ResourceImporterOBJ::get_save_extension() const { + return "msh"; +} + +String ResourceImporterOBJ::get_resource_type() const{ + + return "Mesh"; +} + +bool ResourceImporterOBJ::get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const { + + return true; +} + +int ResourceImporterOBJ::get_preset_count() const { + return 0; +} +String ResourceImporterOBJ::get_preset_name(int p_idx) const { + + return String(); +} + + +void ResourceImporterOBJ::get_import_options(List<ImportOption> *r_options,int p_preset) const { + + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"generate/tangents"),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"generate/normals"),true)); + //not for nowp + //r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"import/materials"))); + //r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"import/textures"))); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"force/flip_faces"),false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"force/smooth_shading"),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"force/weld_vertices"),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL,"force/weld_tolerance",PROPERTY_HINT_RANGE,"0.00001,16,0.00001"),0.0001)); + //r_options->push_back(PropertyInfo(Variant::INT,"compress/bitrate",PROPERTY_HINT_ENUM,"64,96,128,192")); + +} + + + +Error ResourceImporterOBJ::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) { + + FileAccessRef f = FileAccess::open(p_source_file,FileAccess::READ); + ERR_FAIL_COND_V(!f,ERR_CANT_OPEN); + + Ref<Mesh> mesh = Ref<Mesh>( memnew( Mesh ) ); + Map<String,Ref<Material> > name_map; + + + + bool generate_normals=p_options["generate/normals"]; + bool generate_tangents=p_options["generate/tangents"]; + bool flip_faces=p_options["force/flip_faces"]; + bool force_smooth=p_options["force/smooth_shading"]; + bool weld_vertices=p_options["force/weld_vertices"]; + float weld_tolerance=p_options["force/weld_tolerance"]; + Vector<Vector3> vertices; + Vector<Vector3> normals; + Vector<Vector2> uvs; + String name; + + Ref<SurfaceTool> surf_tool = memnew( SurfaceTool) ; + surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES); + if (force_smooth) + surf_tool->add_smooth_group(true); + int has_index_data=false; + + while(true) { + + + String l = f->get_line().strip_edges(); + + if (l.begins_with("v ")) { + //vertex + Vector<String> v = l.split(" ",false); + ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA); + Vector3 vtx; + vtx.x=v[1].to_float(); + vtx.y=v[2].to_float(); + vtx.z=v[3].to_float(); + vertices.push_back(vtx); + } else if (l.begins_with("vt ")) { + //uv + Vector<String> v = l.split(" ",false); + ERR_FAIL_COND_V(v.size()<3,ERR_INVALID_DATA); + Vector2 uv; + uv.x=v[1].to_float(); + uv.y=1.0-v[2].to_float(); + uvs.push_back(uv); + + } else if (l.begins_with("vn ")) { + //normal + Vector<String> v = l.split(" ",false); + ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA); + Vector3 nrm; + nrm.x=v[1].to_float(); + nrm.y=v[2].to_float(); + nrm.z=v[3].to_float(); + normals.push_back(nrm); + } if (l.begins_with("f ")) { + //vertex + + has_index_data=true; + Vector<String> v = l.split(" ",false); + ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA); + + //not very fast, could be sped up + + + Vector<String> face[3]; + face[0] = v[1].split("/"); + face[1] = v[2].split("/"); + ERR_FAIL_COND_V(face[0].size()==0,ERR_PARSE_ERROR); + ERR_FAIL_COND_V(face[0].size()!=face[1].size(),ERR_PARSE_ERROR); + for(int i=2;i<v.size()-1;i++) { + + face[2] = v[i+1].split("/"); + ERR_FAIL_COND_V(face[0].size()!=face[2].size(),ERR_PARSE_ERROR); + for(int j=0;j<3;j++) { + + int idx=j; + + if (!flip_faces && idx<2) { + idx=1^idx; + } + + + if (face[idx].size()==3) { + int norm = face[idx][2].to_int()-1; + ERR_FAIL_INDEX_V(norm,normals.size(),ERR_PARSE_ERROR); + surf_tool->add_normal(normals[norm]); + } + + if (face[idx].size()>=2 && face[idx][1]!=String()) { + + int uv = face[idx][1].to_int()-1; + ERR_FAIL_INDEX_V(uv,uvs.size(),ERR_PARSE_ERROR); + surf_tool->add_uv(uvs[uv]); + } + + int vtx = face[idx][0].to_int()-1; + ERR_FAIL_INDEX_V(vtx,vertices.size(),ERR_PARSE_ERROR); + + Vector3 vertex = vertices[vtx]; + if (weld_vertices) + vertex=vertex.snapped(weld_tolerance); + surf_tool->add_vertex(vertex); + } + + face[1]=face[2]; + } + } else if (l.begins_with("s ") && !force_smooth) { //smoothing + String what = l.substr(2,l.length()).strip_edges(); + if (what=="off") + surf_tool->add_smooth_group(false); + else + surf_tool->add_smooth_group(true); + + } else if (l.begins_with("o ") || f->eof_reached()) { //new surface or done + + if (has_index_data) { + //new object/surface + if (generate_normals || force_smooth) + surf_tool->generate_normals(); + if (uvs.size() && (normals.size() || generate_normals) && generate_tangents) + surf_tool->generate_tangents(); + + surf_tool->index(); + mesh = surf_tool->commit(mesh); + if (name=="") + name=vformat(TTR("Surface %d"),mesh->get_surface_count()-1); + mesh->surface_set_name(mesh->get_surface_count()-1,name); + name=""; + surf_tool->clear(); + surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES); + if (force_smooth) + surf_tool->add_smooth_group(true); + + has_index_data=false; + + if (f->eof_reached()) + break; + } + + if (l.begins_with("o ")) //name + name=l.substr(2,l.length()).strip_edges(); + } + } + +/* + TODO, check existing materials and merge? + //re-apply materials if exist + for(int i=0;i<mesh->get_surface_count();i++) { + + String n = mesh->surface_get_name(i); + if (name_map.has(n)) + mesh->surface_set_material(i,name_map[n]); + } +*/ + + Error err = ResourceSaver::save(p_save_path+".msh",mesh); + + return err; + +} + +ResourceImporterOBJ::ResourceImporterOBJ() +{ + +} diff --git a/tools/editor/import/resource_importer_obj.h b/tools/editor/import/resource_importer_obj.h new file mode 100644 index 0000000000..d2a3c4fddd --- /dev/null +++ b/tools/editor/import/resource_importer_obj.h @@ -0,0 +1,28 @@ +#ifndef RESOURCEIMPORTEROBJ_H +#define RESOURCEIMPORTEROBJ_H + + +#include "io/resource_import.h" + +class ResourceImporterOBJ : public ResourceImporter { + GDCLASS(ResourceImporterOBJ,ResourceImporter) +public: + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const; + virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const; + + virtual Error 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=NULL); + + ResourceImporterOBJ(); +}; + + +#endif // RESOURCEIMPORTEROBJ_H diff --git a/tools/editor/import/resource_importer_scene.cpp b/tools/editor/import/resource_importer_scene.cpp new file mode 100644 index 0000000000..ae840e9e16 --- /dev/null +++ b/tools/editor/import/resource_importer_scene.cpp @@ -0,0 +1,1328 @@ +#include "resource_importer_scene.h" + +#include "scene/resources/packed_scene.h" +#include "io/resource_saver.h" +#include "tools/editor/editor_node.h" + +#include "scene/3d/mesh_instance.h" +#include "scene/3d/navigation.h" +#include "scene/3d/room_instance.h" +#include "scene/3d/body_shape.h" +#include "scene/3d/physics_body.h" +#include "scene/3d/portal.h" +#include "scene/3d/vehicle_body.h" +#include "scene/resources/sphere_shape.h" +#include "scene/resources/box_shape.h" +#include "scene/resources/ray_shape.h" +#include "scene/resources/plane_shape.h" + + +void EditorScenePostImport::_bind_methods() { + + BIND_VMETHOD( MethodInfo("post_import",PropertyInfo(Variant::OBJECT,"scene")) ); + +} + +Node *EditorScenePostImport::post_import(Node* p_scene) { + + if (get_script_instance()) + return get_script_instance()->call("post_import",p_scene); + + return p_scene; +} + +EditorScenePostImport::EditorScenePostImport() { + + +} + + +String ResourceImporterScene::get_importer_name() const { + + return "scene"; +} + +String ResourceImporterScene::get_visible_name() const{ + + return "Scene"; +} + +void ResourceImporterScene::get_recognized_extensions(List<String> *p_extensions) const{ + + for (Set< Ref<EditorSceneImporter> >::Element *E=importers.front();E;E=E->next()) { + E->get()->get_extensions(p_extensions); + } +} + +String ResourceImporterScene::get_save_extension() const { + return "scn"; +} + +String ResourceImporterScene::get_resource_type() const{ + + return "PackedScene"; +} + +bool ResourceImporterScene::get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const { + + if (p_option.begins_with("animation/")) { + if (p_option!="animation/import" && !bool(p_options["animation/import"])) + return false; + + if (p_option.begins_with("animation/optimizer/") && p_option!="animation/optimizer/enabled" && !bool(p_options["animation/optimizer/enabled"])) + return false; + + if (p_option.begins_with("animation/clip_")) { + int max_clip = p_options["animation/clips/amount"]; + int clip = p_option.get_slice("/",1).get_slice("_",1).to_int()-1; + if (clip>=max_clip) + return false; + } + } + + return true; + +} + +int ResourceImporterScene::get_preset_count() const { + return 0; +} +String ResourceImporterScene::get_preset_name(int p_idx) const { + + return ""; +} + + +static bool _teststr(const String& p_what,const String& p_str) { + + if (p_what.findn("$"+p_str)!=-1) //blender and other stuff + return true; + if (p_what.to_lower().ends_with("-"+p_str)) //collada only supports "_" and "-" besides letters + return true; + if (p_what.to_lower().ends_with("_"+p_str)) //collada only supports "_" and "-" besides letters + return true; + return false; +} + +static String _fixstr(const String& p_what,const String& p_str) { + + if (p_what.findn("$"+p_str)!=-1) //blender and other stuff + return p_what.replace("$"+p_str,""); + if (p_what.to_lower().ends_with("-"+p_str)) //collada only supports "_" and "-" besides letters + return p_what.substr(0,p_what.length()-(p_str.length()+1)); + if (p_what.to_lower().ends_with("_"+p_str)) //collada only supports "_" and "-" besides letters + return p_what.substr(0,p_what.length()-(p_str.length()+1)); + return p_what; +} + + +Node* ResourceImporterScene::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>,Ref<Shape> > &collision_map) { + + // children first.. + for(int i=0;i<p_node->get_child_count();i++) { + + + Node *r = _fix_node(p_node->get_child(i),p_root,collision_map); + if (!r) { + print_line("was erased.."); + i--; //was erased + } + } + + String name = p_node->get_name(); + + bool isroot = p_node==p_root; + + + if (!isroot && _teststr(name,"noimp")) { + + memdelete(p_node); + return NULL; + } + + + if (p_node->cast_to<MeshInstance>()) { + + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + + bool bb=false; + + if ((_teststr(name,"bb"))) { + bb=true; + } else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(),"bb"))) { + bb=true; + + } + + if (bb) { + mi->set_flag(GeometryInstance::FLAG_BILLBOARD,true); + if (mi->get_mesh().is_valid()) { + + Ref<Mesh> m = mi->get_mesh(); + for(int i=0;i<m->get_surface_count();i++) { + + Ref<FixedSpatialMaterial> fm = m->surface_get_material(i); + if (fm.is_valid()) { + //fm->set_flag(Material::FLAG_UNSHADED,true); + //fm->set_flag(Material::FLAG_DOUBLE_SIDED,true); + //fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER); + //fm->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_ALPHA,true); + } + } + } + } + } + + + if (p_node->cast_to<MeshInstance>()) { + + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + + Ref<Mesh> m = mi->get_mesh(); + + if (m.is_valid()) { + + for(int i=0;i<m->get_surface_count();i++) { + + Ref<FixedSpatialMaterial> mat = m->surface_get_material(i); + if (!mat.is_valid()) + continue; + + if (_teststr(mat->get_name(),"alpha")) { + + mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT,true); + mat->set_name(_fixstr(mat->get_name(),"alpha")); + } + if (_teststr(mat->get_name(),"vcol")) { + + mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,true); + mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR,true); + mat->set_name(_fixstr(mat->get_name(),"vcol")); + } + + } + } + } + + if (p_node->cast_to<AnimationPlayer>()) { + //remove animations referencing non-importable nodes + AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>(); + + List<StringName> anims; + ap->get_animation_list(&anims); + for(List<StringName>::Element *E=anims.front();E;E=E->next()) { + + Ref<Animation> anim=ap->get_animation(E->get()); + ERR_CONTINUE(anim.is_null()); + for(int i=0;i<anim->get_track_count();i++) { + NodePath path = anim->track_get_path(i); + + for(int j=0;j<path.get_name_count();j++) { + String node = path.get_name(j); + if (_teststr(node,"noimp")) { + anim->remove_track(i); + i--; + break; + } + } + } + + } + } + + + if (p_node->cast_to<MeshInstance>()) { + + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + + String str; + + if ((_teststr(name,"imp"))) { + str=name; + } else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(),"imp"))) { + str=mi->get_mesh()->get_name(); + + } + + + if (p_node->get_parent() && p_node->get_parent()->cast_to<MeshInstance>()) { + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + MeshInstance *mip = p_node->get_parent()->cast_to<MeshInstance>(); + String d=str.substr(str.find("imp")+3,str.length()); + if (d!="") { + if ((d[0]<'0' || d[0]>'9')) + d=d.substr(1,d.length()); + if (d.length() && d[0]>='0' && d[0]<='9') { + float dist = d.to_double(); + mi->set_flag(GeometryInstance::FLAG_BILLBOARD,true); + mi->set_flag(GeometryInstance::FLAG_BILLBOARD_FIX_Y,true); + //mi->set_draw_range_begin(dist); + //mi->set_draw_range_end(100000); + + //mip->set_draw_range_begin(0); + //mip->set_draw_range_end(dist); + + if (mi->get_mesh().is_valid()) { + + Ref<Mesh> m = mi->get_mesh(); + for(int i=0;i<m->get_surface_count();i++) { + + Ref<FixedSpatialMaterial> fm = m->surface_get_material(i); + if (fm.is_valid()) { + //fm->set_flag(Material::FLAG_UNSHADED,true); + //fm->set_flag(Material::FLAG_DOUBLE_SIDED,true); + //fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER); + //fm->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_ALPHA,true); + } + } + } + } + } + } + } +#if 0 + if (p_flags&SCENE_FLAG_CREATE_LODS && p_node->cast_to<MeshInstance>()) { + + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + + String str; + + if ((_teststr(name,"lod"))) { + str=name; + } else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(),"lod"))) { + str=mi->get_mesh()->get_name(); + + } + + + if (p_node->get_parent() && p_node->get_parent()->cast_to<MeshInstance>()) { + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + MeshInstance *mip = p_node->get_parent()->cast_to<MeshInstance>(); + String d=str.substr(str.find("lod")+3,str.length()); + if (d!="") { + if ((d[0]<'0' || d[0]>'9')) + d=d.substr(1,d.length()); + if (d.length() && d[0]>='0' && d[0]<='9') { + float dist = d.to_double(); + /// mi->set_draw_range_begin(dist); + // mi->set_draw_range_end(100000); + + // mip->set_draw_range_begin(0); + // mip->set_draw_range_end(dist); + + /*if (mi->get_mesh().is_valid()) { + + Ref<Mesh> m = mi->get_mesh(); + for(int i=0;i<m->get_surface_count();i++) { + + Ref<FixedSpatialMaterial> fm = m->surface_get_material(i); + if (fm.is_valid()) { + fm->set_flag(Material::FLAG_UNSHADED,true); + fm->set_flag(Material::FLAG_DOUBLE_SIDED,true); + fm->set_hint(Material::HINT_NO_DEPTH_DRAW,true); + fm->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_ALPHA,true); + } + } + }*/ + } + } + } + } + + + if (p_flags&SCENE_FLAG_DETECT_LIGHTMAP_LAYER && _teststr(name,"lm") && p_node->cast_to<MeshInstance>()) { + + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + + String str=name; + int layer = str.substr(str.find("lm")+3,str.length()).to_int(); + //mi->set_baked_light_texture_id(layer); + } +#endif + if (_teststr(name,"colonly")) { + + if (isroot) + return p_node; + + if (p_node->cast_to<MeshInstance>()) { + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + Node * col = mi->create_trimesh_collision_node(); + ERR_FAIL_COND_V(!col,NULL); + + col->set_name(_fixstr(name,"colonly")); + col->cast_to<Spatial>()->set_transform(mi->get_transform()); + p_node->replace_by(col); + memdelete(p_node); + p_node=col; + + StaticBody *sb = col->cast_to<StaticBody>(); + CollisionShape *colshape = memnew( CollisionShape); + colshape->set_shape(sb->get_shape(0)); + colshape->set_name("shape"); + sb->add_child(colshape); + colshape->set_owner(p_node->get_owner()); + } else if (p_node->has_meta("empty_draw_type")) { + String empty_draw_type = String(p_node->get_meta("empty_draw_type")); + print_line(empty_draw_type); + StaticBody *sb = memnew( StaticBody); + sb->set_name(_fixstr(name,"colonly")); + sb->cast_to<Spatial>()->set_transform(p_node->cast_to<Spatial>()->get_transform()); + p_node->replace_by(sb); + memdelete(p_node); + CollisionShape *colshape = memnew( CollisionShape); + if (empty_draw_type == "CUBE") { + BoxShape *boxShape = memnew( BoxShape); + boxShape->set_extents(Vector3(1, 1, 1)); + colshape->set_shape(boxShape); + colshape->set_name("BoxShape"); + } else if (empty_draw_type == "SINGLE_ARROW") { + RayShape *rayShape = memnew( RayShape); + rayShape->set_length(1); + colshape->set_shape(rayShape); + colshape->set_name("RayShape"); + sb->cast_to<Spatial>()->rotate_x(Math_PI / 2); + } else if (empty_draw_type == "IMAGE") { + PlaneShape *planeShape = memnew( PlaneShape); + colshape->set_shape(planeShape); + colshape->set_name("PlaneShape"); + } else { + SphereShape *sphereShape = memnew( SphereShape); + sphereShape->set_radius(1); + colshape->set_shape(sphereShape); + colshape->set_name("SphereShape"); + } + sb->add_child(colshape); + colshape->set_owner(sb->get_owner()); + } + + } else if (_teststr(name,"rigid") && p_node->cast_to<MeshInstance>()) { + + if (isroot) + return p_node; + + // get mesh instance and bounding box + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + Rect3 aabb = mi->get_aabb(); + + // create a new rigid body collision node + RigidBody * rigid_body = memnew( RigidBody ); + Node * col = rigid_body; + ERR_FAIL_COND_V(!col,NULL); + + // remove node name postfix + col->set_name(_fixstr(name,"rigid")); + // get mesh instance xform matrix to the rigid body collision node + col->cast_to<Spatial>()->set_transform(mi->get_transform()); + // save original node by duplicating it into a new instance and correcting the name + Node * mesh = p_node->duplicate(); + mesh->set_name(_fixstr(name,"rigid")); + // reset the xform matrix of the duplicated node so it can inherit parent node xform + mesh->cast_to<Spatial>()->set_transform(Transform(Basis())); + // reparent the new mesh node to the rigid body collision node + p_node->add_child(mesh); + mesh->set_owner(p_node->get_owner()); + // replace the original node with the rigid body collision node + p_node->replace_by(col); + memdelete(p_node); + p_node=col; + + // create an alias for the rigid body collision node + RigidBody *rb = col->cast_to<RigidBody>(); + // create a new Box collision shape and set the right extents + Ref<BoxShape> shape = memnew( BoxShape ); + shape->set_extents(aabb.get_size() * 0.5); + CollisionShape *colshape = memnew( CollisionShape); + colshape->set_name("shape"); + colshape->set_shape(shape); + // reparent the new collision shape to the rigid body collision node + rb->add_child(colshape); + colshape->set_owner(p_node->get_owner()); + + } else if (_teststr(name,"col") && p_node->cast_to<MeshInstance>()) { + + + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + + mi->set_name(_fixstr(name,"col")); + Node *col= mi->create_trimesh_collision_node(); + ERR_FAIL_COND_V(!col,NULL); + + col->set_name("col"); + p_node->add_child(col); + + StaticBody *sb=col->cast_to<StaticBody>(); + CollisionShape *colshape = memnew( CollisionShape); + colshape->set_shape(sb->get_shape(0)); + colshape->set_name("shape"); + col->add_child(colshape); + colshape->set_owner(p_node->get_owner()); + sb->set_owner(p_node->get_owner()); + + } else if (_teststr(name,"navmesh") && p_node->cast_to<MeshInstance>()) { + + if (isroot) + return p_node; + + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + + Ref<Mesh> mesh=mi->get_mesh(); + ERR_FAIL_COND_V(mesh.is_null(),NULL); + NavigationMeshInstance *nmi = memnew( NavigationMeshInstance ); + + + nmi->set_name(_fixstr(name,"navmesh")); + Ref<NavigationMesh> nmesh = memnew( NavigationMesh); + nmesh->create_from_mesh(mesh); + nmi->set_navigation_mesh(nmesh); + nmi->cast_to<Spatial>()->set_transform(mi->get_transform()); + p_node->replace_by(nmi); + memdelete(p_node); + p_node=nmi; + } else if (_teststr(name,"vehicle")) { + + if (isroot) + return p_node; + + Node *owner = p_node->get_owner(); + Spatial *s = p_node->cast_to<Spatial>(); + VehicleBody *bv = memnew( VehicleBody ); + String n = _fixstr(p_node->get_name(),"vehicle"); + bv->set_name(n); + p_node->replace_by(bv); + p_node->set_name(n); + bv->add_child(p_node); + bv->set_owner(owner); + p_node->set_owner(owner); + bv->set_transform(s->get_transform()); + s->set_transform(Transform()); + + p_node=bv; + + + } else if (_teststr(name,"wheel")) { + + if (isroot) + return p_node; + + Node *owner = p_node->get_owner(); + Spatial *s = p_node->cast_to<Spatial>(); + VehicleWheel *bv = memnew( VehicleWheel ); + String n = _fixstr(p_node->get_name(),"wheel"); + bv->set_name(n); + p_node->replace_by(bv); + p_node->set_name(n); + bv->add_child(p_node); + bv->set_owner(owner); + p_node->set_owner(owner); + bv->set_transform(s->get_transform()); + s->set_transform(Transform()); + + p_node=bv; + + } else if (_teststr(name,"room") && p_node->cast_to<MeshInstance>()) { + + + if (isroot) + return p_node; + + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + PoolVector<Face3> faces = mi->get_faces(VisualInstance::FACES_SOLID); + + + BSP_Tree bsptree(faces); + + Ref<RoomBounds> area = memnew( RoomBounds ); + //area->set_bounds(faces); + //area->set_geometry_hint(faces); + + + Room * room = memnew( Room ); + room->set_name(_fixstr(name,"room")); + room->set_transform(mi->get_transform()); + room->set_room(area); + + p_node->replace_by(room); + memdelete(p_node); + p_node=room; + + } else if (_teststr(name,"room")) { + + if (isroot) + return p_node; + + Spatial *dummy = p_node->cast_to<Spatial>(); + ERR_FAIL_COND_V(!dummy,NULL); + + Room * room = memnew( Room ); + room->set_name(_fixstr(name,"room")); + room->set_transform(dummy->get_transform()); + + p_node->replace_by(room); + memdelete(p_node); + p_node=room; + + //room->compute_room_from_subtree(); + + } else if (_teststr(name,"portal") && p_node->cast_to<MeshInstance>()) { + + if (isroot) + return p_node; + + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + PoolVector<Face3> faces = mi->get_faces(VisualInstance::FACES_SOLID); + + ERR_FAIL_COND_V(faces.size()==0,NULL); + //step 1 compute the plane + Set<Vector3> points; + Plane plane; + + Vector3 center; + + for(int i=0;i<faces.size();i++) { + + Face3 f = faces.get(i); + Plane p = f.get_plane(); + plane.normal+=p.normal; + plane.d+=p.d; + + for(int i=0;i<3;i++) { + + Vector3 v = f.vertex[i].snapped(0.01); + if (!points.has(v)) { + points.insert(v); + center+=v; + } + } + } + + plane.normal.normalize(); + plane.d/=faces.size(); + center/=points.size(); + + //step 2, create points + + Transform t; + t.basis.from_z(plane.normal); + t.basis.transpose(); + t.origin=center; + + Vector<Point2> portal_points; + + for(Set<Vector3>::Element *E=points.front();E;E=E->next()) { + + Vector3 local = t.xform_inv(E->get()); + portal_points.push_back(Point2(local.x,local.y)); + } + // step 3 bubbly sort points + + int swaps=0; + + do { + swaps=0; + + for(int i=0;i<portal_points.size()-1;i++) { + + float a = portal_points[i].angle(); + float b = portal_points[i+1].angle(); + + if (a>b) { + SWAP( portal_points[i], portal_points[i+1] ); + swaps++; + } + + } + + } while(swaps); + + + Portal *portal = memnew( Portal ); + + portal->set_shape(portal_points); + portal->set_transform( mi->get_transform() * t); + + p_node->replace_by(portal); + memdelete(p_node); + p_node=portal; + + } else if (p_node->cast_to<MeshInstance>()) { + + //last attempt, maybe collision insde the mesh data + + MeshInstance *mi = p_node->cast_to<MeshInstance>(); + + Ref<Mesh> mesh = mi->get_mesh(); + if (!mesh.is_null()) { + + if (_teststr(mesh->get_name(),"col")) { + + mesh->set_name( _fixstr(mesh->get_name(),"col") ); + Ref<Shape> shape; + + if (collision_map.has(mesh)) { + shape = collision_map[mesh]; + + } else { + + shape = mesh->create_trimesh_shape(); + if (!shape.is_null()) + collision_map[mesh]=shape; + + + } + + if (!shape.is_null()) { +#if 0 + StaticBody* static_body = memnew( StaticBody ); + ERR_FAIL_COND_V(!static_body,NULL); + static_body->set_name( String(mesh->get_name()) + "_col" ); + shape->set_name(static_body->get_name()); + static_body->add_shape(shape); + + mi->add_child(static_body); + if (mi->get_owner()) + static_body->set_owner( mi->get_owner() ); +#endif + } + + } + + for(int i=0;i<mesh->get_surface_count();i++) { + + Ref<FixedSpatialMaterial> fm = mesh->surface_get_material(i); + if (fm.is_valid()) { + String name = fm->get_name(); + /* if (_teststr(name,"alpha")) { + fm->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_ALPHA,true); + name=_fixstr(name,"alpha"); + } + + if (_teststr(name,"vcol")) { + fm->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_COLOR_ARRAY,true); + name=_fixstr(name,"vcol"); + }*/ + fm->set_name(name); + } + } + + } + + } + + + return p_node; +} + + +void ResourceImporterScene::_create_clips(Node *scene, const Array& p_clips,bool p_bake_all) { + + if (!scene->has_node(String("AnimationPlayer"))) + return; + + Node* n = scene->get_node(String("AnimationPlayer")); + ERR_FAIL_COND(!n); + AnimationPlayer *anim = n->cast_to<AnimationPlayer>(); + ERR_FAIL_COND(!anim); + + if (!anim->has_animation("default")) + return; + + + Ref<Animation> default_anim = anim->get_animation("default"); + + for(int i=0;i<p_clips.size();i+=4) { + + String name = p_clips[i]; + float from=p_clips[i+1]; + float to=p_clips[i+2]; + bool loop=p_clips[i+3]; + if (from>=to) + continue; + + Ref<Animation> new_anim = memnew( Animation ); + + for(int j=0;j<default_anim->get_track_count();j++) { + + + List<float> keys; + int kc = default_anim->track_get_key_count(j); + int dtrack=-1; + for(int k=0;k<kc;k++) { + + float kt = default_anim->track_get_key_time(j,k); + if (kt>=from && kt<to) { + + //found a key within range, so create track + if (dtrack==-1) { + new_anim->add_track(default_anim->track_get_type(j)); + dtrack = new_anim->get_track_count()-1; + new_anim->track_set_path(dtrack,default_anim->track_get_path(j)); + + if (kt>(from+0.01) && k>0) { + + if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) { + Quat q; + Vector3 p; + Vector3 s; + default_anim->transform_track_interpolate(j,from,&p,&q,&s); + new_anim->transform_track_insert_key(dtrack,0,p,q,s); + } + } + + } + + if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) { + Quat q; + Vector3 p; + Vector3 s; + default_anim->transform_track_get_key(j,k,&p,&q,&s); + new_anim->transform_track_insert_key(dtrack,kt-from,p,q,s); + } + + } + + if (dtrack!=-1 && kt>=to) { + + if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) { + Quat q; + Vector3 p; + Vector3 s; + default_anim->transform_track_interpolate(j,to,&p,&q,&s); + new_anim->transform_track_insert_key(dtrack,to-from,p,q,s); + } + } + + } + + if (dtrack==-1 && p_bake_all) { + new_anim->add_track(default_anim->track_get_type(j)); + dtrack = new_anim->get_track_count()-1; + new_anim->track_set_path(dtrack,default_anim->track_get_path(j)); + if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) { + + + Quat q; + Vector3 p; + Vector3 s; + default_anim->transform_track_interpolate(j,from,&p,&q,&s); + new_anim->transform_track_insert_key(dtrack,0,p,q,s); + default_anim->transform_track_interpolate(j,to,&p,&q,&s); + new_anim->transform_track_insert_key(dtrack,to-from,p,q,s); + } + + } + } + + + new_anim->set_loop(loop); + new_anim->set_length(to-from); + anim->add_animation(name,new_anim); + } + + anim->remove_animation("default"); //remove default (no longer needed) +} + +void ResourceImporterScene::_filter_anim_tracks(Ref<Animation> anim,Set<String> &keep) { + + Ref<Animation> a = anim; + ERR_FAIL_COND(!a.is_valid()); + + print_line("From Anim "+anim->get_name()+":"); + + for(int j=0;j<a->get_track_count();j++) { + + String path = a->track_get_path(j); + + if (!keep.has(path)) { + + print_line("Remove: "+path); + a->remove_track(j); + j--; + } + + } +} + + +void ResourceImporterScene::_filter_tracks(Node *scene, const String& p_text) { + + if (!scene->has_node(String("AnimationPlayer"))) + return; + Node* n = scene->get_node(String("AnimationPlayer")); + ERR_FAIL_COND(!n); + AnimationPlayer *anim = n->cast_to<AnimationPlayer>(); + ERR_FAIL_COND(!anim); + + Vector<String> strings = p_text.split("\n"); + for(int i=0;i<strings.size();i++) { + + strings[i]=strings[i].strip_edges(); + } + + List<StringName> anim_names; + anim->get_animation_list(&anim_names); + for(List<StringName>::Element *E=anim_names.front();E;E=E->next()) { + + String name = E->get(); + bool valid_for_this=false; + bool valid=false; + + Set<String> keep; + Set<String> keep_local; + + + for(int i=0;i<strings.size();i++) { + + + if (strings[i].begins_with("@")) { + + valid_for_this=false; + for(Set<String>::Element *F=keep_local.front();F;F=F->next()) { + keep.insert(F->get()); + } + keep_local.clear(); + + Vector<String> filters=strings[i].substr(1,strings[i].length()).split(","); + for(int j=0;j<filters.size();j++) { + + String fname = filters[j].strip_edges(); + if (fname=="") + continue; + int fc = fname[0]; + bool plus; + if (fc=='+') + plus=true; + else if (fc=='-') + plus=false; + else + continue; + + String filter=fname.substr(1,fname.length()).strip_edges(); + + if (!name.matchn(filter)) + continue; + valid_for_this=plus; + } + + if (valid_for_this) + valid=true; + + } else if (valid_for_this) { + + Ref<Animation> a = anim->get_animation(name); + if (!a.is_valid()) + continue; + + for(int j=0;j<a->get_track_count();j++) { + + String path = a->track_get_path(j); + + String tname = strings[i]; + if (tname=="") + continue; + int fc = tname[0]; + bool plus; + if (fc=='+') + plus=true; + else if (fc=='-') + plus=false; + else + continue; + + String filter=tname.substr(1,tname.length()).strip_edges(); + + if (!path.matchn(filter)) + continue; + + if (plus) + keep_local.insert(path); + else if (!keep.has(path)) { + keep_local.erase(path); + } + } + + } + + } + + if (valid) { + for(Set<String>::Element *F=keep_local.front();F;F=F->next()) { + keep.insert(F->get()); + } + _filter_anim_tracks(anim->get_animation(name),keep); + } else { + + } + + } + + + +} + +void ResourceImporterScene::_optimize_animations(Node *scene, float p_max_lin_error,float p_max_ang_error,float p_max_angle) { + + if (!scene->has_node(String("AnimationPlayer"))) + return; + Node* n = scene->get_node(String("AnimationPlayer")); + ERR_FAIL_COND(!n); + AnimationPlayer *anim = n->cast_to<AnimationPlayer>(); + ERR_FAIL_COND(!anim); + + + List<StringName> anim_names; + anim->get_animation_list(&anim_names); + for(List<StringName>::Element *E=anim_names.front();E;E=E->next()) { + + Ref<Animation> a = anim->get_animation(E->get()); + a->optimize(p_max_lin_error,p_max_ang_error,Math::deg2rad(p_max_angle)); + } +} + + +static String _make_extname(const String& p_str) { + + String ext_name=p_str.replace(".","_"); + ext_name=ext_name.replace(":","_"); + ext_name=ext_name.replace("\"","_"); + ext_name=ext_name.replace("<","_"); + ext_name=ext_name.replace(">","_"); + ext_name=ext_name.replace("/","_"); + ext_name=ext_name.replace("|","_"); + ext_name=ext_name.replace("\\","_"); + ext_name=ext_name.replace("?","_"); + ext_name=ext_name.replace("*","_"); + + return ext_name; +} + +void ResourceImporterScene::_make_external_resources(Node* p_node,const String& p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>,Ref<Material> >& p_materials, Map<Ref<Mesh>,Ref<Mesh> >& p_meshes) { + + List<PropertyInfo> pi; + + p_node->get_property_list(&pi); + + for (List<PropertyInfo>::Element *E=pi.front();E;E=E->next()) { + + if (E->get().type==Variant::OBJECT) { + + Ref<Material> mat = p_node->get(E->get().name); + if (p_make_materials && mat.is_valid() && mat->get_name()!="") { + + + if (!p_materials.has(mat)) { + + String ext_name = p_base_path+"."+_make_extname(mat->get_name())+".mtl"; + if (FileAccess::exists(ext_name)) { + //if exists, use it + Ref<Material> existing = ResourceLoader::load(ext_name); + p_materials[mat]=existing; + } else { + + ResourceSaver::save(ext_name,mat,ResourceSaver::FLAG_CHANGE_PATH); + p_materials[mat]=mat; + } + } + + if (p_materials[mat]!=mat) { + + p_node->set(E->get().name,p_materials[mat]); + } + } else { + + Ref<Mesh> mesh = p_node->get(E->get().name); + + if (mesh.is_valid()) { + + bool mesh_just_added=false; + + if (p_make_meshes) { + + if (!p_meshes.has(mesh)) { + + String ext_name = p_base_path+"."+_make_extname(mesh->get_name())+".msh"; + if (FileAccess::exists(ext_name)) { + //if exists, use it + Ref<Mesh> existing = ResourceLoader::load(ext_name); + p_meshes[mesh]=existing; + } else { + + ResourceSaver::save(ext_name,mesh,ResourceSaver::FLAG_CHANGE_PATH); + p_meshes[mesh]=mesh; + mesh_just_added=true; + } + + + } + } + + + if (p_make_materials){ + + if (mesh_just_added || !p_meshes.has(mesh)) { + + + for(int i=0;i<mesh->get_surface_count();i++) { + mat=mesh->surface_get_material(i); + if (!mat.is_valid() || mat->get_name()=="") + continue; + + if (!p_materials.has(mat)) { + + String ext_name = p_base_path+"."+_make_extname(mat->get_name())+".mtl"; + if (FileAccess::exists(ext_name)) { + //if exists, use it + Ref<Material> existing = ResourceLoader::load(ext_name); + p_materials[mat]=existing; + } else { + + ResourceSaver::save(ext_name,mat,ResourceSaver::FLAG_CHANGE_PATH); + p_materials[mat]=mat; + } + } + + if (p_materials[mat]!=mat) { + + mesh->surface_set_material(i,p_materials[mat]); + } + + } + + if(!p_make_meshes) { + p_meshes[mesh]=Ref<Mesh>(); //save it anyway, so it won't be checked again + } + } + } + } + } + } + } + + for(int i=0;i<p_node->get_child_count();i++) { + + _make_external_resources(p_node->get_child(i),p_base_path,p_make_materials,p_make_meshes,p_materials,p_meshes); + } +} + + +void ResourceImporterScene::get_import_options(List<ImportOption> *r_options,int p_preset) const { + + + r_options->push_back(ImportOption(PropertyInfo(Variant::STRING,"nodes/root_type",PROPERTY_HINT_TYPE_STRING,"Node"),"Spatial")); + r_options->push_back(ImportOption(PropertyInfo(Variant::STRING,"nodes/root_name"),"Scene Root")); + + List<String> script_extentions; + ResourceLoader::get_recognized_extensions_for_type("Script",&script_extentions); + + String script_ext_hint; + + for(List<String>::Element *E=script_extentions.front();E;E=E->next()) { + if (script_ext_hint!="") + script_ext_hint+=","; + script_ext_hint+="*."+E->get(); + } + + r_options->push_back(ImportOption(PropertyInfo(Variant::STRING,"nodes/custom_script",PROPERTY_HINT_FILE,script_ext_hint),"")); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"materials/location",PROPERTY_HINT_ENUM,"Node,Mesh"),0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"materials/storage",PROPERTY_HINT_ENUM,"Bult-In,Files"),0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"geometry/compress"),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"geometry/ensure_tangents"),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"geometry/storage",PROPERTY_HINT_ENUM,"Built-In,Files"),0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"animation/import",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL,"animation/fps",PROPERTY_HINT_RANGE,"1,120,1"),15)); + r_options->push_back(ImportOption(PropertyInfo(Variant::STRING,"animation/filter_script",PROPERTY_HINT_MULTILINE_TEXT),"")); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"animation/optimizer/enabled",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL,"animation/optimizer/max_linear_error"),0.05)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL,"animation/optimizer/max_angular_error"),0.01)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL,"animation/optimizer/max_angle"),22)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"animation/optimizer/remove_unused_tracks"),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"animation/clips/amount",PROPERTY_HINT_RANGE,"0,256,1",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED),0)); + for(int i=0;i<256;i++) { + r_options->push_back(ImportOption(PropertyInfo(Variant::STRING,"animation/clip_"+itos(i+1)+"/name"),"")); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"animation/clip_"+itos(i+1)+"/start_frame"),0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"animation/clip_"+itos(i+1)+"/end_frame"),0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"animation/clip_"+itos(i+1)+"/loops"),false)); + } +} + +Error ResourceImporterScene::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) { + + String src_path=p_source_file; + + Ref<EditorSceneImporter> importer; + String ext=src_path.get_extension().to_lower(); + + + EditorProgress progress("import",TTR("Import Scene"),104); + progress.step(TTR("Importing Scene.."),0); + + for(Set< Ref<EditorSceneImporter> >::Element *E=importers.front();E;E=E->next()) { + + List<String> extensions; + E->get()->get_extensions(&extensions); + + for(List<String>::Element *F=extensions.front();F;F=F->next()) { + + if (F->get().to_lower()==ext) { + + importer = E->get(); + break; + } + } + + if (importer.is_valid()) + break; + } + + ERR_FAIL_COND_V(!importer.is_valid(),ERR_FILE_UNRECOGNIZED); + + float fps=p_options["animation/fps"]; + + + + int import_flags=EditorSceneImporter::IMPORT_ANIMATION_DETECT_LOOP; + if (!bool(p_options["animation/optimizer/remove_unused_tracks"])) + import_flags|=EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS; + + if (bool(p_options["animation/import"])) + import_flags|=EditorSceneImporter::IMPORT_ANIMATION; + + if (bool(p_options["geometry/ensure_tangents"])) + import_flags|=EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS; + + if (int(p_options["materials/location"])==0) + import_flags|=EditorSceneImporter::IMPORT_MATERIALS_IN_INSTANCES; + + + Error err=OK; + List<String> missing_deps; // for now, not much will be done with this + Node *scene = importer->import_scene(src_path,import_flags,fps,&missing_deps,&err); + if (!scene || err!=OK) { + return err; + } + + String root_type = p_options["nodes/root_type"]; + + if (scene->get_class()!=root_type) { + Object *base = ClassDB::instance(root_type); + Node *base_node = NULL; + if (base) + base_node=base->cast_to<Node>(); + + if (base_node) { + + scene->replace_by(base_node); + memdelete(scene); + scene=base_node; + } + } + + scene->set_name(p_options["nodes/root_name"]); + + + err=OK; + + String animation_filter = String(p_options["animation/filter_script"]).strip_edges(); + + bool use_optimizer = p_options["animation/optimizer/enabled"]; + float anim_optimizer_linerr=p_options["animation/optimizer/max_linear_error"]; + float anim_optimizer_angerr=p_options["animation/optimizer/max_angular_error"]; + float anim_optimizer_maxang=p_options["animation/optimizer/max_angle"]; + + Map<Ref<Mesh>,Ref<Shape> > collision_map; + + scene=_fix_node(scene,scene,collision_map); + + if (use_optimizer) { + _optimize_animations(scene,anim_optimizer_linerr,anim_optimizer_angerr,anim_optimizer_maxang); + } + + Array animation_clips; + { + + + int clip_count = p_options["animation/clips/amount"]; + + for(int i=0;i<clip_count;i++) { + String name = p_options["animation/clip_"+itos(i+1)+"/name"]; + int from_frame = p_options["animation/clip_"+itos(i+1)+"/start_frame"]; + int end_frame = p_options["animation/clip_"+itos(i+1)+"/end_frame"]; + bool loop = p_options["animation/clip_"+itos(i+1)+"/loops"]; + + animation_clips.push_back(name); + animation_clips.push_back(from_frame/fps); + animation_clips.push_back(end_frame/fps); + animation_clips.push_back(loop); + } + + } + if (animation_clips.size()) { + _create_clips(scene,animation_clips,!bool(p_options["animation/optimizer/remove_unused_tracks"])); + } + + if (animation_filter!="") { + _filter_tracks(scene,animation_filter); + } + + + bool external_materials = p_options["materials/storage"]; + bool external_meshes = p_options["geometry/storage"]; + + if (external_materials || external_meshes) { + Map<Ref<Material>, Ref<Material> > mat_map; + Map<Ref<Mesh>, Ref<Mesh> > mesh_map; + _make_external_resources(scene,p_source_file.get_basename(),external_materials,external_meshes,mat_map,mesh_map); + } + + progress.step(TTR("Running Custom Script.."),2); + + String post_import_script_path = p_options["nodes/custom_script"]; + Ref<EditorScenePostImport> post_import_script; + + if (post_import_script_path!="") { + post_import_script_path = post_import_script_path; + Ref<Script> scr = ResourceLoader::load(post_import_script_path); + if (!scr.is_valid()) { + EditorNode::add_io_error(TTR("Couldn't load post-import script:")+" "+post_import_script_path); + } else { + + post_import_script = Ref<EditorScenePostImport>( memnew( EditorScenePostImport ) ); + post_import_script->set_script(scr.get_ref_ptr()); + if (!post_import_script->get_script_instance()) { + EditorNode::add_io_error(TTR("Invalid/broken script for post-import (check console):")+" "+post_import_script_path); + post_import_script.unref(); + return ERR_CANT_CREATE; + } + } + } + + + if (post_import_script.is_valid()) { + scene = post_import_script->post_import(scene); + if (!scene) { + EditorNode::add_io_error(TTR("Error running post-import script:")+" "+post_import_script_path); + return err; + } + + + } + + progress.step(TTR("Saving.."),104); + + Ref<PackedScene> packer = memnew( PackedScene ); + packer->pack(scene); + print_line("SAVING TO: "+p_save_path+".scn"); + err = ResourceSaver::save(p_save_path+".scn",packer); //do not take over, let the changed files reload themselves + + memdelete(scene); + + EditorNode::get_singleton()->reload_scene(p_source_file); + + return OK; +} + +ResourceImporterScene *ResourceImporterScene::singleton=NULL; + +ResourceImporterScene::ResourceImporterScene() +{ + singleton=this; +} diff --git a/tools/editor/import/resource_importer_scene.h b/tools/editor/import/resource_importer_scene.h new file mode 100644 index 0000000000..cfa44b160a --- /dev/null +++ b/tools/editor/import/resource_importer_scene.h @@ -0,0 +1,93 @@ +#ifndef RESOURCEIMPORTERSCENE_H +#define RESOURCEIMPORTERSCENE_H + +#include "io/resource_import.h" +#include "scene/resources/animation.h" +#include "scene/resources/shape.h" + +class Material; + +class EditorSceneImporter : public Reference { + + GDCLASS(EditorSceneImporter,Reference ); +public: + + enum ImportFlags { + IMPORT_SCENE=1, + IMPORT_ANIMATION=2, + IMPORT_ANIMATION_DETECT_LOOP=4, + IMPORT_ANIMATION_OPTIMIZE=8, + IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS=16, + IMPORT_ANIMATION_KEEP_VALUE_TRACKS=32, + IMPORT_GENERATE_TANGENT_ARRAYS=256, + IMPORT_FAIL_ON_MISSING_DEPENDENCIES=512, + IMPORT_MATERIALS_IN_INSTANCES=1024 + + }; + + virtual uint32_t get_import_flags() const=0; + virtual void get_extensions(List<String> *r_extensions) const=0; + virtual Node* import_scene(const String& p_path,uint32_t p_flags,int p_bake_fps,List<String> *r_missing_deps,Error* r_err=NULL)=0; + virtual Ref<Animation> import_animation(const String& p_path,uint32_t p_flags)=0; + + + + EditorSceneImporter() {} +}; + +class EditorScenePostImport : public Reference { + + GDCLASS(EditorScenePostImport,Reference ); +protected: + + static void _bind_methods(); +public: + + virtual Node* post_import(Node* p_scene); + EditorScenePostImport(); +}; + + +class ResourceImporterScene : public ResourceImporter { + GDCLASS(ResourceImporterScene,ResourceImporter) + + Set< Ref<EditorSceneImporter> > importers; + + static ResourceImporterScene *singleton; +public: + + static ResourceImporterScene *get_singleton() { return singleton; } + + const Set< Ref<EditorSceneImporter> >& get_importers() const { return importers; } + + void add_importer(Ref<EditorSceneImporter> p_importer) { importers.insert(p_importer); } + + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const; + virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const; + + void _make_external_resources(Node* p_node,const String& p_base_path, bool p_make_materials, bool p_make_meshes, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<Mesh>, Ref<Mesh> > &p_meshes); + + Node* _fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>,Ref<Shape> > &collision_map); + + void _create_clips(Node *scene, const Array& p_clips,bool p_bake_all); + void _filter_anim_tracks(Ref<Animation> anim,Set<String> &keep); + void _filter_tracks(Node *scene, const String& p_text); + void _optimize_animations(Node *scene, float p_max_lin_error,float p_max_ang_error,float p_max_angle); + + virtual Error 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=NULL); + + ResourceImporterScene(); +}; + + +#endif // RESOURCEIMPORTERSCENE_H diff --git a/tools/editor/import/resource_importer_texture.cpp b/tools/editor/import/resource_importer_texture.cpp new file mode 100644 index 0000000000..21e434fa11 --- /dev/null +++ b/tools/editor/import/resource_importer_texture.cpp @@ -0,0 +1,393 @@ +#include "resource_importer_texture.h" +#include "io/image_loader.h" +#include "scene/resources/texture.h" +#include "tools/editor/editor_file_system.h" +#include "io/config_file.h" + + +void ResourceImporterTexture::_texture_reimport_srgb(const Ref<StreamTexture>& p_tex) { + + singleton->mutex->lock(); + StringName path = p_tex->get_path(); + + if (!singleton->make_flags.has(path)) { + singleton->make_flags[path]=0; + } + + singleton->make_flags[path]|=MAKE_SRGB_FLAG; + + print_line("requesting srgb for "+String(path)); + + singleton->mutex->unlock(); + +} + + + +void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture>& p_tex) { + + + singleton->mutex->lock(); + StringName path = p_tex->get_path(); + + if (!singleton->make_flags.has(path)) { + singleton->make_flags[path]=0; + } + + singleton->make_flags[path]|=MAKE_3D_FLAG; + + print_line("requesting 3d for "+String(path)); + + singleton->mutex->unlock(); + + +} + +void ResourceImporterTexture::update_imports() { + + if (EditorFileSystem::get_singleton()->is_scanning() || EditorFileSystem::get_singleton()->is_importing()) { + return; // do nothing for noe + } + mutex->lock(); + + if (make_flags.empty()) { + mutex->unlock(); + return; + } + + Vector<String> to_reimport; + for (Map<StringName,int>::Element *E=make_flags.front();E;E=E->next()) { + + print_line("checking for reimport "+String(E->key())); + + + Ref<ConfigFile> cf; + cf.instance(); + String src_path = String(E->key())+".import"; + + Error err = cf->load(src_path); + ERR_CONTINUE(err!=OK); + + bool changed=false; + if (E->get()&MAKE_SRGB_FLAG && int(cf->get_value("params","flags/srgb"))==2) { + cf->set_value("params","flags/srgb",1); + changed=true; + } + + if (E->get()&MAKE_3D_FLAG && bool(cf->get_value("params","detect_3d"))) { + cf->set_value("params","detect_3d",false); + cf->set_value("params","compress/mode",2); + cf->set_value("params","flags/repeat",true); + cf->set_value("params","flags/filter",true); + cf->set_value("params","flags/mipmaps",true); + changed=true; + } + + if (changed) { + cf->save(src_path); + to_reimport.push_back(E->key()); + } + + } + + make_flags.clear(); + + mutex->unlock(); + + if (to_reimport.size()) { + EditorFileSystem::get_singleton()->reimport_files(to_reimport); + } + +} + + + +String ResourceImporterTexture::get_importer_name() const { + + return "texture"; +} + +String ResourceImporterTexture::get_visible_name() const{ + + return "Texture"; +} +void ResourceImporterTexture::get_recognized_extensions(List<String> *p_extensions) const{ + + ImageLoader::get_recognized_extensions(p_extensions); +} +String ResourceImporterTexture::get_save_extension() const { + return "stex"; +} + +String ResourceImporterTexture::get_resource_type() const{ + + return "StreamTexture"; +} + +bool ResourceImporterTexture::get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const { + + if (p_option=="compress/lossy_quality" && int(p_options["compress/mode"])!=COMPRESS_LOSSY) + return false; + + return true; +} + +int ResourceImporterTexture::get_preset_count() const { + return 4; +} +String ResourceImporterTexture::get_preset_name(int p_idx) const { + + static const char* preset_names[]={ + "2D, Detect 3D", + "2D", + "2D Pixel", + "3D" + }; + + return preset_names[p_idx]; +} + + +void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options,int p_preset) const { + + + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"compress/mode",PROPERTY_HINT_ENUM,"Lossless,Lossy,Video RAM,Uncompressed",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED),p_preset==PRESET_3D?2:0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL,"compress/lossy_quality",PROPERTY_HINT_RANGE,"0,1,0.01"),0.7)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"flags/repeat",PROPERTY_HINT_ENUM,"Disabled,Enabled,Mirrored"),p_preset==PRESET_3D?1:0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/filter"),p_preset==PRESET_2D_PIXEL?false:true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/mipmaps"),p_preset==PRESET_3D?true:false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"flags/anisotropic"),false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"flags/srgb",PROPERTY_HINT_ENUM,"Disable,Enable,Detect"),2)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"process/fix_alpha_border"),p_preset!=PRESET_3D?true:false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"process/premult_alpha"),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"stream"),false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"size_limit",PROPERTY_HINT_RANGE,"0,4096,1"),0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"detect_3d"),p_preset==PRESET_DETECT)); + +} + + +void ResourceImporterTexture::_save_stex(const Image& p_image, const String& p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb) { + + + FileAccess *f = FileAccess::open(p_to_path,FileAccess::WRITE); + f->store_8('G'); + f->store_8('D'); + f->store_8('S'); + f->store_8('T'); //godot streamable texture + + f->store_32(p_image.get_width()); + f->store_32(p_image.get_height()); + f->store_32(p_texture_flags); + + uint32_t format=0; + + if (p_streamable) + format|=StreamTexture::FORMAT_BIT_STREAM; + if (p_mipmaps || p_compress_mode==COMPRESS_VIDEO_RAM) //VRAM always uses mipmaps + format|=StreamTexture::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit + if (p_detect_3d) + format|=StreamTexture::FORMAT_BIT_DETECT_3D; + if (p_detect_srgb) + format|=StreamTexture::FORMAT_BIT_DETECT_SRGB; + + + switch (p_compress_mode) { + case COMPRESS_LOSSLESS: { + + Image image = p_image; + if (p_mipmaps) { + image.generate_mipmaps(); + } else { + image.clear_mipmaps(); + } + + int mmc = image.get_mipmap_count() + 1; + + format|=StreamTexture::FORMAT_BIT_LOSSLESS; + f->store_32(format); + f->store_32(mmc); + + for(int i=0;i<mmc;i++) { + + if (i>0) { + image.shrink_x2(); + } + + PoolVector<uint8_t> data = Image::lossless_packer(image); + int data_len = data.size(); + f->store_32(data_len); + + PoolVector<uint8_t>::Read r= data.read(); + f->store_buffer(r.ptr(),data_len); + + } + + + } break; + case COMPRESS_LOSSY: { + Image image = p_image; + if (p_mipmaps) { + image.generate_mipmaps(); + } else { + image.clear_mipmaps(); + } + + int mmc = image.get_mipmap_count() + 1; + + format|=StreamTexture::FORMAT_BIT_LOSSY; + f->store_32(format); + f->store_32(mmc); + + for(int i=0;i<mmc;i++) { + + if (i>0) { + image.shrink_x2(); + } + + PoolVector<uint8_t> data = Image::lossy_packer(image,p_lossy_quality); + int data_len = data.size(); + f->store_32(data_len); + + PoolVector<uint8_t>::Read r = data.read(); + f->store_buffer(r.ptr(),data_len); + + } + } break; + case COMPRESS_VIDEO_RAM: { + + Image image = p_image; + image.generate_mipmaps(); + image.compress(p_vram_compression); + + format |= image.get_format(); + + f->store_32(format); + + PoolVector<uint8_t> data=image.get_data(); + int dl = data.size(); + PoolVector<uint8_t>::Read r = data.read(); + f->store_buffer(r.ptr(),dl); + + } break; + case COMPRESS_UNCOMPRESSED: { + + Image image = p_image; + if (p_mipmaps) { + image.generate_mipmaps(); + } else { + image.clear_mipmaps(); + } + + format |= image.get_format(); + f->store_32(format); + + PoolVector<uint8_t> data=image.get_data(); + int dl = data.size(); + PoolVector<uint8_t>::Read r = data.read(); + + f->store_buffer(r.ptr(),dl); + + } break; + } + + memdelete(f); +} + +Error ResourceImporterTexture::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) { + + int compress_mode = p_options["compress/mode"]; + float lossy= p_options["compress/lossy_quality"]; + int repeat= p_options["flags/repeat"]; + bool filter= p_options["flags/filter"]; + bool mipmaps= p_options["flags/mipmaps"]; + bool anisotropic= p_options["flags/anisotropic"]; + int srgb= p_options["flags/srgb"]; + bool fix_alpha_border= p_options["process/fix_alpha_border"]; + bool premult_alpha= p_options["process/premult_alpha"]; + bool stream = p_options["stream"]; + int size_limit = p_options["size_limit"]; + + + Image image; + Error err = ImageLoader::load_image(p_source_file,&image); + if (err!=OK) + return err; + + + int tex_flags=0; + if (repeat>0) + tex_flags|=Texture::FLAG_REPEAT; + if (repeat==2) + tex_flags|=Texture::FLAG_MIRRORED_REPEAT; + if (filter) + tex_flags|=Texture::FLAG_FILTER; + if (mipmaps || compress_mode==COMPRESS_VIDEO_RAM) + tex_flags|=Texture::FLAG_MIPMAPS; + if (anisotropic) + tex_flags|=Texture::FLAG_ANISOTROPIC_FILTER; + if (srgb==1) + tex_flags|=Texture::FLAG_CONVERT_TO_LINEAR; + + if (size_limit >0 && (image.get_width()>size_limit || image.get_height()>size_limit )) { + //limit size + if (image.get_width() >= image.get_height()) { + int new_width = size_limit; + int new_height = image.get_height() * new_width / image.get_width(); + + image.resize(new_width,new_height,Image::INTERPOLATE_CUBIC); + } else { + + int new_height = size_limit; + int new_width = image.get_width() * new_height / image.get_height(); + + image.resize(new_width,new_height,Image::INTERPOLATE_CUBIC); + } + } + + if (fix_alpha_border) { + image.fix_alpha_edges(); + } + + if (premult_alpha) { + image.premultiply_alpha(); + } + + bool detect_3d = p_options["detect_3d"]; + bool detect_srgb = srgb==2; + + if (compress_mode==COMPRESS_VIDEO_RAM) { + //must import in all formats + //Android, GLES 2.x + _save_stex(image,p_save_path+".etc.stex",compress_mode,lossy,Image::COMPRESS_ETC,mipmaps,tex_flags,stream,detect_3d,detect_srgb); + r_platform_variants->push_back("etc"); + //_save_stex(image,p_save_path+".etc2.stex",compress_mode,lossy,Image::COMPRESS_ETC2,mipmaps,tex_flags,stream); + //r_platform_variants->push_back("etc2"); + _save_stex(image,p_save_path+".s3tc.stex",compress_mode,lossy,Image::COMPRESS_S3TC,mipmaps,tex_flags,stream,detect_3d,detect_srgb); + r_platform_variants->push_back("s3tc"); + + } else { + //import normally + _save_stex(image,p_save_path+".stex",compress_mode,lossy,Image::COMPRESS_16BIT /*this is ignored */,mipmaps,tex_flags,stream,detect_3d,detect_srgb); + } + + return OK; +} + +ResourceImporterTexture *ResourceImporterTexture::singleton=NULL; + +ResourceImporterTexture::ResourceImporterTexture() +{ + + singleton=this; + StreamTexture::request_3d_callback=_texture_reimport_3d; + StreamTexture::request_srgb_callback=_texture_reimport_srgb; + mutex = Mutex::create(); +} + +ResourceImporterTexture::~ResourceImporterTexture() +{ + + memdelete(mutex); +} + diff --git a/tools/editor/import/resource_importer_texture.h b/tools/editor/import/resource_importer_texture.h new file mode 100644 index 0000000000..4c795e132c --- /dev/null +++ b/tools/editor/import/resource_importer_texture.h @@ -0,0 +1,70 @@ +#ifndef RESOURCEIMPORTTEXTURE_H +#define RESOURCEIMPORTTEXTURE_H + +#include "io/resource_import.h" +class StreamTexture; + +class ResourceImporterTexture : public ResourceImporter { + GDCLASS(ResourceImporterTexture,ResourceImporter) + + + +protected: + + enum { + MAKE_3D_FLAG=1, + MAKE_SRGB_FLAG=2 + }; + + Mutex *mutex; + Map<StringName,int> make_flags; + + static void _texture_reimport_srgb(const Ref<StreamTexture>& p_tex); + static void _texture_reimport_3d(const Ref<StreamTexture>& p_tex); + + + + + static ResourceImporterTexture *singleton; +public: + + static ResourceImporterTexture *get_singleton() { return singleton; } + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + + enum Preset { + PRESET_DETECT, + PRESET_2D, + PRESET_2D_PIXEL, + PRESET_3D, + }; + + enum CompressMode { + COMPRESS_LOSSLESS, + COMPRESS_LOSSY, + COMPRESS_VIDEO_RAM, + COMPRESS_UNCOMPRESSED + }; + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const; + virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const; + + void _save_stex(const Image& p_image, const String& p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable,bool p_detect_3d,bool p_detect_srgb); + + virtual Error 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=NULL); + + + void update_imports(); + + ResourceImporterTexture(); + ~ResourceImporterTexture(); +}; + +#endif // RESOURCEIMPORTTEXTURE_H diff --git a/tools/editor/import/resource_importer_wav.cpp b/tools/editor/import/resource_importer_wav.cpp new file mode 100644 index 0000000000..ee53b740ca --- /dev/null +++ b/tools/editor/import/resource_importer_wav.cpp @@ -0,0 +1,619 @@ +#include "resource_importer_wav.h" + +#include "scene/resources/audio_stream_sample.h" +#include "os/file_access.h" +#include "io/marshalls.h" +#include "io/resource_saver.h" + +String ResourceImporterWAV::get_importer_name() const { + + return "wav"; +} + +String ResourceImporterWAV::get_visible_name() const{ + + return "Microsoft WAV"; +} +void ResourceImporterWAV::get_recognized_extensions(List<String> *p_extensions) const{ + + p_extensions->push_back("wav"); +} +String ResourceImporterWAV::get_save_extension() const { + return "smp"; +} + +String ResourceImporterWAV::get_resource_type() const{ + + return "AudioStreamSample"; +} + +bool ResourceImporterWAV::get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const { + + return true; +} + +int ResourceImporterWAV::get_preset_count() const { + return 0; +} +String ResourceImporterWAV::get_preset_name(int p_idx) const { + + return String(); +} + + +void ResourceImporterWAV::get_import_options(List<ImportOption> *r_options,int p_preset) const { + + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"force/8_bit"),false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"force/mono"),false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"force/max_rate"),false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL,"force/max_rate_hz",PROPERTY_HINT_EXP_RANGE,"11025,192000,1"),44100)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"edit/trim"),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"edit/normalize"),true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL,"edit/loop"),false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT,"compress/mode",PROPERTY_HINT_ENUM,"Disabled,RAM (Ima-ADPCM)"),0)); + +} + + +Error ResourceImporterWAV::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) { + + /* STEP 1, READ WAVE FILE */ + + Error err; + FileAccess *file=FileAccess::open(p_source_file, FileAccess::READ,&err); + + ERR_FAIL_COND_V( err!=OK, ERR_CANT_OPEN ); + + /* CHECK RIFF */ + char riff[5]; + riff[4]=0; + file->get_buffer((uint8_t*)&riff,4); //RIFF + + if (riff[0]!='R' || riff[1]!='I' || riff[2]!='F' || riff[3]!='F') { + + file->close(); + memdelete(file); + ERR_FAIL_V( ERR_FILE_UNRECOGNIZED ); + } + + + /* GET FILESIZE */ + uint32_t filesize=file->get_32(); + + /* CHECK WAVE */ + + char wave[4]; + + file->get_buffer((uint8_t*)&wave,4); //RIFF + + if (wave[0]!='W' || wave[1]!='A' || wave[2]!='V' || wave[3]!='E') { + + + file->close(); + memdelete(file); + ERR_EXPLAIN("Not a WAV file (no WAVE RIFF Header)") + ERR_FAIL_V( ERR_FILE_UNRECOGNIZED ); + } + + int format_bits=0; + int format_channels=0; + + AudioStreamSample::LoopMode loop=AudioStreamSample::LOOP_DISABLED; + bool format_found=false; + bool data_found=false; + int format_freq=0; + int loop_begin=0; + int loop_end=0; + int frames; + + Vector<float> data; + + while (!file->eof_reached()) { + + + /* chunk */ + char chunkID[4]; + file->get_buffer((uint8_t*)&chunkID,4); //RIFF + + /* chunk size */ + uint32_t chunksize=file->get_32(); + uint32_t file_pos=file->get_pos(); //save file pos, so we can skip to next chunk safely + + if (file->eof_reached()) { + + //ERR_PRINT("EOF REACH"); + break; + } + + if (chunkID[0]=='f' && chunkID[1]=='m' && chunkID[2]=='t' && chunkID[3]==' ' && !format_found) { + /* IS FORMAT CHUNK */ + + uint16_t compression_code=file->get_16(); + + + if (compression_code!=1) { + ERR_PRINT("Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead."); + break; + } + + format_channels=file->get_16(); + if (format_channels!=1 && format_channels !=2) { + + ERR_PRINT("Format not supported for WAVE file (not stereo or mono)"); + break; + + } + + format_freq=file->get_32(); //sampling rate + + file->get_32(); // average bits/second (unused) + file->get_16(); // block align (unused) + format_bits=file->get_16(); // bits per sample + + if (format_bits%8) { + + ERR_PRINT("Strange number of bits in sample (not 8,16,24,32)"); + break; + } + + /* Dont need anything else, continue */ + format_found=true; + } + + + if (chunkID[0]=='d' && chunkID[1]=='a' && chunkID[2]=='t' && chunkID[3]=='a' && !data_found) { + /* IS FORMAT CHUNK */ + data_found=true; + + if (!format_found) { + ERR_PRINT("'data' chunk before 'format' chunk found."); + break; + + } + + frames=chunksize; + + frames/=format_channels; + frames/=(format_bits>>3); + + /*print_line("chunksize: "+itos(chunksize)); + print_line("channels: "+itos(format_channels)); + print_line("bits: "+itos(format_bits)); +*/ + + int len=frames; + if (format_channels==2) + len*=2; + if (format_bits>8) + len*=2; + + + data.resize(frames*format_channels); + + for (int i=0;i<frames;i++) { + + + for (int c=0;c<format_channels;c++) { + + + if (format_bits==8) { + // 8 bit samples are UNSIGNED + + uint8_t s = file->get_8(); + s-=128; + int8_t *sp=(int8_t*)&s; + + data[i*format_channels+c]=float(*sp)/128.0; + + } else { + //16+ bits samples are SIGNED + // if sample is > 16 bits, just read extra bytes + + uint32_t s=0; + for (int b=0;b<(format_bits>>3);b++) { + + s|=((uint32_t)file->get_8())<<(b*8); + } + s<<=(32-format_bits); + int32_t ss=s; + + + data[i*format_channels+c]=(ss>>16)/32768.0; + } + } + + } + + + + if (file->eof_reached()) { + file->close(); + memdelete(file); + ERR_EXPLAIN("Premature end of file."); + ERR_FAIL_V(ERR_FILE_CORRUPT); + } + } + + if (chunkID[0]=='s' && chunkID[1]=='m' && chunkID[2]=='p' && chunkID[3]=='l') { + //loop point info! + + for(int i=0;i<10;i++) + file->get_32(); // i wish to know why should i do this... no doc! + + loop=file->get_32()?AudioStreamSample::LOOP_PING_PONG:AudioStreamSample::LOOP_FORWARD; + loop_begin=file->get_32(); + loop_end=file->get_32(); + + } + file->seek( file_pos+chunksize ); + } + + file->close(); + memdelete(file); + + // STEP 2, APPLY CONVERSIONS + + + bool is16=format_bits!=8; + int rate=format_freq; + + print_line("Input Sample: "); + print_line("\tframes: "+itos(frames)); + print_line("\tformat_channels: "+itos(format_channels)); + print_line("\t16bits: "+itos(is16)); + print_line("\trate: "+itos(rate)); + print_line("\tloop: "+itos(loop)); + print_line("\tloop begin: "+itos(loop_begin)); + print_line("\tloop end: "+itos(loop_end)); + + + //apply frequency limit + + bool limit_rate = p_options["force/max_rate"]; + int limit_rate_hz = p_options["force/max_rate_hz"]; + if (limit_rate && rate > limit_rate_hz) { + //resampleeee!!! + int new_data_frames = frames * limit_rate_hz / rate; + Vector<float> new_data; + new_data.resize( new_data_frames * format_channels ); + for(int c=0;c<format_channels;c++) { + + for(int i=0;i<new_data_frames;i++) { + + //simple cubic interpolation should be enough. + float pos = float(i) * frames / new_data_frames; + float mu = pos-Math::floor(pos); + int ipos = int(Math::floor(pos)); + + float y0=data[MAX(0,ipos-1)*format_channels+c]; + float y1=data[ipos*format_channels+c]; + float y2=data[MIN(frames-1,ipos+1)*format_channels+c]; + float y3=data[MIN(frames-1,ipos+2)*format_channels+c]; + + float mu2 = mu*mu; + float a0 = y3 - y2 - y0 + y1; + float a1 = y0 - y1 - a0; + float a2 = y2 - y0; + float a3 = y1; + + float res=(a0*mu*mu2+a1*mu2+a2*mu+a3); + + new_data[i*format_channels+c]=res; + } + } + + if (loop) { + + loop_begin=loop_begin*new_data_frames/frames; + loop_end=loop_end*new_data_frames/frames; + } + data=new_data; + rate=limit_rate_hz; + frames=new_data_frames; + } + + + bool normalize = p_options["edit/normalize"]; + + if (normalize) { + + float max=0; + for(int i=0;i<data.size();i++) { + + float amp = Math::abs(data[i]); + if (amp>max) + max=amp; + } + + if (max>0) { + + float mult=1.0/max; + for(int i=0;i<data.size();i++) { + + data[i]*=mult; + } + + } + } + + bool trim = p_options["edit/trim"]; + + if (trim && !loop) { + + int first=0; + int last=(frames*format_channels)-1; + bool found=false; + float limit = Math::db2linear((float)-30); + for(int i=0;i<data.size();i++) { + float amp = Math::abs(data[i]); + + if (!found && amp > limit) { + first=i; + found=true; + } + + if (found && amp > limit) { + last=i; + } + } + + first/=format_channels; + last/=format_channels; + + if (first<last) { + + Vector<float> new_data; + new_data.resize((last-first+1)*format_channels); + for(int i=first*format_channels;i<=last*format_channels;i++) { + new_data[i-first*format_channels]=data[i]; + } + + data=new_data; + frames=data.size()/format_channels; + } + + } + + bool make_loop = p_options["edit/loop"]; + + if (make_loop && !loop) { + + loop=AudioStreamSample::LOOP_FORWARD; + loop_begin=0; + loop_end=frames; + } + + int compression = p_options["compress/mode"]; + bool force_mono = p_options["force/mono"]; + + + if (force_mono && format_channels==2) { + + Vector<float> new_data; + new_data.resize(data.size()/2); + for(int i=0;i<frames;i++) { + new_data[i]=(data[i*2+0]+data[i*2+1])/2.0; + } + + data=new_data; + format_channels=1; + } + + bool force_8_bit = p_options["force/8_bit"]; + if (force_8_bit) { + + is16=false; + } + + + PoolVector<uint8_t> dst_data; + AudioStreamSample::Format dst_format; + + if ( compression == 1) { + + dst_format=AudioStreamSample::FORMAT_IMA_ADPCM; + if (format_channels==1) { + _compress_ima_adpcm(data,dst_data); + } else { + + //byte interleave + Vector<float> left; + Vector<float> right; + + int tframes = data.size()/2; + left.resize(tframes); + right.resize(tframes); + + for(int i=0;i<tframes;i++) { + left[i]=data[i*2+0]; + right[i]=data[i*2+1]; + } + + PoolVector<uint8_t> bleft; + PoolVector<uint8_t> bright; + + _compress_ima_adpcm(left,bleft); + _compress_ima_adpcm(right,bright); + + int dl = bleft.size(); + dst_data.resize( dl *2 ); + + PoolVector<uint8_t>::Write w=dst_data.write(); + PoolVector<uint8_t>::Read rl=bleft.read(); + PoolVector<uint8_t>::Read rr=bright.read(); + + for(int i=0;i<dl;i++) { + w[i*2+0]=rl[i]; + w[i*2+1]=rr[i]; + } + } + + //print_line("compressing ima-adpcm, resulting buffersize is "+itos(dst_data.size())+" from "+itos(data.size())); + + } else { + + dst_format=is16?AudioStreamSample::FORMAT_16_BITS:AudioStreamSample::FORMAT_8_BITS; + dst_data.resize( data.size() * (is16?2:1)); + { + PoolVector<uint8_t>::Write w = dst_data.write(); + + int ds=data.size(); + for(int i=0;i<ds;i++) { + + if (is16) { + int16_t v = CLAMP(data[i]*32768,-32768,32767); + encode_uint16(v,&w[i*2]); + } else { + int8_t v = CLAMP(data[i]*128,-128,127); + w[i]=v; + } + } + } + } + + + Ref<AudioStreamSample> sample; + sample.instance(); + sample->set_data(dst_data); + sample->set_format(dst_format); + sample->set_mix_rate(rate); + sample->set_loop_mode(loop); + sample->set_loop_begin(loop_begin); + sample->set_loop_end(loop_end); + sample->set_stereo(format_channels==2); + + ResourceSaver::save(p_save_path+".smp",sample); + + + return OK; + +} + +void ResourceImporterWAV::_compress_ima_adpcm(const Vector<float>& p_data,PoolVector<uint8_t>& dst_data) { + + + /*p_sample_data->data = (void*)malloc(len); + xm_s8 *dataptr=(xm_s8*)p_sample_data->data;*/ + + static const int16_t _ima_adpcm_step_table[89] = { + 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, + 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, + 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, + 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, + 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, + 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, + 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, + 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, + 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 + }; + + static const int8_t _ima_adpcm_index_table[16] = { + -1, -1, -1, -1, 2, 4, 6, 8, + -1, -1, -1, -1, 2, 4, 6, 8 + }; + + + int datalen = p_data.size(); + int datamax=datalen; + if (datalen&1) + datalen++; + + dst_data.resize(datalen/2+4); + PoolVector<uint8_t>::Write w = dst_data.write(); + + + int i,step_idx=0,prev=0; + uint8_t *out = w.ptr(); + //int16_t xm_prev=0; + const float *in=p_data.ptr(); + + + /* initial value is zero */ + *(out++) =0; + *(out++) =0; + /* Table index initial value */ + *(out++) =0; + /* unused */ + *(out++) =0; + + for (i=0;i<datalen;i++) { + int step,diff,vpdiff,mask; + uint8_t nibble; + int16_t xm_sample; + + if (i>=datamax) + xm_sample=0; + else { + + + xm_sample=CLAMP(in[i]*32767.0,-32768,32767); + /* + if (xm_sample==32767 || xm_sample==-32768) + printf("clippy!\n",xm_sample); + */ + } + + //xm_sample=xm_sample+xm_prev; + //xm_prev=xm_sample; + + diff = (int)xm_sample - prev ; + + nibble=0 ; + step = _ima_adpcm_step_table[ step_idx ]; + vpdiff = step >> 3 ; + if (diff < 0) { + nibble=8; + diff=-diff ; + } + mask = 4 ; + while (mask) { + + if (diff >= step) { + + nibble |= mask; + diff -= step; + vpdiff += step; + } + + step >>= 1 ; + mask >>= 1 ; + }; + + if (nibble&8) + prev-=vpdiff ; + else + prev+=vpdiff ; + + if (prev > 32767) { + //printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip up %i\n",i,xm_sample,prev,diff,vpdiff,prev); + prev=32767; + } else if (prev < -32768) { + //printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip down %i\n",i,xm_sample,prev,diff,vpdiff,prev); + prev = -32768 ; + } + + step_idx += _ima_adpcm_index_table[nibble]; + if (step_idx< 0) + step_idx= 0 ; + else if (step_idx> 88) + step_idx= 88 ; + + + if (i&1) { + *out|=nibble<<4; + out++; + } else { + *out=nibble; + } + /*dataptr[i]=prev>>8;*/ + } + + + + +} + +ResourceImporterWAV::ResourceImporterWAV() +{ + +} diff --git a/tools/editor/import/resource_importer_wav.h b/tools/editor/import/resource_importer_wav.h new file mode 100644 index 0000000000..9f1bd57da7 --- /dev/null +++ b/tools/editor/import/resource_importer_wav.h @@ -0,0 +1,30 @@ +#ifndef RESOURCEIMPORTWAV_H +#define RESOURCEIMPORTWAV_H + + +#include "io/resource_import.h" + +class ResourceImporterWAV : public ResourceImporter { + GDCLASS(ResourceImporterWAV,ResourceImporter) +public: + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options,int p_preset=0) const; + virtual bool get_option_visibility(const String& p_option,const Map<StringName,Variant>& p_options) const; + + void _compress_ima_adpcm(const Vector<float>& p_data,PoolVector<uint8_t>& dst_data); + + virtual Error 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=NULL); + + ResourceImporterWAV(); +}; + +#endif // RESOURCEIMPORTWAV_H diff --git a/tools/editor/import_dock.cpp b/tools/editor/import_dock.cpp new file mode 100644 index 0000000000..b1bd698239 --- /dev/null +++ b/tools/editor/import_dock.cpp @@ -0,0 +1,331 @@ +#include "import_dock.h" + +class ImportDockParameters : public Object { + GDCLASS(ImportDockParameters,Object) +public: + Map<StringName,Variant> values; + List<PropertyInfo> properties; + Ref<ResourceImporter> importer; + Vector<String> paths; + + + bool _set(const StringName& p_name, const Variant& p_value) { + + if (values.has(p_name)) { + values[p_name]=p_value; + return true; + } + + return false; + } + + bool _get(const StringName& p_name,Variant &r_ret) const { + + if (values.has(p_name)) { + r_ret=values[p_name]; + return true; + } + + return false; + + } + void _get_property_list( List<PropertyInfo> *p_list) const { + + for (const List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) { + if (!importer->get_option_visibility(E->get().name,values)) + continue; + p_list->push_back(E->get()); + } + } + + void update() { + _change_notify(); + } +}; + +void ImportDock::set_edit_path(const String& p_path) { + + Ref<ConfigFile> config; + config.instance(); + Error err = config->load(p_path+".import"); + if (err!=OK) { + clear(); + return; + } + + + params->importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(config->get_value("remap","importer")); + if (params->importer.is_null()) { + clear(); + return; + } + + List<ResourceImporter::ImportOption> options; + params->importer->get_import_options(&options); + + params->properties.clear(); + params->values.clear(); + + for (List<ResourceImporter::ImportOption>::Element *E=options.front();E;E=E->next()) { + + params->properties.push_back(E->get().option); + if (config->has_section_key("params",E->get().option.name)) { + params->values[E->get().option.name]=config->get_value("params",E->get().option.name); + } else { + params->values[E->get().option.name]=E->get().default_value; + } + } + + params->update(); + + List<Ref<ResourceImporter> > importers; + ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_path.get_extension(),&importers); + List<Pair<String,String> > importer_names; + + for (List<Ref<ResourceImporter> > ::Element *E=importers.front();E;E=E->next()) { + importer_names.push_back(Pair<String,String>(E->get()->get_visible_name(),E->get()->get_importer_name())); + } + + importer_names.sort_custom<PairSort<String,String> >(); + + import_as->clear(); + + for (List<Pair<String,String> >::Element *E=importer_names.front();E;E=E->next()) { + import_as->add_item(E->get().first); + import_as->set_item_metadata(import_as->get_item_count()-1,E->get().second); + if (E->get().second==params->importer->get_importer_name()) { + import_as->select(import_as->get_item_count()-1); + } + } + + preset->get_popup()->clear(); + + if (params->importer->get_preset_count()==0) { + preset->get_popup()->add_item(TTR("Default")); + } else { + for (int i=0;i<params->importer->get_preset_count();i++) { + preset->get_popup()->add_item(params->importer->get_preset_name(i)); + } + } + + params->paths.clear(); + params->paths.push_back(p_path); + import->set_disabled(false); + import_as->set_disabled(false); + + imported->set_text(p_path.get_file()); +} + +void ImportDock::set_edit_multiple_paths(const Vector<String>& p_paths) { + + clear(); + + //use the value that is repeated the mot + Map<String,Dictionary> value_frequency; + + for(int i=0;i<p_paths.size();i++) { + + Ref<ConfigFile> config; + config.instance(); + Error err = config->load(p_paths[i]+".import"); + ERR_CONTINUE(err!=OK); + + if (i==0) { + params->importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(config->get_value("remap","importer")); + if (params->importer.is_null()) { + clear(); + return; + } + } + + List<String> keys; + config->get_section_keys("params",&keys); + + + for (List<String>::Element *E=keys.front();E;E=E->next()) { + + if (!value_frequency.has(E->get())) { + value_frequency[E->get()]=Dictionary(); + } + + Variant value = config->get_value("params",E->get()); + + if (value_frequency[E->get()].has(value)) { + value_frequency[E->get()][value]=int(value_frequency[E->get()][value])+1; + } else { + value_frequency[E->get()][value]=1; + } + } + + } + + ERR_FAIL_COND(params->importer.is_null()); + + List<ResourceImporter::ImportOption> options; + params->importer->get_import_options(&options); + + params->properties.clear(); + params->values.clear(); + + for (List<ResourceImporter::ImportOption>::Element *E=options.front();E;E=E->next()) { + + params->properties.push_back(E->get().option); + + if (value_frequency.has(E->get().option.name)) { + + Dictionary d = value_frequency[E->get().option.name]; + int freq=0; + List<Variant> v; + d.get_key_list(&v); + Variant value; + for (List<Variant>::Element *F=v.front();F;F=F->next()) { + int f = d[F->get()]; + if (f>freq) { + value=F->get(); + } + } + + params->values[E->get().option.name]=value; + } else { + params->values[E->get().option.name]=E->get().default_value; + } + } + + params->update(); + + List<Ref<ResourceImporter> > importers; + ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_paths[0].get_extension(),&importers); + List<Pair<String,String> > importer_names; + + for (List<Ref<ResourceImporter> > ::Element *E=importers.front();E;E=E->next()) { + importer_names.push_back(Pair<String,String>(E->get()->get_visible_name(),E->get()->get_importer_name())); + } + + importer_names.sort_custom<PairSort<String,String> >(); + + import_as->clear(); + + for (List<Pair<String,String> >::Element *E=importer_names.front();E;E=E->next()) { + import_as->add_item(E->get().first); + import_as->set_item_metadata(import_as->get_item_count()-1,E->get().second); + if (E->get().second==params->importer->get_importer_name()) { + import_as->select(import_as->get_item_count()-1); + } + } + + preset->get_popup()->clear(); + + if (params->importer->get_preset_count()==0) { + preset->get_popup()->add_item(TTR("Default")); + } else { + for (int i=0;i<params->importer->get_preset_count();i++) { + preset->get_popup()->add_item(params->importer->get_preset_name(i)); + } + } + + params->paths=p_paths; + import->set_disabled(false); + import_as->set_disabled(false); + + imported->set_text(itos(p_paths.size())+TTR(" Files")); +} + +void ImportDock::_preset_selected(int p_idx) { + + print_line("preset selected? "+p_idx); + List<ResourceImporter::ImportOption> options; + + params->importer->get_import_options(&options,p_idx); + + for (List<ResourceImporter::ImportOption>::Element *E=options.front();E;E=E->next()) { + + params->values[E->get().option.name]=E->get().default_value; + } + + params->update(); + +} + + +void ImportDock::clear() { + + imported->set_text(""); + import->set_disabled(true); + import_as->clear(); + import_as->set_disabled(true); + params->values.clear(); + params->properties.clear(); + params->update(); + preset->get_popup()->clear(); + +} + +void ImportDock::_reimport() { + + for(int i=0;i<params->paths.size();i++) { + + Ref<ConfigFile> config; + config.instance(); + Error err = config->load(params->paths[i]+".import"); + ERR_CONTINUE(err!=OK); + + config->erase_section("params"); + + for (List<PropertyInfo>::Element *E=params->properties.front();E;E=E->next()) { + config->set_value("params",E->get().name,params->values[E->get().name]); + } + + config->save(params->paths[i]+".import"); + } + + EditorFileSystem::get_singleton()->reimport_files(params->paths); + EditorFileSystem::get_singleton()->emit_signal("filesystem_changed"); //it changed, so force emitting the signal + +} + +void ImportDock::_bind_methods() { + + ClassDB::bind_method(_MD("_reimport"),&ImportDock::_reimport); + ClassDB::bind_method(_MD("_preset_selected"),&ImportDock::_preset_selected); +} + +ImportDock::ImportDock() { + + + imported = memnew( LineEdit ); + imported->set_editable(false); + add_child(imported); + HBoxContainer *hb = memnew(HBoxContainer); + add_margin_child(TTR("Import As:"),hb); + import_as = memnew( OptionButton ); + hb->add_child(import_as); + import_as->set_h_size_flags(SIZE_EXPAND_FILL); + preset = memnew( MenuButton ); + preset->set_text(TTR("Preset..")); + preset->get_popup()->connect("index_pressed",this,"_preset_selected"); + hb->add_child(preset); + + import_opts = memnew( PropertyEditor ); + add_child(import_opts); + import_opts->set_v_size_flags(SIZE_EXPAND_FILL); + import_opts->hide_top_label(); + import_opts->set_hide_script(true); + + hb = memnew( HBoxContainer ); + add_child(hb); + import = memnew( Button ); + import->set_text(TTR("Reimport")); + import->connect("pressed",this,"_reimport"); + hb->add_spacer(); + hb->add_child(import); + hb->add_spacer(); + + params = memnew( ImportDockParameters ); + import_opts->edit(params); + +} + +ImportDock::~ImportDock() { + + memdelete(params); +} diff --git a/tools/editor/import_dock.h b/tools/editor/import_dock.h new file mode 100644 index 0000000000..bddf5480b8 --- /dev/null +++ b/tools/editor/import_dock.h @@ -0,0 +1,42 @@ +#ifndef IMPORTDOCK_H +#define IMPORTDOCK_H + +#include "io/resource_import.h" +#include "editor_file_system.h" +#include "scene/gui/box_container.h" +#include "scene/gui/option_button.h" +#include "scene/gui/popup_menu.h" +#include "property_editor.h" + +class ImportDockParameters; +class ImportDock : public VBoxContainer { + GDCLASS(ImportDock,VBoxContainer) + + LineEdit *imported; + OptionButton *import_as; + MenuButton *preset; + PropertyEditor *import_opts; + + List<PropertyInfo> properties; + Map<StringName,Variant> property_values; + + Button *import; + + ImportDockParameters *params; + + void _preset_selected(int p_idx); + + void _reimport(); +protected: + static void _bind_methods(); +public: + + void set_edit_path(const String& p_path); + void set_edit_multiple_paths(const Vector<String>& p_paths); + void clear(); + + ImportDock(); + ~ImportDock(); +}; + +#endif // IMPORTDOCK_H diff --git a/tools/editor/io_plugins/SCsub b/tools/editor/io_plugins/SCsub index 4bf55189cc..f1fa50148f 100644 --- a/tools/editor/io_plugins/SCsub +++ b/tools/editor/io_plugins/SCsub @@ -2,4 +2,4 @@ Import('env') Export('env') -env.add_source_files(env.tool_sources, "*.cpp") +env.add_source_files(env.editor_sources, "*.cpp") diff --git a/tools/editor/io_plugins/editor_atlas.cpp b/tools/editor/io_plugins/editor_atlas.cpp index ac776f4ff5..c5f1ee73cf 100644 --- a/tools/editor/io_plugins/editor_atlas.cpp +++ b/tools/editor/io_plugins/editor_atlas.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_atlas.h" + #include "print_string.h" struct _EditorAtlasWorkRect { diff --git a/tools/editor/io_plugins/editor_bitmask_import_plugin.cpp b/tools/editor/io_plugins/editor_bitmask_import_plugin.cpp index 722b02f77b..587353fef8 100644 --- a/tools/editor/io_plugins/editor_bitmask_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_bitmask_import_plugin.cpp @@ -1,4 +1,33 @@ +/*************************************************************************/ +/* editor_bitmask_import_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #include "editor_bitmask_import_plugin.h" +#if 0 #include "io/image_loader.h" #include "tools/editor/editor_file_dialog.h" #include "tools/editor/editor_dir_dialog.h" @@ -355,3 +384,4 @@ EditorBitMaskImportPlugin::EditorBitMaskImportPlugin(EditorNode* p_editor) { EditorBitMaskExportPlugin::EditorBitMaskExportPlugin() { } +#endif diff --git a/tools/editor/io_plugins/editor_bitmask_import_plugin.h b/tools/editor/io_plugins/editor_bitmask_import_plugin.h index 28dddca50a..89ff58ec93 100644 --- a/tools/editor/io_plugins/editor_bitmask_import_plugin.h +++ b/tools/editor/io_plugins/editor_bitmask_import_plugin.h @@ -1,6 +1,34 @@ +/*************************************************************************/ +/* editor_bitmask_import_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #ifndef EDITOR_BITMASK_IMPORT_PLUGIN_H #define EDITOR_BITMASK_IMPORT_PLUGIN_H - +#if 0 #include "tools/editor/editor_import_export.h" #include "scene/resources/font.h" @@ -38,4 +66,5 @@ public: EditorBitMaskExportPlugin(); }; +#endif #endif // EDITOR_SAMPLE_IMPORT_PLUGIN_H diff --git a/tools/editor/io_plugins/editor_export_scene.cpp b/tools/editor/io_plugins/editor_export_scene.cpp index ea67128f3c..f4ab9880ff 100644 --- a/tools/editor/io_plugins/editor_export_scene.cpp +++ b/tools/editor/io_plugins/editor_export_scene.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_export_scene.h" +#if 0 #include "io/resource_loader.h" #include "io/resource_saver.h" #include "os/dir_access.h" @@ -138,3 +139,4 @@ Vector<uint8_t> EditorSceneExportPlugin::custom_export(String& p_path,const Ref< EditorSceneExportPlugin::EditorSceneExportPlugin() { } +#endif diff --git a/tools/editor/io_plugins/editor_export_scene.h b/tools/editor/io_plugins/editor_export_scene.h index 13493220cb..191029bd84 100644 --- a/tools/editor/io_plugins/editor_export_scene.h +++ b/tools/editor/io_plugins/editor_export_scene.h @@ -31,7 +31,7 @@ #include "tools/editor/editor_import_export.h" - +#if 0 class EditorSceneExportPlugin : public EditorExportPlugin { GDCLASS( EditorSceneExportPlugin, EditorExportPlugin ); public: @@ -40,5 +40,5 @@ public: EditorSceneExportPlugin(); }; - +#endif #endif // EDITOR_EXPORT_SCENE_H diff --git a/tools/editor/io_plugins/editor_font_import_plugin.cpp b/tools/editor/io_plugins/editor_font_import_plugin.cpp index 099535b1ef..417aad0db8 100644 --- a/tools/editor/io_plugins/editor_font_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_font_import_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_font_import_plugin.h" +#if 0 #include "scene/gui/dialogs.h" #include "tools/editor/editor_file_dialog.h" #include "tools/editor/editor_node.h" @@ -34,11 +35,10 @@ #include "editor_atlas.h" #include "io/image_loader.h" #include "io/resource_saver.h" -#ifdef FREETYPE_ENABLED +#ifdef FREETYPE_ENABLED #include <ft2build.h> #include FT_FREETYPE_H - #endif @@ -1473,7 +1473,7 @@ Ref<BitmapFont> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMe sum+=w2[ofs_l]; } - wa[ofs]=Math::pow(float(sum/(r*2+1))/255.0,tr)*255.0; + wa[ofs]=Math::pow(float(sum/(r*2+1))/255.0f,tr)*255.0f; } } @@ -1701,3 +1701,4 @@ EditorFontImportPlugin::EditorFontImportPlugin(EditorNode* p_editor) { dialog = memnew( EditorFontImportDialog(this) ); p_editor->get_gui_base()->add_child(dialog); } +#endif diff --git a/tools/editor/io_plugins/editor_font_import_plugin.h b/tools/editor/io_plugins/editor_font_import_plugin.h index 73c699c090..a5b265736f 100644 --- a/tools/editor/io_plugins/editor_font_import_plugin.h +++ b/tools/editor/io_plugins/editor_font_import_plugin.h @@ -31,7 +31,7 @@ #include "tools/editor/editor_import_export.h" #include "scene/resources/font.h" - +#if 0 class EditorNode; class EditorFontImportDialog; @@ -55,3 +55,4 @@ public: }; #endif // EDITOR_FONT_IMPORT_PLUGIN_H +#endif diff --git a/tools/editor/io_plugins/editor_mesh_import_plugin.cpp b/tools/editor/io_plugins/editor_mesh_import_plugin.cpp index fa0c36be98..fc3f8fd8c9 100644 --- a/tools/editor/io_plugins/editor_mesh_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_mesh_import_plugin.cpp @@ -28,11 +28,13 @@ /*************************************************************************/ #include "editor_mesh_import_plugin.h" +#if 0 + #include "tools/editor/editor_file_dialog.h" #include "tools/editor/editor_dir_dialog.h" #include "tools/editor/editor_node.h" #include "tools/editor/property_editor.h" -#include "scene/resources/sample.h" +//#include "scene/resources/sample.h" #include "io/resource_saver.h" #include "os/file_access.h" #include "io/marshalls.h" @@ -588,3 +590,4 @@ EditorMeshImportPlugin::EditorMeshImportPlugin(EditorNode* p_editor) { dialog = memnew( EditorMeshImportDialog(this)); p_editor->get_gui_base()->add_child(dialog); } +#endif diff --git a/tools/editor/io_plugins/editor_mesh_import_plugin.h b/tools/editor/io_plugins/editor_mesh_import_plugin.h index 1f15fee3a7..ba8ec58191 100644 --- a/tools/editor/io_plugins/editor_mesh_import_plugin.h +++ b/tools/editor/io_plugins/editor_mesh_import_plugin.h @@ -29,7 +29,7 @@ #ifndef EDITOR_MESH_IMPORT_PLUGIN_H #define EDITOR_MESH_IMPORT_PLUGIN_H - +#if 0 #include "tools/editor/editor_import_export.h" #include "scene/resources/font.h" @@ -55,4 +55,5 @@ public: EditorMeshImportPlugin(EditorNode* p_editor); }; +#endif #endif // EDITOR_MESH_IMPORT_PLUGIN_H diff --git a/tools/editor/io_plugins/editor_sample_import_plugin.cpp b/tools/editor/io_plugins/editor_sample_import_plugin.cpp index eeb61fc443..631291ec1b 100644 --- a/tools/editor/io_plugins/editor_sample_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_sample_import_plugin.cpp @@ -27,16 +27,18 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_sample_import_plugin.h" + #include "tools/editor/editor_file_dialog.h" #include "tools/editor/editor_dir_dialog.h" #include "tools/editor/editor_node.h" #include "tools/editor/property_editor.h" -#include "scene/resources/sample.h" #include "io/resource_saver.h" #include "os/file_access.h" #include "io/marshalls.h" #include "tools/editor/editor_settings.h" +#if 0 + class _EditorSampleImportOptions : public Object { GDCLASS(_EditorSampleImportOptions,Object); @@ -539,7 +541,7 @@ Error EditorSampleImportPlugin::import(const String& p_path, const Ref<ResourceI int first=0; int last=(len*chans)-1; bool found=false; - float limit = Math::db2linear(-30); + float limit = Math::db2linear((float)-30); for(int i=0;i<data.size();i++) { float amp = Math::abs(data[i]); @@ -923,3 +925,5 @@ Vector<uint8_t> EditorSampleExportPlugin::custom_export(String& p_path,const Ref EditorSampleExportPlugin::EditorSampleExportPlugin() { } + +#endif diff --git a/tools/editor/io_plugins/editor_sample_import_plugin.h b/tools/editor/io_plugins/editor_sample_import_plugin.h index 6d781756b2..8e02d0e11d 100644 --- a/tools/editor/io_plugins/editor_sample_import_plugin.h +++ b/tools/editor/io_plugins/editor_sample_import_plugin.h @@ -29,6 +29,7 @@ #ifndef EDITOR_SAMPLE_IMPORT_PLUGIN_H #define EDITOR_SAMPLE_IMPORT_PLUGIN_H +#if 0 #include "tools/editor/editor_import_export.h" #include "scene/resources/font.h" @@ -70,3 +71,4 @@ public: }; #endif // EDITOR_SAMPLE_IMPORT_PLUGIN_H +#endif diff --git a/tools/editor/io_plugins/editor_scene_import_plugin.cpp b/tools/editor/io_plugins/editor_scene_import_plugin.cpp index 79c88e7407..bffccb9072 100644 --- a/tools/editor/io_plugins/editor_scene_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_scene_import_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_scene_import_plugin.h" +#if 0 #include "globals.h" #include "tools/editor/editor_node.h" #include "scene/resources/packed_scene.h" @@ -2988,3 +2989,4 @@ EditorSceneAnimationImportPlugin::EditorSceneAnimationImportPlugin(EditorNode* p } +#endif diff --git a/tools/editor/io_plugins/editor_scene_import_plugin.h b/tools/editor/io_plugins/editor_scene_import_plugin.h index 61153e3654..bbafc126bb 100644 --- a/tools/editor/io_plugins/editor_scene_import_plugin.h +++ b/tools/editor/io_plugins/editor_scene_import_plugin.h @@ -28,7 +28,7 @@ /*************************************************************************/ #ifndef EDITOR_SCENE_IMPORT_PLUGIN_H #define EDITOR_SCENE_IMPORT_PLUGIN_H - +#if 0 #include "scene/gui/dialogs.h" #include "scene/gui/tree.h" #include "scene/gui/label.h" @@ -196,5 +196,5 @@ public: }; - +#endif #endif // EDITOR_SCENE_IMPORT_PLUGIN_H diff --git a/tools/editor/io_plugins/editor_scene_importer_fbxconv.cpp b/tools/editor/io_plugins/editor_scene_importer_fbxconv.cpp index e1b0719941..af12d85650 100644 --- a/tools/editor/io_plugins/editor_scene_importer_fbxconv.cpp +++ b/tools/editor/io_plugins/editor_scene_importer_fbxconv.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_scene_importer_fbxconv.h" + #include "os/file_access.h" #include "os/os.h" #include "tools/editor/editor_settings.h" diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.cpp b/tools/editor/io_plugins/editor_texture_import_plugin.cpp index 5ba7d0c417..c41199f291 100644 --- a/tools/editor/io_plugins/editor_texture_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_texture_import_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_texture_import_plugin.h" +#if 0 #include "io/image_loader.h" #include "tools/editor/editor_node.h" #include "io/resource_saver.h" @@ -779,7 +780,7 @@ EditorTextureImportDialog::EditorTextureImportDialog(EditorTextureImportPlugin* set_hide_on_ok(false); - texture_options = memnew( EditorImportTextureOptions );; + texture_options = memnew( EditorImportTextureOptions ); vbc->add_child(texture_options); texture_options->set_v_size_flags(SIZE_EXPAND_FILL); @@ -1889,3 +1890,4 @@ EditorTextureExportPlugin::EditorTextureExportPlugin() { } +#endif diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.h b/tools/editor/io_plugins/editor_texture_import_plugin.h index b2117f1475..ce15df0f18 100644 --- a/tools/editor/io_plugins/editor_texture_import_plugin.h +++ b/tools/editor/io_plugins/editor_texture_import_plugin.h @@ -29,6 +29,12 @@ #ifndef EDITOR_TEXTURE_IMPORT_PLUGIN_H #define EDITOR_TEXTURE_IMPORT_PLUGIN_H + + + + + +#if 0 #include "tools/editor/editor_import_export.h" #include "scene/gui/dialogs.h" #include "scene/gui/tree.h" @@ -170,3 +176,4 @@ public: }; #endif // EDITOR_TEXTURE_IMPORT_PLUGIN_H +#endif diff --git a/tools/editor/io_plugins/editor_translation_import_plugin.cpp b/tools/editor/io_plugins/editor_translation_import_plugin.cpp index d9288f5990..5ecb0b1abf 100644 --- a/tools/editor/io_plugins/editor_translation_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -27,11 +27,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_translation_import_plugin.h" + +#if 0 #include "scene/gui/file_dialog.h" #include "tools/editor/editor_dir_dialog.h" #include "tools/editor/editor_node.h" #include "tools/editor/property_editor.h" -#include "scene/resources/sample.h" +//#include "scene/resources/sample.h" #include "io/resource_saver.h" #include "os/file_access.h" #include "translation.h" @@ -344,7 +346,7 @@ public: add_to_project = memnew( CheckButton); add_to_project->set_pressed(true); - add_to_project->set_text(TTR("Add to Project (engine.cfg)")); + add_to_project->set_text(TTR("Add to Project (godot.cfg)")); tcomp->add_child(add_to_project); file_select = memnew(EditorFileDialog); @@ -473,3 +475,5 @@ EditorTranslationImportPlugin::EditorTranslationImportPlugin(EditorNode* p_edito dialog = memnew(EditorTranslationImportDialog(this)); p_editor->get_gui_base()->add_child(dialog); } + +#endif diff --git a/tools/editor/io_plugins/editor_translation_import_plugin.h b/tools/editor/io_plugins/editor_translation_import_plugin.h index 38727bd778..4884ea71c5 100644 --- a/tools/editor/io_plugins/editor_translation_import_plugin.h +++ b/tools/editor/io_plugins/editor_translation_import_plugin.h @@ -31,7 +31,7 @@ #include "tools/editor/editor_import_export.h" #include "scene/resources/font.h" - +#if 0 class EditorNode; class EditorTranslationImportDialog; @@ -52,4 +52,5 @@ public: EditorTranslationImportPlugin(EditorNode* p_editor); }; +#endif #endif // EDITOR_TRANSLATION_IMPORT_PLUGIN_H diff --git a/tools/editor/multi_node_edit.cpp b/tools/editor/multi_node_edit.cpp index 47b776ed06..97a996fe48 100644 --- a/tools/editor/multi_node_edit.cpp +++ b/tools/editor/multi_node_edit.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "multi_node_edit.h" + #include "editor_node.h" bool MultiNodeEdit::_set(const StringName& p_name, const Variant& p_value){ diff --git a/tools/editor/node_dock.cpp b/tools/editor/node_dock.cpp index a8e66a8680..3d906cf960 100644 --- a/tools/editor/node_dock.cpp +++ b/tools/editor/node_dock.cpp @@ -1,4 +1,33 @@ +/*************************************************************************/ +/* node_dock.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #include "node_dock.h" + #include "editor_node.h" void NodeDock::show_groups() { diff --git a/tools/editor/node_dock.h b/tools/editor/node_dock.h index fd4105d1b2..df41ecf5bd 100644 --- a/tools/editor/node_dock.h +++ b/tools/editor/node_dock.h @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* node_dock.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #ifndef NODE_DOCK_H #define NODE_DOCK_H diff --git a/tools/editor/plugins/SCsub b/tools/editor/plugins/SCsub index 4bf55189cc..f1fa50148f 100644 --- a/tools/editor/plugins/SCsub +++ b/tools/editor/plugins/SCsub @@ -2,4 +2,4 @@ Import('env') Export('env') -env.add_source_files(env.tool_sources, "*.cpp") +env.add_source_files(env.editor_sources, "*.cpp") diff --git a/tools/editor/plugins/animation_player_editor_plugin.cpp b/tools/editor/plugins/animation_player_editor_plugin.cpp index 59ab3bc467..f10526fb77 100644 --- a/tools/editor/plugins/animation_player_editor_plugin.cpp +++ b/tools/editor/plugins/animation_player_editor_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "animation_player_editor_plugin.h" + #include "globals.h" #include "io/resource_loader.h" #include "io/resource_saver.h" @@ -433,7 +434,12 @@ void AnimationPlayerEditor::_animation_save_as(const Ref<Resource>& p_resource) String existing; if (extensions.size()) { - existing = "new_" + p_resource->get_class().to_lower() + "." + extensions.front()->get().to_lower(); + if( p_resource->get_name() != "" ) { + existing = p_resource->get_name() + "." + extensions.front()->get().to_lower(); + } + else { + existing = "new_" + p_resource->get_class().to_lower() + "." + extensions.front()->get().to_lower(); + } } file->set_current_path(existing); @@ -442,22 +448,27 @@ void AnimationPlayerEditor::_animation_save_as(const Ref<Resource>& p_resource) file->set_title(TTR("Save Resource As..")); current_option = RESOURCE_SAVE; } + void AnimationPlayerEditor::_animation_remove() { - if (animation->get_item_count()==0) + if (animation->get_item_count() == 0) return; - String current = animation->get_item_text(animation->get_selected()); - Ref<Animation> anim = player->get_animation(current); + delete_dialog->set_text(TTR("Delete Animation?")); + delete_dialog->popup_centered_minsize(); +} +void AnimationPlayerEditor::_animation_remove_confirmed() { + + String current = animation->get_item_text(animation->get_selected()); + Ref<Animation> anim = player->get_animation(current); undo_redo->create_action(TTR("Remove Animation")); - undo_redo->add_do_method(player,"remove_animation",current); - undo_redo->add_undo_method(player,"add_animation",current,anim); - undo_redo->add_do_method(this,"_animation_player_changed",player); - undo_redo->add_undo_method(this,"_animation_player_changed",player); + undo_redo->add_do_method(player, "remove_animation", current); + undo_redo->add_undo_method(player, "add_animation", current, anim); + undo_redo->add_do_method(this, "_animation_player_changed", player); + undo_redo->add_undo_method(this, "_animation_player_changed", player); undo_redo->commit_action(); - } void AnimationPlayerEditor::_select_anim_by_name(const String& p_anim) { @@ -1262,6 +1273,7 @@ void AnimationPlayerEditor::_bind_methods() { ClassDB::bind_method(_MD("_animation_rename"),&AnimationPlayerEditor::_animation_rename); ClassDB::bind_method(_MD("_animation_load"),&AnimationPlayerEditor::_animation_load); ClassDB::bind_method(_MD("_animation_remove"),&AnimationPlayerEditor::_animation_remove); + ClassDB::bind_method(_MD("_animation_remove_confirmed"),&AnimationPlayerEditor::_animation_remove_confirmed); ClassDB::bind_method(_MD("_animation_blend"),&AnimationPlayerEditor::_animation_blend); ClassDB::bind_method(_MD("_animation_edit"),&AnimationPlayerEditor::_animation_edit); ClassDB::bind_method(_MD("_animation_resource_edit"),&AnimationPlayerEditor::_animation_resource_edit); @@ -1386,6 +1398,10 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { add_child(accept); accept->connect("confirmed", this, "_menu_confirm_current"); + delete_dialog = memnew(ConfirmationDialog); + add_child(delete_dialog); + delete_dialog->connect("confirmed", this, "_animation_remove_confirmed"); + duplicate_anim = memnew( ToolButton ); hb->add_child(duplicate_anim); ED_SHORTCUT("animation_player_editor/duplicate_animation", TTR("Duplicate Animation")); @@ -1399,7 +1415,6 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { rename_anim->set_tooltip(TTR("Rename Animation")); remove_anim = memnew( ToolButton ); - hb->add_child(remove_anim); ED_SHORTCUT("animation_player_editor/remove_animation", TTR("Remove Animation")); remove_anim->set_shortcut(ED_GET_SHORTCUT("animation_player_editor/remove_animation")); diff --git a/tools/editor/plugins/animation_player_editor_plugin.h b/tools/editor/plugins/animation_player_editor_plugin.h index 840c39ba49..e28600a7ab 100644 --- a/tools/editor/plugins/animation_player_editor_plugin.h +++ b/tools/editor/plugins/animation_player_editor_plugin.h @@ -97,6 +97,7 @@ class AnimationPlayerEditor : public VBoxContainer { EditorFileDialog *file; AcceptDialog *accept; + ConfirmationDialog* delete_dialog; int current_option; struct BlendEditor { @@ -138,6 +139,7 @@ class AnimationPlayerEditor : public VBoxContainer { void _animation_save_as(const Ref<Resource>& p_resource); void _animation_remove(); + void _animation_remove_confirmed(); void _animation_blend(); void _animation_edit(); void _animation_duplicate(); diff --git a/tools/editor/plugins/animation_tree_editor_plugin.cpp b/tools/editor/plugins/animation_tree_editor_plugin.cpp index eedebab1c9..1ed52d2df6 100644 --- a/tools/editor/plugins/animation_tree_editor_plugin.cpp +++ b/tools/editor/plugins/animation_tree_editor_plugin.cpp @@ -261,9 +261,9 @@ void AnimationTreeEditor::_popup_edit_dialog() { } edit_option->hide(); - edit_button->hide();; + edit_button->hide(); filter_button->hide(); - edit_check->hide();; + edit_check->hide(); Point2 pos = anim_tree->node_get_pos(edited_node)-Point2(h_scroll->get_value(),v_scroll->get_value()); Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); @@ -450,7 +450,7 @@ void AnimationTreeEditor::_popup_edit_dialog() { edit_label[1]->show(); edit_option->set_begin(Point2(15,75)); - edit_option->clear();; + edit_option->clear(); for(int i=0;i<anim_tree->transition_node_get_input_count(edited_node);i++) { edit_option->add_item(itos(i),i); @@ -1451,14 +1451,14 @@ AnimationTreeEditor::AnimationTreeEditor() { edit_button->set_anchor( MARGIN_RIGHT, ANCHOR_END ); edit_button->set_margin(MARGIN_RIGHT, 10); edit_dialog->add_child(edit_button); - edit_button->hide();; + edit_button->hide(); edit_button->connect("pressed", this,"_edit_oneshot_start"); edit_check = memnew( CheckButton ); edit_check->set_anchor( MARGIN_RIGHT, ANCHOR_END ); edit_check->set_margin(MARGIN_RIGHT, 10); edit_dialog->add_child(edit_check); - edit_check->hide();; + edit_check->hide(); edit_check->connect("pressed", this,"_edit_dialog_changed"); file_dialog = memnew( EditorFileDialog ); @@ -1480,7 +1480,7 @@ AnimationTreeEditor::AnimationTreeEditor() { filter_button->set_anchor( MARGIN_RIGHT, ANCHOR_END ); filter_button->set_margin(MARGIN_RIGHT, 10); edit_dialog->add_child(filter_button); - filter_button->hide();; + filter_button->hide(); filter_button->set_text(TTR("Filters..")); filter_button->connect("pressed", this,"_edit_filters"); diff --git a/tools/editor/plugins/baked_light_baker.cpp b/tools/editor/plugins/baked_light_baker.cpp index 0b12d080e4..52220839d9 100644 --- a/tools/editor/plugins/baked_light_baker.cpp +++ b/tools/editor/plugins/baked_light_baker.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "baked_light_baker.h" + #include <stdlib.h> #include <cmath> #include "io/marshalls.h" @@ -1573,7 +1574,7 @@ double BakedLightBaker::get_normalization(int p_light_idx) const { double nrg=0; const LightData &dl=lights[p_light_idx]; - double cell_area = cell_size*cell_size;; + double cell_area = cell_size*cell_size; //nrg+= /*dl.energy */ (dl.rays_thrown * cell_area / dl.area); nrg=dl.rays_thrown * cell_area; nrg*=(Math_PI*plot_size*plot_size)*0.5; // damping of radial linear gradient kernel @@ -1591,7 +1592,7 @@ double BakedLightBaker::get_modifier(int p_light_idx) const { double nrg=0; const LightData &dl=lights[p_light_idx]; - double cell_area = cell_size*cell_size;; + double cell_area = cell_size*cell_size; //nrg+= /*dl.energy */ (dl.rays_thrown * cell_area / dl.area); nrg=cell_area; nrg*=(Math_PI*plot_size*plot_size)*0.5; // damping of radial linear gradient kernel @@ -2681,7 +2682,7 @@ void BakedLightBaker::clear() { materials.clear(); textures.clear(); lights.clear(); - triangles.clear();; + triangles.clear(); endpoint_normal.clear(); endpoint_normal_bits.clear(); baked_octree_texture_w=0; diff --git a/tools/editor/plugins/baked_light_editor_plugin.cpp b/tools/editor/plugins/baked_light_editor_plugin.cpp index 26c3144188..6a7e708b85 100644 --- a/tools/editor/plugins/baked_light_editor_plugin.cpp +++ b/tools/editor/plugins/baked_light_editor_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "baked_light_editor_plugin.h" + #include "scene/gui/box_container.h" #include "scene/3d/mesh_instance.h" #include "io/marshalls.h" diff --git a/tools/editor/plugins/camera_editor_plugin.cpp b/tools/editor/plugins/camera_editor_plugin.cpp index 1c8c392d65..1e0ec2b4a0 100644 --- a/tools/editor/plugins/camera_editor_plugin.cpp +++ b/tools/editor/plugins/camera_editor_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "camera_editor_plugin.h" + #include "spatial_editor_plugin.h" diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index 66dd98590d..bec7956b8c 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "canvas_item_editor_plugin.h" + #include "print_string.h" #include "tools/editor/editor_node.h" #include "os/keyboard.h" @@ -391,7 +392,7 @@ void CanvasItemEditor::_remove_canvas_item(CanvasItem *p_canvas_item) { } void CanvasItemEditor::_clear_canvas_items() { - editor_selection->clear();; + editor_selection->clear(); #if 0 while(canvas_items.size()) _remove_canvas_item(canvas_items.front()->key()); @@ -601,7 +602,7 @@ bool CanvasItemEditor::_select(CanvasItem *item, Point2 p_click_pos, bool p_appe if (!item) { //clear because nothing clicked - editor_selection->clear();; + editor_selection->clear(); if (p_drag) { drag_from=transform.affine_inverse().xform(p_click_pos); @@ -1319,7 +1320,7 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { { bone_ik_list.clear(); float closest_dist=1e20; - int bone_width = EditorSettings::get_singleton()->get("editors/2dbone_width"); + int bone_width = EditorSettings::get_singleton()->get("editors/2d/bone_width"); for(Map<ObjectID,BoneList>::Element *E=bone_list.front();E;E=E->next()) { if (E->get().from == E->get().to) @@ -1537,7 +1538,7 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { if (p_event.type==InputEvent::MOUSE_MOTION) { - if (!viewport->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) + if (!viewport->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) viewport->call_deferred("grab_focus"); const InputEventMouseMotion &m=p_event.mouse_motion; @@ -1555,7 +1556,6 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent& p_event) { if ( (m.button_mask&BUTTON_MASK_LEFT && tool == TOOL_PAN) || m.button_mask&BUTTON_MASK_MIDDLE || (m.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE))) { - h_scroll->set_value( h_scroll->get_value() - m.relative_x/zoom); v_scroll->set_value( v_scroll->get_value() - m.relative_y/zoom); } @@ -2071,7 +2071,7 @@ void CanvasItemEditor::_viewport_draw() { VisualServer::get_singleton()->canvas_item_add_line(ci,transform.xform(display_rotate_from), transform.xform(display_rotate_to),rotate_color); } - Size2 screen_size = Size2( GlobalConfig::get_singleton()->get("display/width"), GlobalConfig::get_singleton()->get("display/height") ); + Size2 screen_size = Size2( GlobalConfig::get_singleton()->get("display/window/width"), GlobalConfig::get_singleton()->get("display/window/height") ); Vector2 screen_endpoints[4]= { transform.xform(Vector2(0,0)), @@ -2114,11 +2114,11 @@ void CanvasItemEditor::_viewport_draw() { } if (skeleton_show_bones) { - int bone_width = EditorSettings::get_singleton()->get("editors/2dbone_width"); - Color bone_color1 = EditorSettings::get_singleton()->get("editors/2dbone_color1"); - Color bone_color2 = EditorSettings::get_singleton()->get("editors/2dbone_color2"); - Color bone_ik_color = EditorSettings::get_singleton()->get("editors/2dbone_ik_color"); - Color bone_selected_color = EditorSettings::get_singleton()->get("editors/2dbone_selected_color"); + int bone_width = EditorSettings::get_singleton()->get("editors/2d/bone_width"); + Color bone_color1 = EditorSettings::get_singleton()->get("editors/2d/bone_color1"); + Color bone_color2 = EditorSettings::get_singleton()->get("editors/2d/bone_color2"); + Color bone_ik_color = EditorSettings::get_singleton()->get("editors/2d/bone_ik_color"); + Color bone_selected_color = EditorSettings::get_singleton()->get("editors/2d/bone_selected_color"); for(Map<ObjectID,BoneList>::Element*E=bone_list.front();E;E=E->next()) { @@ -2354,7 +2354,7 @@ void CanvasItemEditor::_find_canvas_items_span(Node *p_node, Rect2& r_rect, cons - if (c) { + if (c && c->is_visible_in_tree()) { Rect2 rect = c->get_item_rect(); Transform2D xform = p_xform * c->get_transform(); @@ -2406,13 +2406,14 @@ void CanvasItemEditor::_update_scrollbars() { h_scroll->set_end( Point2(size.width-vmin.width, size.height) ); - Size2 screen_rect = Size2( GlobalConfig::get_singleton()->get("display/width"), GlobalConfig::get_singleton()->get("display/height") ); + Size2 screen_rect = Size2( GlobalConfig::get_singleton()->get("display/window/width"), GlobalConfig::get_singleton()->get("display/window/height") ); + Rect2 local_rect = Rect2(Point2(),viewport->get_size()-Size2(vmin.width,hmin.height)); Rect2 canvas_item_rect=Rect2(Point2(),screen_rect); - lock_list.clear();; + lock_list.clear(); bone_last_frame++; @@ -2477,6 +2478,7 @@ void CanvasItemEditor::_update_scrollbars() { //transform=Matrix32(); transform.elements[2]=-ofs*zoom; + editor->get_scene_root()->set_global_canvas_transform(transform); @@ -2925,7 +2927,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break;*/ case ANIM_COPY_POSE: { - pose_clipboard.clear();; + pose_clipboard.clear(); Map<Node*,Object*> &selection = editor_selection->get_selection(); @@ -3354,8 +3356,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { viewport->connect("gui_input",this,"_viewport_gui_input"); - h_scroll->connect("value_changed", this,"_update_scroll",Vector<Variant>(),true); - v_scroll->connect("value_changed", this,"_update_scroll",Vector<Variant>(),true); + h_scroll->connect("value_changed", this,"_update_scroll",Vector<Variant>(),Object::CONNECT_DEFERRED); + v_scroll->connect("value_changed", this,"_update_scroll",Vector<Variant>(),Object::CONNECT_DEFERRED); h_scroll->hide(); v_scroll->hide(); diff --git a/tools/editor/plugins/canvas_item_editor_plugin.h b/tools/editor/plugins/canvas_item_editor_plugin.h index f4f628fe28..dac8af5ae9 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.h +++ b/tools/editor/plugins/canvas_item_editor_plugin.h @@ -454,8 +454,8 @@ public: }; -class CanvasItemEditorViewport : public VBoxContainer { - GDCLASS( CanvasItemEditorViewport, VBoxContainer ); +class CanvasItemEditorViewport : public Control { + GDCLASS( CanvasItemEditorViewport, Control ); String default_type; Vector<String> types; diff --git a/tools/editor/plugins/collision_polygon_editor_plugin.cpp b/tools/editor/plugins/collision_polygon_editor_plugin.cpp index 010d6f1a47..c5cd15cf72 100644 --- a/tools/editor/plugins/collision_polygon_editor_plugin.cpp +++ b/tools/editor/plugins/collision_polygon_editor_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "collision_polygon_editor_plugin.h" + #include "spatial_editor_plugin.h" #include "os/file_access.h" #include "tools/editor/editor_settings.h" diff --git a/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp b/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp index 626ca9e132..a05eeb7a27 100644 --- a/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -29,7 +29,6 @@ #include "collision_shape_2d_editor_plugin.h" #include "canvas_item_editor_plugin.h" - #include "scene/resources/segment_shape_2d.h" #include "scene/resources/shape_line_2d.h" #include "scene/resources/circle_shape_2d.h" diff --git a/tools/editor/plugins/color_ramp_editor_plugin.cpp b/tools/editor/plugins/color_ramp_editor_plugin.cpp index 90ec1e9f4e..9509eb1b03 100644 --- a/tools/editor/plugins/color_ramp_editor_plugin.cpp +++ b/tools/editor/plugins/color_ramp_editor_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "color_ramp_editor_plugin.h" + #include "spatial_editor_plugin.h" #include "canvas_item_editor_plugin.h" diff --git a/tools/editor/plugins/editor_preview_plugins.cpp b/tools/editor/plugins/editor_preview_plugins.cpp index 478fa2308d..5d9b281874 100644 --- a/tools/editor/plugins/editor_preview_plugins.cpp +++ b/tools/editor/plugins/editor_preview_plugins.cpp @@ -27,12 +27,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "editor_preview_plugins.h" + #include "io/resource_loader.h" #include "tools/editor/editor_settings.h" #include "io/file_access_memory.h" #include "os/os.h" #include "scene/resources/material.h" -#include "scene/resources/sample.h" +//#include "scene/resources/sample.h" #include "scene/resources/mesh.h" #include "scene/resources/bit_mask.h" #include "tools/editor/editor_scale.h" @@ -521,7 +522,7 @@ EditorScriptPreviewPlugin::EditorScriptPreviewPlugin() { } /////////////////////////////////////////////////////////////////// - +#if 0 bool EditorSamplePreviewPlugin::handles(const String& p_type) const { return ClassDB::is_type(p_type,"Sample"); @@ -788,7 +789,7 @@ EditorSamplePreviewPlugin::EditorSamplePreviewPlugin() { } - +#endif /////////////////////////////////////////////////////////////////////////// bool EditorMeshPreviewPlugin::handles(const String& p_type) const { diff --git a/tools/editor/plugins/editor_preview_plugins.h b/tools/editor/plugins/editor_preview_plugins.h index 3c1689e61e..078e4cf8b5 100644 --- a/tools/editor/plugins/editor_preview_plugins.h +++ b/tools/editor/plugins/editor_preview_plugins.h @@ -94,7 +94,7 @@ public: EditorScriptPreviewPlugin(); }; - +#if 0 class EditorSamplePreviewPlugin : public EditorResourcePreviewGenerator { public: @@ -104,7 +104,7 @@ public: EditorSamplePreviewPlugin(); }; - +#endif class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator { RID scenario; diff --git a/tools/editor/plugins/gi_probe_editor_plugin.cpp b/tools/editor/plugins/gi_probe_editor_plugin.cpp index f550b7972a..925ac8ef11 100644 --- a/tools/editor/plugins/gi_probe_editor_plugin.cpp +++ b/tools/editor/plugins/gi_probe_editor_plugin.cpp @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* gi_probe_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #include "gi_probe_editor_plugin.h" @@ -44,7 +72,7 @@ GIProbeEditorPlugin::GIProbeEditorPlugin(EditorNode *p_node) { editor=p_node; bake = memnew( Button ); bake->set_icon(editor->get_gui_base()->get_icon("BakedLight","EditorIcons")); - bake->hide();; + bake->hide(); bake->connect("pressed",this,"_bake"); add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU,bake); gi_probe=NULL; @@ -52,6 +80,4 @@ GIProbeEditorPlugin::GIProbeEditorPlugin(EditorNode *p_node) { GIProbeEditorPlugin::~GIProbeEditorPlugin() { - - memdelete(bake); } diff --git a/tools/editor/plugins/gi_probe_editor_plugin.h b/tools/editor/plugins/gi_probe_editor_plugin.h index 8d2ec17d2f..35e0b93aae 100644 --- a/tools/editor/plugins/gi_probe_editor_plugin.h +++ b/tools/editor/plugins/gi_probe_editor_plugin.h @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* gi_probe_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #ifndef GIPROBEEDITORPLUGIN_H #define GIPROBEEDITORPLUGIN_H diff --git a/tools/editor/plugins/material_editor_plugin.cpp b/tools/editor/plugins/material_editor_plugin.cpp index e9bcf063fd..1aababa91b 100644 --- a/tools/editor/plugins/material_editor_plugin.cpp +++ b/tools/editor/plugins/material_editor_plugin.cpp @@ -1,4 +1,33 @@ +/*************************************************************************/ +/* material_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #include "material_editor_plugin.h" + #include "scene/main/viewport.h" #if 0 diff --git a/tools/editor/plugins/material_editor_plugin.h b/tools/editor/plugins/material_editor_plugin.h index 556e56e66b..5daae124e0 100644 --- a/tools/editor/plugins/material_editor_plugin.h +++ b/tools/editor/plugins/material_editor_plugin.h @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* material_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #ifndef MATERIAL_EDITOR_PLUGIN_H #define MATERIAL_EDITOR_PLUGIN_H diff --git a/tools/editor/plugins/mesh_instance_editor_plugin.cpp b/tools/editor/plugins/mesh_instance_editor_plugin.cpp index de29991057..322e212534 100644 --- a/tools/editor/plugins/mesh_instance_editor_plugin.cpp +++ b/tools/editor/plugins/mesh_instance_editor_plugin.cpp @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* mesh_instance_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #include "mesh_instance_editor_plugin.h" #include "scene/3d/physics_body.h" diff --git a/tools/editor/plugins/mesh_instance_editor_plugin.h b/tools/editor/plugins/mesh_instance_editor_plugin.h index 23dcbfc9b1..441d4d1d3f 100644 --- a/tools/editor/plugins/mesh_instance_editor_plugin.h +++ b/tools/editor/plugins/mesh_instance_editor_plugin.h @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* mesh_instance_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #ifndef MESH_INSTANCE_EDITOR_PLUGIN_H #define MESH_INSTANCE_EDITOR_PLUGIN_H diff --git a/tools/editor/plugins/multimesh_editor_plugin.cpp b/tools/editor/plugins/multimesh_editor_plugin.cpp index cce1c52215..6259ddf473 100644 --- a/tools/editor/plugins/multimesh_editor_plugin.cpp +++ b/tools/editor/plugins/multimesh_editor_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "multimesh_editor_plugin.h" + #include "scene/gui/box_container.h" #include "scene/3d/mesh_instance.h" #include "spatial_editor_plugin.h" @@ -177,7 +178,7 @@ void MultiMeshEditor::_populate() { Map<float,int> triangle_area_map; for(int i=0;i<facecount;i++) { - float area = r[i].get_area();; + float area = r[i].get_area(); if (area<CMP_EPSILON) continue; triangle_area_map[area_accum]=i; @@ -215,7 +216,7 @@ void MultiMeshEditor::_populate() { for(int i=0;i<instance_count;i++) { - float areapos = Math::random(0,area_accum); + float areapos = Math::random(0.0f,area_accum); Map<float,int>::Element *E = triangle_area_map.find_closest(areapos); ERR_FAIL_COND(!E) diff --git a/tools/editor/plugins/navigation_polygon_editor_plugin.cpp b/tools/editor/plugins/navigation_polygon_editor_plugin.cpp index b2d62af7bb..e70f2be9fa 100644 --- a/tools/editor/plugins/navigation_polygon_editor_plugin.cpp +++ b/tools/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -127,7 +127,7 @@ bool NavigationPolygonEditor::forward_gui_input(const InputEvent& p_event) { create_nav->set_text("No NavigationPolygon resource on this node.\nCreate and assign one?"); create_nav->popup_centered_minsize(); } - return (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1);; + return (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1); } diff --git a/tools/editor/plugins/particles_2d_editor_plugin.cpp b/tools/editor/plugins/particles_2d_editor_plugin.cpp index 331a958518..20b1b9d1ca 100644 --- a/tools/editor/plugins/particles_2d_editor_plugin.cpp +++ b/tools/editor/plugins/particles_2d_editor_plugin.cpp @@ -26,8 +26,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ - #include "particles_2d_editor_plugin.h" + #include "canvas_item_editor_plugin.h" #include "io/image_loader.h" #include "scene/gui/separator.h" diff --git a/tools/editor/plugins/particles_editor_plugin.cpp b/tools/editor/plugins/particles_editor_plugin.cpp index 382dc29c61..fd5ec5b5b9 100644 --- a/tools/editor/plugins/particles_editor_plugin.cpp +++ b/tools/editor/plugins/particles_editor_plugin.cpp @@ -212,7 +212,7 @@ void ParticlesEditor::_generate_emission_points() { for(int i=0;i<geometry.size();i++) { - float area = geometry[i].get_area();; + float area = geometry[i].get_area(); if (area<CMP_EPSILON) continue; triangle_area_map[area_accum]=i; diff --git a/tools/editor/plugins/path_editor_plugin.cpp b/tools/editor/plugins/path_editor_plugin.cpp index 4f0afe9e94..2e148d6486 100644 --- a/tools/editor/plugins/path_editor_plugin.cpp +++ b/tools/editor/plugins/path_editor_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "path_editor_plugin.h" + #include "spatial_editor_plugin.h" #include "scene/resources/curve.h" #include "os/keyboard.h" @@ -376,7 +377,7 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve ur->create_action(TTR("Split Path")); ur->add_do_method(c.ptr(),"add_point",closest_seg_point,Vector3(),Vector3(),closest_seg+1); ur->add_undo_method(c.ptr(),"remove_point",closest_seg+1); - ur->commit_action();; + ur->commit_action(); return true; } else { @@ -396,7 +397,7 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve ur->create_action(TTR("Add Point to Curve")); ur->add_do_method(c.ptr(),"add_point",it.xform(inters),Vector3(),Vector3(),-1); ur->add_undo_method(c.ptr(),"remove_point",c->get_point_count()); - ur->commit_action();; + ur->commit_action(); return true; } diff --git a/tools/editor/plugins/polygon_2d_editor_plugin.cpp b/tools/editor/plugins/polygon_2d_editor_plugin.cpp index dc56348700..7958dce75a 100644 --- a/tools/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/tools/editor/plugins/polygon_2d_editor_plugin.cpp @@ -26,8 +26,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ - #include "polygon_2d_editor_plugin.h" + #include "canvas_item_editor_plugin.h" #include "os/file_access.h" #include "tools/editor/editor_settings.h" diff --git a/tools/editor/plugins/resource_preloader_editor_plugin.cpp b/tools/editor/plugins/resource_preloader_editor_plugin.cpp index 0799732e02..cb139cbe24 100644 --- a/tools/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/tools/editor/plugins/resource_preloader_editor_plugin.cpp @@ -27,13 +27,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "resource_preloader_editor_plugin.h" + #include "io/resource_loader.h" #include "globals.h" #include "tools/editor/editor_settings.h" - - void ResourcePreloaderEditor::_gui_input(InputEvent p_event) { diff --git a/tools/editor/plugins/rich_text_editor_plugin.cpp b/tools/editor/plugins/rich_text_editor_plugin.cpp index f91af2fa60..8629d6ec8f 100644 --- a/tools/editor/plugins/rich_text_editor_plugin.cpp +++ b/tools/editor/plugins/rich_text_editor_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "rich_text_editor_plugin.h" + #include "os/file_access.h" #include "canvas_item_editor_plugin.h" diff --git a/tools/editor/plugins/sample_editor_plugin.cpp b/tools/editor/plugins/sample_editor_plugin.cpp index cbeaeb7d60..c333ba017f 100644 --- a/tools/editor/plugins/sample_editor_plugin.cpp +++ b/tools/editor/plugins/sample_editor_plugin.cpp @@ -28,6 +28,7 @@ /*************************************************************************/ #include "sample_editor_plugin.h" +#if 0 #include "io/resource_loader.h" #include "globals.h" #include "tools/editor/editor_settings.h" @@ -447,4 +448,4 @@ SampleEditorPlugin::~SampleEditorPlugin() { } - +#endif diff --git a/tools/editor/plugins/sample_editor_plugin.h b/tools/editor/plugins/sample_editor_plugin.h index 6a416ddfbf..651cd14a84 100644 --- a/tools/editor/plugins/sample_editor_plugin.h +++ b/tools/editor/plugins/sample_editor_plugin.h @@ -29,7 +29,7 @@ #ifndef SAMPLE_EDITOR_PLUGIN_H #define SAMPLE_EDITOR_PLUGIN_H - +#if 0 #include "tools/editor/editor_plugin.h" #include "tools/editor/editor_node.h" #include "scene/audio/sample_player.h" @@ -87,4 +87,6 @@ public: }; +#endif + #endif // SAMPLE_EDITOR_PLUGIN_H diff --git a/tools/editor/plugins/sample_library_editor_plugin.cpp b/tools/editor/plugins/sample_library_editor_plugin.cpp index c3e2481b5a..116c5d11b6 100644 --- a/tools/editor/plugins/sample_library_editor_plugin.cpp +++ b/tools/editor/plugins/sample_library_editor_plugin.cpp @@ -26,6 +26,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + +#if 0 #include "sample_library_editor_plugin.h" #include "io/resource_loader.h" @@ -541,3 +543,4 @@ SampleLibraryEditorPlugin::SampleLibraryEditorPlugin(EditorNode *p_node) { SampleLibraryEditorPlugin::~SampleLibraryEditorPlugin() { } +#endif diff --git a/tools/editor/plugins/sample_library_editor_plugin.h b/tools/editor/plugins/sample_library_editor_plugin.h index 1856d338ed..35028df859 100644 --- a/tools/editor/plugins/sample_library_editor_plugin.h +++ b/tools/editor/plugins/sample_library_editor_plugin.h @@ -30,7 +30,7 @@ #define SAMPLE_LIBRARY_EDITOR_PLUGIN_H - +#if 0 #include "tools/editor/editor_plugin.h" #include "tools/editor/editor_node.h" #include "scene/audio/sample_player.h" @@ -104,4 +104,5 @@ public: }; +#endif #endif // SAMPLE_LIBRARY_EDITOR_PLUGIN_H diff --git a/tools/editor/plugins/sample_player_editor_plugin.cpp b/tools/editor/plugins/sample_player_editor_plugin.cpp index ae958a5c6e..dd6450bfe7 100644 --- a/tools/editor/plugins/sample_player_editor_plugin.cpp +++ b/tools/editor/plugins/sample_player_editor_plugin.cpp @@ -26,7 +26,11 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + +#if 0 #include "sample_player_editor_plugin.h" + + #include "scene/resources/sample_library.h" @@ -89,7 +93,7 @@ void SamplePlayerEditor::_update_sample_library() { Ref<SampleLibrary> sl = node->call("get_sample_library"); if (sl.is_null()) { samples->add_item("<NO SAMPLE LIBRARY>"); - return; //no sample library;; + return; //no sample library; } List<StringName> samplenames; @@ -196,3 +200,4 @@ SamplePlayerEditorPlugin::~SamplePlayerEditorPlugin() } +#endif diff --git a/tools/editor/plugins/sample_player_editor_plugin.h b/tools/editor/plugins/sample_player_editor_plugin.h index d18496b4fd..ba1684497c 100644 --- a/tools/editor/plugins/sample_player_editor_plugin.h +++ b/tools/editor/plugins/sample_player_editor_plugin.h @@ -29,6 +29,8 @@ #ifndef SAMPLE_PLAYER_EDITOR_PLUGIN_H #define SAMPLE_PLAYER_EDITOR_PLUGIN_H +#if 0 + #include "tools/editor/editor_plugin.h" #include "tools/editor/editor_node.h" #include "scene/3d/spatial_sample_player.h" @@ -84,4 +86,5 @@ public: }; +#endif #endif // SAMPLE_PLAYER_EDITOR_PLUGIN_H diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index fa53e87fad..5f97fce4e7 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "script_editor_plugin.h" + #include "tools/editor/editor_settings.h" #include "io/resource_loader.h" #include "io/resource_saver.h" @@ -445,7 +446,7 @@ void ScriptEditor::_go_to_tab(int p_idx) { _update_selected_editor_menu(); } -void ScriptEditor::_close_tab(int p_idx) { +void ScriptEditor::_close_tab(int p_idx, bool p_save) { int selected = p_idx; if (selected<0 || selected>=tab_container->get_child_count()) @@ -454,7 +455,9 @@ void ScriptEditor::_close_tab(int p_idx) { Node *tselected = tab_container->get_child(selected); ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>(); if (current) { - apply_scripts(); + if (p_save) { + apply_scripts(); + } if (current->get_edit_menu()) { memdelete(current->get_edit_menu()); } @@ -504,6 +507,11 @@ void ScriptEditor::_close_current_tab() { } +void ScriptEditor::_close_discard_current_tab(const String& p_str) { + _close_tab(tab_container->get_current_tab(), false); + erase_tab_confirm->hide(); +} + void ScriptEditor::_close_docs_tab() { int child_count = tab_container->get_child_count(); @@ -1326,6 +1334,7 @@ void ScriptEditor::_find_scripts(Node* p_base, Node* p_current, Set<Ref<Script> struct _ScriptEditorItemData { String name; + String sort_key; Ref<Texture> icon; int index; String tooltip; @@ -1335,7 +1344,7 @@ struct _ScriptEditorItemData { bool operator<(const _ScriptEditorItemData& id) const { - return category==id.category?name.nocasecmp_to(id.name)<0:category<id.category; + return category==id.category?sort_key<id.sort_key:category<id.category; } }; @@ -1396,6 +1405,8 @@ void ScriptEditor::_update_script_names() { script_list->clear(); bool split_script_help = EditorSettings::get_singleton()->get("text_editor/open_scripts/group_help_pages"); + ScriptSortBy sort_by = (ScriptSortBy) (int) EditorSettings::get_singleton()->get("text_editor/open_scripts/sort_scripts_by"); + ScriptListName display_as = (ScriptListName) (int) EditorSettings::get_singleton()->get("text_editor/open_scripts/list_script_names_as"); Vector<_ScriptEditorItemData> sedata; @@ -1407,15 +1418,41 @@ void ScriptEditor::_update_script_names() { String name = se->get_name(); Ref<Texture> icon = se->get_icon(); - String tooltip = se->get_edited_script()->get_path(); + String path = se->get_edited_script()->get_path(); _ScriptEditorItemData sd; sd.icon=icon; sd.name=name; - sd.tooltip=tooltip; + sd.tooltip=path; sd.index=i; sd.used=used.has(se->get_edited_script()); sd.category=0; + + switch (sort_by) { + case SORT_BY_NAME: { + sd.sort_key=name.to_lower(); + } break; + case SORT_BY_PATH: { + sd.sort_key=path; + } break; + } + + switch (display_as) { + case DISPLAY_NAME: { + sd.name=name; + } break; + case DISPLAY_DIR_AND_NAME: { + if (!path.get_base_dir().get_file().empty()) { + sd.name=path.get_base_dir().get_file() + "/" + name; + } else { + sd.name=name; + } + } break; + case DISPLAY_FULL_PATH: { + sd.name=path; + } break; + } + sedata.push_back(sd); } @@ -1430,6 +1467,7 @@ void ScriptEditor::_update_script_names() { _ScriptEditorItemData sd; sd.icon=icon; sd.name=name; + sd.sort_key=name; sd.tooltip=tooltip; sd.index=i; sd.used=false; @@ -1719,6 +1757,7 @@ void ScriptEditor::_editor_settings_changed() { se->update_settings(); } _update_script_colors(); + _update_script_names(); ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/files/auto_reload_and_parse_scripts_on_save",true)); @@ -2033,6 +2072,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_tab_changed",&ScriptEditor::_tab_changed); ClassDB::bind_method("_menu_option",&ScriptEditor::_menu_option); ClassDB::bind_method("_close_current_tab",&ScriptEditor::_close_current_tab); + ClassDB::bind_method("_close_discard_current_tab", &ScriptEditor::_close_discard_current_tab); ClassDB::bind_method("_close_docs_tab", &ScriptEditor::_close_docs_tab); ClassDB::bind_method("_close_all_tabs", &ScriptEditor::_close_all_tabs); ClassDB::bind_method("_editor_play",&ScriptEditor::_editor_play); @@ -2225,8 +2265,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { tab_container->connect("tab_changed", this,"_tab_changed"); erase_tab_confirm = memnew( ConfirmationDialog ); - add_child(erase_tab_confirm); + erase_tab_confirm->get_ok()->set_text(TTR("Save")); + erase_tab_confirm->add_button(TTR("Discard"), OS::get_singleton()->get_swap_ok_cancel(), "discard"); erase_tab_confirm->connect("confirmed", this,"_close_current_tab"); + erase_tab_confirm->connect("custom_action", this, "_close_discard_current_tab"); + add_child(erase_tab_confirm); script_create_dialog = memnew(ScriptCreateDialog); script_create_dialog->set_title(TTR("Create Script")); @@ -2428,9 +2471,13 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) { EDITOR_DEF("text_editor/open_scripts/script_temperature_cold_color",Color(0,0,1,0.3)); EDITOR_DEF("text_editor/open_scripts/current_script_background_color",Color(0.81,0.81,0.14,0.63)); EDITOR_DEF("text_editor/open_scripts/group_help_pages",true); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT,"text_editor/open_scripts/sort_scripts_by",PROPERTY_HINT_ENUM,"Name,Path")); + EDITOR_DEF("text_editor/open_scripts/sort_scripts_by",0); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT,"text_editor/open_scripts/list_script_names_as",PROPERTY_HINT_ENUM,"Name,Parent Directory And Name,Full Path")); + EDITOR_DEF("text_editor/open_scripts/list_script_names_as",0); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"text_editor/external/exec_path",PROPERTY_HINT_GLOBAL_FILE)); EDITOR_DEF("text_editor/external/exec_flags",""); - + } diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h index 655568e262..75099fc5ec 100644 --- a/tools/editor/plugins/script_editor_plugin.h +++ b/tools/editor/plugins/script_editor_plugin.h @@ -154,6 +154,17 @@ class ScriptEditor : public VBoxContainer { WINDOW_PREV, WINDOW_SELECT_BASE=100 }; + + enum ScriptSortBy { + SORT_BY_NAME, + SORT_BY_PATH, + }; + + enum ScriptListName { + DISPLAY_NAME, + DISPLAY_DIR_AND_NAME, + DISPLAY_FULL_PATH, + }; HBoxContainer *menu_hb; MenuButton *file_menu; @@ -219,9 +230,10 @@ class ScriptEditor : public VBoxContainer { bool _test_script_times_on_disk(Ref<Script> p_for_script=Ref<Script>()); - void _close_tab(int p_idx); + void _close_tab(int p_idx, bool p_save=true); void _close_current_tab(); + void _close_discard_current_tab(const String& p_str); void _close_docs_tab(); void _close_all_tabs(); diff --git a/tools/editor/plugins/script_text_editor.cpp b/tools/editor/plugins/script_text_editor.cpp index 95e7afa04c..9ec6266419 100644 --- a/tools/editor/plugins/script_text_editor.cpp +++ b/tools/editor/plugins/script_text_editor.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "script_text_editor.h" + #include "tools/editor/editor_settings.h" #include "os/keyboard.h" #include "tools/editor/script_editor_debugger.h" @@ -114,6 +115,7 @@ void ScriptTextEditor::_load_theme_settings() { text_edit->add_color_override("selection_color",EDITOR_DEF("text_editor/highlighting/selection_color",Color(0.2,0.2,1))); text_edit->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/highlighting/brace_mismatch_color",Color(1,0.2,0.2))); text_edit->add_color_override("current_line_color",EDITOR_DEF("text_editor/highlighting/current_line_color",Color(0.3,0.5,0.8,0.15))); + text_edit->add_color_override("line_length_guideline_color", EDITOR_DEF("text_editor/highlighting/line_length_guideline_color", Color(0,0,0))); text_edit->add_color_override("word_highlighted_color",EDITOR_DEF("text_editor/highlighting/word_highlighted_color",Color(0.8,0.9,0.9,0.15))); text_edit->add_color_override("number_color",EDITOR_DEF("text_editor/highlighting/number_color",Color(0.9,0.6,0.0,2))); text_edit->add_color_override("function_color",EDITOR_DEF("text_editor/highlighting/function_color",Color(0.4,0.6,0.8))); diff --git a/tools/editor/plugins/shader_editor_plugin.cpp b/tools/editor/plugins/shader_editor_plugin.cpp index 90d0f7fc93..56a8fccb9c 100644 --- a/tools/editor/plugins/shader_editor_plugin.cpp +++ b/tools/editor/plugins/shader_editor_plugin.cpp @@ -27,8 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "shader_editor_plugin.h" -#include "tools/editor/editor_settings.h" +#include "tools/editor/editor_settings.h" #include "spatial_editor_plugin.h" #include "scene/resources/shader_graph.h" #include "io/resource_loader.h" diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index d989c5b30d..d86fec11d8 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -464,8 +464,7 @@ void GraphCurveMapEdit::_plot_curve(const Vector2& p_a,const Vector2& p_b,const /* compose the basis and geometry matrices */ - static const float CR_basis[4][4] = - { + static const float CR_basis[4][4] = { { -0.5, 1.5, -1.5, 0.5 }, { 1.0, -2.5, 2.0, -0.5 }, { -0.5, 0.0, 0.5, 0.0 }, diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 0f01f71294..3ba1a2cbdc 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -27,8 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "spatial_editor_plugin.h" -#include "print_string.h" +#include "print_string.h" #include "os/keyboard.h" #include "scene/3d/visual_instance.h" #include "scene/3d/camera.h" @@ -277,12 +277,10 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2& p_pos, bool p_append,b Vector<ObjectID> instances=VisualServer::get_singleton()->instances_cull_ray(pos,ray,get_tree()->get_root()->get_world()->get_scenario() ); Set<Ref<SpatialEditorGizmo> > found_gizmos; - //uint32_t closest=0; - //float closest_dist=0; - - r_includes_current=false; - - List<_RayResult> results; + ObjectID closest=0; + Spatial *item=NULL; + float closest_dist=1e20; + int selected_handle=-1; for (int i=0;i<instances.size();i++) { @@ -318,84 +316,30 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2& p_pos, bool p_append,b if (dist<0) continue; + if (dist < closest_dist) { + closest=instances[i]; + closest_dist=dist; + selected_handle=handle; + item=spat; + } + // if (editor_selection->is_selected(spat)) + // r_includes_current=true; - if (editor_selection->is_selected(spat)) - r_includes_current=true; - - _RayResult res; - res.item=spat; - res.depth=dist; - res.handle=handle; - results.push_back(res); } - if (results.empty()) + if (!item) return 0; - results.sort(); - Spatial *s=NULL; - + if (!editor_selection->is_selected(item) || (r_gizmo_handle && selected_handle>=0)) { - if (!r_includes_current || results.size()==1 || (r_gizmo_handle && results.front()->get().handle>=0)) { - - //return the nearest one - s = results.front()->get().item; if (r_gizmo_handle) - *r_gizmo_handle=results.front()->get().handle; - - } else { - - //returns the next one from a curent selection - List<_RayResult>::Element *E=results.front(); - List<_RayResult>::Element *S=NULL; - + *r_gizmo_handle=selected_handle; - while(true) { - - //very strange loop algorithm that complies with object selection standards (tm). - - if (S==E) { - //went all around and anothing was found - //since can't rotate the selection - //just return the first one - - s=results.front()->get().item; - break; - - } - - if (!S && editor_selection->is_selected(E->get().item)) { - //found an item currently in the selection, - //so start from this one - S=E; - } - - if (S && !editor_selection->is_selected(E->get().item)) { - // free item after a selected item, this one is desired. - s=E->get().item; - break; - } - - E=E->next(); - if (!E) { - - if (!S) { - //did a loop but nothing was selected, select first - s=results.front()->get().item; - break; - - } - E=results.front(); - } - } } - if (!s) - return 0; - - return s->get_instance_ID(); + return closest; } @@ -1527,11 +1471,11 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (m.mod.meta) mod=KEY_META; - if (mod == _get_key_modifier("3d_editor/pan_modifier")) + if (mod == _get_key_modifier("editors/3d/pan_modifier")) nav_mode = NAVIGATION_PAN; - else if (mod == _get_key_modifier("3d_editor/zoom_modifier")) + else if (mod == _get_key_modifier("editors/3d/zoom_modifier")) nav_mode = NAVIGATION_ZOOM; - else if (mod == _get_key_modifier("3d_editor/orbit_modifier")) + else if (mod == _get_key_modifier("editors/3d/orbit_modifier")) nav_mode = NAVIGATION_ORBIT; } else if (nav_scheme == NAVIGATION_MAYA) { @@ -1552,11 +1496,11 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { mod=KEY_META; if(mod){ - if (mod == _get_key_modifier("3d_editor/pan_modifier")) + if (mod == _get_key_modifier("editors/3d/pan_modifier")) nav_mode = NAVIGATION_PAN; - else if (mod == _get_key_modifier("3d_editor/zoom_modifier")) + else if (mod == _get_key_modifier("editors/3d/zoom_modifier")) nav_mode = NAVIGATION_ZOOM; - else if (mod == _get_key_modifier("3d_editor/orbit_modifier")) + else if (mod == _get_key_modifier("editors/3d/orbit_modifier")) nav_mode = NAVIGATION_ORBIT; } } @@ -1587,7 +1531,7 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (nav_scheme==NAVIGATION_MAYA && m.mod.shift) zoom_speed *= zoom_speed_modifier; - NavigationZoomStyle zoom_style = (NavigationZoomStyle)EditorSettings::get_singleton()->get("3d_editor/zoom_style").operator int(); + NavigationZoomStyle zoom_style = (NavigationZoomStyle)EditorSettings::get_singleton()->get("editors/3d/zoom_style").operator int(); if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) { if ( m.relative_x > 0) cursor.distance*=1-m.relative_x*zoom_speed; @@ -1821,10 +1765,10 @@ void SpatialEditorViewport::_notification(int p_what) { //update msaa if changed - int msaa_mode = GlobalConfig::get_singleton()->get("rendering/antialias/msaa"); + int msaa_mode = GlobalConfig::get_singleton()->get("rendering/quality/msaa"); viewport->set_msaa(Viewport::MSAA(msaa_mode)); - bool hdr = GlobalConfig::get_singleton()->get("rendering/dynamic_range/hdr"); + bool hdr = GlobalConfig::get_singleton()->get("rendering/quality/hdr"); viewport->set_hdr(hdr); @@ -2297,10 +2241,10 @@ void SpatialEditorViewport::reset() { message_time=0; message=""; last_message=""; - name=TTR("Top"); + name=""; - cursor.x_rot=0; - cursor.y_rot=0; + cursor.x_rot=0.5; + cursor.y_rot=0.5; cursor.distance=4; cursor.region_select=false; _update_name(); @@ -2350,7 +2294,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed index=p_index; editor=p_editor; - editor_selection=editor->get_editor_selection();; + editor_selection=editor->get_editor_selection(); undo_redo=editor->get_undo_redo(); clicked=0; clicked_includes_current=false; @@ -2606,12 +2550,12 @@ Dictionary SpatialEditor::get_state() const { d["viewports"]=vpdata; - d["default_light"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT) );; + d["default_light"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT) ); d["ambient_light_color"]=settings_ambient_color->get_pick_color(); - d["default_srgb"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB) );; - d["show_grid"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_GRID) );; - d["show_origin"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN) );; + d["default_srgb"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB) ); + d["show_grid"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_GRID) ); + d["show_origin"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN) ); d["fov"]=get_fov(); d["znear"]=get_znear(); d["zfar"]=get_zfar(); @@ -3141,9 +3085,9 @@ void SpatialEditor::_init_indicators() { { - indicator_mat.instance();; + indicator_mat.instance(); indicator_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); - indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true); + //indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true); indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,true); indicator_mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR,true); @@ -3437,7 +3381,7 @@ void SpatialEditor::_instance_scene() { #if 0 EditorNode *en = get_scene()->get_root_node()->cast_to<EditorNode>(); ERR_FAIL_COND(!en); - String path = en->get_scenes_dock()->get_selected_path(); + String path = en->get_filesystem_dock()->get_selected_path(); if (path=="") { set_message(TTR("No scene selected to instance!")); return; @@ -4095,7 +4039,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { add_to_group("_spatial_editor_group"); EDITOR_DEF("editors/3d/manipulator_gizmo_size",80); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT,"3d_editor/manipulator_gizmo_size",PROPERTY_HINT_RANGE,"16,1024,1")); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT,"editors/3d/manipulator_gizmo_size",PROPERTY_HINT_RANGE,"16,1024,1")); EDITOR_DEF("editors/3d/manipulator_gizmo_opacity",0.2); over_gizmo_handle=-1; diff --git a/tools/editor/plugins/spatial_editor_plugin.h b/tools/editor/plugins/spatial_editor_plugin.h index 6e5243e6ab..36f807c11f 100644 --- a/tools/editor/plugins/spatial_editor_plugin.h +++ b/tools/editor/plugins/spatial_editor_plugin.h @@ -208,7 +208,7 @@ private: bool region_select; Point2 region_begin,region_end; - Cursor() { x_rot=y_rot=0; distance=4; region_select=false; } + Cursor() { x_rot=y_rot=0.5; distance=4; region_select=false; } } cursor; RID move_gizmo_instance[3], rotate_gizmo_instance[3]; diff --git a/tools/editor/plugins/stream_editor_plugin.cpp b/tools/editor/plugins/stream_editor_plugin.cpp index 00d7b208c8..991c29b6db 100644 --- a/tools/editor/plugins/stream_editor_plugin.cpp +++ b/tools/editor/plugins/stream_editor_plugin.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "stream_editor_plugin.h" - +#if 0 void StreamEditor::_notification(int p_what) { @@ -146,3 +146,4 @@ StreamEditorPlugin::~StreamEditorPlugin() { } +#endif diff --git a/tools/editor/plugins/stream_editor_plugin.h b/tools/editor/plugins/stream_editor_plugin.h index af29f64f93..cc853d4661 100644 --- a/tools/editor/plugins/stream_editor_plugin.h +++ b/tools/editor/plugins/stream_editor_plugin.h @@ -29,7 +29,7 @@ #ifndef STREAM_EDITOR_PLUGIN_H #define STREAM_EDITOR_PLUGIN_H - +#if 0 #include "tools/editor/editor_plugin.h" #include "tools/editor/editor_node.h" #include "scene/audio/stream_player.h" @@ -81,3 +81,4 @@ public: }; #endif // STREAM_EDITOR_PLUGIN_H +#endif diff --git a/tools/editor/plugins/texture_editor_plugin.cpp b/tools/editor/plugins/texture_editor_plugin.cpp index a846a908d2..82cba7ac0e 100644 --- a/tools/editor/plugins/texture_editor_plugin.cpp +++ b/tools/editor/plugins/texture_editor_plugin.cpp @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* texture_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #include "texture_editor_plugin.h" #include "io/resource_loader.h" diff --git a/tools/editor/plugins/texture_editor_plugin.h b/tools/editor/plugins/texture_editor_plugin.h index 4b05f7f7ab..456a5249de 100644 --- a/tools/editor/plugins/texture_editor_plugin.h +++ b/tools/editor/plugins/texture_editor_plugin.h @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* texture_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #ifndef TEXTURE_EDITOR_PLUGIN_H #define TEXTURE_EDITOR_PLUGIN_H diff --git a/tools/editor/plugins/texture_region_editor_plugin.cpp b/tools/editor/plugins/texture_region_editor_plugin.cpp index 1ad880c4d6..9b0ca0a482 100644 --- a/tools/editor/plugins/texture_region_editor_plugin.cpp +++ b/tools/editor/plugins/texture_region_editor_plugin.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* texture_region_editor_plugin.cpp */ +/* texture_region_editor_plugin.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,9 +28,9 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "texture_region_editor_plugin.h" #include "core/core_string_names.h" -#include "texture_region_editor_plugin.h" #include "scene/gui/check_box.h" #include "os/input.h" #include "os/keyboard.h" diff --git a/tools/editor/plugins/texture_region_editor_plugin.h b/tools/editor/plugins/texture_region_editor_plugin.h index 35c0f18efa..da713a53d3 100644 --- a/tools/editor/plugins/texture_region_editor_plugin.h +++ b/tools/editor/plugins/texture_region_editor_plugin.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* texture_region_editor_plugin.h */ +/* texture_region_editor_plugin.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ diff --git a/tools/editor/plugins/theme_editor_plugin.cpp b/tools/editor/plugins/theme_editor_plugin.cpp index 027e91ade8..4b8fea5a45 100644 --- a/tools/editor/plugins/theme_editor_plugin.cpp +++ b/tools/editor/plugins/theme_editor_plugin.cpp @@ -26,8 +26,9 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "version.h" #include "theme_editor_plugin.h" + +#include "version.h" #include "os/file_access.h" void ThemeEditor::edit(const Ref<Theme>& p_theme) { @@ -584,7 +585,7 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { List<StringName> types; base_theme->get_type_list(&types); - type_menu->get_popup()->clear();; + type_menu->get_popup()->clear(); if (p_option==0 || p_option==1) {//add diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp index 1a8c35a0be..7c232f0c32 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.cpp +++ b/tools/editor/plugins/tile_map_editor_plugin.cpp @@ -26,12 +26,10 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ - #include "tile_map_editor_plugin.h" #include "os/keyboard.h" #include "os/input.h" - #include "canvas_item_editor_plugin.h" #include "tools/editor/editor_settings.h" #include "tools/editor/editor_scale.h" diff --git a/tools/editor/plugins/tile_set_editor_plugin.cpp b/tools/editor/plugins/tile_set_editor_plugin.cpp index bb6236a6d6..3db6c94917 100644 --- a/tools/editor/plugins/tile_set_editor_plugin.cpp +++ b/tools/editor/plugins/tile_set_editor_plugin.cpp @@ -27,8 +27,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "tile_set_editor_plugin.h" + #include "scene/2d/sprite.h" #include "scene/2d/physics_body_2d.h" + void TileSetEditor::edit(const Ref<TileSet>& p_tileset) { tileset=p_tileset; diff --git a/tools/editor/progress_dialog.cpp b/tools/editor/progress_dialog.cpp index 03303b8c48..76626c4556 100644 --- a/tools/editor/progress_dialog.cpp +++ b/tools/editor/progress_dialog.cpp @@ -27,10 +27,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "progress_dialog.h" + #include "main/main.h" #include "message_queue.h" #include "os/os.h" #include "editor_scale.h" + void BackgroundProgress::_add_task(const String& p_task,const String& p_label, int p_steps) { _THREAD_SAFE_METHOD_ diff --git a/tools/editor/project_export.cpp b/tools/editor/project_export.cpp index 10005b6850..2fa62df5bc 100644 --- a/tools/editor/project_export.cpp +++ b/tools/editor/project_export.cpp @@ -27,16 +27,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "project_export.h" - +#if 0 #include "os/dir_access.h" #include "os/file_access.h" #include "globals.h" - #include "io/resource_loader.h" #include "io/resource_saver.h" #include "os/os.h" #include "scene/gui/box_container.h" - #include "scene/gui/tab_container.h" #include "scene/gui/scroll_container.h" #include "editor_data.h" @@ -452,8 +450,8 @@ void ProjectExportDialog::_export_action(const String& p_file) { while(true) { - print_line("TESTING: "+location.plus_file("engine.cfg")); - if (FileAccess::exists(location.plus_file("engine.cfg"))) { + print_line("TESTING: "+location.plus_file("godot.cfg")); + if (FileAccess::exists(location.plus_file("godot.cfg"))) { error->set_text(TTR("Please export outside the project folder!")); error->popup_centered_minsize(); @@ -2101,7 +2099,7 @@ Error ProjectExport::export_project(const String& p_preset) { added_settings["remap/"+platform]=Variant(remaps).operator Array(); } - String engine_cfg_path=d->get_current_dir()+"/engine.cfg"; + String engine_cfg_path=d->get_current_dir()+"/godot.cfg"; print_line("enginecfg: "+engine_cfg_path); GlobalConfig::get_singleton()->save_custom(engine_cfg_path,added_settings); @@ -2129,3 +2127,4 @@ ProjectExport::ProjectExport(EditorData* p_data) { } +#endif diff --git a/tools/editor/project_export.h b/tools/editor/project_export.h index 06992a7e34..c528a23121 100644 --- a/tools/editor/project_export.h +++ b/tools/editor/project_export.h @@ -46,6 +46,7 @@ #include "property_editor.h" #include "editor_import_export.h" +#if 0 class EditorNode; class ProjectExportDialog : public ConfirmationDialog { @@ -242,3 +243,4 @@ public: #endif // PROJECT_EXPORT_SETTINGS_H +#endif diff --git a/tools/editor/project_manager.cpp b/tools/editor/project_manager.cpp index 2cf940a29a..af73414ab0 100644 --- a/tools/editor/project_manager.cpp +++ b/tools/editor/project_manager.cpp @@ -26,8 +26,9 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "version.h" #include "project_manager.h" + +#include "version.h" #include "os/os.h" #include "os/dir_access.h" #include "os/file_access.h" @@ -36,20 +37,16 @@ #include "scene/gui/separator.h" #include "scene/gui/tool_button.h" #include "io/config_file.h" - #include "scene/gui/line_edit.h" #include "scene/gui/panel_container.h" #include "scene/gui/center_container.h" #include "io/stream_peer_ssl.h" - #include "scene/gui/texture_rect.h" #include "scene/gui/margin_container.h" #include "io/resource_saver.h" - #include "editor_themes.h" #include "editor_initialize_ssl.h" #include "editor_scale.h" - #include "io/zip_io.h" class NewProjectDialog : public ConfirmationDialog { @@ -95,18 +92,18 @@ private: if (mode!=MODE_IMPORT) { - if (d->file_exists("engine.cfg")) { + if (d->file_exists("godot.cfg")) { - error->set_text(TTR("Invalid project path, engine.cfg must not exist.")); + error->set_text(TTR("Invalid project path, godot.cfg must not exist.")); memdelete(d); return ""; } } else { - if (valid_path != "" && !d->file_exists("engine.cfg")) { + if (valid_path != "" && !d->file_exists("godot.cfg")) { - error->set_text(TTR("Invalid project path, engine.cfg must exist.")); + error->set_text(TTR("Invalid project path, godot.cfg must exist.")); memdelete(d); return ""; } @@ -140,7 +137,7 @@ private: String p = p_path; if (mode==MODE_IMPORT) { - if (p.ends_with("engine.cfg")) { + if (p.ends_with("godot.cfg")) { p=p.get_base_dir(); } @@ -166,7 +163,7 @@ private: fdialog->set_mode(FileDialog::MODE_OPEN_FILE); fdialog->clear_filters(); - fdialog->add_filter("engine.cfg ; " _MKSTR(VERSION_NAME) " Project"); + fdialog->add_filter("godot.cfg ; " _MKSTR(VERSION_NAME) " Project"); } else { fdialog->set_mode(FileDialog::MODE_OPEN_DIR); } @@ -193,9 +190,9 @@ private: - FileAccess *f = FileAccess::open(dir.plus_file("/engine.cfg"),FileAccess::WRITE); + FileAccess *f = FileAccess::open(dir.plus_file("/godot.cfg"),FileAccess::WRITE); if (!f) { - error->set_text(TTR("Couldn't create engine.cfg in project path.")); + error->set_text(TTR("Couldn't create godot.cfg in project path.")); } else { f->store_line("; Engine configuration file."); @@ -762,7 +759,7 @@ void ProjectManager::_load_recent_projects() { continue; String project = _name.get_slice("/",1); - String conf=path.plus_file("engine.cfg"); + String conf=path.plus_file("godot.cfg"); bool favorite = (_name.begins_with("favorite_projects/"))?true:false; uint64_t last_modified = 0; @@ -1030,7 +1027,7 @@ void ProjectManager::_scan_dir(DirAccess *da,float pos, float total,List<String> while(n!=String()) { if (da->current_is_dir() && !n.begins_with(".")) { subdirs.push_front(n); - } else if (n=="engine.cfg") { + } else if (n=="godot.cfg") { r_projects->push_back(da->get_current_dir()); } n=da->get_next(); @@ -1154,7 +1151,7 @@ void ProjectManager::_files_dropped(PoolStringArray p_files, int p_screen) { dir->list_dir_begin(); String file = dir->get_next(); while(confirm && file!=String()) { - if (!dir->current_is_dir() && file.ends_with("engine.cfg")) { + if (!dir->current_is_dir() && file.ends_with("godot.cfg")) { confirm = false; } file = dir->get_next(); diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp index 0396456c49..e725786f94 100644 --- a/tools/editor/project_settings.cpp +++ b/tools/editor/project_settings.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "project_settings.h" + #include "scene/gui/tab_container.h" #include "globals.h" #include "os/keyboard.h" @@ -779,7 +780,7 @@ void ProjectSettings::_copy_to_platform(int p_which) { String name = catname+"/"+propname; Variant value=GlobalConfig::get_singleton()->get(name); - catname+="."+popup_platform->get_popup()->get_item_text(p_which);; + catname+="."+popup_platform->get_popup()->get_item_text(p_which); name = catname+"/"+propname; GlobalConfig::get_singleton()->set(name,value); @@ -1216,7 +1217,7 @@ ProjectSettings::ProjectSettings(EditorData *p_data) { singleton=this; - set_title(TTR("Project Settings (engine.cfg)")); + set_title(TTR("Project Settings (godot.cfg)")); undo_redo=&p_data->get_undo_redo(); data=p_data; @@ -1341,7 +1342,7 @@ ProjectSettings::ProjectSettings(EditorData *p_data) { hbc->add_spacer(); - List<StringName> ep; + /*List<StringName> ep; EditorImportExport::get_singleton()->get_export_platforms(&ep); ep.sort_custom<StringName::AlphCompare>(); @@ -1349,7 +1350,7 @@ ProjectSettings::ProjectSettings(EditorData *p_data) { popup_platform->get_popup()->add_item( E->get() ); - } + }*/ popup_platform->get_popup()->connect("id_pressed",this,"_copy_to_platform"); get_ok()->set_text(TTR("Close")); @@ -1362,7 +1363,7 @@ ProjectSettings::ProjectSettings(EditorData *p_data) { Control *input_base = memnew( Control ); input_base->set_name(TTR("Input Map")); - input_base->set_area_as_parent_rect();; + input_base->set_area_as_parent_rect(); tab_container->add_child(input_base); VBoxContainer *vbc = memnew( VBoxContainer ); diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index 8f294a5102..8e3791eb8d 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -27,10 +27,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "property_editor.h" + #include "scene/gui/label.h" #include "io/resource_loader.h" #include "io/image_loader.h" -#include "object_type_db.h" +#include "class_db.h" #include "print_string.h" #include "globals.h" #include "scene/resources/font.h" @@ -117,7 +118,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { Set<String> valid_extensions; for (List<String>::Element *E=extensions.front();E;E=E->next()) { - + print_line("found: "+E->get()); valid_extensions.insert(E->get()); } @@ -207,13 +208,13 @@ void CustomPropertyEditor::_menu_option(int p_which) { case OBJ_MENU_REIMPORT: { RES r=v; - if (r.is_valid() && r->get_import_metadata().is_valid()) { +/* if (r.is_valid() && r->get_import_metadata().is_valid()) { Ref<ResourceImportMetadata> rimd = r->get_import_metadata(); Ref<EditorImportPlugin> eip = EditorImportExport::get_singleton()->get_import_plugin_by_name(rimd->get_editor()); if (eip.is_valid()) { eip->import_dialog(r->get_path()); } - } + }*/ } break; case OBJ_MENU_NEW_SCRIPT: { @@ -944,11 +945,11 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty menu->add_icon_item(get_icon("EditResource","EditorIcons"),"Edit",OBJ_MENU_EDIT); menu->add_icon_item(get_icon("Del","EditorIcons"),"Clear",OBJ_MENU_CLEAR); menu->add_icon_item(get_icon("Duplicate","EditorIcons"),"Make Unique",OBJ_MENU_MAKE_UNIQUE); - RES r = v; + /*RES r = v; if (r.is_valid() && r->get_path().is_resource_file() && r->get_import_metadata().is_valid()) { menu->add_separator(); menu->add_icon_item(get_icon("ReloadSmall","EditorIcons"),"Re-Import",OBJ_MENU_REIMPORT); - } + }*/ /*if (r.is_valid() && r->get_path().is_resource_file()) { menu->set_item_tooltip(1,r->get_path()); } else if (r.is_valid()) { @@ -1502,12 +1503,12 @@ void CustomPropertyEditor::_drag_easing(const InputEvent& p_ev) { bool sg = val < 0; val = Math::absf(val); - val = Math::log(val)/Math::log(2); + val = Math::log(val)/Math::log((float)2.0); //logspace val+=rel*0.05; // - val = Math::pow(2,val); + val = Math::pow(2.0f,val); if (sg) val=-val; @@ -2430,7 +2431,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p } break; case Variant::COLOR: { - p_item->set_custom_bg_color(1,obj->get(p_name)); + tree->update(); //p_item->set_text(1,obj->get(p_name)); } break; @@ -3139,6 +3140,10 @@ void PropertyEditor::update_tree() { } else if ( ! (p.usage&PROPERTY_USAGE_EDITOR ) ) continue; + + if (hide_script && p.name=="script/script") + continue; + String basename=p.name; if (group!="") { if (group_base!="") { @@ -3707,7 +3712,7 @@ void PropertyEditor::update_tree() { item->set_cell_mode( 1, TreeItem::CELL_MODE_CUSTOM ); item->set_editable( 1, !read_only ); //item->set_text(1,obj->get(p.name)); - item->set_custom_bg_color(1,obj->get(p.name)); + item->set_custom_draw(1,this,"_draw_transparency"); if (show_type_icons) item->set_icon( 0,get_icon("Color","EditorIcons") ); @@ -3730,7 +3735,7 @@ void PropertyEditor::update_tree() { item->set_cell_mode(1, TreeItem::CELL_MODE_STRING); item->set_editable( 1, !read_only ); item->set_text(1,obj->get(p.name)); - item->add_button(1, get_icon("Collapse", "EditorIcons")); + item->add_button(1, get_icon("CopyNodePath", "EditorIcons")); } break; case Variant::OBJECT: { @@ -3855,6 +3860,25 @@ void PropertyEditor::update_tree() { } } +void PropertyEditor::_draw_transparency(Object *t, const Rect2& p_rect) { + + TreeItem *ti=t->cast_to<TreeItem>(); + if (!ti) + return; + + Color color=obj->get(ti->get_metadata(1)); + Ref<Texture> arrow=tree->get_icon("select_arrow"); + + // make a little space between consecutive color fields + Rect2 area=p_rect; + area.pos.y+=1; + area.size.height-=2; + area.size.width-=arrow->get_size().width+5; + tree->draw_texture_rect(get_icon("Transparent", "EditorIcons"), area, true); + tree->draw_rect(area, color); + +} + void PropertyEditor::_item_selected() { @@ -3866,7 +3890,7 @@ void PropertyEditor::_item_selected() { } -void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value) { +void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value, bool p_refresh_all) { if (autoclear) { TreeItem *item = tree->get_selected(); @@ -3879,7 +3903,11 @@ void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value) { if (!undo_redo || obj->cast_to<MultiNodeEdit>() || obj->cast_to<ArrayPropertyEdit>()) { //kind of hacky obj->set(p_name,p_value); - _changed_callbacks(obj,p_name); + if (p_refresh_all) + _changed_callbacks(obj,""); + else + _changed_callbacks(obj,p_name); + emit_signal(_prop_edited,p_name); @@ -3889,9 +3917,14 @@ void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value) { undo_redo->add_do_property(obj,p_name,p_value); undo_redo->add_undo_property(obj,p_name,obj->get(p_name)); + if (p_refresh_all) { + undo_redo->add_do_method(this,"_changed_callback",obj,""); + undo_redo->add_undo_method(this,"_changed_callback",obj,""); + } else { - undo_redo->add_do_method(this,"_changed_callback",obj,p_name); - undo_redo->add_undo_method(this,"_changed_callback",obj,p_name); + undo_redo->add_do_method(this,"_changed_callback",obj,p_name); + undo_redo->add_undo_method(this,"_changed_callback",obj,p_name); + } Resource *r = obj->cast_to<Resource>(); if (r) { @@ -3953,6 +3986,9 @@ void PropertyEditor::_item_edited() { int type=d["type"]; int hint= d["hint"]; + int usage = d["usage"]; + bool refresh_all = usage&PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED; + String hint_text=d["hint_text"]; switch(type) { @@ -3961,7 +3997,7 @@ void PropertyEditor::_item_edited() { } break; case Variant::BOOL: { - _edit_set(name,item->is_checked(1)); + _edit_set(name,item->is_checked(1),refresh_all); item->set_tooltip(1, item->is_checked(1) ? "True" : "False"); } break; case Variant::INT: @@ -3975,9 +4011,9 @@ void PropertyEditor::_item_edited() { break; if (type==Variant::INT) - _edit_set(name,int(item->get_range(1))); + _edit_set(name,int(item->get_range(1)),refresh_all); else - _edit_set(name,item->get_range(1)); + _edit_set(name,item->get_range(1),refresh_all); } break; case Variant::STRING: { @@ -3992,9 +4028,9 @@ void PropertyEditor::_item_edited() { txt=strings[idx]; } - _edit_set(name,txt); + _edit_set(name,txt,refresh_all); } else { - _edit_set(name,item->get_text(1)); + _edit_set(name,item->get_text(1),refresh_all); } } break; // math types @@ -4025,7 +4061,7 @@ void PropertyEditor::_item_edited() { } break; case Variant::NODE_PATH: { - _edit_set(name, NodePath(item->get_text(1))); + _edit_set(name, NodePath(item->get_text(1)),refresh_all); } break; @@ -4365,6 +4401,7 @@ void PropertyEditor::_bind_methods() { ClassDB::bind_method( "update_tree",&PropertyEditor::update_tree); ClassDB::bind_method( "_resource_preview_done",&PropertyEditor::_resource_preview_done); ClassDB::bind_method( "refresh",&PropertyEditor::refresh); + ClassDB::bind_method( "_draw_transparency",&PropertyEditor::_draw_transparency); ClassDB::bind_method(_MD("get_drag_data_fw"), &PropertyEditor::get_drag_data_fw); ClassDB::bind_method(_MD("can_drop_data_fw"), &PropertyEditor::can_drop_data_fw); @@ -4455,6 +4492,8 @@ PropertyEditor::PropertyEditor() { _prop_edited="property_edited"; + hide_script=false; + undo_redo=NULL; obj=NULL; search_box=NULL; @@ -4660,7 +4699,7 @@ void SectionedPropertyEditor::_section_selected() { void SectionedPropertyEditor::set_current_section(const String& p_section) { if (section_map.has(p_section)) { - section_map[p_section]->select(0);; + section_map[p_section]->select(0); } } diff --git a/tools/editor/property_editor.h b/tools/editor/property_editor.h index 900d06497f..969340d5a2 100644 --- a/tools/editor/property_editor.h +++ b/tools/editor/property_editor.h @@ -192,6 +192,7 @@ class PropertyEditor : public Control { bool use_doc_hints; bool use_filter; bool subsection_selectable; + bool hide_script; HashMap<String,String> pending; String selected_property; @@ -224,7 +225,7 @@ class PropertyEditor : public Control { void _node_removed(Node *p_node); friend class ProjectExportDialog; - void _edit_set(const String& p_name, const Variant& p_value); + void _edit_set(const String& p_name, const Variant& p_value,bool p_refresh_all=false); void _draw_flags(Object *ti,const Rect2& p_rect); bool _might_be_in_instance(); @@ -245,6 +246,7 @@ friend class ProjectExportDialog; void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from); void _resource_preview_done(const String& p_path,const Ref<Texture>& p_preview,Variant p_ud); + void _draw_transparency(Object *t, const Rect2& p_rect); UndoRedo *undo_redo; protected: @@ -275,6 +277,7 @@ public: void set_show_categories(bool p_show); void set_use_doc_hints(bool p_enable) { use_doc_hints=p_enable; } + void set_hide_script(bool p_hide) { hide_script=p_hide; } void set_use_filter(bool p_use); void register_text_enter(Node *p_line_edit); diff --git a/tools/editor/property_selector.cpp b/tools/editor/property_selector.cpp index 3d9695ac2a..3eeec1634d 100644 --- a/tools/editor/property_selector.cpp +++ b/tools/editor/property_selector.cpp @@ -1,6 +1,34 @@ +/*************************************************************************/ +/* property_selector.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #include "property_selector.h" -#include "editor_scale.h" +#include "editor_scale.h" #include "os/keyboard.h" void PropertySelector::_text_changed(const String& p_newtext) { diff --git a/tools/editor/property_selector.h b/tools/editor/property_selector.h index 4823d50e0f..d29183f85e 100644 --- a/tools/editor/property_selector.h +++ b/tools/editor/property_selector.h @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* property_selector.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ #ifndef PROPERTYSELECTOR_H #define PROPERTYSELECTOR_H diff --git a/tools/editor/pvrtc_compress.cpp b/tools/editor/pvrtc_compress.cpp index 7f84d8d00e..b130f6c773 100644 --- a/tools/editor/pvrtc_compress.cpp +++ b/tools/editor/pvrtc_compress.cpp @@ -27,12 +27,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "pvrtc_compress.h" + #include "editor_settings.h" #include "scene/resources/texture.h" #include "io/resource_saver.h" #include "io/resource_loader.h" #include "os/os.h" #include "os/file_access.h" + static void (*_base_image_compress_pvrtc2_func)(Image *)=NULL; static void (*_base_image_compress_pvrtc4_func)(Image *)=NULL; diff --git a/tools/editor/quick_open.cpp b/tools/editor/quick_open.cpp index ff5ecdf01b..615b42b411 100644 --- a/tools/editor/quick_open.cpp +++ b/tools/editor/quick_open.cpp @@ -27,8 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "quick_open.h" -#include "os/keyboard.h" +#include "os/keyboard.h" void EditorQuickOpen::popup(const StringName &p_base, bool p_enable_multi, bool p_add_dirs, bool p_dontclear) { diff --git a/tools/editor/reparent_dialog.cpp b/tools/editor/reparent_dialog.cpp index 4b6a032b64..c5b74d9006 100644 --- a/tools/editor/reparent_dialog.cpp +++ b/tools/editor/reparent_dialog.cpp @@ -30,8 +30,6 @@ #include "scene/gui/label.h" #include "scene/gui/box_container.h" - - #include "print_string.h" void ReparentDialog::_notification(int p_what) { @@ -107,7 +105,7 @@ ReparentDialog::ReparentDialog() { vbc->add_child(keep_transform); - //vbc->add_margin_child("Options:",node_only);; + //vbc->add_margin_child("Options:",node_only); //cancel->connect("pressed", this,"_cancel"); diff --git a/tools/editor/resources_dock.cpp b/tools/editor/resources_dock.cpp index ddd4a782e4..e89262db25 100644 --- a/tools/editor/resources_dock.cpp +++ b/tools/editor/resources_dock.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "resources_dock.h" + #include "editor_node.h" #include "io/resource_loader.h" #include "io/resource_saver.h" @@ -122,7 +123,7 @@ void ResourcesDock::_notification(int p_what) { void ResourcesDock::save_resource(const String& p_path,const Ref<Resource>& p_resource) { - editor->get_editor_data().apply_changes_in_editors();; + editor->get_editor_data().apply_changes_in_editors(); int flg=0; if (EditorSettings::get_singleton()->get("on_save/compress_binary_resources")) flg|=ResourceSaver::FLAG_COMPRESS; diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 6a1d1ed3b2..f3e5fd85de 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "scene_tree_dock.h" + #include "editor_node.h" #include "globals.h" #include "os/keyboard.h" @@ -104,6 +105,9 @@ void SceneTreeDock::_unhandled_key_input(InputEvent p_event) { else if (ED_IS_SHORTCUT("scene_tree/delete_no_confirm", p_event)) { _tool_selected(TOOL_ERASE, true); } + else if(ED_IS_SHORTCUT("scene_tree/copy_node_path", p_event)) { + _tool_selected(TOOL_COPY_NODE_PATH); + } else if (ED_IS_SHORTCUT("scene_tree/delete", p_event)) { _tool_selected(TOOL_ERASE); } @@ -399,6 +403,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if(existing.is_valid()) { const RefPtr empty; selected->set_script(empty); + button_create_script->show(); + button_clear_script->hide(); } } break; @@ -645,6 +651,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *tocopy = selection.front()->get(); + if (tocopy==scene){ + accept->get_ok()->set_text(TTR("I see..")); + accept->set_text(TTR("Can not perform with the root node.")); + accept->popup_centered_minsize(); + break; + } + if (tocopy!=editor_data->get_edited_scene_root() && tocopy->get_filename()!="") { accept->get_ok()->set_text(TTR("I see..")); accept->set_text(TTR("This operation can't be done on instanced scenes.")); @@ -673,7 +686,17 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { new_scene_from_dialog->set_title(TTR("Save New Scene As..")); } break; + case TOOL_COPY_NODE_PATH: { + List<Node*> selection = editor_selection->get_selected_node_list(); + if(List<Node*>::Element *e = selection.front()) { + if(Node *node = e->get()) { + Node *root = EditorNode::get_singleton()->get_edited_scene(); + NodePath path = root->get_path().rel_path_to(node->get_path()); + OS::get_singleton()->set_clipboard(path); + } + } + } break; } } @@ -697,7 +720,7 @@ void SceneTreeDock::_notification(int p_what) { button_add->set_icon(get_icon("Add","EditorIcons")); button_instance->set_icon(get_icon("Instance","EditorIcons")); button_create_script->set_icon(get_icon("ScriptCreate","EditorIcons")); - button_clear_script->set_icon(get_icon("Remove", "EditorIcons")); + button_clear_script->set_icon(get_icon("ScriptRemove", "EditorIcons")); filter_icon->set_texture(get_icon("Zoom","EditorIcons")); @@ -754,6 +777,7 @@ Node *SceneTreeDock::_duplicate(Node *p_node, Map<Node*,Node*> &duplimap) { ERR_FAIL_COND_V(!sd.is_valid(),NULL); node = sd->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); ERR_FAIL_COND_V(!node,NULL); + node->set_scene_instance_load_placeholder(p_node->get_scene_instance_load_placeholder()); //node->generate_instance_state(); } else { Object *obj = ClassDB::instance(p_node->get_class()); @@ -1230,6 +1254,8 @@ void SceneTreeDock::_script_created(Ref<Script> p_script) { return; selected->set_script(p_script.get_ref_ptr()); editor->push_item(p_script.operator->()); + button_create_script->hide(); + button_clear_script->show(); } @@ -1746,7 +1772,9 @@ void SceneTreeDock::_nodes_dragged(Array p_nodes,NodePath p_to,int p_type) { for(int i=0;i<p_nodes.size();i++) { Node *n=get_node((p_nodes[i])); - nodes.push_back(n); + if (n) { + nodes.push_back(n); + } } if (nodes.size()==0) @@ -1794,7 +1822,7 @@ void SceneTreeDock::_tree_rmb(const Vector2& p_menu_pos) { //menu->add_icon_item(get_icon("Connect","EditorIcons"),TTR("Edit Connections"),TOOL_CONNECT); menu->add_separator(); menu->add_icon_shortcut(get_icon("ScriptCreate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/attach_script"), TOOL_ATTACH_SCRIPT); - menu->add_icon_shortcut(get_icon("Remove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT); + menu->add_icon_shortcut(get_icon("ScriptRemove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT); menu->add_separator(); } @@ -1806,12 +1834,12 @@ void SceneTreeDock::_tree_rmb(const Vector2& p_menu_pos) { if (selection.size()==1) { menu->add_separator(); menu->add_icon_shortcut(get_icon("Blend","EditorIcons"),ED_GET_SHORTCUT("scene_tree/merge_from_scene"), TOOL_MERGE_FROM_SCENE); - menu->add_icon_shortcut(get_icon("Save","EditorIcons"),ED_GET_SHORTCUT("scene_tree/save_branch_as_scene"), TOOL_NEW_SCENE_FROM); + menu->add_icon_shortcut(get_icon("CreateNewSceneFrom","EditorIcons"),ED_GET_SHORTCUT("scene_tree/save_branch_as_scene"), TOOL_NEW_SCENE_FROM); + menu->add_separator(); + menu->add_icon_shortcut(get_icon("CopyNodePath","EditorIcons"), ED_GET_SHORTCUT("scene_tree/copy_node_path"), TOOL_COPY_NODE_PATH); } menu->add_separator(); - menu->add_icon_shortcut(get_icon("Remove","EditorIcons"), ED_SHORTCUT("scene_tree/delete", TTR("Delete Node(s)"), KEY_DELETE), TOOL_ERASE); - menu->set_size(Size2(1,1)); menu->set_pos(p_menu_pos); menu->popup(); @@ -1913,6 +1941,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec ED_SHORTCUT("scene_tree/reparent", TTR("Reparent")); ED_SHORTCUT("scene_tree/merge_from_scene", TTR("Merge From Scene")); ED_SHORTCUT("scene_tree/save_branch_as_scene", TTR("Save Branch as Scene")); + ED_SHORTCUT("scene_tree/copy_node_path", TTR("Copy Node Path"), KEY_MASK_CMD|KEY_C); ED_SHORTCUT("scene_tree/delete_no_confirm", TTR("Delete (No Confirm)"), KEY_MASK_SHIFT|KEY_DELETE); ED_SHORTCUT("scene_tree/delete", TTR("Delete"), KEY_DELETE); diff --git a/tools/editor/scene_tree_dock.h b/tools/editor/scene_tree_dock.h index 0699da3474..2ee7ba3d06 100644 --- a/tools/editor/scene_tree_dock.h +++ b/tools/editor/scene_tree_dock.h @@ -68,6 +68,7 @@ class SceneTreeDock : public VBoxContainer { TOOL_MERGE_FROM_SCENE, TOOL_MULTI_EDIT, TOOL_ERASE, + TOOL_COPY_NODE_PATH, TOOL_BUTTON_MAX }; diff --git a/tools/editor/scene_tree_editor.cpp b/tools/editor/scene_tree_editor.cpp index 7b6a03e20e..dd1fdeb400 100644 --- a/tools/editor/scene_tree_editor.cpp +++ b/tools/editor/scene_tree_editor.cpp @@ -27,13 +27,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "scene_tree_editor.h" + #include "scene/gui/label.h" #include "editor_node.h" #include "print_string.h" #include "message_queue.h" #include "scene/main/viewport.h" #include "tools/editor/plugins/canvas_item_editor_plugin.h" - #include "scene/resources/packed_scene.h" Node *SceneTreeEditor::get_scene_node() { @@ -208,14 +208,15 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item,int p_column,int p_id) if (n->is_class("Spatial")) { - bool v = !bool(n->call("is_hidden")); + bool v = bool(n->call("is_visible")); undo_redo->create_action(TTR("Toggle Spatial Visible")); - undo_redo->add_do_method(n,"_set_visible_",!v); - undo_redo->add_undo_method(n,"_set_visible_",v); + undo_redo->add_do_method(n,"set_visible",!v); + undo_redo->add_undo_method(n,"set_visible",v); undo_redo->commit_action(); + } else if (n->is_class("CanvasItem")) { - bool v = !bool(n->call("is_hidden")); + bool v = bool(n->call("is_visible")); undo_redo->create_action(TTR("Toggle CanvasItem Visible")); undo_redo->add_do_method(n,v?"hide":"show"); undo_redo->add_undo_method(n,v?"show":"hide"); @@ -393,11 +394,11 @@ bool SceneTreeEditor::_add_nodes(Node *p_node,TreeItem *p_parent) { if (is_grouped) item->add_button(0,get_icon("Group", "EditorIcons"), BUTTON_GROUP); - bool h = p_node->call("is_hidden"); - if (h) - item->add_button(0,get_icon("Hidden","EditorIcons"),BUTTON_VISIBILITY); - else + bool v = p_node->call("is_visible"); + if (v) item->add_button(0,get_icon("Visible","EditorIcons"),BUTTON_VISIBILITY); + else + item->add_button(0,get_icon("Hidden","EditorIcons"),BUTTON_VISIBILITY); if (!p_node->is_connected("visibility_changed",this,"_node_visibility_changed")) p_node->connect("visibility_changed",this,"_node_visibility_changed",varray(p_node)); @@ -405,11 +406,11 @@ bool SceneTreeEditor::_add_nodes(Node *p_node,TreeItem *p_parent) { _update_visibility_color(p_node, item); } else if (p_node->is_class("Spatial")) { - bool h = p_node->call("is_hidden"); - if (h) - item->add_button(0,get_icon("Hidden","EditorIcons"),BUTTON_VISIBILITY); - else + bool v = p_node->call("is_visible"); + if (v) item->add_button(0,get_icon("Visible","EditorIcons"),BUTTON_VISIBILITY); + else + item->add_button(0,get_icon("Hidden","EditorIcons"),BUTTON_VISIBILITY); if (!p_node->is_connected("visibility_changed",this,"_node_visibility_changed")) p_node->connect("visibility_changed",this,"_node_visibility_changed",varray(p_node)); @@ -470,15 +471,16 @@ void SceneTreeEditor::_node_visibility_changed(Node *p_node) { bool visible=false; if (p_node->is_class("CanvasItem")) { - visible = !p_node->call("is_hidden"); + visible = p_node->call("is_visible"); + CanvasItemEditor::get_singleton()->get_viewport_control()->update(); } else if (p_node->is_class("Spatial")) { - visible = !p_node->call("is_hidden"); + visible = p_node->call("is_visible"); } - if (!visible) - item->set_button(0,idx,get_icon("Hidden","EditorIcons")); - else + if (visible) item->set_button(0,idx,get_icon("Visible","EditorIcons")); + else + item->set_button(0,idx,get_icon("Hidden","EditorIcons")); _update_visibility_color(p_node, item); } diff --git a/tools/editor/script_create_dialog.cpp b/tools/editor/script_create_dialog.cpp index 2a76224e33..496d8670eb 100644 --- a/tools/editor/script_create_dialog.cpp +++ b/tools/editor/script_create_dialog.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "script_create_dialog.h" + #include "script_language.h" #include "globals.h" #include "io/resource_saver.h" @@ -127,7 +128,7 @@ void ScriptCreateDialog::_create_new() { Ref<Script> scr = ScriptServer::get_language( language_menu->get_selected() )->get_template(cname,parent_name->get_text()); String selected_language = language_menu->get_item_text(language_menu->get_selected()); - editor_settings->set_last_selected_language(selected_language); + editor_settings->set_project_metadata("script_setup", "last_selected_language", selected_language); if (cname!="") scr->set_name(cname); @@ -379,7 +380,7 @@ ScriptCreateDialog::ScriptCreateDialog() { } editor_settings = EditorSettings::get_singleton(); - String last_selected_language = editor_settings->get_last_selected_language(); + String last_selected_language = editor_settings->get_project_metadata("script_setup", "last_selected_language", ""); if (last_selected_language != "") for (int i = 0; i < language_menu->get_item_count(); i++) if (language_menu->get_item_text(i) == last_selected_language) diff --git a/tools/editor/script_editor_debugger.cpp b/tools/editor/script_editor_debugger.cpp index e53e69d9e0..d5cca06820 100644 --- a/tools/editor/script_editor_debugger.cpp +++ b/tools/editor/script_editor_debugger.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "script_editor_debugger.h" + #include "scene/gui/separator.h" #include "scene/gui/label.h" #include "scene/gui/split_container.h" @@ -825,7 +826,7 @@ void ScriptEditorDebugger::_performance_draw() { Ref<StyleBox> graph_sb = get_stylebox("normal","TextEdit"); Ref<Font> graph_font = get_font("font","TextEdit"); - int cols = Math::ceil(Math::sqrt(which.size())); + int cols = Math::ceil(Math::sqrt((float)which.size())); int rows = (which.size()+1)/cols; if (which.size()==1) rows=1; @@ -1188,7 +1189,7 @@ void ScriptEditorDebugger::_profiler_seeked() { if (breaked) return; - debug_break();; + debug_break(); } diff --git a/tools/editor/settings_config_dialog.cpp b/tools/editor/settings_config_dialog.cpp index c72f2641b7..31cbcee5ae 100644 --- a/tools/editor/settings_config_dialog.cpp +++ b/tools/editor/settings_config_dialog.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "settings_config_dialog.h" + #include "editor_settings.h" #include "scene/gui/margin_container.h" #include "globals.h" diff --git a/tools/editor/spatial_editor_gizmos.cpp b/tools/editor/spatial_editor_gizmos.cpp index 82dfa94c06..3ed101cdd6 100644 --- a/tools/editor/spatial_editor_gizmos.cpp +++ b/tools/editor/spatial_editor_gizmos.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "spatial_editor_gizmos.h" + #include "geometry.h" #include "scene/3d/camera.h" #include "scene/resources/surface_tool.h" @@ -285,7 +286,8 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi Vector<Vector3> normals; int vtx_idx=0; -#define ADD_VTX(m_idx);\ + +#define ADD_VTX(m_idx) \ vertices.push_back( (face_points[m_idx]*HANDLE_HALF_SIZE+p_handles[ih]) );\ normals.push_back( normal_points[m_idx] );\ vtx_idx++;\ @@ -837,8 +839,8 @@ void LightSpatialGizmo::redraw() { for(int i=0;i<=360;i++) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+1); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+1); Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*r; Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*r; @@ -879,8 +881,8 @@ void LightSpatialGizmo::redraw() { for(int i=0;i<360;i++) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+1); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+1); Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*w; Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*w; @@ -953,28 +955,6 @@ LightSpatialGizmo::LightSpatialGizmo(Light* p_light){ set_spatial_node(p_light); } -////// - -void ListenerSpatialGizmo::redraw() { - - clear(); - - add_unscaled_billboard(SpatialEditorGizmos::singleton->listener_icon, 0.05); - - add_mesh(SpatialEditorGizmos::singleton->listener_line_mesh); - Vector<Vector3> cursor_points; - cursor_points.push_back(Vector3(0, 0, 0)); - cursor_points.push_back(Vector3(0, 0, -1.0)); - add_collision_segments(cursor_points); - -} - -ListenerSpatialGizmo::ListenerSpatialGizmo(Listener* p_listener){ - - set_spatial_node(p_listener); - listener = p_listener; -} - ////// @@ -1391,32 +1371,6 @@ SkeletonSpatialGizmo::SkeletonSpatialGizmo(Skeleton* p_skel) { set_spatial_node(p_skel); } -///// - - -void SpatialPlayerSpatialGizmo::redraw() { - - clear(); - if (splayer->cast_to<SpatialStreamPlayer>()) { - - add_unscaled_billboard(SpatialEditorGizmos::singleton->stream_player_icon,0.05); - - } else if (splayer->cast_to<SpatialSamplePlayer>()) { - - add_unscaled_billboard(SpatialEditorGizmos::singleton->sample_player_icon,0.05); - - } - -} - -SpatialPlayerSpatialGizmo::SpatialPlayerSpatialGizmo(SpatialPlayer* p_splayer){ - - set_spatial_node(p_splayer); - splayer=p_splayer; -} - - -///// void RoomSpatialGizmo::redraw() { @@ -1565,8 +1519,8 @@ void VehicleWheelSpatialGizmo::redraw() { const int skip=10; for(int i=0;i<=360;i+=skip) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+skip); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+skip); Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*r; Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*r; @@ -1872,8 +1826,8 @@ void CollisionShapeSpatialGizmo::redraw(){ for(int i=0;i<=360;i++) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+1); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+1); Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*r; Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*r; @@ -1953,8 +1907,8 @@ void CollisionShapeSpatialGizmo::redraw(){ Vector3 d(0,0,height*0.5); for(int i=0;i<360;i++) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+1); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+1); Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*radius; Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*radius; @@ -2168,7 +2122,7 @@ void VisibilityNotifierGizmo::set_handle(int p_idx,Camera *p_camera, const Point Vector3 ray_dir = p_camera->project_ray_normal(p_point); Vector3 sg[2]={gi.xform(ray_from),gi.xform(ray_from+ray_dir*4096)}; - Vector3 ofs = aabb.pos+aabb.size*0.5;; + Vector3 ofs = aabb.pos+aabb.size*0.5; Vector3 axis; axis[p_idx]=1.0; @@ -2530,7 +2484,7 @@ void GIProbeGizmo::redraw(){ } - add_lines(lines,SpatialEditorGizmos::singleton->reflection_probe_material_internal); + add_lines(lines,SpatialEditorGizmos::singleton->gi_probe_material_internal); Vector<Vector3> handles; @@ -2890,8 +2844,8 @@ void ConeTwistJointSpatialGizmo::redraw() { //swing for(int i=0;i<360;i+=10) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+10); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+10); Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*w; Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*w; @@ -2922,8 +2876,8 @@ void ConeTwistJointSpatialGizmo::redraw() { for(int i=0;i<int(ts);i+=5) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+5); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+5); float c = i/720.0; float cn = (i+5)/720.0; Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*w*c; @@ -3165,11 +3119,7 @@ Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) { return lsg; } - if (p_spatial->cast_to<Listener>()) { - Ref<ListenerSpatialGizmo> misg = memnew(ListenerSpatialGizmo(p_spatial->cast_to<Listener>())); - return misg; - } if (p_spatial->cast_to<Camera>()) { @@ -3227,12 +3177,6 @@ Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) { return misg; } - if (p_spatial->cast_to<SpatialPlayer>()) { - - Ref<SpatialPlayerSpatialGizmo> misg = memnew( SpatialPlayerSpatialGizmo(p_spatial->cast_to<SpatialPlayer>()) ); - return misg; - } - if (p_spatial->cast_to<CollisionShape>()) { Ref<CollisionShapeSpatialGizmo> misg = memnew( CollisionShapeSpatialGizmo(p_spatial->cast_to<CollisionShape>()) ); @@ -3462,7 +3406,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() { reflection_probe_material = create_line_material(Color(0.5,1.0,0.7)); reflection_probe_material_internal = create_line_material(Color(0.3,0.8,0.5,0.15)); gi_probe_material = create_line_material(Color(0.7,1.0,0.5)); - gi_probe_material_internal = create_line_material(Color(0.5,0.8,0.3,0.4)); + gi_probe_material_internal = create_line_material(Color(0.5,0.8,0.3,0.1)); joint_material = create_line_material(Color(0.6,0.8,1.0)); stream_player_icon = Ref<FixedSpatialMaterial>( memnew( FixedSpatialMaterial )); @@ -3494,7 +3438,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() { PoolVector<Vector3> vertices; #undef ADD_VTX -#define ADD_VTX(m_idx);\ +#define ADD_VTX(m_idx) \ vertices.push_back( face_points[m_idx] ); for (int i=0;i<6;i++) { diff --git a/tools/editor/spatial_editor_gizmos.h b/tools/editor/spatial_editor_gizmos.h index 8fde52b05a..8a63d4f81e 100644 --- a/tools/editor/spatial_editor_gizmos.h +++ b/tools/editor/spatial_editor_gizmos.h @@ -35,8 +35,6 @@ #include "scene/3d/listener.h" #include "scene/3d/camera.h" #include "scene/3d/position_3d.h" -#include "scene/3d/spatial_sample_player.h" -#include "scene/3d/spatial_stream_player.h" #include "scene/3d/test_cube.h" #include "scene/3d/mesh_instance.h" #include "scene/3d/body_shape.h" @@ -146,19 +144,6 @@ public: }; -class ListenerSpatialGizmo : public EditorSpatialGizmo { - - GDCLASS(ListenerSpatialGizmo, EditorSpatialGizmo); - - Listener* listener; - -public: - - void redraw(); - ListenerSpatialGizmo(Listener* p_listener = NULL); - -}; - class CameraSpatialGizmo : public EditorSpatialGizmo { GDCLASS(CameraSpatialGizmo,EditorSpatialGizmo); @@ -220,23 +205,6 @@ public: }; - - -class SpatialPlayerSpatialGizmo : public EditorSpatialGizmo { - - GDCLASS(SpatialPlayerSpatialGizmo,EditorSpatialGizmo); - - SpatialPlayer* splayer; - -public: - - void redraw(); - SpatialPlayerSpatialGizmo(SpatialPlayer* p_splayer=NULL); - -}; - - - class TestCubeSpatialGizmo : public EditorSpatialGizmo { GDCLASS(TestCubeSpatialGizmo,EditorSpatialGizmo); diff --git a/tools/translations/Makefile b/tools/editor/translations/Makefile index bea20e877d..bea20e877d 100644 --- a/tools/translations/Makefile +++ b/tools/editor/translations/Makefile diff --git a/tools/translations/README.md b/tools/editor/translations/README.md index 351bc9e2d1..351bc9e2d1 100644 --- a/tools/translations/README.md +++ b/tools/editor/translations/README.md diff --git a/tools/translations/ar.po b/tools/editor/translations/ar.po index 0bfef1cfe1..539b94ab62 100644 --- a/tools/translations/ar.po +++ b/tools/editor/translations/ar.po @@ -3252,7 +3252,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5844,11 +5844,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5860,7 +5860,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6094,7 +6094,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/bg.po b/tools/editor/translations/bg.po index 9197a6e702..fe711e1b30 100644 --- a/tools/translations/bg.po +++ b/tools/editor/translations/bg.po @@ -3295,7 +3295,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5890,11 +5890,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5906,7 +5906,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6140,7 +6140,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/bn.po b/tools/editor/translations/bn.po index a3a3a072fc..0b1993caa0 100644 --- a/tools/translations/bn.po +++ b/tools/editor/translations/bn.po @@ -3381,8 +3381,8 @@ msgid "Compress" msgstr "সঙ্কোচন করুন" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "প্রকল্পে সংযুক্ত করুন (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "প্রকল্পে সংযুক্ত করুন (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -5989,12 +5989,12 @@ msgid "Invalid project path, the path must exist!" msgstr "অকার্যকর প্রকল্পের পথ, পথটি অবশ্যই বিদ্যমান হতে হবে!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "অকার্যকর প্রকল্পের পথ, engine.cfg অবশ্যই অনুপস্থিত হতে হবে।" +msgid "Invalid project path, godot.cfg must not exist." +msgstr "অকার্যকর প্রকল্পের পথ, godot.cfg অবশ্যই অনুপস্থিত হতে হবে।" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "অকার্যকর প্রকল্পের পথ, engine.cfg অবশ্যই উপস্থিত হতে হবে।" +msgid "Invalid project path, godot.cfg must exist." +msgstr "অকার্যকর প্রকল্পের পথ, godot.cfg অবশ্যই উপস্থিত হতে হবে।" #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -6005,8 +6005,8 @@ msgid "Invalid project path (changed anything?)." msgstr "অকার্যকর প্রকল্পের পথ (কোনোকিছু পরিবর্তন করেছেন?)।" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "প্রকল্পের পথে engine.cfg তৈরি করা সম্ভব হয়নি।" +msgid "Couldn't create godot.cfg in project path." +msgstr "প্রকল্পের পথে godot.cfg তৈরি করা সম্ভব হয়নি।" #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6241,8 +6241,8 @@ msgid "Remove Resource Remap Option" msgstr "রিসোর্সের পুনঃ-নকশার সিদ্ধান্ত অপসারণ করুন" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "প্রকল্পের সেটিংস (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "প্রকল্পের সেটিংস (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/ca.po b/tools/editor/translations/ca.po index 266551ee60..c45cad964b 100644 --- a/tools/translations/ca.po +++ b/tools/editor/translations/ca.po @@ -3406,7 +3406,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -6004,11 +6004,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -6020,7 +6020,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6254,8 +6254,8 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "Configuració del Projecte (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "Configuració del Projecte (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/cs.po b/tools/editor/translations/cs.po index 4020725d74..3dc52fa536 100644 --- a/tools/translations/cs.po +++ b/tools/editor/translations/cs.po @@ -3321,7 +3321,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5918,11 +5918,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5934,7 +5934,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6168,7 +6168,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/da.po b/tools/editor/translations/da.po index e0d4d9bd98..6148d0b82d 100644 --- a/tools/translations/da.po +++ b/tools/editor/translations/da.po @@ -3323,7 +3323,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5918,11 +5918,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5934,7 +5934,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6168,7 +6168,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/de.po b/tools/editor/translations/de.po index 68ce048b5b..0545ea2f21 100644 --- a/tools/translations/de.po +++ b/tools/editor/translations/de.po @@ -3419,8 +3419,8 @@ msgid "Compress" msgstr "Komprimieren" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "Zu Projekt hinzufügen (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "Zu Projekt hinzufügen (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -6036,12 +6036,12 @@ msgid "Invalid project path, the path must exist!" msgstr "Ungültiger Projektpfad, der Pfad muss existieren!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "Ungültiger Projektpfad, engine.cfg darf nicht existieren." +msgid "Invalid project path, godot.cfg must not exist." +msgstr "Ungültiger Projektpfad, godot.cfg darf nicht existieren." #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "Ungültiger Projektpfad, engine.cfg muss existieren." +msgid "Invalid project path, godot.cfg must exist." +msgstr "Ungültiger Projektpfad, godot.cfg muss existieren." #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -6052,8 +6052,8 @@ msgid "Invalid project path (changed anything?)." msgstr "Ungültiger Projektpfad (etwas geändert?)." #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "Konnte engine.cfg in Projektpfad nicht erzeugen." +msgid "Couldn't create godot.cfg in project path." +msgstr "Konnte godot.cfg in Projektpfad nicht erzeugen." #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6288,8 +6288,8 @@ msgid "Remove Resource Remap Option" msgstr "Ressourcen-Remap-Option entfernen" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "Projekteinstellungen (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "Projekteinstellungen (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/de_CH.po b/tools/editor/translations/de_CH.po index e6e0efdb23..0420d3fc97 100644 --- a/tools/translations/de_CH.po +++ b/tools/editor/translations/de_CH.po @@ -3295,8 +3295,8 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "Zum Projekt hinzufügen (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "Zum Projekt hinzufügen (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -5900,12 +5900,12 @@ msgid "Invalid project path, the path must exist!" msgstr "Ungültiger Projektpfad, Pfad existiert nicht!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "Ungültiger Projektpfad, engine.cfg vorhanden!" +msgid "Invalid project path, godot.cfg must not exist." +msgstr "Ungültiger Projektpfad, godot.cfg vorhanden!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "Ungültiger Projektpfad, engine.cfg nicht vorhanden!" +msgid "Invalid project path, godot.cfg must exist." +msgstr "Ungültiger Projektpfad, godot.cfg nicht vorhanden!" #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -5916,8 +5916,8 @@ msgid "Invalid project path (changed anything?)." msgstr "Ungültiger Projektpfad, (wurde was geändert?)!" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "Die engine.cfg kann im Projektverzeichnis nicht erstellt werden." +msgid "Couldn't create godot.cfg in project path." +msgstr "Die godot.cfg kann im Projektverzeichnis nicht erstellt werden." #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6150,7 +6150,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/es.po b/tools/editor/translations/es.po index cec4730148..a1108822fa 100644 --- a/tools/translations/es.po +++ b/tools/editor/translations/es.po @@ -3449,8 +3449,8 @@ msgid "Compress" msgstr "Comprimir" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "Añadir al proyecto (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "Añadir al proyecto (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -6084,12 +6084,12 @@ msgid "Invalid project path, the path must exist!" msgstr "¡La ruta del proyecto no es correcta, tiene que existir!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "La ruta del proyecto no es correcta, engine.cfg no debe existir." +msgid "Invalid project path, godot.cfg must not exist." +msgstr "La ruta del proyecto no es correcta, godot.cfg no debe existir." #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "¡La ruta del proyecto no es correcta, engine.cfg debe existir." +msgid "Invalid project path, godot.cfg must exist." +msgstr "¡La ruta del proyecto no es correcta, godot.cfg debe existir." #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -6100,8 +6100,8 @@ msgid "Invalid project path (changed anything?)." msgstr "La ruta del proyecto no es correcta (¿has cambiado algo?)." #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "No se pudo crear engine.cfg en la ruta de proyecto." +msgid "Couldn't create godot.cfg in project path." +msgstr "No se pudo crear godot.cfg en la ruta de proyecto." #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6338,8 +6338,8 @@ msgid "Remove Resource Remap Option" msgstr "Quitar opción de remapeo de recursos" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "Ajustes de proyecto (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "Ajustes de proyecto (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/es_AR.po b/tools/editor/translations/es_AR.po index 08376f39c5..d921254859 100644 --- a/tools/translations/es_AR.po +++ b/tools/editor/translations/es_AR.po @@ -3403,8 +3403,8 @@ msgid "Compress" msgstr "Comprimir" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "Agregar al Proyecto (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "Agregar al Proyecto (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -6019,12 +6019,12 @@ msgid "Invalid project path, the path must exist!" msgstr "Ruta de proyecto inválida, la ruta debe existir!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "Ruta de proyecto inválida, engine.cfg no debe existir." +msgid "Invalid project path, godot.cfg must not exist." +msgstr "Ruta de proyecto inválida, godot.cfg no debe existir." #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "Ruta de proyecto inválida, engine.cfg debe existir." +msgid "Invalid project path, godot.cfg must exist." +msgstr "Ruta de proyecto inválida, godot.cfg debe existir." #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -6035,8 +6035,8 @@ msgid "Invalid project path (changed anything?)." msgstr "Ruta de proyecto inválida (cambiaste algo?)." #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "No se pudo crear engine.cfg en la ruta de proyecto." +msgid "Couldn't create godot.cfg in project path." +msgstr "No se pudo crear godot.cfg en la ruta de proyecto." #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6273,8 +6273,8 @@ msgid "Remove Resource Remap Option" msgstr "Remover Opción de Remapeo de Recursos" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "Ajustes de Proyecto (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "Ajustes de Proyecto (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/extract.py b/tools/editor/translations/extract.py index 1192c19011..1192c19011 100755 --- a/tools/translations/extract.py +++ b/tools/editor/translations/extract.py diff --git a/tools/translations/fa.po b/tools/editor/translations/fa.po index 8e29cda45f..41a686ba52 100644 --- a/tools/translations/fa.po +++ b/tools/editor/translations/fa.po @@ -3350,7 +3350,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5948,11 +5948,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5964,7 +5964,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6200,7 +6200,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/fr.po b/tools/editor/translations/fr.po index 10f82e2840..2c4f7144fe 100644 --- a/tools/translations/fr.po +++ b/tools/editor/translations/fr.po @@ -3437,8 +3437,8 @@ msgid "Compress" msgstr "Compresser" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "Ajouter au projet (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "Ajouter au projet (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -6072,12 +6072,12 @@ msgid "Invalid project path, the path must exist!" msgstr "Chemin de projet invalide, le chemin doit exister !" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "Chemin de projet invalide, engine.cfg ne doit pas exister." +msgid "Invalid project path, godot.cfg must not exist." +msgstr "Chemin de projet invalide, godot.cfg ne doit pas exister." #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "Chemin de projet invalide, engine.cfg doit exister." +msgid "Invalid project path, godot.cfg must exist." +msgstr "Chemin de projet invalide, godot.cfg doit exister." #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -6088,9 +6088,9 @@ msgid "Invalid project path (changed anything?)." msgstr "Chemin de projet non valide (avez-vous changé quelque chose ?)." #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" -"Impossible de créer le fichier engine.cfg dans le répertoire du projet." +"Impossible de créer le fichier godot.cfg dans le répertoire du projet." #: tools/editor/project_manager.cpp #, fuzzy @@ -6332,8 +6332,8 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "Paramètres du projet (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "Paramètres du projet (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/hu.po b/tools/editor/translations/hu.po index ef78f27138..335ab25c6a 100644 --- a/tools/translations/hu.po +++ b/tools/editor/translations/hu.po @@ -3245,7 +3245,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5836,11 +5836,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5852,7 +5852,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6086,7 +6086,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/id.po b/tools/editor/translations/id.po index 917bd21e82..30bd357a21 100644 --- a/tools/translations/id.po +++ b/tools/editor/translations/id.po @@ -3410,7 +3410,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -6006,11 +6006,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -6022,7 +6022,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6256,7 +6256,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/it.po b/tools/editor/translations/it.po index f49c953a7d..8fefe67677 100644 --- a/tools/translations/it.po +++ b/tools/editor/translations/it.po @@ -3416,8 +3416,8 @@ msgid "Compress" msgstr "Comprimi" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "Aggiungi a Progetto (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "Aggiungi a Progetto (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -6031,12 +6031,12 @@ msgid "Invalid project path, the path must exist!" msgstr "Percorso di progetto invalido, il percorso deve esistere!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "Percorso di progetto invalido, engine.cfg non deve esistere." +msgid "Invalid project path, godot.cfg must not exist." +msgstr "Percorso di progetto invalido, godot.cfg non deve esistere." #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "Percorso di progetto invalido, engine.cfg deve esistere." +msgid "Invalid project path, godot.cfg must exist." +msgstr "Percorso di progetto invalido, godot.cfg deve esistere." #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -6047,8 +6047,8 @@ msgid "Invalid project path (changed anything?)." msgstr "Percorso di progetto invalido (cambiato qualcosa?)." #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "Impossibile creare engine.cfg nel percorso di progetto." +msgid "Couldn't create godot.cfg in project path." +msgstr "Impossibile creare godot.cfg nel percorso di progetto." #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6283,8 +6283,8 @@ msgid "Remove Resource Remap Option" msgstr "Rimuovi Opzione di Remap Rimorse" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "Impostazioni Progetto (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "Impostazioni Progetto (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/ja.po b/tools/editor/translations/ja.po index 279f59c9c8..ea314db101 100644 --- a/tools/translations/ja.po +++ b/tools/editor/translations/ja.po @@ -3347,7 +3347,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5945,11 +5945,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5961,7 +5961,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6195,7 +6195,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/ko.po b/tools/editor/translations/ko.po index ea2b130d37..a0ecb70bf5 100644 --- a/tools/translations/ko.po +++ b/tools/editor/translations/ko.po @@ -3350,8 +3350,8 @@ msgid "Compress" msgstr "압축" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "프로젝트에 추가 (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "프로젝트에 추가 (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -5954,12 +5954,12 @@ msgid "Invalid project path, the path must exist!" msgstr "프로젝트 경로가 유효하지 않습니다. 경로가 반드시 존재해야 합니다!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "프로젝트 경로가 유효하지 않습니다. engine.cfg가 있으면 안됩니다." +msgid "Invalid project path, godot.cfg must not exist." +msgstr "프로젝트 경로가 유효하지 않습니다. godot.cfg가 있으면 안됩니다." #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "프로젝트 경로가 유효하지 않습니다. engine.cfg가 존재해야합니다." +msgid "Invalid project path, godot.cfg must exist." +msgstr "프로젝트 경로가 유효하지 않습니다. godot.cfg가 존재해야합니다." #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -5970,8 +5970,8 @@ msgid "Invalid project path (changed anything?)." msgstr "유효하지 않은 프로젝트 경로 (뭔가 변경하신 거라도?)." #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "프로젝트 경로에 engine.cfg를 생성할 수 없습니다." +msgid "Couldn't create godot.cfg in project path." +msgstr "프로젝트 경로에 godot.cfg를 생성할 수 없습니다." #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6205,8 +6205,8 @@ msgid "Remove Resource Remap Option" msgstr "리소스 리맵핑 옵션 제거" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "프로젝트 설정 (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "프로젝트 설정 (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/nb.po b/tools/editor/translations/nb.po index ff659eae8b..cbd2a09951 100644 --- a/tools/translations/nb.po +++ b/tools/editor/translations/nb.po @@ -3245,7 +3245,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5836,11 +5836,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5852,7 +5852,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6086,7 +6086,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/pl.po b/tools/editor/translations/pl.po index 465fbe133d..50afecad1b 100644 --- a/tools/translations/pl.po +++ b/tools/editor/translations/pl.po @@ -1601,7 +1601,7 @@ msgstr "" #: tools/editor/dependency_editor.cpp msgid "Remove selected files from the project? (no undo)" -msgstr "Usunąć wybrane pliki z projektu? (Nie można tego cofnąć)" +msgstr "Usunąć wybrane pliki z projektu? (Nie można tego cofnąć)" #: tools/editor/dependency_editor.cpp msgid "Error loading:" @@ -3388,8 +3388,8 @@ msgid "Compress" msgstr "Skompresuj" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "Dodaj do projektu (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "Dodaj do projektu (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -5995,12 +5995,12 @@ msgid "Invalid project path, the path must exist!" msgstr "Niepoprawna ścieżka projektu, ścieżka musi istnieć!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "Niepoprawna ścieżka projektu, engine.cfg nie może istnieć." +msgid "Invalid project path, godot.cfg must not exist." +msgstr "Niepoprawna ścieżka projektu, godot.cfg nie może istnieć." #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "Niepoprawna ścieżka projektu, engine.cfg musi istnieć." +msgid "Invalid project path, godot.cfg must exist." +msgstr "Niepoprawna ścieżka projektu, godot.cfg musi istnieć." #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -6011,8 +6011,8 @@ msgid "Invalid project path (changed anything?)." msgstr "Niepoprawna ścieżka projektu (zmienić cokolwiek?)." #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "Nie można było utworzyć engine.cfg w ścieżce projektu." +msgid "Couldn't create godot.cfg in project path." +msgstr "Nie można było utworzyć godot.cfg w ścieżce projektu." #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6245,8 +6245,8 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "Ustawienia projektu (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "Ustawienia projektu (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" @@ -6884,7 +6884,7 @@ msgstr "Skróty" #: tools/editor/spatial_editor_gizmos.cpp msgid "Change Light Radius" -msgstr "Zmień promień światła" +msgstr "Zmień promień światła" #: tools/editor/spatial_editor_gizmos.cpp msgid "Change Camera FOV" @@ -6912,7 +6912,7 @@ msgstr "Zmień wysokośc Capsule Shape" #: tools/editor/spatial_editor_gizmos.cpp msgid "Change Ray Shape Length" -msgstr "Zmień długość Ray Shape" +msgstr "Zmień długość Ray Shape" #: tools/editor/spatial_editor_gizmos.cpp msgid "Change Notifier Extents" diff --git a/tools/translations/pr.po b/tools/editor/translations/pr.po index f8a9505066..8ea2967a22 100644 --- a/tools/translations/pr.po +++ b/tools/editor/translations/pr.po @@ -3263,7 +3263,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5854,11 +5854,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5870,7 +5870,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6104,7 +6104,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/pt_BR.po b/tools/editor/translations/pt_BR.po index 106142b4ea..9ab81786b1 100644 --- a/tools/translations/pt_BR.po +++ b/tools/editor/translations/pt_BR.po @@ -3388,8 +3388,8 @@ msgid "Compress" msgstr "Comprimir" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "Adicionar ao Projeto (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "Adicionar ao Projeto (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -6012,12 +6012,12 @@ msgid "Invalid project path, the path must exist!" msgstr "Caminho de projeto inválido, o caminho deve existir!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "Caminho de projeto inválido, engine.cfg não deve existir." +msgid "Invalid project path, godot.cfg must not exist." +msgstr "Caminho de projeto inválido, godot.cfg não deve existir." #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "Caminho de projeto inválido, engine.cfg deve existir." +msgid "Invalid project path, godot.cfg must exist." +msgstr "Caminho de projeto inválido, godot.cfg deve existir." #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -6028,8 +6028,8 @@ msgid "Invalid project path (changed anything?)." msgstr "Caminho de projeto inválido (mudou alguma coisa?)." #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "Não se pôde criar engine.cfg no caminho do projeto." +msgid "Couldn't create godot.cfg in project path." +msgstr "Não se pôde criar godot.cfg no caminho do projeto." #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6265,8 +6265,8 @@ msgid "Remove Resource Remap Option" msgstr "Remover Opção de Remapeamento de Recurso" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "Configurações do Projeto (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "Configurações do Projeto (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/pt_PT.po b/tools/editor/translations/pt_PT.po index 7b3c814f8c..da9d971347 100644 --- a/tools/translations/pt_PT.po +++ b/tools/editor/translations/pt_PT.po @@ -3258,7 +3258,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5850,11 +5850,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5866,7 +5866,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6100,7 +6100,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/ru.po b/tools/editor/translations/ru.po index 73262dbd5e..0595a675b3 100644 --- a/tools/translations/ru.po +++ b/tools/editor/translations/ru.po @@ -3391,8 +3391,8 @@ msgid "Compress" msgstr "Сжимать" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "Добавить в проект (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "Добавить в проект (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -6004,12 +6004,12 @@ msgid "Invalid project path, the path must exist!" msgstr "Неверный путь к проекту, путь должен существовать!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "Недопустимый путь к проекту, engine.cfg не должен существовать." +msgid "Invalid project path, godot.cfg must not exist." +msgstr "Недопустимый путь к проекту, godot.cfg не должен существовать." #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "Недопустимый путь к проекту, engine.cfg должен существовать." +msgid "Invalid project path, godot.cfg must exist." +msgstr "Недопустимый путь к проекту, godot.cfg должен существовать." #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -6020,8 +6020,8 @@ msgid "Invalid project path (changed anything?)." msgstr "Неверный путь к проекту (Что-то изменили?)." #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "Не могу создать engine.cfg в папке проекта." +msgid "Couldn't create godot.cfg in project path." +msgstr "Не могу создать godot.cfg в папке проекта." #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6256,8 +6256,8 @@ msgid "Remove Resource Remap Option" msgstr "Удалён параметр ресурса перенаправления" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "Настройки проекта (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "Настройки проекта (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/sk.po b/tools/editor/translations/sk.po index f1bd9f1300..6aa2e16664 100644 --- a/tools/translations/sk.po +++ b/tools/editor/translations/sk.po @@ -3261,7 +3261,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5857,11 +5857,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5873,7 +5873,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6107,7 +6107,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/sl.po b/tools/editor/translations/sl.po index 12903cba83..4934be97d7 100644 --- a/tools/translations/sl.po +++ b/tools/editor/translations/sl.po @@ -3270,7 +3270,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5862,11 +5862,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5878,7 +5878,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6112,7 +6112,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/tools.pot b/tools/editor/translations/tools.pot index 447067beb3..8e54d88989 100644 --- a/tools/translations/tools.pot +++ b/tools/editor/translations/tools.pot @@ -3239,7 +3239,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5830,11 +5830,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5846,7 +5846,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6080,7 +6080,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/tr.po b/tools/editor/translations/tr.po index b930e302f2..5c0b6ebca8 100644 --- a/tools/translations/tr.po +++ b/tools/editor/translations/tr.po @@ -3382,8 +3382,8 @@ msgid "Compress" msgstr "Sıkıştır" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "Tasarıya Ekle (engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "Tasarıya Ekle (godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -5994,12 +5994,12 @@ msgid "Invalid project path, the path must exist!" msgstr "Geçersiz tasarı yolu, yolun var olması gerekir!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." -msgstr "Geçersiz tasarı yolu, engine.cfg var olmaması gerekir." +msgid "Invalid project path, godot.cfg must not exist." +msgstr "Geçersiz tasarı yolu, godot.cfg var olmaması gerekir." #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." -msgstr "Geçersiz tasarı yolu, engine.cfg var olması gerekir." +msgid "Invalid project path, godot.cfg must exist." +msgstr "Geçersiz tasarı yolu, godot.cfg var olması gerekir." #: tools/editor/project_manager.cpp msgid "Imported Project" @@ -6010,8 +6010,8 @@ msgid "Invalid project path (changed anything?)." msgstr "Geçersiz tasarı yolu (bir şey değişti mi?)." #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "engine.cfg tasarı yolunda oluşturulamadı." +msgid "Couldn't create godot.cfg in project path." +msgstr "godot.cfg tasarı yolunda oluşturulamadı." #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6247,8 +6247,8 @@ msgid "Remove Resource Remap Option" msgstr "Kaynak Yeniden Eşle Seçeneğini Kaldır" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "Tasarı Ayarları (engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "Tasarı Ayarları (godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/ur_PK.po b/tools/editor/translations/ur_PK.po index 0eed08b52a..b898301d0c 100644 --- a/tools/translations/ur_PK.po +++ b/tools/editor/translations/ur_PK.po @@ -3255,7 +3255,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5850,11 +5850,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5866,7 +5866,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6100,7 +6100,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/zh_CN.po b/tools/editor/translations/zh_CN.po index 58f79fac56..47c77f6170 100644 --- a/tools/translations/zh_CN.po +++ b/tools/editor/translations/zh_CN.po @@ -3312,8 +3312,8 @@ msgid "Compress" msgstr "压缩" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" -msgstr "添加到项目(engine.cfg)" +msgid "Add to Project (godot.cfg)" +msgstr "添加到项目(godot.cfg)" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp msgid "Import Languages:" @@ -5912,11 +5912,11 @@ msgid "Invalid project path, the path must exist!" msgstr "项目目录不存在!" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "项目目录下必须包含engin.cfg文件。" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "项目目录下必须包含engin.cfg文件。" #: tools/editor/project_manager.cpp @@ -5928,8 +5928,8 @@ msgid "Invalid project path (changed anything?)." msgstr "项目路径非法(被外部修改?)。" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." -msgstr "无法在项目目录下创建engine.cfg文件。" +msgid "Couldn't create godot.cfg in project path." +msgstr "无法在项目目录下创建godot.cfg文件。" #: tools/editor/project_manager.cpp msgid "The following files failed extraction from package:" @@ -6162,8 +6162,8 @@ msgid "Remove Resource Remap Option" msgstr "移除资源重定向选项" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" -msgstr "项目设置(engine.cfg)" +msgid "Project Settings (godot.cfg)" +msgstr "项目设置(godot.cfg)" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp msgid "General" diff --git a/tools/translations/zh_HK.po b/tools/editor/translations/zh_HK.po index 60f2b51464..b0bb11d527 100644 --- a/tools/translations/zh_HK.po +++ b/tools/editor/translations/zh_HK.po @@ -3272,7 +3272,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5872,11 +5872,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5888,7 +5888,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6122,7 +6122,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp diff --git a/tools/translations/zh_TW.po b/tools/editor/translations/zh_TW.po index efad7ee167..3e9b61ec0f 100644 --- a/tools/translations/zh_TW.po +++ b/tools/editor/translations/zh_TW.po @@ -3259,7 +3259,7 @@ msgid "Compress" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp -msgid "Add to Project (engine.cfg)" +msgid "Add to Project (godot.cfg)" msgstr "" #: tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -5850,11 +5850,11 @@ msgid "Invalid project path, the path must exist!" msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must not exist." +msgid "Invalid project path, godot.cfg must not exist." msgstr "" #: tools/editor/project_manager.cpp -msgid "Invalid project path, engine.cfg must exist." +msgid "Invalid project path, godot.cfg must exist." msgstr "" #: tools/editor/project_manager.cpp @@ -5866,7 +5866,7 @@ msgid "Invalid project path (changed anything?)." msgstr "" #: tools/editor/project_manager.cpp -msgid "Couldn't create engine.cfg in project path." +msgid "Couldn't create godot.cfg in project path." msgstr "" #: tools/editor/project_manager.cpp @@ -6100,7 +6100,7 @@ msgid "Remove Resource Remap Option" msgstr "" #: tools/editor/project_settings.cpp -msgid "Project Settings (engine.cfg)" +msgid "Project Settings (godot.cfg)" msgstr "" #: tools/editor/project_settings.cpp tools/editor/settings_config_dialog.cpp |