void ScriptDebuggerRemote::_poll_events() { while(packet_peer_stream->get_available_packet_count()>0) { _get_output(); //send over output_strings Variant var; Error err = packet_peer_stream->get_var(var); ERR_CONTINUE( err != OK); ERR_CONTINUE( var.get_type()!=Variant::ARRAY ); Array cmd = var; ERR_CONTINUE( cmd.size()==0); ERR_CONTINUE( cmd[0].get_type()!=Variant::STRING ); String command = cmd[0]; //cmd.remove(0); if (command=="break") { if (get_break_language()) debug(get_break_language()); } else if (command=="request_scene_tree") { if (request_scene_tree) request_scene_tree(request_scene_tree_ud); } else if (command=="request_video_mem") { _send_video_memory(); } else if (command=="breakpoint") { bool set = cmd[3]; if (set) insert_breakpoint(cmd[2],cmd[1]); else remove_breakpoint(cmd[2],cmd[1]); } else { _parse_live_edit(cmd); } } }
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_slice("/",1).to_int(); String what=path.get_slice("/",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; 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; }
Object::~Object() { if (script_instance) memdelete(script_instance); script_instance = NULL; List<Connection> sconnections; const StringName *S = NULL; while ((S = signal_map.next(S))) { Signal *s = &signal_map[*S]; ERR_EXPLAIN("Attempt to delete an object in the middle of a signal emission from it"); ERR_CONTINUE(s->lock > 0); for (int i = 0; i < s->slot_map.size(); i++) { sconnections.push_back(s->slot_map.getv(i).conn); } } for (List<Connection>::Element *E = sconnections.front(); E; E = E->next()) { Connection &c = E->get(); ERR_CONTINUE(c.source != this); //bug? this->disconnect(c.signal, c.target, c.method); } while (connections.size()) { Connection c = connections.front()->get(); c.source->disconnect(c.signal, c.target, c.method); } ObjectDB::remove_instance(this); _instance_ID = 0; _predelete_ok = 2; for (int i = 0; i < MAX_SCRIPT_INSTANCE_BINDINGS; i++) { if (_script_instance_bindings[i]) { ScriptServer::get_language(i)->free_instance_binding_data(_script_instance_bindings[i]); } } }
void BitmapFont::_set_textures(const Vector<Variant> &p_textures) { for (int i = 0; i < p_textures.size(); i++) { Ref<Texture> tex = p_textures[i]; ERR_CONTINUE(!tex.is_valid()); add_texture(tex); } }
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_NORMAL_FLAG && int(cf->get_value("params", "compress/normal_map")) == 0) { cf->set_value("params", "compress/normal_map", 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); } }
void BakedLightBaker::_add_mesh(const Ref<Mesh>& p_mesh,const Ref<Material>& p_mat_override,const Transform& p_xform) { for(int i=0;i<p_mesh->get_surface_count();i++) { if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES) continue; Ref<Material> mat = p_mat_override.is_valid()?p_mat_override:p_mesh->surface_get_material(i); int facecount=0; if (p_mesh->surface_get_format(i)&Mesh::ARRAY_FORMAT_INDEX) { facecount=p_mesh->surface_get_array_index_len(i); } else { facecount=p_mesh->surface_get_array_len(i); } ERR_CONTINUE((facecount==0 || (facecount%3)!=0)); facecount/=3; int tbase=triangles.size(); triangles.resize(facecount+tbase); Array a = p_mesh->surface_get_arrays(i); DVector<Vector3> vertices = a[Mesh::ARRAY_VERTEX]; DVector<Vector3>::Read vr=vertices.read(); if (p_mesh->surface_get_format(i)&Mesh::ARRAY_FORMAT_INDEX) { DVector<int> indices = a[Mesh::ARRAY_INDEX]; DVector<int>::Read ir = indices.read(); for(int i=0;i<facecount;i++) { Triangle &t=triangles[tbase+i]; t.vertices[0]=p_xform.xform(vr[ ir[i*3+0] ]); t.vertices[1]=p_xform.xform(vr[ ir[i*3+1] ]); t.vertices[2]=p_xform.xform(vr[ ir[i*3+2] ]); } } else { for(int i=0;i<facecount;i++) { Triangle &t=triangles[tbase+i]; t.vertices[0]=p_xform.xform(vr[ i*3+0 ]); t.vertices[1]=p_xform.xform(vr[ i*3+1 ]); t.vertices[2]=p_xform.xform(vr[ i*3+2 ]); } } } }
void GDFunction::debug_get_stack_member_state(int p_line,List<Pair<StringName,int> > *r_stackvars) const { int oc=0; Map<StringName,_GDFKC> sdmap; for( const List<StackDebug>::Element *E=stack_debug.front();E;E=E->next()) { const StackDebug &sd=E->get(); if (sd.line>p_line) break; if (sd.added) { if (!sdmap.has(sd.identifier)) { _GDFKC d; d.order=oc++; d.pos.push_back(sd.pos); sdmap[sd.identifier]=d; } else { sdmap[sd.identifier].pos.push_back(sd.pos); } } else { ERR_CONTINUE(!sdmap.has(sd.identifier)); sdmap[sd.identifier].pos.pop_back(); if (sdmap[sd.identifier].pos.empty()) sdmap.erase(sd.identifier); } } List<_GDFKCS> stackpositions; for(Map<StringName,_GDFKC>::Element *E=sdmap.front();E;E=E->next() ) { _GDFKCS spp; spp.id=E->key(); spp.order=E->get().order; spp.pos=E->get().pos.back()->get(); stackpositions.push_back(spp); } stackpositions.sort(); for(List<_GDFKCS>::Element *E=stackpositions.front();E;E=E->next()) { Pair<StringName,int> p; p.first=E->get().id; p.second=E->get().pos; r_stackvars->push_back(p); } }
void FilterBankFR::mouse_motion(const GUI::Point& p_pos, const GUI::Point& p_rel, int p_button_mask) { if (drag.index==-1) { /* no drag, find over */ int closest=-1; int closest_dist=0; for (int i=0;i<filters;i++) { //just check ERR_CONTINUE(filter[i].mode==NULL || filter[i].stages==NULL || filter[i].cutoff==NULL || filter[i].resonance==NULL || cutoff_offset==NULL); if (filter[i].mode->get()==0) continue; int x=freq_2_pixel( filter[i].cutoff->get()*pow( 2 , cutoff_offset->get() ) ,MIN_FREQ,filter[i].cutoff->get_max(),get_size_cache().width); int distance=fabsf(p_pos.x-x); if (distance>10) continue; if (closest==-1 || closest_dist>distance) closest=i; } if (closest!=drag.over) { drag.over=closest; update(); } } else { float freq= float_2_freq( (float)p_pos.x/(float)get_size_cache().width ,MIN_FREQ,filter[drag.index].cutoff->get_max() ); freq/=pow( 2 , cutoff_offset->get() ); //filter[drag.index].cutoff->set(freq); filter[drag.index].cutoff->set(freq); float reso=(float)(get_size_cache().height-p_pos.y)/get_size_cache().height; if (reso<0) reso=0; if (reso>1) reso=1; reso*=filter[drag.index].resonance->get_max(); filter[drag.index].resonance->set(reso); update(); } }
bool Skeleton::_get(const StringName& p_name,Variant &r_ret) const { String path=p_name; 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_childs") { 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=obj->cast_to<Node>(); ERR_CONTINUE(!node); NodePath path=get_path_to(node); children.push_back(path); } r_ret=children; } else return false; return true; }
void AnimationNode::get_parameter_list(List<PropertyInfo> *r_list) const { if (get_script_instance()) { Array parameters = get_script_instance()->call("get_parameter_list"); for (int i = 0; i < parameters.size(); i++) { Dictionary d = parameters[i]; ERR_CONTINUE(d.empty()); r_list->push_back(PropertyInfo::from_dict(d)); } } }
void Resource::notify_change_to_owners() { for (Set<ObjectID>::Element *E = owners.front(); E; E = E->next()) { Object *obj = ObjectDB::get_instance(E->get()); ERR_EXPLAIN("Object was deleted, while still owning a resource"); ERR_CONTINUE(!obj); //wtf //TODO store string obj->call("resource_changed", RES(this)); } }
void Skeleton::get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) const { ERR_FAIL_INDEX(p_bone, bones.size()); for (const List<uint32_t>::Element *E = bones[p_bone].nodes_bound.front(); E; E = E->next()) { Object *obj = ObjectDB::get_instance(E->get()); ERR_CONTINUE(!obj); p_bound->push_back(Object::cast_to<Node>(obj)); } }
void EditorReImportDialog::ok_pressed() { if (EditorFileSystem::get_singleton()->is_scanning()) { error->set_text(TTR("Please wait for scan to complete")); error->popup_centered_minsize(); return; } EditorProgress ep("reimport",TTR("Re-Importing"),items.size()); String reload_fname; if (scene_must_save && EditorNode::get_singleton()->get_edited_scene()) { reload_fname = EditorNode::get_singleton()->get_edited_scene()->get_filename(); EditorNode::get_singleton()->save_scene(reload_fname); EditorNode::get_singleton()->clear_scene(); } for(int i=0;i<items.size();i++) { String it = items[i]->get_metadata(0); ep.step(items[i]->get_text(0),i); print_line("reload import from: "+it); Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(it); ERR_CONTINUE(rimd.is_null()); String editor = rimd->get_editor(); Ref<EditorImportPlugin> eip = EditorImportExport::get_singleton()->get_import_plugin_by_name(editor); ERR_CONTINUE(eip.is_null()); Error err = eip->import(it,rimd); if (err!=OK) { EditorNode::add_io_error("Error Importing:\n "+it); } } if (reload_fname!="") { EditorNode::get_singleton()->load_scene(reload_fname); } EditorFileSystem::get_singleton()->scan_sources(); }
void BakedLightmap::_assign_lightmaps() { ERR_FAIL_COND(!light_data.is_valid()); for (int i = 0; i < light_data->get_user_count(); i++) { Ref<Texture> lightmap = light_data->get_user_lightmap(i); ERR_CONTINUE(!lightmap.is_valid()); Node *node = get_node(light_data->get_user_path(i)); int instance_idx = light_data->get_user_instance(i); if (instance_idx >= 0) { RID instance = node->call("get_bake_mesh_instance", instance_idx); if (instance.is_valid()) { VS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), lightmap->get_rid()); } } else { VisualInstance *vi = Object::cast_to<VisualInstance>(node); ERR_CONTINUE(!vi); VS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), lightmap->get_rid()); } } }
void Navigation::_navmesh_unlink(int p_id) { ERR_FAIL_COND(!navmesh_map.has(p_id)); NavMesh &nm=navmesh_map[p_id]; ERR_FAIL_COND(!nm.linked); print_line("UNLINK"); for (List<Polygon>::Element *E=nm.polygons.front();E;E=E->next()) { Polygon &p=E->get(); int ec = p.edges.size(); Polygon::Edge *edges=p.edges.ptr(); for(int i=0;i<ec;i++) { int next = (i+1)%ec; EdgeKey ek(edges[i].point,edges[next].point); Map<EdgeKey,Connection>::Element *C=connections.find(ek); ERR_CONTINUE(!C); if (C->get().B) { //disconnect C->get().B->edges[C->get().B_edge].C=NULL; C->get().B->edges[C->get().B_edge].C_edge=-1; C->get().A->edges[C->get().A_edge].C=NULL; C->get().A->edges[C->get().A_edge].C_edge=-1; if (C->get().A==&E->get()) { C->get().A=C->get().B; C->get().A_edge=C->get().B_edge; } C->get().B=NULL; C->get().B_edge=-1; } else { connections.erase(C); //erase } } } nm.polygons.clear(); nm.linked=false; }
static void _initialize_java_modules() { String modules = Globals::get_singleton()->get("android/modules"); Vector<String> mods = modules.split(",",false); __android_log_print(ANDROID_LOG_INFO,"godot","mod count: %i",mods.size()); if (mods.size()) { JNIEnv *env = ThreadAndroid::get_env(); jclass activityClass = env->FindClass("com/android/godot/Godot"); jmethodID getClassLoader = env->GetMethodID(activityClass,"getClassLoader", "()Ljava/lang/ClassLoader;"); jobject cls = env->CallObjectMethod(_godot_instance, getClassLoader); jclass classLoader = env->FindClass("java/lang/ClassLoader"); jmethodID findClass = env->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); for (int i=0;i<mods.size();i++) { String m = mods[i]; //jclass singletonClass = env->FindClass(m.utf8().get_data()); print_line("LOADING MODULE: "+m); jstring strClassName = env->NewStringUTF(m.utf8().get_data()); jclass singletonClass = (jclass)env->CallObjectMethod(cls, findClass, strClassName); if (!singletonClass) { ERR_EXPLAIN("Couldn't find singleton for class: "+m); ERR_CONTINUE(!singletonClass); } __android_log_print(ANDROID_LOG_INFO,"godot","****^*^*?^*^*class data %x",singletonClass); jmethodID initialize = env->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lcom/android/godot/Godot$SingletonBase;"); jobject obj = env->CallStaticObjectMethod(singletonClass,initialize,_godot_instance); __android_log_print(ANDROID_LOG_INFO,"godot","****^*^*?^*^*class instance %x",obj); jobject gob = env->NewGlobalRef(obj); } } }
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 ResourcePreloaderEditor::_update_library() { tree->clear(); tree->set_hide_root(true); TreeItem *root = tree->create_item(NULL); List<StringName> rnames; preloader->get_resource_list(&rnames); List<String> names; for (List<StringName>::Element *E = rnames.front(); E; E = E->next()) { names.push_back(E->get()); } names.sort(); for (List<String>::Element *E = names.front(); E; E = E->next()) { TreeItem *ti = tree->create_item(root); ti->set_cell_mode(0, TreeItem::CELL_MODE_STRING); ti->set_editable(0, true); ti->set_selectable(0, true); ti->set_text(0, E->get()); ti->set_metadata(0, E->get()); RES r = preloader->get_resource(E->get()); ERR_CONTINUE(r.is_null()); String type = r->get_class(); ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(type, "Object")); ti->set_tooltip(0, TTR("Instance:") + " " + r->get_path() + "\n" + TTR("Type:") + " " + type); ti->set_text(1, r->get_path()); ti->set_editable(1, false); ti->set_selectable(1, false); if (type == "PackedScene") { ti->add_button(1, get_icon("InstanceOptions", "EditorIcons"), BUTTON_OPEN_SCENE, false, TTR("Open in Editor")); } else { ti->add_button(1, get_icon("Load", "EditorIcons"), BUTTON_EDIT_RESOURCE, false, TTR("Open in Editor")); } ti->add_button(1, get_icon("Remove", "EditorIcons"), BUTTON_REMOVE, false, TTR("Remove")); } //player->add_resource("default",resource); }
void ExportTemplateManager::_http_download_mirror_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data) { if (p_status != HTTPRequest::RESULT_SUCCESS || p_code != 200) { EditorNode::get_singleton()->show_warning("Error getting the list of mirrors."); return; } String mirror_str; { PoolByteArray::Read r = p_data.read(); mirror_str.parse_utf8((const char *)r.ptr(), p_data.size()); } template_list_state->hide(); template_download_progress->hide(); Variant r; String errs; int errline; Error err = JSON::parse(mirror_str, r, errs, errline); if (err != OK) { EditorNode::get_singleton()->show_warning("Error parsing JSON of mirror list. Please report this issue!"); return; } bool mirrors_found = false; Dictionary d = r; print_line(r); if (d.has("mirrors")) { Array mirrors = d["mirrors"]; for (int i = 0; i < mirrors.size(); i++) { Dictionary m = mirrors[i]; ERR_CONTINUE(!m.has("url") || !m.has("name")); LinkButton *lb = memnew(LinkButton); lb->set_text(m["name"]); lb->connect("pressed", this, "_begin_template_download", varray(m["url"])); template_list->add_child(lb); mirrors_found = true; } } if (!mirrors_found) { EditorNode::get_singleton()->show_warning(TTR("No download links found for this version. Direct download is only available for official releases.")); return; } }
void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { ERR_FAIL_COND(!tile_map.has(p_id)); Vector<ShapeData> shapes_data; Transform2D default_transform = tile_get_shape_transform(p_id, 0); bool default_one_way = tile_get_shape_one_way(p_id, 0); for (int i = 0; i < p_shapes.size(); i++) { ShapeData s = ShapeData(); if (p_shapes[i].get_type() == Variant::OBJECT) { Ref<Shape2D> shape = p_shapes[i]; if (shape.is_null()) continue; s.shape = shape; s.shape_transform = default_transform; s.one_way_collision = default_one_way; } else if (p_shapes[i].get_type() == Variant::DICTIONARY) { Dictionary d = p_shapes[i]; if (d.has("shape") && d["shape"].get_type() == Variant::OBJECT) s.shape = d["shape"]; else continue; if (d.has("shape_transform") && d["shape_transform"].get_type() == Variant::TRANSFORM2D) s.shape_transform = d["shape_transform"]; else if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2) s.shape_transform = Transform2D(0, (Vector2)d["shape_offset"]); else s.shape_transform = default_transform; if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL) s.one_way_collision = d["one_way"]; else s.one_way_collision = default_one_way; } else { ERR_EXPLAIN("Expected an array of objects or dictionaries for tile_set_shapes"); ERR_CONTINUE(true); } shapes_data.push_back(s); } tile_map[p_id].shapes_data = shapes_data; }
void GridMap::_octant_enter_tree(const OctantKey &p_key) { ERR_FAIL_COND(!octant_map.has(p_key)); if (navigation) { Octant &g = *octant_map[p_key]; Vector3 ofs(cell_size * 0.5 * int(center_x), cell_size * 0.5 * int(center_y), cell_size * 0.5 * int(center_z)); _octant_clear_navmesh(p_key); for (Map<int, Octant::ItemInstances>::Element *E = g.items.front(); E; E = E->next()) { Octant::ItemInstances &ii = E->get(); for (Set<IndexKey>::Element *F = ii.cells.front(); F; F = F->next()) { IndexKey ik = F->get(); Map<IndexKey, Cell>::Element *C = cell_map.find(ik); ERR_CONTINUE(!C); Vector3 cellpos = Vector3(ik.x, ik.y, ik.z); Transform xform; if (clip && ((clip_above && cellpos[clip_axis] > clip_floor) || (!clip_above && cellpos[clip_axis] < clip_floor))) { xform.basis.set_zero(); } else { xform.basis.set_orthogonal_index(C->get().rot); } xform.set_origin(cellpos * cell_size + ofs); xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); // add the item's navmesh at given xform to GridMap's Navigation ancestor if (ii.navmesh.is_valid()) { int nm_id = navigation->navmesh_create(ii.navmesh, xform, this); Octant::NavMesh nm; nm.id = nm_id; nm.xform = xform; g.navmesh_ids[ik] = nm; } } } } }
void ResourcePreloaderEditor::_update_library() { tree->clear(); tree->set_hide_root(true); TreeItem *root = tree->create_item(NULL); List<StringName> rnames; preloader->get_resource_list(&rnames); List<String> names; for(List<StringName>::Element *E=rnames.front();E;E=E->next()) { names.push_back(E->get()); } names.sort(); for(List<String>::Element *E=names.front();E;E=E->next()) { TreeItem *ti = tree->create_item(root); ti->set_cell_mode(0,TreeItem::CELL_MODE_STRING); ti->set_editable(0,true); ti->set_selectable(0,true); ti->set_text(0,E->get()); ti->set_metadata(0,E->get()); RES r = preloader->get_resource(E->get()); ERR_CONTINUE(r.is_null()); ti->set_tooltip(0,r->get_path()); String type = r->get_type(); ti->set_text(1,type); ti->set_selectable(1,false); if (has_icon(type,"EditorIcons")) ti->set_icon( 1, get_icon(type,"EditorIcons") ); } //player->add_resource("default",resource); }
void ResourcePreloader::_set_resources(const Array& p_data) { resources.clear(); ERR_FAIL_COND(p_data.size()!=2); DVector<String> names=p_data[0]; Array resdata=p_data[1]; ERR_FAIL_COND(names.size()!=resdata.size()); for(int i=0;i<resdata.size();i++) { String name=names[i]; RES resource = resdata[i]; ERR_CONTINUE( !resource.is_valid() ); resources[name]=resource; //add_resource(name,resource); } }
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 ScriptEditor::get_breakpoints(List<String> *p_breakpoints) { for(int i=0;i<tab_container->get_child_count();i++) { ScriptTextEditor *ste = tab_container->get_child(i)->cast_to<ScriptTextEditor>(); if (!ste) continue; List<int> bpoints; ste->get_text_edit()->get_breakpoints(&bpoints); Ref<Script> script = ste->get_edited_script(); String base = script->get_path(); ERR_CONTINUE( base.begins_with("local://") || base=="" ); for(List<int>::Element *E=bpoints.front();E;E=E->next()) { p_breakpoints->push_back(base+":"+itos(E->get()+1)); } } }
void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_for_script) { if (!bool(EditorSettings::get_singleton()->get("external_editor/use_external_editor"))) return; Set<Ref<Script> > scripts; Node *base = get_tree()->get_edited_scene_root(); if (base) { _find_changed_scripts_for_external_editor(base,base,scripts); } for (Set<Ref<Script> >::Element *E=scripts.front();E;E=E->next()) { Ref<Script> script = E->get(); if (p_for_script.is_valid() && p_for_script!=script) continue; if (script->get_path()=="" || script->get_path().find("local://")!=-1 || script->get_path().find("::")!=-1) { continue; //internal script, who cares, though weird } uint64_t last_date = script->get_last_modified_time(); uint64_t date = FileAccess::get_modified_time(script->get_path()); if (last_date!=date) { Ref<Script> rel_script = ResourceLoader::load(script->get_path(),script->get_type(),true); ERR_CONTINUE(!rel_script.is_valid()); script->set_source_code( rel_script->get_source_code() ); script->set_last_modified_time( rel_script->get_last_modified_time() ); script->update_exports(); } } }
void VisualServerViewport::draw_viewports() { //sort viewports //draw viewports clear_color = GLOBAL_GET("rendering/viewport/default_clear_color"); active_viewports.sort_custom<ViewportSort>(); for (int i = 0; i < active_viewports.size(); i++) { Viewport *vp = active_viewports[i]; if (vp->update_mode == VS::VIEWPORT_UPDATE_DISABLED) continue; ERR_CONTINUE(!vp->render_target.is_valid()); bool visible = vp->viewport_to_screen_rect != Rect2() || vp->update_mode == VS::VIEWPORT_UPDATE_ALWAYS || vp->update_mode == VS::VIEWPORT_UPDATE_ONCE; if (!visible) continue; VSG::rasterizer->set_current_render_target(vp->render_target); _draw_viewport(vp); if (vp->viewport_to_screen_rect != Rect2()) { //copy to screen if set as such VSG::rasterizer->set_current_render_target(RID()); VSG::rasterizer->blit_render_target_to_screen(vp->render_target, vp->viewport_to_screen_rect, vp->viewport_to_screen); } if (vp->update_mode == VS::VIEWPORT_UPDATE_ONCE) { vp->update_mode = VS::VIEWPORT_UPDATE_DISABLED; } } }
void ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_progress) { FileAccess *fa = NULL; zlib_filefunc_def io = zipio_create_io_from_file(&fa); unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io); if (!pkg) { EditorNode::get_singleton()->show_warning(TTR("Can't open export templates zip.")); return; } int ret = unzGoToFirstFile(pkg); int fc = 0; //count them and find version String version; while (ret == UNZ_OK) { unz_file_info info; char fname[16384]; ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); String file = fname; if (file.ends_with("version.txt")) { Vector<uint8_t> data; data.resize(info.uncompressed_size); //read unzOpenCurrentFile(pkg); ret = unzReadCurrentFile(pkg, data.ptrw(), data.size()); unzCloseCurrentFile(pkg); String data_str; data_str.parse_utf8((const char *)data.ptr(), data.size()); data_str = data_str.strip_edges(); // Version number should be of the form major.minor[.patch].status[.module_config] // so it can in theory have 3 or more slices. if (data_str.get_slice_count(".") < 3) { EditorNode::get_singleton()->show_warning(vformat(TTR("Invalid version.txt format inside templates: %s."), data_str)); unzClose(pkg); return; } version = data_str; } if (file.get_file().size() != 0) { fc++; } ret = unzGoToNextFile(pkg); } if (version == String()) { EditorNode::get_singleton()->show_warning(TTR("No version.txt found inside templates.")); unzClose(pkg); return; } String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(version); DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); Error err = d->make_dir_recursive(template_path); if (err != OK) { EditorNode::get_singleton()->show_warning(TTR("Error creating path for templates:") + "\n" + template_path); unzClose(pkg); return; } memdelete(d); ret = unzGoToFirstFile(pkg); EditorProgress *p = NULL; if (p_use_progress) { p = memnew(EditorProgress("ltask", TTR("Extracting Export Templates"), fc)); } fc = 0; while (ret == UNZ_OK) { //get filename unz_file_info info; char fname[16384]; unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); String file = String(fname).get_file(); if (file.size() == 0) { ret = unzGoToNextFile(pkg); continue; } Vector<uint8_t> data; data.resize(info.uncompressed_size); //read unzOpenCurrentFile(pkg); unzReadCurrentFile(pkg, data.ptrw(), data.size()); unzCloseCurrentFile(pkg); if (p) { p->step(TTR("Importing:") + " " + file, fc); } FileAccess *f = FileAccess::open(template_path.plus_file(file), FileAccess::WRITE); if (!f) { ret = unzGoToNextFile(pkg); fc++; ERR_CONTINUE(!f); } f->store_buffer(data.ptr(), data.size()); memdelete(f); ret = unzGoToNextFile(pkg); fc++; } if (p) { memdelete(p); } unzClose(pkg); _update_template_list(); }
void RichTextLabel::_process_line(ItemFrame *p_frame,const Vector2& p_ofs,int &y, int p_width, int p_line, ProcessMode p_mode,const Ref<Font> &p_base_font,const Color &p_base_color,const Point2i& p_click_pos,Item **r_click_item,int *r_click_char,bool *r_outside,int p_char_count) { RID ci; if (r_outside) *r_outside=false; if (p_mode==PROCESS_DRAW) { ci=get_canvas_item(); if (r_click_item) *r_click_item=NULL; } Line &l = p_frame->lines[p_line]; Item *it = l.from; int line_ofs=0; int margin=_find_margin(it,p_base_font); Align align=_find_align(it);; int line=0; int spaces=0; if (p_mode!=PROCESS_CACHE) { ERR_FAIL_INDEX(line,l.offset_caches.size()); line_ofs = l.offset_caches[line]; } if (p_mode==PROCESS_CACHE) { l.offset_caches.clear(); l.height_caches.clear(); l.char_count=0; l.minimum_width=0; } int wofs=margin; int spaces_size=0; int align_ofs=0; if (p_mode!=PROCESS_CACHE && align!=ALIGN_FILL) wofs+=line_ofs; int begin=wofs; Ref<Font> cfont = _find_font(it); if (cfont.is_null()) cfont=p_base_font; //line height should be the font height for the first time, this ensures that an empty line will never have zero height and succesive newlines are displayed int line_height=cfont->get_height(); Variant meta; #define NEW_LINE \ {\ if (p_mode!=PROCESS_CACHE) {\ line++;\ if (line < l.offset_caches.size())\ line_ofs=l.offset_caches[line];\ wofs=margin;\ if (align!=ALIGN_FILL)\ wofs+=line_ofs;\ } else {\ int used=wofs-margin;\ switch(align) {\ case ALIGN_LEFT: l.offset_caches.push_back(0); break;\ case ALIGN_CENTER: l.offset_caches.push_back(((p_width-margin)-used)/2); break;\ case ALIGN_RIGHT: l.offset_caches.push_back(((p_width-margin)-used)); break;\ case ALIGN_FILL: l.offset_caches.push_back((p_width-margin)-used/*+spaces_size*/); break;\ }\ l.height_caches.push_back(line_height);\ l.space_caches.push_back(spaces);\ }\ y+=line_height+get_constant(SceneStringNames::get_singleton()->line_separation);\ line_height=0;\ spaces=0;\ spaces_size=0;\ wofs=begin;\ align_ofs=0;\ if (p_mode!=PROCESS_CACHE) {\ lh=line<l.height_caches.size()?l.height_caches[line]:1;\ }\ if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh && p_click_pos.x<p_ofs.x+wofs) {\ if (r_outside) *r_outside=true;\ *r_click_item=it;\ *r_click_char=rchar;\ return;\ }\ } #define ENSURE_WIDTH(m_width) \ if (p_mode==PROCESS_CACHE) { \ l.minimum_width=MAX(l.minimum_width,wofs+m_width);\ }\ if (wofs + m_width > p_width) {\ if (p_mode==PROCESS_CACHE) {\ if (spaces>0) \ spaces-=1;\ }\ if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh && p_click_pos.x>p_ofs.x+wofs) {\ if (r_outside) *r_outside=true; \ *r_click_item=it;\ *r_click_char=rchar;\ return;\ }\ NEW_LINE\ } #define ADVANCE(m_width) \ {\ if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh && p_click_pos.x>=p_ofs.x+wofs && p_click_pos.x<p_ofs.x+wofs+m_width) {\ if (r_outside) *r_outside=false; \ *r_click_item=it;\ *r_click_char=rchar;\ return;\ }\ wofs+=m_width;\ } #define CHECK_HEIGHT( m_height ) \ if (m_height > line_height) {\ line_height=m_height;\ } Color selection_fg; Color selection_bg; if (p_mode==PROCESS_DRAW) { selection_fg = get_color("font_color_selected"); selection_bg = get_color("selection_color"); } int rchar=0; int lh=0; while (it) { switch(it->type) { case ITEM_TEXT: { ItemText *text = static_cast<ItemText*>(it); Ref<Font> font=_find_font(it); if (font.is_null()) font=p_base_font; const CharType *c = text->text.c_str(); const CharType *cf=c; int fh=font->get_height(); int ascent = font->get_ascent(); Color color; bool underline=false; if (p_mode==PROCESS_DRAW) { color=_find_color(text,p_base_color); underline=_find_underline(text); if (_find_meta(text,&meta)) { underline=true; } } else if (p_mode==PROCESS_CACHE) { l.char_count+=text->text.length(); } rchar=0; while(*c) { int end=0; int w=0; int fw=0; lh=0; if (p_mode!=PROCESS_CACHE) { lh=line<l.height_caches.size()?l.height_caches[line]:1; } while (c[end]!=0 && !(end && c[end-1]==' ' && c[end]!=' ')) { int cw = font->get_char_size(c[end],c[end+1]).width; if (c[end]=='\t') { cw=tab_size*font->get_char_size(' ').width; } if (end>0 && w+cw+begin > p_width ) { break; //don't allow lines longer than assigned width } w+=cw; fw+=cw; end++; } ENSURE_WIDTH(w); if (end && c[end-1]==' ') { if (p_mode==PROCESS_CACHE) { spaces_size+=font->get_char_size(' ').width; } else if (align==ALIGN_FILL) { int ln = MIN(l.offset_caches.size()-1,line); if (l.space_caches[ln]) { align_ofs = spaces * l.offset_caches[ln] / l.space_caches[ln]; } } spaces++; } { int ofs=0; for(int i=0;i<end;i++) { int pofs=wofs+ofs; if (p_mode==PROCESS_POINTER && r_click_char && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh) { //int o = (wofs+w)-p_click_pos.x; int cw=font->get_char_size(c[i],c[i+1]).x; if (c[i]=='\t') { cw=tab_size*font->get_char_size(' ').width; } if (p_click_pos.x-cw/2>p_ofs.x+align_ofs+pofs) { rchar=int((&c[i])-cf); } ofs+=cw; } else if (p_mode==PROCESS_DRAW) { bool selected=false; if (selection.active) { int cofs = (&c[i])-cf; if ((text->index > selection.from->index || (text->index == selection.from->index && cofs >=selection.from_char)) && (text->index < selection.to->index || (text->index == selection.to->index && cofs <=selection.to_char))) { selected=true; } } int cw=0; bool visible = visible_characters<0 || p_char_count<visible_characters; if (c[i]=='\t') visible=false; if (selected) { cw = font->get_char_size(c[i],c[i+1]).x; draw_rect(Rect2(p_ofs.x+pofs,p_ofs.y+y,cw,lh),selection_bg); if (visible) font->draw_char(ci,p_ofs+Point2(align_ofs+pofs,y+lh-(fh-ascent)),c[i],c[i+1],selection_fg); } else { if (visible) cw=font->draw_char(ci,p_ofs+Point2(align_ofs+pofs,y+lh-(fh-ascent)),c[i],c[i+1],color); } p_char_count++; if (c[i]=='\t') { cw=tab_size*font->get_char_size(' ').width; } if (underline) { Color uc=color; uc.a*=0.5; int uy = y+lh-fh+ascent+2; VS::get_singleton()->canvas_item_add_line(ci,p_ofs+Point2(align_ofs+pofs,uy),p_ofs+Point2(align_ofs+pofs+cw,uy),uc); } ofs+=cw; } } } ADVANCE(fw); CHECK_HEIGHT(fh); //must be done somewhere c=&c[end]; } } break; case ITEM_IMAGE: { lh=0; if (p_mode!=PROCESS_CACHE) lh = line<l.height_caches.size()?l.height_caches[line]:1; else l.char_count+=1; //images count as chars too ItemImage *img = static_cast<ItemImage*>(it); Ref<Font> font=_find_font(it); if (font.is_null()) font=p_base_font; if (p_mode==PROCESS_POINTER && r_click_char) *r_click_char=0; ENSURE_WIDTH( img->image->get_width() ); bool visible = visible_characters<0 || p_char_count<visible_characters; if (p_mode==PROCESS_DRAW && visible) { img->image->draw(ci,p_ofs+Point2(align_ofs+wofs,y+lh-font->get_descent()-img->image->get_height())); } p_char_count++; ADVANCE( img->image->get_width() ); CHECK_HEIGHT( (img->image->get_height()+font->get_descent()) ); } break; case ITEM_NEWLINE: { lh=0; if (p_mode!=PROCESS_CACHE) lh = line<l.height_caches.size()?l.height_caches[line]:1; } break; case ITEM_TABLE: { lh=0; ItemTable *table = static_cast<ItemTable*>(it); int hseparation=get_constant("table_hseparation"); int vseparation=get_constant("table_vseparation"); Color ccolor = _find_color(table,p_base_color); Vector2 draw_ofs = Point2(wofs,y); if (p_mode==PROCESS_CACHE) { int idx=0; //set minimums to zero for(int i=0;i<table->columns.size();i++) { table->columns[i].min_width=0; table->columns[i].width=0; } //compute minimum width for each cell for (List<Item*>::Element *E=table->subitems.front();E;E=E->next()) { ERR_CONTINUE(E->get()->type!=ITEM_FRAME); //children should all be frames ItemFrame *frame = static_cast<ItemFrame*>(E->get()); int column = idx % table->columns.size(); int ly=0; for(int i=0;i<frame->lines.size();i++) { _process_line(frame,Point2(),ly,p_width,i,PROCESS_CACHE,cfont,Color()); table->columns[column].min_width=MAX( table->columns[i].min_width, frame->lines[i].minimum_width ); } idx++; } //compute available width and total radio (for expanders) int total_ratio=0; int available_width=p_width - hseparation * (table->columns.size() -1); table->total_width=hseparation; for(int i=0;i<table->columns.size();i++) { available_width-=table->columns[i].min_width; if (table->columns[i].expand) total_ratio+=table->columns[i].expand_ratio; } //assign actual widths for(int i=0;i<table->columns.size();i++) { table->columns[i].width = table->columns[i].min_width; if (table->columns[i].expand) table->columns[i].width+=table->columns[i].expand_ratio*available_width/total_ratio; table->total_width+=table->columns[i].width+hseparation; } //compute caches properly again with the right width idx=0; for (List<Item*>::Element *E=table->subitems.front();E;E=E->next()) { ERR_CONTINUE(E->get()->type!=ITEM_FRAME); //children should all be frames ItemFrame *frame = static_cast<ItemFrame*>(E->get()); int column = idx % table->columns.size(); for(int i=0;i<frame->lines.size();i++) { int ly=0; _process_line(frame,Point2(),ly,table->columns[column].width,i,PROCESS_CACHE,cfont,Color()); frame->lines[i].height_cache=ly; //actual height frame->lines[i].height_accum_cache=ly; //actual height } idx++; } } Point2 offset(align_ofs+hseparation,vseparation); int row_height=0; //draw using computed caches int idx=0; for (List<Item*>::Element *E=table->subitems.front();E;E=E->next()) { ERR_CONTINUE(E->get()->type!=ITEM_FRAME); //children should all be frames ItemFrame *frame = static_cast<ItemFrame*>(E->get()); int column = idx % table->columns.size(); int ly=0; int yofs=0; int lines_h = frame->lines[frame->lines.size()-1].height_accum_cache - (frame->lines[0].height_accum_cache - frame->lines[0].height_cache); int lines_ofs = p_ofs.y+offset.y+draw_ofs.y; bool visible = lines_ofs < get_size().height && lines_ofs+lines_h >=0; for(int i=0;i<frame->lines.size();i++) { if (visible) { if (p_mode==PROCESS_DRAW) { _process_line(frame,p_ofs+offset+draw_ofs+Vector2(0,yofs),ly,table->columns[column].width,i,PROCESS_DRAW,cfont,ccolor); } else if (p_mode==PROCESS_POINTER) { _process_line(frame,p_ofs+offset+draw_ofs+Vector2(0,yofs),ly,table->columns[column].width,i,PROCESS_POINTER,cfont,ccolor,p_click_pos,r_click_item,r_click_char,r_outside); } } yofs+=frame->lines[i].height_cache; if (p_mode==PROCESS_CACHE) { frame->lines[i].height_accum_cache=offset.y+draw_ofs.y+frame->lines[i].height_cache; } } row_height=MAX(yofs,row_height); offset.x+=table->columns[column].width+hseparation; if (column==table->columns.size()-1) { offset.y+=row_height+vseparation; offset.x=hseparation; row_height=0; } idx++; } int total_height = offset.y; if (row_height) { total_height=row_height+vseparation; } ADVANCE( table->total_width ); CHECK_HEIGHT( total_height ); } break; default: {} } Item *itp = it; it = _get_next_item(it); if (p_mode == PROCESS_POINTER && r_click_item && itp && !it && p_click_pos.y>p_ofs.y+y+lh) { //at the end of all, return this if (r_outside) *r_outside=true; *r_click_item=itp; *r_click_char=rchar; return; } if (it && (p_line+1 < p_frame->lines.size()) && p_frame->lines[p_line+1].from==it) { if (p_mode==PROCESS_POINTER && r_click_item && p_click_pos.y>=p_ofs.y+y && p_click_pos.y<=p_ofs.y+y+lh) { //went to next line, but pointer was on the previous one if (r_outside) *r_outside=true; *r_click_item=itp; *r_click_char=rchar; return; } break; } } NEW_LINE; #undef NEW_LINE #undef ENSURE_WIDTH #undef ADVANCE #undef CHECK_HEIGHT }
void ScriptDebuggerRemote::_poll_events() { //this si called from ::idle_poll, happens only when running the game, //does not get called while on debug break while (packet_peer_stream->get_available_packet_count() > 0) { _get_output(); //send over output_strings Variant var; Error err = packet_peer_stream->get_var(var); ERR_CONTINUE(err != OK); ERR_CONTINUE(var.get_type() != Variant::ARRAY); Array cmd = var; ERR_CONTINUE(cmd.size() == 0); ERR_CONTINUE(cmd[0].get_type() != Variant::STRING); String command = cmd[0]; //cmd.remove(0); if (command == "break") { if (get_break_language()) debug(get_break_language()); } else if (command == "request_scene_tree") { if (request_scene_tree) request_scene_tree(request_scene_tree_ud); } else if (command == "request_video_mem") { _send_video_memory(); } else if (command == "inspect_object") { ObjectID id = cmd[1]; _send_object_id(id); } else if (command == "set_object_property") { _set_object_property(cmd[1], cmd[2], cmd[3]); } else if (command == "start_profiling") { for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptServer::get_language(i)->profiling_start(); } max_frame_functions = cmd[1]; profiler_function_signature_map.clear(); profiling = true; frame_time = 0; idle_time = 0; fixed_time = 0; fixed_frame_time = 0; print_line("PROFILING ALRIGHT!"); } else if (command == "stop_profiling") { for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptServer::get_language(i)->profiling_stop(); } profiling = false; _send_profiling_data(false); print_line("PROFILING END!"); } else if (command == "reload_scripts") { reload_all_scripts = true; } else if (command == "breakpoint") { bool set = cmd[3]; if (set) insert_breakpoint(cmd[2], cmd[1]); else remove_breakpoint(cmd[2], cmd[1]); } else { _parse_live_edit(cmd); } } }