Esempio n. 1
0
PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) {

	PropertyInfo pi;

	if (p_dict.has("type"))
		pi.type = Variant::Type(int(p_dict["type"]));

	if (p_dict.has("name"))
		pi.name = p_dict["name"];

	if (p_dict.has("class_name"))
		pi.class_name = p_dict["class_name"];

	if (p_dict.has("hint"))
		pi.hint = PropertyHint(int(p_dict["hint"]));

	if (p_dict.has("hint_string"))

		pi.hint_string = p_dict["hint_string"];

	if (p_dict.has("usage"))
		pi.usage = p_dict["usage"];

	return pi;
}
Esempio n. 2
0
void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
	script->get_script_property_list(p_properties);

	NativeScriptDesc *script_data = GET_SCRIPT_DESC();

	while (script_data) {

		Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_get_property_list");
		if (E) {

			godot_variant result;
			result = E->get().method.method((godot_object *)owner,
					E->get().method.method_data,
					userdata,
					0,
					NULL);
			Variant res = *(Variant *)&result;
			godot_variant_destroy(&result);

			if (res.get_type() != Variant::ARRAY) {
				ERR_EXPLAIN("_get_property_list must return an array of dictionaries");
				ERR_FAIL();
			}

			Array arr = res;
			for (int i = 0; i < arr.size(); i++) {
				Dictionary d = arr[i];

				ERR_CONTINUE(!d.has("name"));
				ERR_CONTINUE(!d.has("type"));

				PropertyInfo info;

				info.type = Variant::Type(d["type"].operator int64_t());
				ERR_CONTINUE(info.type < 0 || info.type >= Variant::VARIANT_MAX);

				info.name = d["name"];
				ERR_CONTINUE(info.name == "");

				if (d.has("hint")) {
					info.hint = PropertyHint(d["hint"].operator int64_t());
				}

				if (d.has("hint_string")) {
					info.hint_string = d["hint_string"];
				}

				if (d.has("usage")) {
					info.usage = d["usage"];
				}

				p_properties->push_back(info);
			}
		}

		script_data = script_data->base_data;
	}
	return;
}
Esempio n. 3
0
void VisualScript::_set_variable_info(const StringName& p_name,const Dictionary& p_info) {

	PropertyInfo pinfo;
	if (p_info.has("type"))
		pinfo.type=Variant::Type(int(p_info["type"]));
	if (p_info.has("name"))
		pinfo.name=p_info["name"];
	if (p_info.has("hint"))
		pinfo.hint=PropertyHint(int(p_info["hint"]));
	if (p_info.has("hint_string"))
		pinfo.hint_string=p_info["hint_string"];
	if (p_info.has("usage"))
		pinfo.usage=p_info["usage"];

	set_variable_info(p_name,pinfo);
}
void ScriptEditorDebugger::_parse_message(const String& p_msg,const Array& p_data) {



	if (p_msg=="debug_enter") {

		Array msg;
		msg.push_back("get_stack_dump");
		ppeer->put_var(msg);
		ERR_FAIL_COND(p_data.size()!=2);
		bool can_continue=p_data[0];
		String error = p_data[1];
		step->set_disabled(!can_continue);
		next->set_disabled(!can_continue);
		reason->set_text(error);
		reason->set_tooltip(error);
		breaked=true;
		dobreak->set_disabled(true);
		docontinue->set_disabled(false);
		emit_signal("breaked",true,can_continue);
		OS::get_singleton()->move_window_to_foreground();
		if (error!="") {
			tabs->set_current_tab(0);
		}

		profiler->set_enabled(false);

		EditorNode::get_singleton()->get_pause_button()->set_pressed(true);


		EditorNode::get_singleton()->make_bottom_panel_item_visible(this);

	} else if (p_msg=="debug_exit") {

		breaked=false;
		step->set_disabled(true);
		next->set_disabled(true);
		reason->set_text("");
		reason->set_tooltip("");
		back->set_disabled(true);
		forward->set_disabled(true);
		dobreak->set_disabled(false);
		docontinue->set_disabled(true);
		emit_signal("breaked",false,false,Variant());
		//tabs->set_current_tab(0);
		profiler->set_enabled(true);
		profiler->disable_seeking();

		EditorNode::get_singleton()->get_pause_button()->set_pressed(false);


	} else if (p_msg=="message:click_ctrl") {

		clicked_ctrl->set_text(p_data[0]);
		clicked_ctrl_type->set_text(p_data[1]);

	} else if (p_msg=="message:scene_tree") {

		inspect_scene_tree->clear();
		Map<int,TreeItem*> lv;

		updating_scene_tree=true;

		for(int i=0;i<p_data.size();i+=4) {

			TreeItem *p;
			int level = p_data[i];
			if (level==0) {
				p = NULL;
			} else {
				ERR_CONTINUE(!lv.has(level-1));
				p=lv[level-1];
			}


			TreeItem *it = inspect_scene_tree->create_item(p);

			ObjectID id = ObjectID(p_data[i+3]);

			it->set_text(0,p_data[i+1]);
			if (has_icon(p_data[i+2],"EditorIcons"))
				it->set_icon(0,get_icon(p_data[i+2],"EditorIcons"));
			it->set_metadata(0,id);
			if (id==inspected_object_id) {
				it->select(0);
			}

			if (p) {
				if (!unfold_cache.has(id)) {
					it->set_collapsed(true);
				}
			} else {
				if (unfold_cache.has(id)) { //reverse for root
					it->set_collapsed(true);
				}
			}
			lv[level]=it;
		}
		updating_scene_tree=false;

		le_clear->set_disabled(false);
		le_set->set_disabled(false);
	} else if (p_msg=="message:inspect_object") {


		ObjectID id = p_data[0];
		String type = p_data[1];
		Variant path = p_data[2]; //what to do yet, i don't  know
		int prop_count=p_data[3];

		int idx=4;


		if (inspected_object->last_edited_id!=id) {
			inspected_object->prop_list.clear();
			inspected_object->prop_values.clear();
		}

		for(int i=0;i<prop_count;i++) {

			PropertyInfo pinfo;
			pinfo.name=p_data[idx++];
			pinfo.type=Variant::Type(int(p_data[idx++]));
			pinfo.hint=PropertyHint(int(p_data[idx++]));
			pinfo.hint_string=p_data[idx++];
			if (pinfo.name.begins_with("*")) {
				pinfo.name=pinfo.name.substr(1,pinfo.name.length());
				pinfo.usage=PROPERTY_USAGE_CATEGORY;
			} else {
				pinfo.usage=PROPERTY_USAGE_EDITOR;
			}

			if (inspected_object->last_edited_id!=id) {
				//don't update.. it's the same, instead refresh
				inspected_object->prop_list.push_back(pinfo);
			}


			inspected_object->prop_values[pinfo.name]=p_data[idx++];

			if (inspected_object->last_edited_id==id) {
				//same, just update value, don't rebuild
				inspected_object->update_single(pinfo.name.ascii().get_data());
			}

		}



		if (inspected_object->last_edited_id!=id) {
			//only if different
			inspected_object->update();
		}

		inspected_object->last_edited_id=id;


		inspect_properties->edit(inspected_object);

	} else if (p_msg=="message:video_mem") {

		vmem_tree->clear();
		TreeItem* root=vmem_tree->create_item();

		int total=0;

		for(int i=0;i<p_data.size();i+=4) {

			TreeItem *it = vmem_tree->create_item(root);
			String type=p_data[i+1];
			int bytes=p_data[i+3].operator int();
			it->set_text(0,p_data[i+0]); //path
			it->set_text(1,type); //type
			it->set_text(2,p_data[i+2]); //type
			it->set_text(3,String::humanize_size(bytes)); //type
			total+=bytes;

			if (has_icon(type,"EditorIcons"))
				it->set_icon(0,get_icon(type,"EditorIcons"));
		}

		vmem_total->set_tooltip(TTR("Bytes:")+" "+itos(total));
		vmem_total->set_text(String::humanize_size(total));

	} else if (p_msg=="stack_dump") {

		stack_dump->clear();
		TreeItem *r = stack_dump->create_item();

		for(int i=0;i<p_data.size();i++) {

			Dictionary d = p_data[i];
			ERR_CONTINUE(!d.has("function"));
			ERR_CONTINUE(!d.has("file"));
			ERR_CONTINUE(!d.has("line"));
			ERR_CONTINUE(!d.has("id"));
			TreeItem *s = stack_dump->create_item(r);
			d["frame"]=i;
			s->set_metadata(0,d);

//			String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"])+" - at func: "+d["function"];
			String line = itos(i)+" - "+String(d["file"])+":"+itos(d["line"]);
			s->set_text(0,line);

			if (i==0)
				s->select(0);
		}
	} else if (p_msg=="stack_frame_vars") {


		variables->clear();



		int ofs =0;
		int mcount = p_data[ofs];

		ofs++;
		for(int i=0;i<mcount;i++) {

			String n = p_data[ofs+i*2+0];
			Variant v = p_data[ofs+i*2+1];

			if (n.begins_with("*")) {

				n=n.substr(1,n.length());
			}

			variables->add_property("members/"+n,v);
		}
		ofs+=mcount*2;

		mcount = p_data[ofs];

		ofs++;
		for(int i=0;i<mcount;i++) {

			String n = p_data[ofs+i*2+0];
			Variant v = p_data[ofs+i*2+1];

			if (n.begins_with("*")) {

				n=n.substr(1,n.length());
			}


			variables->add_property("locals/"+n,v);
		}

		variables->update();
		inspector->edit(variables);

	} else if (p_msg=="output") {

		//OUT
		for(int i=0;i<p_data.size();i++) {

			String t = p_data[i];
			//LOG

			if (EditorNode::get_log()->is_hidden()) {
				log_forced_visible=true;
				if (EditorNode::get_singleton()->are_bottom_panels_hidden()) {
					EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log());
				}
			}
			EditorNode::get_log()->add_message(t);

		}

	} else if (p_msg=="performance") {
		Array arr = p_data[0];
		Vector<float> p;
		p.resize(arr.size());
		for(int i=0;i<arr.size();i++) {
			p[i]=arr[i];
			if (i<perf_items.size()) {
				perf_items[i]->set_text(1,rtos(p[i]));
				if (p[i]>perf_max[i])
					perf_max[i]=p[i];
			}

		}
		perf_history.push_front(p);
		perf_draw->update();

	} else if (p_msg=="error") {

		Array err = p_data[0];

		Array vals;
		vals.push_back(err[0]);
		vals.push_back(err[1]);
		vals.push_back(err[2]);
		vals.push_back(err[3]);

		bool warning = err[9];
		bool e;
		String time = String("%d:%02d:%02d:%04d").sprintf(vals,&e);
		String txt=time+" - "+(err[8].is_zero()?String(err[7]):String(err[8]));

		String tooltip=TTR("Type:")+String(warning?TTR("Warning"):TTR("Error"));
		tooltip+="\n"+TTR("Description:")+" "+String(err[8]);
		tooltip+="\n"+TTR("Time:")+" "+time;
		tooltip+="\nC "+TTR("Error:")+" "+String(err[7]);
		tooltip+="\nC "+TTR("Source:")+" "+String(err[5])+":"+String(err[6]);
		tooltip+="\nC "+TTR("Function:")+" "+String(err[4]);



		error_list->add_item(txt,EditorNode::get_singleton()->get_gui_base()->get_icon(warning?"Warning":"Error","EditorIcons"));
		error_list->set_item_tooltip( error_list->get_item_count() -1,tooltip );

		int scc = p_data[1];

		Array stack;
		stack.resize(scc);
		for(int i=0;i<scc;i++) {
			stack[i]=p_data[2+i];
		}

		error_list->set_item_metadata( error_list->get_item_count() -1,stack );

		error_count++;
		/*
		int count = p_data[1];

		Array cstack;

		OutputError oe = errors.front()->get();

		packet_peer_stream->put_var(oe.hr);
		packet_peer_stream->put_var(oe.min);
		packet_peer_stream->put_var(oe.sec);
		packet_peer_stream->put_var(oe.msec);
		packet_peer_stream->put_var(oe.source_func);
		packet_peer_stream->put_var(oe.source_file);
		packet_peer_stream->put_var(oe.source_line);
		packet_peer_stream->put_var(oe.error);
		packet_peer_stream->put_var(oe.error_descr);
		packet_peer_stream->put_var(oe.warning);
		packet_peer_stream->put_var(oe.callstack);
		*/

	} else if (p_msg=="profile_sig") {
		//cache a signature
		print_line("SIG: "+String(Variant(p_data)));
		profiler_signature[p_data[1]]=p_data[0];

	} else if (p_msg=="profile_frame" || p_msg=="profile_total") {

		EditorProfiler::Metric metric;
		metric.valid=true;
		metric.frame_number=p_data[0];
		metric.frame_time=p_data[1];
		metric.idle_time=p_data[2];
		metric.fixed_time=p_data[3];
		metric.fixed_frame_time=p_data[4];
		int frame_data_amount = p_data[6];
		int frame_function_amount = p_data[7];


		if (frame_data_amount) {
			EditorProfiler::Metric::Category frame_time;
			frame_time.signature="category_frame_time";
			frame_time.name="Frame Time";
			frame_time.total_time=metric.frame_time;

			EditorProfiler::Metric::Category::Item item;
			item.calls=1;
			item.line=0;
			item.name="Fixed Time";
			item.total=metric.fixed_time;
			item.self=item.total;
			item.signature="fixed_time";


			frame_time.items.push_back(item);

			item.name="Idle Time";
			item.total=metric.idle_time;
			item.self=item.total;
			item.signature="idle_time";

			frame_time.items.push_back(item);

			item.name="Fixed Frame Time";
			item.total=metric.fixed_frame_time;
			item.self=item.total;
			item.signature="fixed_frame_time";

			frame_time.items.push_back(item);

			metric.categories.push_back(frame_time);

		}



		int idx=8;
		for(int i=0;i<frame_data_amount;i++) {

			EditorProfiler::Metric::Category c;
			String name=p_data[idx++];
			Array values=p_data[idx++];
			c.name=name.capitalize();
			c.items.resize(values.size()/2);
			c.total_time=0;
			c.signature="categ::"+name;
			for(int i=0;i<values.size();i+=2) {

				EditorProfiler::Metric::Category::Item item;
				item.name=values[i];
				item.calls=1;
				item.self=values[i+1];
				item.total=item.self;
				item.signature="categ::"+name+"::"+item.name;
				item.name=item.name.capitalize();
				c.total_time+=item.total;
				c.items[i/2]=item;


			}
			metric.categories.push_back(c);
		}

		EditorProfiler::Metric::Category funcs;
		funcs.total_time=p_data[5]; //script time
		funcs.items.resize(frame_function_amount);
		funcs.name="Script Functions";
		funcs.signature="script_functions";
		for(int i=0;i<frame_function_amount;i++) {

			int signature = p_data[idx++];
			int calls = p_data[idx++];
			float total = p_data[idx++];
			float self = p_data[idx++];



			EditorProfiler::Metric::Category::Item item;
			if (profiler_signature.has(signature)) {

				item.signature=profiler_signature[signature];

				String name = profiler_signature[signature];
				Vector<String> strings = name.split("::");
				if (strings.size()==3) {
					item.name=strings[2];
					item.script=strings[0];
					item.line=strings[1].to_int();
				}

			} else {
				item.name="SigErr "+itos(signature);
			}




			item.calls=calls;
			item.self=self;
			item.total=total;
			funcs.items[i]=item;

		}

		metric.categories.push_back(funcs);

		if (p_msg=="profile_frame")
			profiler->add_frame_metric(metric,false);
		else
			profiler->add_frame_metric(metric,true);

	} else if (p_msg=="kill_me") {

		editor->call_deferred("stop_child_process");
	}

}