void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Texture> &p_texture, ObjectID id, const StringName &p_func, const Variant &p_ud) { //print_line("preview is ready"); preview_mutex->lock(); String path = p_str; uint32_t hash = 0; uint64_t modified_time = 0; if (p_str.begins_with("ID:")) { hash = p_str.get_slicec(':', 2).to_int(); path = "ID:" + p_str.get_slicec(':', 1); } else { modified_time = FileAccess::get_modified_time(path); } Item item; item.order = order++; item.preview = p_texture; item.last_hash = hash; item.modified_time = modified_time; cache[path] = item; preview_mutex->unlock(); MessageQueue::get_singleton()->push_call(id, p_func, path, p_texture, p_ud); }
bool CollisionObject::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name == "shape_count") { shapes.resize(p_value); _update_shapes(); _change_notify(); } else if (name.begins_with("shapes/")) { int idx = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (what == "shape") set_shape(idx, RefPtr(p_value)); else if (what == "transform") set_shape_transform(idx, p_value); else if (what == "trigger") set_shape_as_trigger(idx, p_value); } else return false; return true; }
bool SoftBody::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; String which = name.get_slicec('/', 0); if ("pinned_points" == which) { Array arr_ret; const int pinned_points_indices_size = pinned_points_indices.size(); PoolVector<PinnedPoint>::Read r = pinned_points_indices.read(); arr_ret.resize(pinned_points_indices_size); for (int i = 0; i < pinned_points_indices_size; ++i) { arr_ret[i] = r[i].point_index; } r_ret = arr_ret; return true; } else if ("attachments" == which) { int idx = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); return _get_property_pinned_points(idx, what, r_ret); } return false; }
bool BakedLight::_get(const StringName& p_name,Variant &r_ret) const{ String n = p_name; if (!n.begins_with("lightmap")) return false; int idx = n.get_slicec('/',1).to_int(); ERR_FAIL_COND_V(idx<0,false); ERR_FAIL_COND_V(idx>lightmaps.size(),false); String what = n.get_slicec('/',2); if (what=="texture") { if (idx==lightmaps.size()) r_ret=Ref<Texture>(); else r_ret=lightmaps[idx].texture; } else if (what=="gen_size") { if (idx==lightmaps.size()) r_ret=Size2(); else r_ret=Size2(lightmaps[idx].gen_size); } else return false; return true; }
PropertyInfo MethodBind::get_argument_info(int p_argument) const { if (p_argument>=0) { String name = (p_argument<arg_names.size())?String(arg_names[p_argument]):String("arg"+itos(p_argument)); PropertyInfo pi( get_argument_type(p_argument), name ); if ((pi.type==Variant::OBJECT) && name.find(":")!=-1) { pi.hint=PROPERTY_HINT_RESOURCE_TYPE; pi.hint_string=name.get_slicec(':',1); pi.name=name.get_slicec(':',0); } return pi; } else { Variant::Type at = get_argument_type(-1); if (at==Variant::OBJECT && ret_type) return PropertyInfo( at, "ret", PROPERTY_HINT_RESOURCE_TYPE, ret_type ); else return PropertyInfo( at, "ret" ); } return PropertyInfo(); }
bool BakedLight::_set(const StringName& p_name, const Variant& p_value) { String n = p_name; if (!n.begins_with("lightmap")) return false; int idx = n.get_slicec('/',1).to_int(); ERR_FAIL_COND_V(idx<0,false); ERR_FAIL_COND_V(idx>lightmaps.size(),false); String what = n.get_slicec('/',2); Ref<Texture> tex; Size2 gens; if (what=="texture") tex=p_value; else if (what=="gen_size") gens=p_value; if (idx==lightmaps.size()) { if (tex.is_valid() || gens!=Size2()) add_lightmap(tex,gens); } else { if (tex.is_valid()) set_lightmap_texture(idx,tex); else if (gens!=Size2()) set_lightmap_gen_size(idx,gens); } return true; }
bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name.begins_with("item/")) { int idx = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (!item_map.has(idx)) create_item(idx); if (what == "name") set_item_name(idx, p_value); else if (what == "mesh") set_item_mesh(idx, p_value); else if (what == "shape") { Vector<ShapeData> shapes; ShapeData sd; sd.shape = p_value; shapes.push_back(sd); set_item_shapes(idx, shapes); } else if (what == "shapes") { _set_item_shapes(idx, p_value); } else if (what == "preview") set_item_preview(idx, p_value); else if (what == "navmesh") set_item_navmesh(idx, p_value); else return false; return true; } return false; }
bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name == "theme") { r_ret = get_theme(); } else if (name == "cell_size") { r_ret = get_cell_size(); } else if (name == "cell_octant_size") { r_ret = get_octant_size(); } else if (name == "cell_center_x") { r_ret = get_center_x(); } else if (name == "cell_center_y") { r_ret = get_center_y(); } else if (name == "cell_center_z") { r_ret = get_center_z(); } else if (name == "cell_scale") { r_ret = cell_scale; } else if (name == "data") { Dictionary d; PoolVector<int> cells; cells.resize(cell_map.size() * 3); { PoolVector<int>::Write w = cells.write(); int i = 0; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) { encode_uint64(E->key().key, (uint8_t *)&w[i * 3]); encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]); } } d["cells"] = cells; r_ret = d; } else if (name.begins_with("areas/")) { int which = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (what == "bounds") r_ret = area_get_bounds(which); else if (what == "name") r_ret = area_get_name(which); else if (what == "disable_distance") r_ret = area_get_portal_disable_distance(which); else if (what == "exterior_portal") r_ret = area_is_exterior_portal(which); else return false; } else return false; return true; }
bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name == "playback/speed") { //bw compatibility r_ret = speed_scale; } else if (name == "playback/active") { r_ret = is_active(); } else if (name == "playback/play") { if (is_active() && is_playing()) r_ret = playback.assigned; else r_ret = "[stop]"; } else if (name.begins_with("anims/")) { String which = name.get_slicec('/', 1); r_ret = get_animation(which).get_ref_ptr(); } else if (name.begins_with("next/")) { String which = name.get_slicec('/', 1); r_ret = animation_get_next(which); } else if (name == "blend_times") { Vector<BlendKey> keys; for (Map<BlendKey, float>::Element *E = blend_times.front(); E; E = E->next()) { 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; } else return false; return true; }
bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (p_name == SceneStringNames::get_singleton()->playback_speed || p_name == SceneStringNames::get_singleton()->speed) { //bw compatibility set_speed_scale(p_value); } else if (p_name == SceneStringNames::get_singleton()->playback_active) { set_active(p_value); } else if (name.begins_with("playback/play")) { String which = p_value; if (which == "[stop]") stop(); else play(which); } else if (name.begins_with("anims/")) { String which = name.get_slicec('/', 1); add_animation(which, p_value); } else if (name.begins_with("next/")) { String which = name.get_slicec('/', 1); animation_set_next(which, p_value); } else if (p_name == SceneStringNames::get_singleton()->blend_times) { Array array = p_value; int len = array.size(); ERR_FAIL_COND_V(len % 3, false); for (int i = 0; i < len / 3; i++) { StringName from = array[i * 3 + 0]; StringName to = array[i * 3 + 1]; float time = array[i * 3 + 2]; set_blend_time(from, to, time); } } else if (p_name == SceneStringNames::get_singleton()->autoplay) { autoplay = p_value; } else return false; return true; }
bool Skeleton::_set(const StringName& p_path, const Variant& p_value) { String path = p_path; if (!path.begins_with("bones/")) return false; int which=path.get_slicec('/',1).to_int(); String what=path.get_slicec('/',2); if (which==bones.size() && what=="name") { add_bone(p_value); return true; } ERR_FAIL_INDEX_V( which, bones.size(), false ); if (what=="parent") set_bone_parent(which, p_value ); else if (what=="rest") set_bone_rest(which, p_value); else if (what=="enabled") set_bone_enabled(which, p_value); else if (what=="pose") set_bone_pose(which, p_value); else if (what=="bound_childs") { Array children=p_value; if (is_inside_tree()) { bones[which].nodes_bound.clear(); for (int i=0;i<children.size();i++) { NodePath path=children[i]; ERR_CONTINUE( path.operator String()=="" ); Node *node = get_node(path); ERR_CONTINUE(!node); bind_child_node_to_bone(which,node); } } } else { return false; } return true; }
bool ButtonArray::_set(const StringName &p_name, const Variant &p_value) { String n = String(p_name); if (n.begins_with("button/")) { String what = n.get_slicec('/', 1); if (what == "count") { int new_size = p_value; if (new_size > 0 && buttons.size() == 0) { selected = 0; } if (new_size < buttons.size()) { if (selected >= new_size) selected = new_size - 1; } buttons.resize(new_size); _change_notify(); minimum_size_changed(); } else if (what == "align") { set_align(Align(p_value.operator int())); } else if (what == "selected") { set_selected(p_value); } else if (what == "min_button_size") { min_button_size = p_value; } else { int idx = what.to_int(); ERR_FAIL_INDEX_V(idx, buttons.size(), false); String f = n.get_slicec('/', 2); if (f == "text") { buttons[idx].text = p_value; buttons[idx].xl_text = XL_MESSAGE(p_value); } else if (f == "tooltip") buttons[idx].tooltip = p_value; else if (f == "icon") buttons[idx].icon = p_value; else return false; } update(); return true; } return false; }
bool SoftBody::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; String which = name.get_slicec('/', 0); if ("pinned_points" == which) { return _set_property_pinned_points_indices(p_value); } else if ("attachments" == which) { int idx = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); return _set_property_pinned_points_attachment(idx, what, p_value); } return false; }
bool CollisionObject2D::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; if (name.begins_with("shapes/")) { int idx = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (what == "shape") r_ret = get_shape(idx); else if (what == "transform") r_ret = get_shape_transform(idx); else if (what == "trigger") r_ret = is_shape_set_as_trigger(idx); } else return false; return true; }
void AnimationNodeBlendSpace1D::_validate_property(PropertyInfo &property) const { if (property.name.begins_with("blend_point_")) { String left = property.name.get_slicec('/', 0); int idx = left.get_slicec('_', 2).to_int(); if (idx >= blend_points_used) { property.usage = 0; } } AnimationRootNode::_validate_property(property); }
bool Skeleton::_get(const StringName &p_path, Variant &r_ret) const { String path = p_path; if (!path.begins_with("bones/")) return false; int which = path.get_slicec('/', 1).to_int(); String what = path.get_slicec('/', 2); ERR_FAIL_INDEX_V(which, bones.size(), false); if (what == "name") r_ret = get_bone_name(which); else if (what == "parent") r_ret = get_bone_parent(which); else if (what == "rest") r_ret = get_bone_rest(which); else if (what == "enabled") r_ret = is_bone_enabled(which); else if (what == "pose") r_ret = get_bone_pose(which); else if (what == "bound_children") { Array children; for (const List<uint32_t>::Element *E = bones[which].nodes_bound.front(); E; E = E->next()) { Object *obj = ObjectDB::get_instance(E->get()); ERR_CONTINUE(!obj); Node *node = Object::cast_to<Node>(obj); ERR_CONTINUE(!node); NodePath path = get_path_to(node); children.push_back(path); } r_ret = children; } else return false; return true; }
bool CollisionObject2D::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name.begins_with("shapes/")) { int idx = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (what == "shape") { if (idx >= shapes.size()) add_shape(RefPtr(p_value)); else set_shape(idx, RefPtr(p_value)); } else if (what == "transform") set_shape_transform(idx, p_value); else if (what == "trigger") set_shape_as_trigger(idx, p_value); } else return false; return true; }
bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; int idx = name.get_slicec('/', 1).to_int(); ERR_FAIL_COND_V(!item_map.has(idx), false); String what = name.get_slicec('/', 2); if (what == "name") r_ret = get_item_name(idx); else if (what == "mesh") r_ret = get_item_mesh(idx); else if (what == "shape") r_ret = get_item_shape(idx); else if (what == "navmesh") r_ret = get_item_navmesh(idx); else if (what == "preview") r_ret = get_item_preview(idx); else return false; return true; }
void IP_Address::_parse_ipv4(const String& p_string, int p_start, uint8_t* p_ret) { String ip; if (p_start != 0) { ip = p_string.substr(p_start, p_string.length() - p_start); } else { ip = p_string; }; int slices = ip.get_slice_count("."); if (slices!=4) { ERR_EXPLAIN("Invalid IP Address String: "+ip); ERR_FAIL(); } for(int i=0;i<4;i++) { p_ret[i]=ip.get_slicec('.',i).to_int(); } };
Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phase) { RID_OwnerBase::init_rid(); OS::get_singleton()->initialize_core(); ObjectTypeDB::init(); MAIN_PRINT("Main: Initialize CORE"); register_core_types(); register_core_driver_types(); MAIN_PRINT("Main: Initialize Globals"); Thread::_main_thread_id = Thread::get_caller_ID(); globals = memnew( Globals ); input_map = memnew( InputMap ); path_remap = memnew( PathRemap ); translation_server = memnew( TranslationServer ); performance = memnew( Performance ); globals->add_singleton(Globals::Singleton("Performance",performance)); MAIN_PRINT("Main: Parse CMDLine"); /* argument parsing and main creation */ List<String> args; List<String> main_args; for(int i=0;i<argc;i++) { args.push_back(String::utf8(argv[i])); } List<String>::Element *I=args.front(); I=args.front(); while (I) { I->get()=unescape_cmdline(I->get().strip_escapes()); // print_line("CMD: "+I->get()); I=I->next(); } I=args.front(); video_mode = OS::get_singleton()->get_default_video_mode(); String video_driver=""; String audio_driver=""; String game_path="."; String debug_mode; String debug_host; String main_pack; bool quiet_stdout=false; int rtm=-1; String remotefs; String remotefs_pass; String screen = ""; List<String> pack_list; Vector<String> breakpoints; bool use_custom_res=true; bool force_res=false; I=args.front(); packed_data = PackedData::get_singleton(); if (!packed_data) packed_data = memnew(PackedData); #ifdef MINIZIP_ENABLED //XXX: always get_singleton() == 0x0 zip_packed_data = ZipArchive::get_singleton(); //TODO: remove this temporary fix if (!zip_packed_data) { zip_packed_data = memnew(ZipArchive); } packed_data->add_pack_source(zip_packed_data); #endif bool editor=false; while(I) { List<String>::Element *N=I->next(); if (I->get() == "-noop") { // no op } else if (I->get()=="-h" || I->get()=="--help" || I->get()=="/?") { // resolution goto error; } else if (I->get()=="-r") { // resolution if (I->next()) { String vm=I->next()->get(); if (vm.find("x")==-1) { // invalid parameter format OS::get_singleton()->print("Invalid -r argument: %s\n",vm.utf8().get_data()); goto error; } int w=vm.get_slice("x",0).to_int(); int h=vm.get_slice("x",1).to_int(); if (w==0 || h==0) { OS::get_singleton()->print("Invalid -r resolution, x and y must be >0\n"); goto error; } video_mode.width=w; video_mode.height=h; force_res=true; N=I->next()->next(); } else { OS::get_singleton()->print("Invalid -p argument, needs resolution\n"); goto error; } } else if (I->get()=="-p") { // position if (I->next()) { String vm=I->next()->get(); if (vm.find("x")==-1) { // invalid parameter format OS::get_singleton()->print("Invalid -p argument: %s\n",vm.utf8().get_data()); goto error; } int x=vm.get_slice("x",0).to_int(); int y=vm.get_slice("x",1).to_int(); init_custom_pos=Point2(x,y); init_use_custom_pos=true; N=I->next()->next(); } else { OS::get_singleton()->print("Invalid -r argument, needs position\n"); goto error; } } else if (I->get()=="-mx") { // video driver init_maximized=true; } else if (I->get()=="-w") { // video driver init_windowed=true; } else if (I->get()=="-vd") { // video driver if (I->next()) { video_driver=I->next()->get(); N=I->next()->next(); } else { OS::get_singleton()->print("Invalid -cd argument, needs driver name\n"); goto error; } } else if (I->get()=="-lang") { // language if (I->next()) { locale=I->next()->get(); N=I->next()->next(); } else { OS::get_singleton()->print("Invalid -lang argument, needs language code\n"); goto error; } } else if (I->get()=="-rfs") { // language if (I->next()) { remotefs=I->next()->get(); N=I->next()->next(); } else { goto error; } } else if (I->get()=="-rfs_pass") { // language if (I->next()) { remotefs_pass=I->next()->get(); N=I->next()->next(); } else { goto error; } } else if (I->get()=="-rthread") { // language if (I->next()) { if (I->next()->get()=="safe") rtm=OS::RENDER_THREAD_SAFE; else if (I->next()->get()=="unsafe") rtm=OS::RENDER_THREAD_UNSAFE; else if (I->next()->get()=="separate") rtm=OS::RENDER_SEPARATE_THREAD; N=I->next()->next(); } else { goto error; } } else if (I->get()=="-ad") { // video driver if (I->next()) { audio_driver=I->next()->get(); N=I->next()->next(); } else { goto error; } } else if (I->get()=="-f") { // fullscreen //video_mode.fullscreen=false; init_fullscreen=true; } else if (I->get()=="-e" || I->get()=="-editor") { // fonud editor editor=true; } else if (I->get()=="-nowindow") { // fullscreen OS::get_singleton()->set_no_window_mode(true); } else if (I->get()=="-quiet") { // fullscreen quiet_stdout=true; } else if (I->get()=="-v") { // fullscreen OS::get_singleton()->_verbose_stdout=true; } else if (I->get()=="-path") { // resolution if (I->next()) { String p = I->next()->get(); if (OS::get_singleton()->set_cwd(p)==OK) { //nothing } else { game_path=I->next()->get(); //use game_path instead } N=I->next()->next(); } else { goto error; } } else if (I->get()=="-bp") { // /breakpoints if (I->next()) { String bplist = I->next()->get(); breakpoints= bplist.split(","); N=I->next()->next(); } else { goto error; } } else if (I->get()=="-fdelay") { // resolution if (I->next()) { OS::get_singleton()->set_frame_delay(I->next()->get().to_int()); N=I->next()->next(); } else { goto error; } } else if (I->get()=="-timescale") { // resolution if (I->next()) { OS::get_singleton()->set_time_scale(I->next()->get().to_double()); N=I->next()->next(); } else { goto error; } } else if (I->get() == "-pack") { if (I->next()) { pack_list.push_back(I->next()->get()); N = I->next()->next(); } else { goto error; }; } else if (I->get() == "-main_pack") { if (I->next()) { main_pack=I->next()->get(); N = I->next()->next(); } else { goto error; }; } else if (I->get()=="-debug" || I->get()=="-d") { debug_mode="local"; } else if (I->get()=="-debugcol" || I->get()=="-dc") { debug_collisions=true; } else if (I->get()=="-debugnav" || I->get()=="-dn") { debug_navigation=true; } else if (I->get()=="-editor_scene") { if (I->next()) { Globals::get_singleton()->set("editor_scene",game_path=I->next()->get()); } else { goto error; } } else if (I->get()=="-rdebug") { if (I->next()) { debug_mode="remote"; debug_host=I->next()->get(); if (debug_host.find(":")==-1) { //wrong host OS::get_singleton()->print("Invalid debug host string\n"); goto error; } N=I->next()->next(); } else { goto error; } } else { //test for game path bool gpfound=false; if (!I->get().begins_with("-") && game_path=="") { DirAccess* da = DirAccess::open(I->get()); if (da!=NULL) { game_path=I->get(); gpfound=true; memdelete(da); } } if (!gpfound) { main_args.push_back(I->get()); } } I=N; } GLOBAL_DEF("debug/max_remote_stdout_chars_per_second",2048); if (debug_mode == "remote") { ScriptDebuggerRemote *sdr = memnew( ScriptDebuggerRemote ); uint16_t debug_port = GLOBAL_DEF("debug/remote_port",6007); if (debug_host.find(":")!=-1) { debug_port=debug_host.get_slicec(':',1).to_int(); debug_host=debug_host.get_slicec(':',0); } Error derr = sdr->connect_to_host(debug_host,debug_port); if (derr!=OK) { memdelete(sdr); } else { script_debugger=sdr; } } else if (debug_mode=="local") { script_debugger = memnew( ScriptDebuggerLocal ); } if (remotefs!="") { file_access_network_client=memnew(FileAccessNetworkClient); int port; if (remotefs.find(":")!=-1) { port=remotefs.get_slicec(':',1).to_int(); remotefs=remotefs.get_slicec(':',0); } else { port=6010; } Error err = file_access_network_client->connect(remotefs,port,remotefs_pass); if (err) { OS::get_singleton()->printerr("Could not connect to remotefs: %s:%i\n",remotefs.utf8().get_data(),port); goto error; } FileAccess::make_default<FileAccessNetwork>(FileAccess::ACCESS_RESOURCES); } if (script_debugger) { //there is a debugger, parse breakpoints for(int i=0;i<breakpoints.size();i++) { String bp = breakpoints[i]; int sp=bp.find_last(":"); if (sp==-1) { ERR_EXPLAIN("Invalid breakpoint: '"+bp+"', expected file:line format."); ERR_CONTINUE(sp==-1); } script_debugger->insert_breakpoint(bp.substr(sp+1,bp.length()).to_int(),bp.substr(0,sp)); } } #ifdef TOOLS_ENABLED if (editor) { packed_data->set_disabled(true); globals->set_disable_platform_override(true); StreamPeerSSL::initialize_certs=false; //will be initialized by editor } #endif if (globals->setup(game_path,main_pack)!=OK) { #ifdef TOOLS_ENABLED editor=false; #else OS::get_singleton()->print("error: Couldn't load game path '%s'\n",game_path.ascii().get_data()); goto error; #endif } if (editor) { main_args.push_back("-editor"); init_maximized=true; use_custom_res=false; } if (bool(Globals::get_singleton()->get("application/disable_stdout"))) { quiet_stdout=true; } if (bool(Globals::get_singleton()->get("application/disable_stderr"))) { _print_error_enabled = false; }; if (quiet_stdout) _print_line_enabled=false; OS::get_singleton()->set_cmdline(execpath, main_args); #ifdef TOOLS_ENABLED if (main_args.size()==0 && (!Globals::get_singleton()->has("application/main_loop_type")) && (!Globals::get_singleton()->has("application/main_scene") || String(Globals::get_singleton()->get("application/main_scene"))=="")) use_custom_res=false; //project manager (run without arguments) #endif input_map->load_from_globals(); if (video_driver=="") // specified in engine.cfg video_driver=_GLOBAL_DEF("display/driver",Variant((const char*)OS::get_singleton()->get_video_driver_name(0))); if (!force_res && use_custom_res && globals->has("display/width")) video_mode.width=globals->get("display/width"); if (!force_res &&use_custom_res && globals->has("display/height")) video_mode.height=globals->get("display/height"); if (use_custom_res && globals->has("display/fullscreen")) video_mode.fullscreen=globals->get("display/fullscreen"); if (use_custom_res && globals->has("display/resizable")) video_mode.resizable=globals->get("display/resizable"); if (use_custom_res && globals->has("display/borderless_window")) video_mode.borderless_window = globals->get("display/borderless_window"); if (!force_res && use_custom_res && globals->has("display/test_width") && globals->has("display/test_height")) { int tw = globals->get("display/test_width"); int th = globals->get("display/test_height"); if (tw>0 && th>0) { video_mode.width=tw; video_mode.height=th; } } GLOBAL_DEF("display/width",video_mode.width); GLOBAL_DEF("display/height",video_mode.height); GLOBAL_DEF("display/fullscreen",video_mode.fullscreen); GLOBAL_DEF("display/resizable",video_mode.resizable); GLOBAL_DEF("display/borderless_window", video_mode.borderless_window); GLOBAL_DEF("display/test_width",0); GLOBAL_DEF("display/test_height",0); OS::get_singleton()->_pixel_snap=GLOBAL_DEF("display/use_2d_pixel_snap",false); OS::get_singleton()->_keep_screen_on=GLOBAL_DEF("display/keep_screen_on",true); if (rtm==-1) { rtm=GLOBAL_DEF("render/thread_model",OS::RENDER_THREAD_SAFE); if (rtm>=1) //hack for now rtm=1; } if (rtm>=0 && rtm<3) { if (editor) { rtm=OS::RENDER_THREAD_SAFE; } OS::get_singleton()->_render_thread_mode=OS::RenderThreadMode(rtm); } /* Determine Video Driver */ if (audio_driver=="") { // specified in engine.cfg audio_driver=GLOBAL_DEF("audio/driver",OS::get_singleton()->get_audio_driver_name(0)); } for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) { if (video_driver==OS::get_singleton()->get_video_driver_name(i)) { video_driver_idx=i; break; } } if (video_driver_idx<0) { OS::get_singleton()->alert( "Invalid Video Driver: "+video_driver ); video_driver_idx = 0; //goto error; } for (int i=0;i<OS::get_singleton()->get_audio_driver_count();i++) { if (audio_driver==OS::get_singleton()->get_audio_driver_name(i)) { audio_driver_idx=i; break; } } if (audio_driver_idx<0) { OS::get_singleton()->alert( "Invalid Audio Driver: "+audio_driver ); audio_driver_idx = 0; //goto error; } { String orientation = GLOBAL_DEF("display/orientation","landscape"); if (orientation=="portrait") OS::get_singleton()->set_screen_orientation(OS::SCREEN_PORTRAIT); else if (orientation=="reverse_landscape") OS::get_singleton()->set_screen_orientation(OS::SCREEN_REVERSE_LANDSCAPE); else if (orientation=="reverse_portrait") OS::get_singleton()->set_screen_orientation(OS::SCREEN_REVERSE_PORTRAIT); else if (orientation=="sensor_landscape") OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR_LANDSCAPE); else if (orientation=="sensor_portrait") OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR_PORTRAIT); else if (orientation=="sensor") OS::get_singleton()->set_screen_orientation(OS::SCREEN_SENSOR); else OS::get_singleton()->set_screen_orientation(OS::SCREEN_LANDSCAPE); } OS::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/fixed_fps",60)); OS::get_singleton()->set_target_fps(GLOBAL_DEF("application/target_fps",0)); if (!OS::get_singleton()->_verbose_stdout) //overrided OS::get_singleton()->_verbose_stdout=GLOBAL_DEF("debug/verbose_stdout",false); message_queue = memnew( MessageQueue ); Globals::get_singleton()->register_global_defaults(); if (p_second_phase) return setup2(); return OK; error: video_driver=""; audio_driver=""; game_path=""; args.clear(); main_args.clear(); print_help(execpath); if (performance) memdelete(performance); if (input_map) memdelete(input_map); if (translation_server) memdelete( translation_server ); if (globals) memdelete(globals); if (script_debugger) memdelete(script_debugger); if (packed_data) 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. //#ifdef MINIZIP_ENABLED // if (zip_packed_data) // memdelete( zip_packed_data ); //#endif unregister_core_driver_types(); unregister_core_types(); OS::get_singleton()->_cmdline.clear(); if (message_queue) memdelete( message_queue); OS::get_singleton()->finalize_core(); locale=String(); return ERR_INVALID_PARAMETER; }
Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndType &r_path_and_type, bool *r_valid) const { Error err; FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); if (!f) { if (r_valid) { *r_valid = false; } return err; } VariantParser::StreamFile stream; stream.f = f; String assign; Variant value; VariantParser::Tag next_tag; if (r_valid) { *r_valid = true; } int lines = 0; String error_text; bool path_found = false; //first match must have priority 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 (!path_found && assign.begins_with("path.") && r_path_and_type.path == String()) { String feature = assign.get_slicec('.', 1); if (OS::get_singleton()->has_feature(feature)) { r_path_and_type.path = value; path_found = true; //first match must have priority } } else if (!path_found && assign == "path") { r_path_and_type.path = value; path_found = true; //first match must have priority } else if (assign == "type") { r_path_and_type.type = value; } else if (assign == "importer") { r_path_and_type.importer = value; } else if (assign == "valid") { if (r_valid) { *r_valid = 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; }
void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue) { print_line("Debugger Break, Reason: '" + p_script->debug_get_error() + "'"); print_line("*Frame " + itos(0) + " - " + p_script->debug_get_stack_level_source(0) + ":" + itos(p_script->debug_get_stack_level_line(0)) + " in function '" + p_script->debug_get_stack_level_function(0) + "'"); print_line("Enter \"help\" for assistance."); int current_frame = 0; int total_frames = p_script->debug_get_stack_level_count(); while (true) { OS::get_singleton()->print("debug> "); String line = OS::get_singleton()->get_stdin_string().strip_edges(); if (line == "") { print_line("Debugger Break, Reason: '" + p_script->debug_get_error() + "'"); print_line("*Frame " + itos(current_frame) + " - " + p_script->debug_get_stack_level_source(current_frame) + ":" + itos(p_script->debug_get_stack_level_line(current_frame)) + " in function '" + p_script->debug_get_stack_level_function(current_frame) + "'"); print_line("Enter \"help\" for assistance."); } else if (line == "c" || line == "continue") break; else if (line == "bt" || line == "breakpoint") { for (int i = 0; i < total_frames; i++) { String cfi = (current_frame == i) ? "*" : " "; //current frame indicator print_line(cfi + "Frame " + itos(i) + " - " + p_script->debug_get_stack_level_source(i) + ":" + itos(p_script->debug_get_stack_level_line(i)) + " in function '" + p_script->debug_get_stack_level_function(i) + "'"); } } else if (line.begins_with("fr") || line.begins_with("frame")) { if (line.get_slice_count(" ") == 1) { print_line("*Frame " + itos(current_frame) + " - " + p_script->debug_get_stack_level_source(current_frame) + ":" + itos(p_script->debug_get_stack_level_line(current_frame)) + " in function '" + p_script->debug_get_stack_level_function(current_frame) + "'"); } else { int frame = line.get_slicec(' ', 1).to_int(); if (frame < 0 || frame >= total_frames) { print_line("Error: Invalid frame."); } else { current_frame = frame; print_line("*Frame " + itos(frame) + " - " + p_script->debug_get_stack_level_source(frame) + ":" + itos(p_script->debug_get_stack_level_line(frame)) + " in function '" + p_script->debug_get_stack_level_function(frame) + "'"); } } } else if (line == "lv" || line == "locals") { List<String> locals; List<Variant> values; p_script->debug_get_stack_level_locals(current_frame, &locals, &values); List<Variant>::Element *V = values.front(); for (List<String>::Element *E = locals.front(); E; E = E->next()) { print_line(E->get() + ": " + String(V->get())); V = V->next(); } } else if (line == "gv" || line == "globals") { List<String> locals; List<Variant> values; p_script->debug_get_globals(&locals, &values); List<Variant>::Element *V = values.front(); for (List<String>::Element *E = locals.front(); E; E = E->next()) { print_line(E->get() + ": " + String(V->get())); V = V->next(); } } else if (line == "mv" || line == "members") { List<String> locals; List<Variant> values; p_script->debug_get_stack_level_members(current_frame, &locals, &values); List<Variant>::Element *V = values.front(); for (List<String>::Element *E = locals.front(); E; E = E->next()) { print_line(E->get() + ": " + String(V->get())); V = V->next(); } } else if (line.begins_with("p") || line.begins_with("print")) { if (line.get_slice_count(" ") <= 1) { print_line("Usage: print <expre>"); } else { String expr = line.get_slicec(' ', 2); String res = p_script->debug_parse_stack_level_expression(current_frame, expr); print_line(res); } } else if (line == "s" || line == "step") { set_depth(-1); set_lines_left(1); break; } else if (line.begins_with("n") || line.begins_with("next")) { set_depth(0); set_lines_left(1); break; } else if (line.begins_with("br") || line.begins_with("break")) { if (line.get_slice_count(" ") <= 1) { //show breakpoints } else { String bppos = line.get_slicec(' ', 1); String source = bppos.get_slicec(':', 0).strip_edges(); int line = bppos.get_slicec(':', 1).strip_edges().to_int(); source = breakpoint_find_source(source); insert_breakpoint(line, source); print_line("BreakPoint at " + source + ":" + itos(line)); } } else if (line.begins_with("delete")) { if (line.get_slice_count(" ") <= 1) { clear_breakpoints(); } else { String bppos = line.get_slicec(' ', 1); String source = bppos.get_slicec(':', 0).strip_edges(); int line = bppos.get_slicec(':', 1).strip_edges().to_int(); source = breakpoint_find_source(source); remove_breakpoint(line, source); print_line("Removed BreakPoint at " + source + ":" + itos(line)); } } else if (line == "h" || line == "help") { print_line("Built-In Debugger command list:\n"); print_line("\tc,continue :\t\t Continue execution."); print_line("\tbt,backtrace :\t\t Show stack trace (frames)."); print_line("\tfr,frame <frame>:\t Change current frame."); print_line("\tlv,locals :\t\t Show local variables for current frame."); print_line("\tmv,members :\t\t Show member variables for \"this\" in frame."); print_line("\tgv,globals :\t\t Show global variables."); print_line("\tp,print <expr> :\t Execute and print variable in expression."); print_line("\ts,step :\t\t Step to next line."); print_line("\tn,next :\t\t Next line."); print_line("\tbr,break source:line :\t Place a breakpoint."); print_line("\tdelete [source:line]:\t\t Delete one/all breakpoints."); } else { print_line("Error: Invalid command, enter \"help\" for assistance."); } } }
bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { String sname = p_name; if (p_name == "blend_shape/names") { PoolVector<String> sk = p_value; int sz = sk.size(); PoolVector<String>::Read r = sk.read(); for (int i = 0; i < sz; i++) add_blend_shape(r[i]); return true; } if (p_name == "blend_shape/mode") { set_blend_shape_mode(BlendShapeMode(int(p_value))); return true; } if (sname.begins_with("surface_")) { int sl = sname.find("/"); if (sl == -1) return false; int idx = sname.substr(8, sl - 8).to_int() - 1; String what = sname.get_slicec('/', 1); if (what == "material") surface_set_material(idx, p_value); else if (what == "name") surface_set_name(idx, p_value); return true; } if (!sname.begins_with("surfaces")) return false; int idx = sname.get_slicec('/', 1).to_int(); String what = sname.get_slicec('/', 2); if (idx == surfaces.size()) { //create Dictionary d = p_value; ERR_FAIL_COND_V(!d.has("primitive"), false); if (d.has("arrays")) { //old format ERR_FAIL_COND_V(!d.has("morph_arrays"), false); add_surface_from_arrays(PrimitiveType(int(d["primitive"])), d["arrays"], d["morph_arrays"]); } else if (d.has("array_data")) { PoolVector<uint8_t> array_data = d["array_data"]; PoolVector<uint8_t> array_index_data; if (d.has("array_index_data")) array_index_data = d["array_index_data"]; ERR_FAIL_COND_V(!d.has("format"), false); uint32_t format = d["format"]; uint32_t primitive = d["primitive"]; ERR_FAIL_COND_V(!d.has("vertex_count"), false); int vertex_count = d["vertex_count"]; int index_count = 0; if (d.has("index_count")) index_count = d["index_count"]; Vector<PoolVector<uint8_t> > blend_shapes; if (d.has("blend_shape_data")) { Array blend_shape_data = d["blend_shape_data"]; for (int i = 0; i < blend_shape_data.size(); i++) { PoolVector<uint8_t> shape = blend_shape_data[i]; blend_shapes.push_back(shape); } } ERR_FAIL_COND_V(!d.has("aabb"), false); AABB aabb = d["aabb"]; Vector<AABB> bone_aabb; if (d.has("skeleton_aabb")) { Array baabb = d["skeleton_aabb"]; bone_aabb.resize(baabb.size()); for (int i = 0; i < baabb.size(); i++) { bone_aabb[i] = baabb[i]; } } add_surface(format, PrimitiveType(primitive), array_data, vertex_count, array_index_data, index_count, aabb, blend_shapes, bone_aabb); } else { ERR_FAIL_V(false); } if (d.has("material")) { surface_set_material(idx, d["material"]); } if (d.has("name")) { surface_set_name(idx, d["name"]); } return true; } return false; }
bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { if (_is_generated()) return false; String sname = p_name; if (p_name == "blend_shape/names") { PoolVector<String> sk; for (int i = 0; i < blend_shapes.size(); i++) sk.push_back(blend_shapes[i]); r_ret = sk; return true; } else if (p_name == "blend_shape/mode") { r_ret = get_blend_shape_mode(); return true; } else if (sname.begins_with("surface_")) { int sl = sname.find("/"); if (sl == -1) return false; int idx = sname.substr(8, sl - 8).to_int() - 1; String what = sname.get_slicec('/', 1); if (what == "material") r_ret = surface_get_material(idx); else if (what == "name") r_ret = surface_get_name(idx); return true; } else if (!sname.begins_with("surfaces")) return false; int idx = sname.get_slicec('/', 1).to_int(); ERR_FAIL_INDEX_V(idx, surfaces.size(), false); Dictionary d; d["array_data"] = VS::get_singleton()->mesh_surface_get_array(mesh, idx); d["vertex_count"] = VS::get_singleton()->mesh_surface_get_array_len(mesh, idx); d["array_index_data"] = VS::get_singleton()->mesh_surface_get_index_array(mesh, idx); d["index_count"] = VS::get_singleton()->mesh_surface_get_array_index_len(mesh, idx); d["primitive"] = VS::get_singleton()->mesh_surface_get_primitive_type(mesh, idx); d["format"] = VS::get_singleton()->mesh_surface_get_format(mesh, idx); d["aabb"] = VS::get_singleton()->mesh_surface_get_aabb(mesh, idx); Vector<AABB> skel_aabb = VS::get_singleton()->mesh_surface_get_skeleton_aabb(mesh, idx); Array arr; for (int i = 0; i < skel_aabb.size(); i++) { arr[i] = skel_aabb[i]; } d["skeleton_aabb"] = arr; Vector<PoolVector<uint8_t> > blend_shape_data = VS::get_singleton()->mesh_surface_get_blend_shapes(mesh, idx); Array md; for (int i = 0; i < blend_shape_data.size(); i++) { md.push_back(blend_shape_data[i]); } d["blend_shape_data"] = md; Ref<Material> m = surface_get_material(idx); if (m.is_valid()) d["material"] = m; String n = surface_get_name(idx); if (n != "") d["name"] = n; r_ret = d; return true; }
bool GridMap::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name == "theme") { set_theme(p_value); } else if (name == "cell_size") { set_cell_size(p_value); } else if (name == "cell_octant_size") { set_octant_size(p_value); } else if (name == "cell_center_x") { set_center_x(p_value); } else if (name == "cell_center_y") { set_center_y(p_value); } else if (name == "cell_center_z") { set_center_z(p_value); } else if (name == "cell_scale") { set_cell_scale(p_value); /* } else if (name=="cells") { PoolVector<int> cells = p_value; int amount=cells.size(); PoolVector<int>::Read r = cells.read(); ERR_FAIL_COND_V(amount&1,false); // not even cell_map.clear(); for(int i=0;i<amount/3;i++) { IndexKey ik; ik.key=decode_uint64(&r[i*3]); Cell cell; cell.cell=uint32_t(r[i*+1]); cell_map[ik]=cell; } _recreate_octant_data();*/ } else if (name == "data") { Dictionary d = p_value; if (d.has("cells")) { PoolVector<int> cells = d["cells"]; int amount = cells.size(); PoolVector<int>::Read r = cells.read(); ERR_FAIL_COND_V(amount % 3, false); // not even cell_map.clear(); for (int i = 0; i < amount / 3; i++) { IndexKey ik; ik.key = decode_uint64((const uint8_t *)&r[i * 3]); Cell cell; cell.cell = decode_uint32((const uint8_t *)&r[i * 3 + 2]); cell_map[ik] = cell; } } _recreate_octant_data(); } else if (name.begins_with("areas/")) { int which = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (what == "bounds") { ERR_FAIL_COND_V(area_map.has(which), false); create_area(which, p_value); return true; } ERR_FAIL_COND_V(!area_map.has(which), false); if (what == "name") area_set_name(which, p_value); else if (what == "disable_distance") area_set_portal_disable_distance(which, p_value); else if (what == "exterior_portal") area_set_portal_disable_color(which, p_value); else return false; } else return false; return true; }
bool Main::start() { ERR_FAIL_COND_V(!_start_success,false); bool editor=false; String doc_tool; bool doc_base=true; String game_path; 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 convert_old=false; bool export_debug=false; bool project_manager_request = false; List<String> args = OS::get_singleton()->get_cmdline_args(); for (int i=0;i<args.size();i++) { //parameters that do not have an argument to the right if (args[i]=="-nodocbase") { doc_base=false; } else if (args[i]=="-noquit") { noquit=true; } else if (args[i]=="-convert_old") { convert_old=true; } else if (args[i]=="-editor" || args[i]=="-e") { editor=true; } else if (args[i] == "-pm" || args[i] == "-project_manager") { project_manager_request = true; } else if (args[i].length() && args[i][0] != '-' && game_path == "") { game_path=args[i]; } //parameters that have an argument to the right else if (i < (args.size()-1)) { bool parsed_pair=true; if (args[i]=="-doctool") { doc_tool=args[i+1]; } else if (args[i]=="-script" || args[i]=="-s") { script=args[i+1]; } else if (args[i]=="-level" || args[i]=="-l") { OS::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]; } else if (args[i]=="-export_debug") { editor=true; //needs editor _export_platform=args[i+1]; export_debug=true; } else if (args[i]=="-import") { editor=true; //needs editor _import=args[i+1]; } 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; } if (parsed_pair) { i++; } } } if (editor) Globals::get_singleton()->set("editor_active",true); String main_loop_type; #ifdef TOOLS_ENABLED if(doc_tool!="") { DocData doc; doc.generate(doc_base); DocData docsrc; if (docsrc.load(doc_tool)==OK) { print_line("Doc exists. Merging.."); doc.merge_from(docsrc); } else { print_line("No Doc exists. Generating empty."); } doc.save(doc_tool); return false; } if (optimize!="") editor=true; //need editor #endif if (_export_platform!="") { if (game_path=="") { String err="Command line param "; err+=export_debug?"-export_debug":"-export"; err+=" passed but no destination path given.\n"; err+="Please specify the binary's file path to export to. Aborting export."; ERR_PRINT(err.utf8().get_data()); return false; } } if(script=="" && game_path=="" && String(GLOBAL_DEF("application/main_scene",""))!="") { game_path=GLOBAL_DEF("application/main_scene",""); } MainLoop *main_loop=NULL; if (editor) { main_loop = memnew(SceneTree); }; if (test!="") { #ifdef DEBUG_ENABLED main_loop = test_main(test,args); if (!main_loop) return false; #endif } else if (script!="") { Ref<Script> script_res = ResourceLoader::load(script); ERR_EXPLAIN("Can't load script: "+script); ERR_FAIL_COND_V(script_res.is_null(),false); if( script_res->can_instance() /*&& script_res->inherits_from("SceneTreeScripted")*/) { StringName instance_type=script_res->get_instance_base_type(); Object *obj = ObjectTypeDB::instance(instance_type); MainLoop *script_loop = obj?obj->cast_to<MainLoop>():NULL; if (!script_loop) { if (obj) memdelete(obj); ERR_EXPLAIN("Can't load script '"+script+"', it does not inherit from a MainLoop type"); ERR_FAIL_COND_V(!script_loop,false); } script_loop->set_init_script(script_res); main_loop=script_loop; } else { return false; } } else { main_loop_type=GLOBAL_DEF("application/main_loop_type",""); } if (!main_loop && main_loop_type=="") main_loop_type="SceneTree"; if (!main_loop) { if (!ObjectTypeDB::type_exists(main_loop_type)) { OS::get_singleton()->alert("godot: error: MainLoop type doesn't exist: "+main_loop_type); return false; } else { Object *ml = ObjectTypeDB::instance(main_loop_type); if (!ml) { ERR_EXPLAIN("Can't instance MainLoop type"); ERR_FAIL_V(false); } main_loop=ml->cast_to<MainLoop>(); if (!main_loop) { memdelete(ml); ERR_EXPLAIN("Invalid MainLoop type"); ERR_FAIL_V(false); } } } if (main_loop->is_type("SceneTree")) { SceneTree *sml = main_loop->cast_to<SceneTree>(); if (debug_collisions) { sml->set_debug_collisions_hint(true); } if (debug_navigation) { sml->set_debug_navigation_hint(true); } #ifdef TOOLS_ENABLED EditorNode *editor_node=NULL; if (editor) { editor_node = memnew( EditorNode ); sml->get_root()->add_child(editor_node); //root_node->set_editor(editor); //startup editor if (_export_platform!="") { editor_node->export_platform(_export_platform,game_path,export_debug,"",true); game_path=""; //no load anything } } #endif if (!editor) { //standard helpers that can be changed from main config String stretch_mode = GLOBAL_DEF("display/stretch_mode","disabled"); String stretch_aspect = GLOBAL_DEF("display/stretch_aspect","ignore"); Size2i stretch_size = Size2(GLOBAL_DEF("display/width",0),GLOBAL_DEF("display/height",0)); SceneTree::StretchMode sml_sm=SceneTree::STRETCH_MODE_DISABLED; if (stretch_mode=="2d") sml_sm=SceneTree::STRETCH_MODE_2D; else if (stretch_mode=="viewport") sml_sm=SceneTree::STRETCH_MODE_VIEWPORT; SceneTree::StretchAspect sml_aspect=SceneTree::STRETCH_ASPECT_IGNORE; if (stretch_aspect=="keep") sml_aspect=SceneTree::STRETCH_ASPECT_KEEP; else if (stretch_aspect=="keep_width") sml_aspect=SceneTree::STRETCH_ASPECT_KEEP_WIDTH; else if (stretch_aspect=="keep_height") sml_aspect=SceneTree::STRETCH_ASPECT_KEEP_HEIGHT; sml->set_screen_stretch(sml_sm,sml_aspect,stretch_size); sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit",true)); String appname = Globals::get_singleton()->get("application/name"); appname = TranslationServer::get_singleton()->translate(appname); OS::get_singleton()->set_window_title(appname); } else { GLOBAL_DEF("display/stretch_mode","disabled"); Globals::get_singleton()->set_custom_property_info("display/stretch_mode",PropertyInfo(Variant::STRING,"display/stretch_mode",PROPERTY_HINT_ENUM,"disabled,2d,viewport")); GLOBAL_DEF("display/stretch_aspect","ignore"); Globals::get_singleton()->set_custom_property_info("display/stretch_aspect",PropertyInfo(Variant::STRING,"display/stretch_aspect",PROPERTY_HINT_ENUM,"ignore,keep,keep_width,keep_height")); sml->set_auto_accept_quit(GLOBAL_DEF("application/auto_accept_quit",true)); } if (game_path!="" && !project_manager_request) { String 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]==':'); if (!absolute) { if (Globals::get_singleton()->is_using_datapack()) { local_game_path="res://"+local_game_path; } else { int sep=local_game_path.find_last("/"); if (sep==-1) { DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); local_game_path=da->get_current_dir()+"/"+local_game_path; memdelete(da) ; } else { 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());; memdelete(da); } } } } } local_game_path=Globals::get_singleton()->localize_path(local_game_path); #ifdef TOOLS_ENABLED if (editor) { if (_import!="") { //editor_node->import_scene(_import,local_game_path,_import_script); if (!noquit) sml->quit(); game_path=""; //no load anything } else { 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); //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()); } } } //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()); } 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); } } } for(List<Node*>::Element *E=to_add.front();E;E=E->next()) { sml->get_root()->add_child(E->get()); } } Node *scene=NULL; Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path); if (scenedata.is_valid()) scene=scenedata->instance(); ERR_EXPLAIN("Failed loading scene: "+local_game_path); ERR_FAIL_COND_V(!scene,false) //sml->get_root()->add_child(scene); sml->add_current_scene(scene); String iconpath = GLOBAL_DEF("application/icon","Variant()"""); if (iconpath!="") { Image icon; if (icon.load(iconpath)==OK) OS::get_singleton()->set_icon(icon); } //singletons #ifdef TOOLS_ENABLED } #endif } #ifdef TOOLS_ENABLED /*if (_export_platform!="") { sml->quit(); }*/ /* if (sml->get_root_node()) { Console *console = memnew( Console ); sml->get_root_node()->cast_to<RootNode>()->set_console(console); if (GLOBAL_DEF("console/visible_default",false).operator bool()) { console->show(); } else {P console->hide(); }; } */ if (project_manager_request || (script=="" && test=="" && game_path=="" && !editor)) { ProjectManager *pmanager = memnew( ProjectManager ); sml->get_root()->add_child(pmanager); OS::get_singleton()->set_context(OS::CONTEXT_PROJECTMAN); } #endif } OS::get_singleton()->set_main_loop( main_loop ); return true; }