From 5dbf1809c6e3e905b94b8764e99491e608122261 Mon Sep 17 00:00:00 2001 From: Rémi Verschelde Date: Sun, 5 Mar 2017 16:44:50 +0100 Subject: A Whole New World (clang-format edition) I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code --- modules/gdscript/gd_script.cpp | 1069 ++++++++++++++++++---------------------- 1 file changed, 474 insertions(+), 595 deletions(-) (limited to 'modules/gdscript/gd_script.cpp') diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 4e72bc39a..e1cc75acf 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -27,18 +27,18 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "gd_script.h" +#include "gd_compiler.h" #include "global_config.h" #include "global_constants.h" -#include "gd_compiler.h" -#include "os/file_access.h" #include "io/file_access_encrypted.h" +#include "os/file_access.h" #include "os/os.h" /////////////////////////// -GDNativeClass::GDNativeClass(const StringName& p_name) { +GDNativeClass::GDNativeClass(const StringName &p_name) { - name=p_name; + name = p_name; } /*void GDNativeClass::call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount){ @@ -46,33 +46,30 @@ GDNativeClass::GDNativeClass(const StringName& p_name) { }*/ - -bool GDNativeClass::_get(const StringName& p_name,Variant &r_ret) const { +bool GDNativeClass::_get(const StringName &p_name, Variant &r_ret) const { bool ok; int v = ClassDB::get_integer_constant(name, p_name, &ok); if (ok) { - r_ret=v; + r_ret = v; return true; } else { return false; } } - void GDNativeClass::_bind_methods() { - ClassDB::bind_method(D_METHOD("new"),&GDNativeClass::_new); - + ClassDB::bind_method(D_METHOD("new"), &GDNativeClass::_new); } Variant GDNativeClass::_new() { Object *o = instance(); if (!o) { - ERR_EXPLAIN("Class type: '"+String(name)+"' is not instantiable."); - ERR_FAIL_COND_V(!o,Variant()); + ERR_EXPLAIN("Class type: '" + String(name) + "' is not instantiable."); + ERR_FAIL_COND_V(!o, Variant()); } Reference *ref = o->cast_to(); @@ -81,7 +78,6 @@ Variant GDNativeClass::_new() { } else { return o; } - } Object *GDNativeClass::instance() { @@ -89,27 +85,24 @@ Object *GDNativeClass::instance() { return ClassDB::instance(name); } - - -GDInstance* GDScript::_create_instance(const Variant** p_args,int p_argcount,Object *p_owner,bool p_isref,Variant::CallError& r_error) { - +GDInstance *GDScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error) { /* STEP 1, CREATE */ - GDInstance* instance = memnew( GDInstance ); - instance->base_ref=p_isref; + GDInstance *instance = memnew(GDInstance); + instance->base_ref = p_isref; instance->members.resize(member_indices.size()); - instance->script=Ref(this); - instance->owner=p_owner; + instance->script = Ref(this); + instance->owner = p_owner; #ifdef DEBUG_ENABLED //needed for hot reloading - for(Map::Element *E=member_indices.front();E;E=E->next()) { - instance->member_indices_cache[E->key()]=E->get().index; + for (Map::Element *E = member_indices.front(); E; E = E->next()) { + instance->member_indices_cache[E->key()] = E->get().index; } #endif instance->owner->set_script_instance(instance); - /* STEP 2, INITIALIZE AND CONSRTUCT */ +/* STEP 2, INITIALIZE AND CONSRTUCT */ #ifndef NO_THREADS GDScriptLanguage::singleton->lock->lock(); @@ -121,10 +114,10 @@ GDInstance* GDScript::_create_instance(const Variant** p_args,int p_argcount,Obj GDScriptLanguage::singleton->lock->unlock(); #endif - initializer->call(instance,p_args,p_argcount,r_error); + initializer->call(instance, p_args, p_argcount, r_error); - if (r_error.error!=Variant::CallError::CALL_OK) { - instance->script=Ref(); + if (r_error.error != Variant::CallError::CALL_OK) { + instance->script = Ref(); instance->owner->set_script_instance(NULL); #ifndef NO_THREADS GDScriptLanguage::singleton->lock->lock(); @@ -134,47 +127,45 @@ GDInstance* GDScript::_create_instance(const Variant** p_args,int p_argcount,Obj GDScriptLanguage::singleton->lock->unlock(); #endif - ERR_FAIL_COND_V(r_error.error!=Variant::CallError::CALL_OK, NULL); //error constructing + ERR_FAIL_COND_V(r_error.error != Variant::CallError::CALL_OK, NULL); //error constructing } //@TODO make thread safe return instance; - } -Variant GDScript::_new(const Variant** p_args,int p_argcount,Variant::CallError& r_error) { +Variant GDScript::_new(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { /* STEP 1, CREATE */ if (!valid) { - r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD; + r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; return Variant(); } - r_error.error=Variant::CallError::CALL_OK; + r_error.error = Variant::CallError::CALL_OK; REF ref; - Object *owner=NULL; + Object *owner = NULL; - GDScript *_baseptr=this; + GDScript *_baseptr = this; while (_baseptr->_base) { - _baseptr=_baseptr->_base; + _baseptr = _baseptr->_base; } ERR_FAIL_COND_V(_baseptr->native.is_null(), Variant()); if (_baseptr->native.ptr()) { - owner=_baseptr->native->instance(); + owner = _baseptr->native->instance(); } else { - owner=memnew( Reference ); //by default, no base means use reference + owner = memnew(Reference); //by default, no base means use reference } - Reference *r=owner->cast_to(); + Reference *r = owner->cast_to(); if (r) { - ref=REF(r); + ref = REF(r); } - - GDInstance* instance = _create_instance(p_args,p_argcount,owner,r!=NULL,r_error); + GDInstance *instance = _create_instance(p_args, p_argcount, owner, r != NULL, r_error); if (!instance) { if (ref.is_null()) { memdelete(owner); //no owner, sorry @@ -193,13 +184,12 @@ bool GDScript::can_instance() const { //return valid; //any script in GDscript can instance return valid || (!tool && !ScriptServer::is_scripting_enabled()); - } Ref