diff options
Diffstat (limited to 'main/main.cpp')
-rw-r--r-- | main/main.cpp | 165 |
1 files changed, 84 insertions, 81 deletions
diff --git a/main/main.cpp b/main/main.cpp index aa8540632f..ec4386ab20 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1294,9 +1294,10 @@ bool Main::start() { } + String local_game_path; if (game_path!="" && !project_manager_request) { - String local_game_path=game_path.replace("\\","/"); + local_game_path=game_path.replace("\\","/"); if (!local_game_path.begins_with("res://")) { bool absolute=(local_game_path.size()>1) && (local_game_path[0]=='/' || local_game_path[1]==':'); @@ -1363,98 +1364,99 @@ bool Main::start() { OS::get_singleton()->set_context(OS::CONTEXT_EDITOR); //editor_node->set_edited_scene(game); - } else { + } #endif + } - { - //autoload - List<PropertyInfo> props; - Globals::get_singleton()->get_property_list(&props); - - //first pass, add the constants so they exist before any script is loaded - for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) { - - String s = E->get().name; - if (!s.begins_with("autoload/")) - continue; - String name = s.get_slicec('/',1); - String path = Globals::get_singleton()->get(s); - bool global_var=false; - if (path.begins_with("*")) { - global_var=true; - } - - if (global_var) { - for(int i=0;i<ScriptServer::get_language_count();i++) { - ScriptServer::get_language(i)->add_global_constant(name,Variant()); - } - } - + if (!project_manager_request && !editor) { + if (game_path!="" || script!="") { + //autoload + List<PropertyInfo> props; + Globals::get_singleton()->get_property_list(&props); + + //first pass, add the constants so they exist before any script is loaded + for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) { + + String s = E->get().name; + if (!s.begins_with("autoload/")) + continue; + String name = s.get_slicec('/',1); + String path = Globals::get_singleton()->get(s); + bool global_var=false; + if (path.begins_with("*")) { + global_var=true; } - //second pass, load into global constants - List<Node*> to_add; - for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) { - - String s = E->get().name; - if (!s.begins_with("autoload/")) - continue; - String name = s.get_slicec('/',1); - String path = Globals::get_singleton()->get(s); - bool global_var=false; - if (path.begins_with("*")) { - global_var=true; - path=path.substr(1,path.length()-1); - } - - RES res = ResourceLoader::load(path); - ERR_EXPLAIN("Can't autoload: "+path); - ERR_CONTINUE(res.is_null()); - Node *n=NULL; - if (res->is_type("PackedScene")) { - Ref<PackedScene> ps = res; - n=ps->instance(); - } else if (res->is_type("Script")) { - Ref<Script> s = res; - StringName ibt = s->get_instance_base_type(); - bool valid_type = ObjectTypeDB::is_type(ibt,"Node"); - ERR_EXPLAIN("Script does not inherit a Node: "+path); - ERR_CONTINUE( !valid_type ); - - Object *obj = ObjectTypeDB::instance(ibt); - - ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: "+String(ibt)); - ERR_CONTINUE( obj==NULL ); - - n = obj->cast_to<Node>(); - n->set_script(s.get_ref_ptr()); + if (global_var) { + for(int i=0;i<ScriptServer::get_language_count();i++) { + ScriptServer::get_language(i)->add_global_constant(name,Variant()); } + } - ERR_EXPLAIN("Path in autoload not a node or script: "+path); - ERR_CONTINUE(!n); - n->set_name(name); - - //defer so references are all valid on _ready() - //sml->get_root()->add_child(n); - to_add.push_back(n); + } - if (global_var) { - for(int i=0;i<ScriptServer::get_language_count();i++) { - ScriptServer::get_language(i)->add_global_constant(name,n); - } - } + //second pass, load into global constants + List<Node*> to_add; + for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) { + + String s = E->get().name; + if (!s.begins_with("autoload/")) + continue; + String name = s.get_slicec('/',1); + String path = Globals::get_singleton()->get(s); + bool global_var=false; + if (path.begins_with("*")) { + global_var=true; + path=path.substr(1,path.length()-1); + } + RES res = ResourceLoader::load(path); + ERR_EXPLAIN("Can't autoload: "+path); + ERR_CONTINUE(res.is_null()); + Node *n=NULL; + if (res->is_type("PackedScene")) { + Ref<PackedScene> ps = res; + n=ps->instance(); + } else if (res->is_type("Script")) { + Ref<Script> s = res; + StringName ibt = s->get_instance_base_type(); + bool valid_type = ObjectTypeDB::is_type(ibt,"Node"); + ERR_EXPLAIN("Script does not inherit a Node: "+path); + ERR_CONTINUE( !valid_type ); + + Object *obj = ObjectTypeDB::instance(ibt); + + ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: "+String(ibt)); + ERR_CONTINUE( obj==NULL ); + + n = obj->cast_to<Node>(); + n->set_script(s.get_ref_ptr()); } - for(List<Node*>::Element *E=to_add.front();E;E=E->next()) { + ERR_EXPLAIN("Path in autoload not a node or script: "+path); + ERR_CONTINUE(!n); + n->set_name(name); - sml->get_root()->add_child(E->get()); + //defer so references are all valid on _ready() + //sml->get_root()->add_child(n); + to_add.push_back(n); + + if (global_var) { + for(int i=0;i<ScriptServer::get_language_count();i++) { + ScriptServer::get_language(i)->add_global_constant(name,n); + } } + } + for(List<Node*>::Element *E=to_add.front();E;E=E->next()) { + sml->get_root()->add_child(E->get()); } + //singletons + } + if (game_path!="") { Node *scene=NULL; Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path); if (scenedata.is_valid()) @@ -1471,12 +1473,7 @@ bool Main::start() { if (icon.load(iconpath)==OK) OS::get_singleton()->set_icon(icon); } - - - //singletons -#ifdef TOOLS_ENABLED } -#endif } #ifdef TOOLS_ENABLED @@ -1560,6 +1557,8 @@ bool Main::iteration() { int iters = 0; + OS::get_singleton()->_in_fixed=true; + while(time_accum>frame_slice) { uint64_t fixed_begin = OS::get_singleton()->get_ticks_usec(); @@ -1590,8 +1589,11 @@ bool Main::iteration() { fixed_process_ticks=MAX(fixed_process_ticks,OS::get_singleton()->get_ticks_usec()-fixed_begin); // keep the largest one for reference fixed_process_max=MAX(OS::get_singleton()->get_ticks_usec()-fixed_begin,fixed_process_max); iters++; + OS::get_singleton()->_fixed_frames++; } + OS::get_singleton()->_in_fixed=false; + uint64_t idle_begin = OS::get_singleton()->get_ticks_usec(); OS::get_singleton()->get_main_loop()->idle( step*time_scale ); @@ -1640,6 +1642,7 @@ bool Main::iteration() { // x11_delay_usec(10000); frames++; + OS::get_singleton()->_idle_frames++; if (frame>1000000) { |