Пример #1
0
int EditorData::add_edited_scene(int p_at_pos) {

	if (p_at_pos < 0)
		p_at_pos = edited_scene.size();
	EditedScene es;
	es.root = NULL;
	es.history_current = -1;
	es.version = 0;
	es.live_edit_root = NodePath(String("/root"));

	if (p_at_pos == edited_scene.size())
		edited_scene.push_back(es);
	else
		edited_scene.insert(p_at_pos, es);

	if (current_edited_scene < 0)
		current_edited_scene = 0;
	return p_at_pos;
}
Пример #2
0
void AnimationTreePlayer::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			if (!processing) {
				//make sure that a previous process state was not saved
				//only process if "processing" is set
				set_fixed_process(false);
				set_process(false);
			}
		} break;
		case NOTIFICATION_READY: {
			dirty_caches=true;
			if (master!=NodePath()) {
				_update_sources();
			}
		} break;
		case NOTIFICATION_PROCESS: {
			if (animation_process_mode==ANIMATION_PROCESS_FIXED)
				break;

			if (processing)
				_process_animation( get_process_delta_time() );
		} break;
		case NOTIFICATION_FIXED_PROCESS: {

			if (animation_process_mode==ANIMATION_PROCESS_IDLE)
				break;

			if (processing)
				_process_animation(get_fixed_process_delta_time());
		} break;
	}

}
Пример #3
0
LevelInterface::LevelInterface(WindowFramework* window):
m_interface(NodePath("LevelInterface")),
m_lifes(new TextNode("lifes"))
{
	m_interface.reparent_to(window->get_render_2d());
	hide();
	//
	PT(Texture) tex;
	tex = TexturePool::load_texture( "resources/gui/lifes.png"); 
	CardMaker cm("cardMaker");
	cm.set_frame_fullscreen_quad();
	PT(PandaNode) readyCard = cm.generate(); 
	NodePath lifes(readyCard);
	lifes.set_texture( tex ); 
	lifes.reparent_to(m_interface);
	lifes.set_scale(0.1, 0.1, 0.05);
	lifes.set_pos(0.9, 0.8, 0.9);
	//
	m_lifes->set_text_color(0.f, 0.f, 1.f, 1.f);
	m_lifes->set_text("0");
	NodePath lifeText = m_interface.attach_new_node(m_lifes);
	lifeText.set_scale(0.1);
	lifeText.set_pos(0.91, 0.9, 0.875);
}
Пример #4
0
void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path,Vector<StringName> new_base_path,Node * p_node, List<Pair<NodePath,NodePath> > *p_renames) {

	base_path.push_back(p_node->get_name());
	if (new_base_path.size())
		new_base_path.push_back(p_node->get_name());

	NodePath from( base_path,true );
	NodePath to;
	if (new_base_path.size())
		to=NodePath( new_base_path,true );

	Pair<NodePath,NodePath> npp;
	npp.first=from;
	npp.second=to;

	p_renames->push_back(npp);

	for(int i=0;i<p_node->get_child_count();i++) {

		_fill_path_renames(base_path,new_base_path,p_node->get_child(i),p_renames);
	}


}
Пример #5
0
void GDAPI godot_node_path_new(godot_node_path *r_dest, const godot_string *p_from) {
	NodePath *dest = (NodePath *)r_dest;
	const String *from = (const String *)p_from;
	memnew_placement(dest, NodePath(*from));
}
Пример #6
0
Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,int &line,String &r_err_str,ResourceParser *p_res_parser) {



/*	{
		Error err = get_token(p_stream,token,line,r_err_str);
		if (err)
			return err;
	}*/


	if (token.type==TK_CURLY_BRACKET_OPEN) {

		Dictionary d;
		Error err = _parse_dictionary(d,p_stream,line,r_err_str,p_res_parser);
		if (err)
			return err;
		value=d;
		return OK;
	} else if (token.type==TK_BRACKET_OPEN) {

		Array a;
		Error err = _parse_array(a,p_stream,line,r_err_str,p_res_parser);
		if (err)
			return err;
		value=a;
		return OK;

	} else if (token.type==TK_IDENTIFIER) {
/*
		VECTOR2,		// 5
		RECT2,
		VECTOR3,
		MATRIX32,
		PLANE,
		QUAT,			// 10
		_AABB, //sorry naming convention fail :( not like it's used often
		MATRIX3,
		TRANSFORM,

		// misc types
		COLOR,
		IMAGE,			// 15
		NODE_PATH,
		_RID,
		OBJECT,
		INPUT_EVENT,
		DICTIONARY,		// 20
		ARRAY,

		// arrays
		RAW_ARRAY,
		INT_ARRAY,
		REAL_ARRAY,
		STRING_ARRAY,	// 25
		VECTOR2_ARRAY,
		VECTOR3_ARRAY,
		COLOR_ARRAY,

		VARIANT_MAX

*/
		String id = token.value;
		if (id=="true")
			value=true;
		else if (id=="false")
			value=false;
		else if (id=="null" || id=="nil")
			value=Variant();
		else if (id=="Vector2"){

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			if (args.size()!=2) {
				r_err_str="Expected 2 arguments for constructor";
			}

			value=Vector2(args[0],args[1]);
			return OK;
		} else if (id=="Rect2"){

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			if (args.size()!=4) {
				r_err_str="Expected 4 arguments for constructor";
			}

			value=Rect2(args[0],args[1],args[2],args[3]);
			return OK;
		} else if (id=="Vector3"){

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			if (args.size()!=3) {
				r_err_str="Expected 3 arguments for constructor";
			}

			value=Vector3(args[0],args[1],args[2]);
			return OK;
		} else if (id=="Matrix32"){

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			if (args.size()!=6) {
				r_err_str="Expected 6 arguments for constructor";
			}
			Matrix32 m;
			m[0]=Vector2(args[0],args[1]);
			m[1]=Vector2(args[2],args[3]);
			m[2]=Vector2(args[4],args[5]);
			value=m;
			return OK;
		} else if (id=="Plane") {

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			if (args.size()!=4) {
				r_err_str="Expected 4 arguments for constructor";
			}

			value=Plane(args[0],args[1],args[2],args[3]);
			return OK;
		} else if (id=="Quat") {

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			if (args.size()!=4) {
				r_err_str="Expected 4 arguments for constructor";
			}

			value=Quat(args[0],args[1],args[2],args[3]);
			return OK;

		} else if (id=="AABB"){

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			if (args.size()!=6) {
				r_err_str="Expected 6 arguments for constructor";
			}

			value=AABB(Vector3(args[0],args[1],args[2]),Vector3(args[3],args[4],args[5]));
			return OK;

		} else if (id=="Matrix3"){

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			if (args.size()!=9) {
				r_err_str="Expected 9 arguments for constructor";
			}

			value=Matrix3(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]);
			return OK;
		} else if (id=="Transform"){

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			if (args.size()!=12) {
				r_err_str="Expected 12 arguments for constructor";
			}

			value=Transform(Matrix3(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]),Vector3(args[9],args[10],args[11]));
			return OK;

		} else if (id=="Color") {

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			if (args.size()!=4) {
				r_err_str="Expected 4 arguments for constructor";
			}

			value=Color(args[0],args[1],args[2],args[3]);
			return OK;

		} else if (id=="Image") {

			//:|

			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_PARENTHESIS_OPEN) {
				r_err_str="Expected '('";
				return ERR_PARSE_ERROR;
			}


			get_token(p_stream,token,line,r_err_str);
			if (token.type==TK_PARENTHESIS_CLOSE) {
				value=Image(); // just an Image()
				return OK;
			} else if (token.type!=TK_NUMBER) {
				r_err_str="Expected number (width)";
				return ERR_PARSE_ERROR;
			}

			get_token(p_stream,token,line,r_err_str);

			int width=token.value;
			if (token.type!=TK_COMMA) {
				r_err_str="Expected ','";
				return ERR_PARSE_ERROR;
			}

			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_NUMBER) {
				r_err_str="Expected number (height)";
				return ERR_PARSE_ERROR;
			}

			int height=token.value;

			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_COMMA) {
				r_err_str="Expected ','";
				return ERR_PARSE_ERROR;
			}

			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_NUMBER) {
				r_err_str="Expected number (mipmaps)";
				return ERR_PARSE_ERROR;
			}

			int mipmaps=token.value;

			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_COMMA) {
				r_err_str="Expected ','";
				return ERR_PARSE_ERROR;
			}


			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_IDENTIFIER) {
				r_err_str="Expected identifier (format)";
				return ERR_PARSE_ERROR;
			}


			String sformat=token.value;

			Image::Format format;

			if (sformat=="GRAYSCALE") format=Image::FORMAT_GRAYSCALE;
			else if (sformat=="INTENSITY") format=Image::FORMAT_INTENSITY;
			else if (sformat=="GRAYSCALE_ALPHA") format=Image::FORMAT_GRAYSCALE_ALPHA;
			else if (sformat=="RGB") format=Image::FORMAT_RGB;
			else if (sformat=="RGBA") format=Image::FORMAT_RGBA;
			else if (sformat=="INDEXED") format=Image::FORMAT_INDEXED;
			else if (sformat=="INDEXED_ALPHA") format=Image::FORMAT_INDEXED_ALPHA;
			else if (sformat=="BC1") format=Image::FORMAT_BC1;
			else if (sformat=="BC2") format=Image::FORMAT_BC2;
			else if (sformat=="BC3") format=Image::FORMAT_BC3;
			else if (sformat=="BC4") format=Image::FORMAT_BC4;
			else if (sformat=="BC5") format=Image::FORMAT_BC5;
			else if (sformat=="PVRTC2") format=Image::FORMAT_PVRTC2;
			else if (sformat=="PVRTC2_ALPHA") format=Image::FORMAT_PVRTC2_ALPHA;
			else if (sformat=="PVRTC4") format=Image::FORMAT_PVRTC4;
			else if (sformat=="PVRTC4_ALPHA") format=Image::FORMAT_PVRTC4_ALPHA;
			else if (sformat=="ATC") format=Image::FORMAT_ATC;
			else if (sformat=="ATC_ALPHA_EXPLICIT") format=Image::FORMAT_ATC_ALPHA_EXPLICIT;
			else if (sformat=="ATC_ALPHA_INTERPOLATED") format=Image::FORMAT_ATC_ALPHA_INTERPOLATED;
			else if (sformat=="CUSTOM") format=Image::FORMAT_CUSTOM;
			else {
				r_err_str="Invalid image format: '"+sformat+"'";
				return ERR_PARSE_ERROR;
			};

			int len = Image::get_image_data_size(width,height,format,mipmaps);

			DVector<uint8_t> buffer;
			buffer.resize(len);

			if (buffer.size()!=len) {
				r_err_str="Couldn't allocate image buffer of size: "+itos(len);
			}

			{
				DVector<uint8_t>::Write w=buffer.write();

				for(int i=0;i<len;i++) {
					get_token(p_stream,token,line,r_err_str);
					if (token.type!=TK_COMMA) {
						r_err_str="Expected ','";
						return ERR_PARSE_ERROR;
					}

					get_token(p_stream,token,line,r_err_str);
					if (token.type!=TK_NUMBER) {
						r_err_str="Expected number";
						return ERR_PARSE_ERROR;
					}

					w[i]=int(token.value);

				}
			}


			Image img(width,height,mipmaps,format,buffer);

			value=img;

			return OK;


		} else if (id=="NodePath") {



			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_PARENTHESIS_OPEN) {
				r_err_str="Expected '('";
				return ERR_PARSE_ERROR;
			}

			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_STRING) {
				r_err_str="Expected string as argument for NodePath()";
				return ERR_PARSE_ERROR;
			}

			value=NodePath(String(token.value));

			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_PARENTHESIS_CLOSE) {
				r_err_str="Expected ')'";
				return ERR_PARSE_ERROR;
			}

		} else if (id=="RID") {



			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_PARENTHESIS_OPEN) {
				r_err_str="Expected '('";
				return ERR_PARSE_ERROR;
			}

			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_NUMBER) {
				r_err_str="Expected number as argument";
				return ERR_PARSE_ERROR;
			}

			value=token.value;

			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_PARENTHESIS_CLOSE) {
				r_err_str="Expected ')'";
				return ERR_PARSE_ERROR;
			}


			return OK;

		} else if (id=="Resource" || id=="SubResource" || id=="ExtResource") {



			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_PARENTHESIS_OPEN) {
				r_err_str="Expected '('";
				return ERR_PARSE_ERROR;
			}


			if (p_res_parser && id=="Resource" && p_res_parser->func){

				RES res;
				Error err = p_res_parser->func(p_res_parser->userdata,p_stream,res,line,r_err_str);
				if (err)
					return err;

				value=res;

				return OK;
			} else if (p_res_parser && id=="ExtResource" && p_res_parser->ext_func){

				RES res;
				Error err = p_res_parser->ext_func(p_res_parser->userdata,p_stream,res,line,r_err_str);
				if (err)
					return err;

				value=res;

				return OK;
			} else if (p_res_parser && id=="SubResource" && p_res_parser->sub_func){

				RES res;
				Error err = p_res_parser->sub_func(p_res_parser->userdata,p_stream,res,line,r_err_str);
				if (err)
					return err;

				value=res;

				return OK;
			} else {

				get_token(p_stream,token,line,r_err_str);
				if (token.type==TK_STRING) {
					String path=token.value;
					RES res = ResourceLoader::load(path);
					if (res.is_null()) {
						r_err_str="Can't load resource at path: '"+path+"'.";
						return ERR_PARSE_ERROR;
					}

					get_token(p_stream,token,line,r_err_str);
					if (token.type!=TK_PARENTHESIS_CLOSE) {
						r_err_str="Expected ')'";
						return ERR_PARSE_ERROR;
					}

					value=res;
					return OK;

				} else {
					r_err_str="Expected string as argument for Resource().";
					return ERR_PARSE_ERROR;
				}
			}

			return OK;


		} else if (id=="InputEvent") {



			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_PARENTHESIS_OPEN) {
				r_err_str="Expected '('";
				return ERR_PARSE_ERROR;
			}

			get_token(p_stream,token,line,r_err_str);

			if (token.type!=TK_IDENTIFIER) {
				r_err_str="Expected identifier";
				return ERR_PARSE_ERROR;
			}


			String id = token.value;

			InputEvent ie;

			if (id=="KEY") {

				get_token(p_stream,token,line,r_err_str);
				if (token.type!=TK_COMMA) {
					r_err_str="Expected ','";
					return ERR_PARSE_ERROR;
				}

				ie.type=InputEvent::KEY;


				get_token(p_stream,token,line,r_err_str);
				if (token.type==TK_IDENTIFIER) {
					String name=token.value;
					ie.key.scancode=find_keycode(name);
				} else if (token.type==TK_NUMBER) {

					ie.key.scancode=token.value;
				} else {

					r_err_str="Expected string or integer for keycode";
					return ERR_PARSE_ERROR;
				}

				get_token(p_stream,token,line,r_err_str);

				if (token.type==TK_COMMA) {

					get_token(p_stream,token,line,r_err_str);

					if (token.type!=TK_IDENTIFIER) {
						r_err_str="Expected identifier with modifier flas";
						return ERR_PARSE_ERROR;
					}

					String mods=token.value;

					if (mods.findn("C")!=-1)
						ie.key.mod.control=true;
					if (mods.findn("A")!=-1)
						ie.key.mod.alt=true;
					if (mods.findn("S")!=-1)
						ie.key.mod.shift=true;
					if (mods.findn("M")!=-1)
						ie.key.mod.meta=true;

					get_token(p_stream,token,line,r_err_str);
					if (token.type!=TK_PARENTHESIS_CLOSE) {
						r_err_str="Expected ')'";
						return ERR_PARSE_ERROR;
					}

				} else if (token.type!=TK_PARENTHESIS_CLOSE) {

					r_err_str="Expected ')' or modifier flags.";
					return ERR_PARSE_ERROR;
				}


			} else if (id=="MBUTTON") {

				get_token(p_stream,token,line,r_err_str);
				if (token.type!=TK_COMMA) {
					r_err_str="Expected ','";
					return ERR_PARSE_ERROR;
				}

				ie.type=InputEvent::MOUSE_BUTTON;

				get_token(p_stream,token,line,r_err_str);
				if (token.type!=TK_NUMBER) {
					r_err_str="Expected button index";
					return ERR_PARSE_ERROR;
				}

				ie.mouse_button.button_index = token.value;

				get_token(p_stream,token,line,r_err_str);
				if (token.type!=TK_PARENTHESIS_CLOSE) {
					r_err_str="Expected ')'";
					return ERR_PARSE_ERROR;
				}

			} else if (id=="JBUTTON") {

				get_token(p_stream,token,line,r_err_str);
				if (token.type!=TK_COMMA) {
					r_err_str="Expected ','";
					return ERR_PARSE_ERROR;
				}

				ie.type=InputEvent::JOYSTICK_BUTTON;

				get_token(p_stream,token,line,r_err_str);
				if (token.type!=TK_NUMBER) {
					r_err_str="Expected button index";
					return ERR_PARSE_ERROR;
				}

				ie.joy_button.button_index = token.value;

				get_token(p_stream,token,line,r_err_str);
				if (token.type!=TK_PARENTHESIS_CLOSE) {
					r_err_str="Expected ')'";
					return ERR_PARSE_ERROR;
				}

			} else if (id=="JAXIS") {

				get_token(p_stream,token,line,r_err_str);
				if (token.type!=TK_COMMA) {
					r_err_str="Expected ','";
					return ERR_PARSE_ERROR;
				}

				ie.type=InputEvent::JOYSTICK_MOTION;

				get_token(p_stream,token,line,r_err_str);
				if (token.type!=TK_NUMBER) {
					r_err_str="Expected axis index";
					return ERR_PARSE_ERROR;
				}

				ie.joy_motion.axis = token.value;

				get_token(p_stream,token,line,r_err_str);

				if (token.type!=TK_COMMA) {
					r_err_str="Expected ',' after axis index";
					return ERR_PARSE_ERROR;
				}

				get_token(p_stream,token,line,r_err_str);
				if (token.type!=TK_NUMBER) {
					r_err_str="Expected axis sign";
					return ERR_PARSE_ERROR;
				}

				ie.joy_motion.axis_value = token.value;

				get_token(p_stream,token,line,r_err_str);

				if (token.type!=TK_PARENTHESIS_CLOSE) {
					r_err_str="Expected ')' for jaxis";
					return ERR_PARSE_ERROR;
				}

			} else {

				r_err_str="Invalid input event type.";
				return ERR_PARSE_ERROR;
			}

			value=ie;

			return OK;

		} else if (id=="ByteArray") {

			Vector<uint8_t> args;
			Error err = _parse_construct<uint8_t>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			DVector<uint8_t> arr;
			{
				int len=args.size();
				arr.resize(len);
				DVector<uint8_t>::Write w = arr.write();
				for(int i=0;i<len;i++) {
					w[i]=args[i];
				}
			}

			value=arr;

			return OK;

		} else if (id=="IntArray") {

			Vector<int32_t> args;
			Error err = _parse_construct<int32_t>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			DVector<int32_t> arr;
			{
				int len=args.size();
				arr.resize(len);
				DVector<int32_t>::Write w = arr.write();
				for(int i=0;i<len;i++) {
					w[i]=int(args[i]);
				}
			}

			value=arr;

			return OK;

		} else if (id=="FloatArray") {

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			DVector<float> arr;
			{
				int len=args.size();
				arr.resize(len);
				DVector<float>::Write w = arr.write();
				for(int i=0;i<len;i++) {
					w[i]=args[i];
				}
			}

			value=arr;

			return OK;
		} else if (id=="StringArray") {


			get_token(p_stream,token,line,r_err_str);
			if (token.type!=TK_PARENTHESIS_OPEN) {
				r_err_str="Expected '('";
				return ERR_PARSE_ERROR;
			}

			Vector<String> cs;

			bool first=true;
			while(true) {

				if (!first) {
					get_token(p_stream,token,line,r_err_str);
					if (token.type==TK_COMMA) {
						//do none
					} else if (token.type==TK_PARENTHESIS_CLOSE) {
						break;
					} else {
						r_err_str="Expected ',' or ')'";
						return ERR_PARSE_ERROR;

					}
				}
				get_token(p_stream,token,line,r_err_str);

				if (token.type!=TK_STRING) {
					r_err_str="Expected string";
					return ERR_PARSE_ERROR;
				}

				first=false;
				cs.push_back(token.value);
			}


			DVector<String> arr;
			{
				int len=cs.size();
				arr.resize(len);
				DVector<String>::Write w = arr.write();
				for(int i=0;i<len;i++) {
					w[i]=cs[i];
				}
			}

			value=arr;

			return OK;


		} else if (id=="Vector2Array") {

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			DVector<Vector2> arr;
			{
				int len=args.size()/2;
				arr.resize(len);
				DVector<Vector2>::Write w = arr.write();
				for(int i=0;i<len;i++) {
					w[i]=Vector2(args[i*2+0],args[i*2+1]);
				}
			}

			value=arr;

			return OK;

		} else if (id=="Vector3Array") {

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			DVector<Vector3> arr;
			{
				int len=args.size()/3;
				arr.resize(len);
				DVector<Vector3>::Write w = arr.write();
				for(int i=0;i<len;i++) {
					w[i]=Vector3(args[i*3+0],args[i*3+1],args[i*3+2]);
				}
			}

			value=arr;

			return OK;

		} else if (id=="ColorArray") {

			Vector<float> args;
			Error err = _parse_construct<float>(p_stream,args,line,r_err_str);
			if (err)
				return err;

			DVector<Color> arr;
			{
				int len=args.size()/4;
				arr.resize(len);
				DVector<Color>::Write w = arr.write();
				for(int i=0;i<len;i++) {
					w[i]=Color(args[i*4+0],args[i*4+1],args[i*4+2],args[i*4+3]);
				}
			}

			value=arr;

			return OK;
		} else if (id=="key") { // compatibility with engine.cfg

			Vector<String> params;
			Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
			if (err)
				return err;
			ERR_FAIL_COND_V(params.size()!=1 && params.size()!=2,ERR_PARSE_ERROR);

			int scode=0;

			if (params[0].is_numeric()) {
				scode=params[0].to_int();
				if (scode < 10) {
					scode=KEY_0+scode;
				}
			} else
				scode=find_keycode(params[0]);

			InputEvent ie;
			ie.type=InputEvent::KEY;
			ie.key.scancode=scode;

			if (params.size()==2) {
				String mods=params[1];
				if (mods.findn("C")!=-1)
					ie.key.mod.control=true;
				if (mods.findn("A")!=-1)
					ie.key.mod.alt=true;
				if (mods.findn("S")!=-1)
					ie.key.mod.shift=true;
				if (mods.findn("M")!=-1)
					ie.key.mod.meta=true;
			}
			value=ie;
			return OK;

		} else if (id=="mbutton") {  // compatibility with engine.cfg

			Vector<String> params;
			Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
			if (err)
				return err;
			ERR_FAIL_COND_V(params.size()!=2,ERR_PARSE_ERROR);

			InputEvent ie;
			ie.type=InputEvent::MOUSE_BUTTON;
			ie.device=params[0].to_int();
			ie.mouse_button.button_index=params[1].to_int();

			value=ie;
			return OK;
		} else if (id=="jbutton") {  // compatibility with engine.cfg

			Vector<String> params;
			Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
			if (err)
				return err;
			ERR_FAIL_COND_V(params.size()!=2,ERR_PARSE_ERROR);
			InputEvent ie;
			ie.type=InputEvent::JOYSTICK_BUTTON;
			ie.device=params[0].to_int();
			ie.joy_button.button_index=params[1].to_int();

			value=ie;

			return OK;
		} else if (id=="jaxis") {  // compatibility with engine.cfg

			Vector<String> params;
			Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
			if (err)
				return err;
			ERR_FAIL_COND_V(params.size()!=2,ERR_PARSE_ERROR);

			InputEvent ie;
			ie.type=InputEvent::JOYSTICK_MOTION;
			ie.device=params[0].to_int();
			int axis=params[1].to_int();
			ie.joy_motion.axis=axis>>1;
			ie.joy_motion.axis_value=axis&1?1:-1;

			value= ie;

			return OK;
		} else if (id=="img") {  // compatibility with engine.cfg
Пример #7
0
void GDAPI godot_node_path_new(godot_node_path *p_np, const godot_string *p_from) {
	NodePath *np = (NodePath *)p_np;
	String *from = (String *)p_from;
	memnew_placement_custom(np, NodePath, NodePath(*from));
}
Пример #8
0
void World6::rotate_planets()
   {
   m_dayPeriodSun = new CLerpNodePathInterval("dayPeriodSunInterval",
                                              20,
                                              CLerpInterval::BT_no_blend,
                                              true,
                                              false,
                                              m_sun,
                                              NodePath());
   m_dayPeriodSun->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_dayPeriodSun->set_end_hpr  (LVecBase3f(360, 0, 0));

   m_orbitPeriodMercury =
      new CLerpNodePathInterval("orbitPeriodMercuryInterval",
                                0.241 * m_yearscale,
                                CLerpInterval::BT_no_blend,
                                true,
                                false,
                                m_orbitRootMercury,
                                NodePath());
   m_orbitPeriodMercury->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_orbitPeriodMercury->set_end_hpr  (LVecBase3f(360, 0, 0));

   m_dayPeriodMercury = new CLerpNodePathInterval("dayPeriodMercuryInterval",
                                                  59 * m_dayscale,
                                                  CLerpInterval::BT_no_blend,
                                                  true,
                                                  false,
                                                  m_mercury,
                                                  NodePath());
   m_dayPeriodMercury->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_dayPeriodMercury->set_end_hpr  (LVecBase3f(360, 0, 0));

   m_orbitPeriodVenus = new CLerpNodePathInterval("orbitPeriodVenusInterval",
                                                  0.615 * m_yearscale,
                                                  CLerpInterval::BT_no_blend,
                                                  true,
                                                  false,
                                                  m_orbitRootVenus,
                                                  NodePath());
   m_orbitPeriodVenus->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_orbitPeriodVenus->set_end_hpr  (LVecBase3f(360, 0, 0));

   m_dayPeriodVenus = new CLerpNodePathInterval("dayPeriodVenusInterval",
                                                  243 * m_dayscale,
                                                  CLerpInterval::BT_no_blend,
                                                  true,
                                                  false,
                                                  m_venus,
                                                  NodePath());
   m_dayPeriodVenus->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_dayPeriodVenus->set_end_hpr  (LVecBase3f(360, 0, 0));

   // Here the earth interval has been changed to rotate like the rest of the
   // planets and send a message before it starts turning again. To send a
   // message, the call is simply messenger.send("message"). The "newYear"
   // message is picked up by the accept("newYear"...) statement earlier, and
   // calls the incYear function as a result
   m_orbitPeriodEarth = new CLerpNodePathInterval("orbitPeriodEarthInterval",
                                                  m_yearscale,
                                                  CLerpInterval::BT_no_blend,
                                                  true,
                                                  false,
                                                  m_orbitRootEarth,
                                                  NodePath());
   m_orbitPeriodEarth->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_orbitPeriodEarth->set_end_hpr  (LVecBase3f(360, 0, 0));
   m_orbitPeriodEarth->set_done_event("newYear");

   m_dayPeriodEarth = new CLerpNodePathInterval("dayPeriodEarthInterval",
                                                  m_dayscale,
                                                  CLerpInterval::BT_no_blend,
                                                  true,
                                                  false,
                                                  m_earth,
                                                  NodePath());
   m_dayPeriodEarth->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_dayPeriodEarth->set_end_hpr  (LVecBase3f(360, 0, 0));

   m_orbitPeriodMoon = new CLerpNodePathInterval("orbitPeriodMoonInterval",
                                                  0.0749 * m_yearscale,
                                                  CLerpInterval::BT_no_blend,
                                                  true,
                                                  false,
                                                  m_orbitRootMoon,
                                                  NodePath());
   m_orbitPeriodMoon->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_orbitPeriodMoon->set_end_hpr  (LVecBase3f(360, 0, 0));

   m_dayPeriodMoon = new CLerpNodePathInterval("dayPeriodMoonInterval",
                                                  0.0749 * m_dayscale,
                                                  CLerpInterval::BT_no_blend,
                                                  true,
                                                  false,
                                                  m_moon,
                                                  NodePath());
   m_dayPeriodMoon->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_dayPeriodMoon->set_end_hpr  (LVecBase3f(360, 0, 0));

   m_orbitPeriodMars = new CLerpNodePathInterval("orbitPeriodMarsInterval",
                                                 1.881 * m_yearscale,
                                                 CLerpInterval::BT_no_blend,
                                                 true,
                                                 false,
                                                 m_orbitRootMars,
                                                 NodePath());
   m_orbitPeriodMars->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_orbitPeriodMars->set_end_hpr  (LVecBase3f(360, 0, 0));

   m_dayPeriodMars = new CLerpNodePathInterval("dayPeriodMarsInterval",
                                               1.03 * m_dayscale,
                                               CLerpInterval::BT_no_blend,
                                               true,
                                               false,
                                               m_mars,
                                               NodePath());
   m_dayPeriodMars->set_start_hpr(LVecBase3f(  0, 0, 0));
   m_dayPeriodMars->set_end_hpr  (LVecBase3f(360, 0, 0));

   m_dayPeriodSun->loop();
   m_orbitPeriodMercury->loop();
   m_dayPeriodMercury->loop();
   m_orbitPeriodVenus->loop();
   m_dayPeriodVenus->loop();
   m_orbitPeriodEarth->loop();
   m_dayPeriodEarth->loop();
   m_orbitPeriodMoon->loop();
   m_dayPeriodMoon->loop();
   m_orbitPeriodMars->loop();
   m_dayPeriodMars->loop();

   // Note: setup a task to step the interval manager
   AsyncTaskManager::get_global_ptr()->add(
      new GenericAsyncTask("intervalManagerTask", step_interval_manager, this));
   }
Пример #9
0
NodePath Polygon2D::get_bone_path(int p_index) const {
	ERR_FAIL_INDEX_V(p_index, bone_weights.size(), NodePath());
	return bone_weights[p_index].path;
}
Пример #10
0
void LegIKController::_ready() {
	global_leg_ik_enabled_changed();
	global_leg_ik_feet_reposition_rate_changed();
	global_leg_ik_body_reposition_rate_changed();

	//Ignore player collision hull
	ray_exclusion_array = Set<RID>();

	CollisionObject *collision_object = static_cast<CollisionObject *>(get_node(NodePath("..")));
	if (collision_object)
		ray_exclusion_array.insert(collision_object->get_rid());

	skeleton = static_cast<Skeleton *>(get_node(skeleton_path));

	if (skeleton != NULL) {
		root_bone = skeleton->find_bone(root_bone_name);
		pelvis = skeleton->find_bone(pelvis_name);

		left_leg = skeleton->find_bone(left_leg_name);
		left_knee = skeleton->find_bone(left_knee_name);
		left_ankle = skeleton->find_bone(left_ankle_name);
		left_toe = skeleton->find_bone(left_toe_name);

		right_leg = skeleton->find_bone(right_leg_name);
		right_knee = skeleton->find_bone(right_knee_name);
		right_ankle = skeleton->find_bone(right_ankle_name);
		right_toe = skeleton->find_bone(right_toe_name);

		if (root_bone != -1 && pelvis != -1 &&
			left_leg != -1 && left_knee != -1 && left_ankle != -1 &&
			right_leg != -1 && right_knee != -1 && right_ankle != -1 &&
			left_toe != -1 && right_toe != -1) {

			left_thigh_length = skeleton->get_bone_global_pose(left_leg).origin.distance_to(skeleton->get_bone_global_pose(left_knee).origin);
			left_calf_length = skeleton->get_bone_global_pose(left_knee).origin.distance_to(skeleton->get_bone_global_pose(left_ankle).origin);
			left_leg_full_length = left_thigh_length + left_calf_length;

			right_thigh_length = skeleton->get_bone_global_pose(right_leg).origin.distance_to(skeleton->get_bone_global_pose(right_knee).origin);
			right_calf_length = skeleton->get_bone_global_pose(right_knee).origin.distance_to(skeleton->get_bone_global_pose(right_ankle).origin);
			right_leg_full_length = right_thigh_length + right_calf_length;

			prev_target_height = skeleton->get_bone_global_pose(root_bone).origin.y;

			Transform left_foot_local_transform = skeleton->get_bone_global_pose(left_ankle);
			Transform right_foot_local_transform = skeleton->get_bone_global_pose(right_ankle);

			Transform left_foot_transform = skeleton->get_global_transform() * left_foot_local_transform;
			Transform right_foot_transform = skeleton->get_global_transform() * right_foot_local_transform;

			targeted_left_ground = left_foot_transform.origin;
			targeted_right_ground = right_foot_transform.origin;

			prev_left_ground = left_foot_local_transform.origin;
			prev_right_ground = right_foot_local_transform.origin;

			ik_valid = true;
		}
		else {
			ik_valid = false;
		}
	}
}
Пример #11
0
LegIKController::LegIKController() {
	skeleton_path = NodePath();

	bool ik_on = false;
	bool ik_valid = false;

	root_global_transform = Transform();
	ray_exclusion_array = Set<RID>();

	root_bone_name = "root";
	pelvis_name = "lower_body";

	left_leg_name = "leg.L";
	left_knee_name = "knee.L";
	left_ankle_name = "ankle.L";
	left_toe_name = "toe.L";

	right_leg_name = "leg.R";
	right_knee_name = "knee.R";
	right_ankle_name = "ankle.R";
	right_toe_name = "toe.R";

	root_bone = -1;
	pelvis = -1;

	left_leg = -1;
	left_knee = -1;
	left_ankle = -1;
	left_toe = -1;

	right_leg = -1;
	right_knee = -1;
	right_ankle = -1;
	right_toe = -1;

	left_thigh_length = 0.0f;
	right_thigh_length = 0.0f;
	left_calf_length = 0.0f;
	right_calf_length = 0.0f;
	left_leg_full_length = 0.0f;
	right_leg_full_length = 0.0f;

	animation_offset = 0.01f;
	ankle_height_L = 0.0f;
	ankle_height_R = 0.0f;
	root_offset = 0.0f;

	target_height = 0.0f;
	prev_target_height = 0.0f;
	target_height_velocity = 0.0f;
		
	left_foot_down = false;
	right_foot_down = false;

	root = NULL;
	skeleton = NULL;
	dss = NULL;

	targeted_left_ground = Vector3();
	targeted_right_ground = Vector3();

	ik_feet_reposition_rate = 15.0f;
	ik_body_reposition_rate = 1.0f;

	prev_left_ground = Vector3();
	prev_right_ground = Vector3();
}
Пример #12
0
void AnimationTreeEditor::_popup_edit_dialog() {

	updating_edit=true;

	for(int i=0;i<2;i++)
		edit_scroll[i]->hide();

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

		edit_line[i]->hide();
		edit_label[i]->hide();
	}

	edit_option->hide();
	edit_button->hide();;
	filter_button->hide();
	edit_check->hide();;

	Point2 pos = anim_tree->node_get_pos(edited_node)-Point2(h_scroll->get_val(),v_scroll->get_val());
	Ref<StyleBox> style = get_stylebox("panel","PopupMenu");
	Size2 size = get_node_size(edited_node);
	Point2 popup_pos( pos.x+style->get_margin(MARGIN_LEFT), pos.y+size.y-style->get_margin(MARGIN_BOTTOM));
	popup_pos+=get_global_pos();

	if (renaming_edit) {

		edit_label[0]->set_text("New name:");
		edit_label[0]->set_pos(Point2(5,5));
		edit_label[0]->show();
		edit_line[0]->set_begin(Point2(15,25));
		edit_line[0]->set_text(edited_node);
		edit_line[0]->show();
		edit_dialog->set_size(Size2(150,50));

	} else {

		AnimationTreePlayer::NodeType type=anim_tree->node_get_type(edited_node);


		switch(type) {

			case AnimationTreePlayer::NODE_ANIMATION:

				if (anim_tree->get_master_player()!=NodePath() && anim_tree->has_node(anim_tree->get_master_player())  && anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>()) {

					AnimationPlayer *ap = anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>();
					master_anim_popup->clear();
					List<StringName> sn;
					ap->get_animation_list(&sn);
					sn.sort_custom<StringName::AlphCompare>();
					for (List<StringName>::Element *E=sn.front();E;E=E->next()) {
						master_anim_popup->add_item(E->get());
					}

					master_anim_popup->set_pos(popup_pos);
					master_anim_popup->popup();
				} else {
					property_editor->edit(this,"",Variant::OBJECT,anim_tree->animation_node_get_animation(edited_node),PROPERTY_HINT_RESOURCE_TYPE,"Animation");
					property_editor->set_pos(popup_pos);
					property_editor->popup();
					updating_edit=false;
				}
				return;
			 case AnimationTreePlayer::NODE_TIMESCALE:
				edit_label[0]->set_text("Scale:");
				edit_label[0]->set_pos(Point2(5,5));
				edit_label[0]->show();
				edit_line[0]->set_begin(Point2(15,25));
				edit_line[0]->set_text(rtos(anim_tree->timescale_node_get_scale(edited_node)));
				edit_line[0]->show();
				edit_dialog->set_size(Size2(150,50));
				break;
			 case AnimationTreePlayer::NODE_ONESHOT:
				edit_label[0]->set_text("Fade In (s):");
				edit_label[0]->set_pos(Point2(5,5));
				edit_label[0]->show();
				edit_line[0]->set_begin(Point2(15,25));
				edit_line[0]->set_text(rtos(anim_tree->oneshot_node_get_fadein_time(edited_node)));
				edit_line[0]->show();
				edit_label[1]->set_text("Fade Out (s):");
				edit_label[1]->set_pos(Point2(5,55));
				edit_label[1]->show();
				edit_line[1]->set_begin(Point2(15,75));
				edit_line[1]->set_text(rtos(anim_tree->oneshot_node_get_fadeout_time(edited_node)));
				edit_line[1]->show();

				edit_option->clear();
				edit_option->add_item("Blend",0);
				edit_option->add_item("Mix",1);
				edit_option->set_begin(Point2(15,105));

				edit_option->select( anim_tree->oneshot_node_get_mix_mode(edited_node));
				edit_option->show();

				edit_check->set_text("Auto Restart:");
				edit_check->set_begin(Point2(15,125));
				edit_check->set_pressed(anim_tree->oneshot_node_has_autorestart(edited_node));
				edit_check->show();

				edit_label[2]->set_text("Restart (s):");
				edit_label[2]->set_pos(Point2(5,145));
				edit_label[2]->show();
				edit_line[2]->set_begin(Point2(15,165));
				edit_line[2]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_delay(edited_node)));
				edit_line[2]->show();
				edit_label[3]->set_text("Random Restart (s):");
				edit_label[3]->set_pos(Point2(5,195));
				edit_label[3]->show();
				edit_line[3]->set_begin(Point2(15,215));
				edit_line[3]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_random_delay(edited_node)));
				edit_line[3]->show();

				filter_button->set_begin(Point2(10,245));
				filter_button->show();

				edit_button->set_begin(Point2(10,268));
				edit_button->set_text("Start!");

				edit_button->show();

				edit_dialog->set_size(Size2(180,293));

				break;

			 case AnimationTreePlayer::NODE_MIX:

				 edit_label[0]->set_text("Amount:");
				 edit_label[0]->set_pos(Point2(5,5));
				 edit_label[0]->show();
				 edit_scroll[0]->set_min(0);
				 edit_scroll[0]->set_max(1);
				 edit_scroll[0]->set_val(anim_tree->mix_node_get_amount(edited_node));
				 edit_scroll[0]->set_begin(Point2(15,25));
				 edit_scroll[0]->show();
				 edit_dialog->set_size(Size2(150,50));

				 break;
			 case AnimationTreePlayer::NODE_BLEND2:
				 edit_label[0]->set_text("Blend:");
				 edit_label[0]->set_pos(Point2(5,5));
				 edit_label[0]->show();
				 edit_scroll[0]->set_min(0);
				 edit_scroll[0]->set_max(1);
				 edit_scroll[0]->set_val(anim_tree->blend2_node_get_amount(edited_node));
				 edit_scroll[0]->set_begin(Point2(15,25));
				 edit_scroll[0]->show();
				 filter_button->set_begin(Point2(10,47));
				 filter_button->show();
				 edit_dialog->set_size(Size2(150,74));

				 break;

			 case AnimationTreePlayer::NODE_BLEND3:
				 edit_label[0]->set_text("Blend:");
				 edit_label[0]->set_pos(Point2(5,5));
				 edit_label[0]->show();
				 edit_scroll[0]->set_min(-1);
				 edit_scroll[0]->set_max(1);
				 edit_scroll[0]->set_val(anim_tree->blend3_node_get_amount(edited_node));
				 edit_scroll[0]->set_begin(Point2(15,25));
				 edit_scroll[0]->show();
				 edit_dialog->set_size(Size2(150,50));

				 break;
			case AnimationTreePlayer::NODE_BLEND4:

				edit_label[0]->set_text("Blend 0:");
				edit_label[0]->set_pos(Point2(5,5));
				edit_label[0]->show();
				edit_scroll[0]->set_min(0);
				edit_scroll[0]->set_max(1);
				edit_scroll[0]->set_val(anim_tree->blend4_node_get_amount(edited_node).x);
				edit_scroll[0]->set_begin(Point2(15,25));
				edit_scroll[0]->show();
				edit_label[1]->set_text("Blend 1:");
				edit_label[1]->set_pos(Point2(5,55));
				edit_label[1]->show();
				edit_scroll[1]->set_min(0);
				edit_scroll[1]->set_max(1);
				edit_scroll[1]->set_val(anim_tree->blend4_node_get_amount(edited_node).y);
				edit_scroll[1]->set_begin(Point2(15,75));
				edit_scroll[1]->show();
				edit_dialog->set_size(Size2(150,100));

				break;

			 case AnimationTreePlayer::NODE_TRANSITION: {


				 edit_label[0]->set_text("X-Fade Time (s):");
				 edit_label[0]->set_pos(Point2(5,5));
				 edit_label[0]->show();
				 edit_line[0]->set_begin(Point2(15,25));
				 edit_line[0]->set_text(rtos(anim_tree->transition_node_get_xfade_time(edited_node)));
				 edit_line[0]->show();

				 edit_label[1]->set_text("Current:");
				 edit_label[1]->set_pos(Point2(5,55));
				 edit_label[1]->show();
				 edit_option->set_begin(Point2(15,75));

				 edit_option->clear();;

				 for(int i=0;i<anim_tree->transition_node_get_input_count(edited_node);i++) {
					 edit_option->add_item(itos(i),i);
				 }

				 edit_option->select(anim_tree->transition_node_get_current(edited_node));
				 edit_option->show();
				 edit_dialog->set_size(Size2(150,100));

			} break;
			default: {}

		}

	}



	edit_dialog->set_pos(popup_pos);
	edit_dialog->popup();

	updating_edit=false;
}
Пример #13
0
MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_type) {
	switch (p_type.type_encoding) {
		case MONO_TYPE_BOOLEAN: {
			MonoBoolean val = p_var->operator bool();
			return BOX_BOOLEAN(val);
		}

		case MONO_TYPE_I1: {
			char val = p_var->operator signed char();
			return BOX_INT8(val);
		}
		case MONO_TYPE_I2: {
			short val = p_var->operator signed short();
			return BOX_INT16(val);
		}
		case MONO_TYPE_I4: {
			int val = p_var->operator signed int();
			return BOX_INT32(val);
		}
		case MONO_TYPE_I8: {
			int64_t val = p_var->operator int64_t();
			return BOX_INT64(val);
		}

		case MONO_TYPE_U1: {
			char val = p_var->operator unsigned char();
			return BOX_UINT8(val);
		}
		case MONO_TYPE_U2: {
			short val = p_var->operator unsigned short();
			return BOX_UINT16(val);
		}
		case MONO_TYPE_U4: {
			int val = p_var->operator unsigned int();
			return BOX_UINT32(val);
		}
		case MONO_TYPE_U8: {
			uint64_t val = p_var->operator uint64_t();
			return BOX_UINT64(val);
		}

		case MONO_TYPE_R4: {
			float val = p_var->operator float();
			return BOX_FLOAT(val);
		}
		case MONO_TYPE_R8: {
			double val = p_var->operator double();
			return BOX_DOUBLE(val);
		}

		case MONO_TYPE_STRING: {
			return (MonoObject *)mono_string_from_godot(p_var->operator String());
		} break;

		case MONO_TYPE_VALUETYPE: {
			GDMonoClass *tclass = p_type.type_class;

			if (tclass == CACHED_CLASS(Vector2))
				RETURN_BOXED_STRUCT(Vector2, p_var);

			if (tclass == CACHED_CLASS(Rect2))
				RETURN_BOXED_STRUCT(Rect2, p_var);

			if (tclass == CACHED_CLASS(Transform2D))
				RETURN_BOXED_STRUCT(Transform2D, p_var);

			if (tclass == CACHED_CLASS(Vector3))
				RETURN_BOXED_STRUCT(Vector3, p_var);

			if (tclass == CACHED_CLASS(Basis))
				RETURN_BOXED_STRUCT(Basis, p_var);

			if (tclass == CACHED_CLASS(Quat))
				RETURN_BOXED_STRUCT(Quat, p_var);

			if (tclass == CACHED_CLASS(Transform))
				RETURN_BOXED_STRUCT(Transform, p_var);

			if (tclass == CACHED_CLASS(Rect3))
				RETURN_BOXED_STRUCT(Rect3, p_var);

			if (tclass == CACHED_CLASS(Color))
				RETURN_BOXED_STRUCT(Color, p_var);

			if (tclass == CACHED_CLASS(Plane))
				RETURN_BOXED_STRUCT(Plane, p_var);

			if (mono_class_is_enum(tclass->get_raw())) {
				int val = p_var->operator signed int();
				return BOX_ENUM(tclass->get_raw(), val);
			}
		} break;

		case MONO_TYPE_ARRAY:
		case MONO_TYPE_SZARRAY: {
			MonoArrayType *array_type = mono_type_get_array_type(GDMonoClass::get_raw_type(p_type.type_class));

			if (array_type->eklass == CACHED_CLASS_RAW(MonoObject))
				return (MonoObject *)Array_to_mono_array(p_var->operator Array());

			if (array_type->eklass == CACHED_CLASS_RAW(uint8_t))
				return (MonoObject *)PoolByteArray_to_mono_array(p_var->operator PoolByteArray());

			if (array_type->eklass == CACHED_CLASS_RAW(int32_t))
				return (MonoObject *)PoolIntArray_to_mono_array(p_var->operator PoolIntArray());

			if (array_type->eklass == REAL_T_MONOCLASS)
				return (MonoObject *)PoolRealArray_to_mono_array(p_var->operator PoolRealArray());

			if (array_type->eklass == CACHED_CLASS_RAW(String))
				return (MonoObject *)PoolStringArray_to_mono_array(p_var->operator PoolStringArray());

			if (array_type->eklass == CACHED_CLASS_RAW(Vector2))
				return (MonoObject *)PoolVector2Array_to_mono_array(p_var->operator PoolVector2Array());

			if (array_type->eklass == CACHED_CLASS_RAW(Vector3))
				return (MonoObject *)PoolVector3Array_to_mono_array(p_var->operator PoolVector3Array());

			if (array_type->eklass == CACHED_CLASS_RAW(Color))
				return (MonoObject *)PoolColorArray_to_mono_array(p_var->operator PoolColorArray());

			ERR_EXPLAIN(String() + "Attempted to convert Variant to a managed array of unmarshallable element type.");
			ERR_FAIL_V(NULL);
		} break;

		case MONO_TYPE_CLASS: {
			GDMonoClass *type_class = p_type.type_class;

			// GodotObject
			if (CACHED_CLASS(GodotObject)->is_assignable_from(type_class)) {
				return GDMonoUtils::unmanaged_get_managed(p_var->operator Object *());
			}

			if (CACHED_CLASS(NodePath) == type_class) {
				return GDMonoUtils::create_managed_from(p_var->operator NodePath());
			}

			if (CACHED_CLASS(RID) == type_class) {
				return GDMonoUtils::create_managed_from(p_var->operator RID());
			}
		} break;
		case MONO_TYPE_OBJECT: {
			// Variant
			switch (p_var->get_type()) {
				case Variant::BOOL: {
					MonoBoolean val = p_var->operator bool();
					return BOX_BOOLEAN(val);
				}
				case Variant::INT: {
					int val = p_var->operator signed int();
					return BOX_INT32(val);
				}
				case Variant::REAL: {
#ifdef REAL_T_IS_DOUBLE
					double val = p_var->operator double();
					return BOX_DOUBLE(val);
#else
					float val = p_var->operator float();
					return BOX_FLOAT(val);
#endif
				}
				case Variant::STRING:
					return (MonoObject *)mono_string_from_godot(p_var->operator String());
				case Variant::VECTOR2:
					RETURN_BOXED_STRUCT(Vector2, p_var);
				case Variant::RECT2:
					RETURN_BOXED_STRUCT(Rect2, p_var);
				case Variant::VECTOR3:
					RETURN_BOXED_STRUCT(Vector3, p_var);
				case Variant::TRANSFORM2D:
					RETURN_BOXED_STRUCT(Transform2D, p_var);
				case Variant::PLANE:
					RETURN_BOXED_STRUCT(Plane, p_var);
				case Variant::QUAT:
					RETURN_BOXED_STRUCT(Quat, p_var);
				case Variant::RECT3:
					RETURN_BOXED_STRUCT(Rect3, p_var);
				case Variant::BASIS:
					RETURN_BOXED_STRUCT(Basis, p_var);
				case Variant::TRANSFORM:
					RETURN_BOXED_STRUCT(Transform, p_var);
				case Variant::COLOR:
					RETURN_BOXED_STRUCT(Color, p_var);
				case Variant::NODE_PATH:
					return GDMonoUtils::create_managed_from(p_var->operator NodePath());
				case Variant::_RID:
					return GDMonoUtils::create_managed_from(p_var->operator RID());
				case Variant::OBJECT: {
					return GDMonoUtils::unmanaged_get_managed(p_var->operator Object *());
				}
				case Variant::DICTIONARY:
					return Dictionary_to_mono_object(p_var->operator Dictionary());
				case Variant::ARRAY:
					return (MonoObject *)Array_to_mono_array(p_var->operator Array());
				case Variant::POOL_BYTE_ARRAY:
					return (MonoObject *)PoolByteArray_to_mono_array(p_var->operator PoolByteArray());
				case Variant::POOL_INT_ARRAY:
					return (MonoObject *)PoolIntArray_to_mono_array(p_var->operator PoolIntArray());
				case Variant::POOL_REAL_ARRAY:
					return (MonoObject *)PoolRealArray_to_mono_array(p_var->operator PoolRealArray());
				case Variant::POOL_STRING_ARRAY:
					return (MonoObject *)PoolStringArray_to_mono_array(p_var->operator PoolStringArray());
				case Variant::POOL_VECTOR2_ARRAY:
					return (MonoObject *)PoolVector2Array_to_mono_array(p_var->operator PoolVector2Array());
				case Variant::POOL_VECTOR3_ARRAY:
					return (MonoObject *)PoolVector3Array_to_mono_array(p_var->operator PoolVector3Array());
				case Variant::POOL_COLOR_ARRAY:
					return (MonoObject *)PoolColorArray_to_mono_array(p_var->operator PoolColorArray());
				default:
					return NULL;
			}
			break;
			case MONO_TYPE_GENERICINST: {
				if (CACHED_RAW_MONO_CLASS(Dictionary) == p_type.type_class->get_raw()) {
					return Dictionary_to_mono_object(p_var->operator Dictionary());
				}
			} break;
		} break;
	}

	ERR_EXPLAIN(String() + "Attempted to convert Variant to an unmarshallable managed type. Name: \'" +
				p_type.type_class->get_name() + "\' Encoding: " + itos(p_type.type_encoding));
	ERR_FAIL_V(NULL);
}
Пример #14
0
Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_resource,uint32_t p_flags) {

	if (p_path.ends_with(".tscn")) {
		packed_scene=p_resource;
	}

	Error err;
	f = FileAccess::open(p_path, FileAccess::WRITE,&err);
	ERR_FAIL_COND_V( err, ERR_CANT_OPEN );
	FileAccessRef _fref(f);

	local_path = Globals::get_singleton()->localize_path(p_path);

	relative_paths=p_flags&ResourceSaver::FLAG_RELATIVE_PATHS;
	skip_editor=p_flags&ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES;
	bundle_resources=p_flags&ResourceSaver::FLAG_BUNDLE_RESOURCES;
	takeover_paths=p_flags&ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
	if (!p_path.begins_with("res://")) {
		takeover_paths=false;
	}

	// save resources
	_find_resources(p_resource,true);

	if (packed_scene.is_valid()) {
		//add instances to external resources if saving a packed scene
		for(int i=0;i<packed_scene->get_state()->get_node_count();i++) {
			if (packed_scene->get_state()->is_node_instance_placeholder(i))
				continue;

			Ref<PackedScene> instance=packed_scene->get_state()->get_node_instance(i);
			if (instance.is_valid() && !external_resources.has(instance)) {
				int index = external_resources.size();
				external_resources[instance]=index;
			}
		}
	}


	ERR_FAIL_COND_V(err!=OK,err);

	{
		String title=packed_scene.is_valid()?"[gd_scene ":"[gd_resource ";
		if (packed_scene.is_null())
			title+="type=\""+p_resource->get_type()+"\" ";
		int load_steps=saved_resources.size()+external_resources.size();
		//if (packed_scene.is_valid()) {
		//	load_steps+=packed_scene->get_node_count();
		//}
		//no, better to not use load steps from nodes, no point to that

		if (load_steps>1) {
			title+="load_steps="+itos(load_steps)+" ";
		}
		title+="format="+itos(FORMAT_VERSION)+"";
		//title+="engine_version=\""+itos(VERSION_MAJOR)+"."+itos(VERSION_MINOR)+"\"";

		f->store_string(title);
		f->store_line("]\n"); //one empty line
	}


	Vector<RES> sorted_er;
	sorted_er.resize(external_resources.size());

	for(Map<RES,int>::Element *E=external_resources.front();E;E=E->next()) {

		sorted_er[E->get()]=E->key();
	}

	for(int i=0;i<sorted_er.size();i++) {
		String p = sorted_er[i]->get_path();

		f->store_string("[ext_resource path=\""+p+"\" type=\""+sorted_er[i]->get_save_type()+"\" id="+itos(i+1)+"]\n"); //bundled
	}

	if (external_resources.size())
		f->store_line(String()); //separate

	Set<int> used_indices;

	for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) {

		RES res = E->get();
		if (E->next() && (res->get_path()=="" || res->get_path().find("::") != -1 )) {

			if (res->get_subindex()!=0) {
				if (used_indices.has(res->get_subindex())) {
					res->set_subindex(0); //repeated
				} else {
					used_indices.insert(res->get_subindex());
				}
			}
		}
	}

	for(List<RES>::Element *E=saved_resources.front();E;E=E->next()) {

		RES res = E->get();
		ERR_CONTINUE(!resource_set.has(res));
		bool main = (E->next()==NULL);

		if (main && packed_scene.is_valid())
			break; //save as a scene

		if (main) {
			f->store_line("[resource]\n");
		} else {
			String line="[sub_resource ";
			if (res->get_subindex()==0) {
				int new_subindex=1;
				if (used_indices.size()) {
					new_subindex=used_indices.back()->get()+1;
				}

				res->set_subindex(new_subindex);
				used_indices.insert(new_subindex);
			}

			int idx = res->get_subindex();
			line+="type=\""+res->get_type()+"\" id="+itos(idx);
			f->store_line(line+"]\n");
			if (takeover_paths) {
				res->set_path(p_path+"::"+itos(idx),true);
			}

			internal_resources[res]=idx;

		}


		List<PropertyInfo> property_list;
		res->get_property_list(&property_list);
//		property_list.sort();
		for(List<PropertyInfo>::Element *PE = property_list.front();PE;PE=PE->next()) {


			if (skip_editor && PE->get().name.begins_with("__editor"))
				continue;

			if (PE->get().usage&PROPERTY_USAGE_STORAGE || (bundle_resources && PE->get().usage&PROPERTY_USAGE_BUNDLE)) {

				String name = PE->get().name;
				Variant value = res->get(name);


				if ((PE->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero())||(PE->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && value.is_one()) )
					continue;

				if (PE->get().type==Variant::OBJECT && value.is_zero() && !(PE->get().usage&PROPERTY_USAGE_STORE_IF_NULL))
					continue;

				String vars;
				VariantWriter::write_to_string(value,vars,_write_resources,this);
				f->store_string(_valprop(name)+" = "+vars+"\n");
			}


		}

		f->store_string("\n");

	}

	if (packed_scene.is_valid()) {
		//if this is a scene, save nodes and connections!
		Ref<SceneState> state = packed_scene->get_state();
		for(int i=0;i<state->get_node_count();i++) {

			StringName type = state->get_node_type(i);
			StringName name = state->get_node_name(i);
			NodePath path = state->get_node_path(i,true);
			NodePath owner = state->get_node_owner_path(i);
			Ref<PackedScene> instance = state->get_node_instance(i);
			String instance_placeholder = state->get_node_instance_placeholder(i);
			Vector<StringName> groups = state->get_node_groups(i);



			String header="[node";
			header+=" name=\""+String(name)+"\"";
			if (type!=StringName()) {
				header+=" type=\""+String(type)+"\"";
			}
			if (path!=NodePath()) {
				header+=" parent=\""+String(path.simplified())+"\"";
			}
			if (owner!=NodePath() && owner!=NodePath(".")) {
				header+=" owner=\""+String(owner.simplified())+"\"";
			}

			if (groups.size()) {
				String sgroups=" groups=[ ";
				for(int j=0;j<groups.size();j++) {
					if (j>0)
						sgroups+=", ";
					sgroups+="\""+groups[j].operator String().c_escape()+"\"";
				}
				sgroups+=" ]";
				header+=sgroups;
			}

			f->store_string(header);

			if (instance_placeholder!=String()) {

				String vars;
				f->store_string(" instance_placeholder=");
				VariantWriter::write_to_string(instance_placeholder,vars,_write_resources,this);
				f->store_string(vars);
			}

			if (instance.is_valid()) {

				String vars;
				f->store_string(" instance=");
				VariantWriter::write_to_string(instance,vars,_write_resources,this);
				f->store_string(vars);

			}

			f->store_line("]\n");

			for(int j=0;j<state->get_node_property_count(i);j++) {

				String vars;
				VariantWriter::write_to_string(state->get_node_property_value(i,j),vars,_write_resources,this);

				f->store_string(_valprop(String(state->get_node_property_name(i,j)))+" = "+vars+"\n");
			}

			if (state->get_node_property_count(i)) {
				//add space
				f->store_line(String());
			}

		}

		for(int i=0;i<state->get_connection_count();i++) {

			String connstr="[connection";
			connstr+=" signal=\""+String(state->get_connection_signal(i))+"\"";
			connstr+=" from=\""+String(state->get_connection_source(i).simplified())+"\"";
			connstr+=" to=\""+String(state->get_connection_target(i).simplified())+"\"";
			connstr+=" method=\""+String(state->get_connection_method(i))+"\"";
			int flags = state->get_connection_flags(i);
			if (flags!=Object::CONNECT_PERSIST) {
				connstr+=" flags="+itos(flags);
			}

			Array binds=state->get_connection_binds(i);
			f->store_string(connstr);
			if (binds.size()) {
				String vars;
				VariantWriter::write_to_string(binds,vars,_write_resources,this);
				f->store_string(" binds= "+vars);

			}

			f->store_line("]\n");
		}

		f->store_line(String());

		Vector<NodePath> editable_instances = state->get_editable_instances();
		for(int i=0;i<editable_instances.size();i++) {
			f->store_line("[editable path=\""+editable_instances[i].operator String()+"\"]");
		}
	}

	if (f->get_error()!=OK && f->get_error()!=ERR_FILE_EOF) {
		f->close();
		return ERR_CANT_CREATE;
	}

	f->close();
	//memdelete(f);

	return OK;
}
Пример #15
0
void AnimationTreeEditor::_edit_filters() {

	filter_dialog->popup_centered_ratio();
	filter->clear();

	Set<String> npb;
	_find_paths_for_filter(edited_node,npb);

	TreeItem *root = filter->create_item();
	filter->set_hide_root(true);
	Map<String,TreeItem*> pm;

	Node *base = anim_tree->get_node( anim_tree->get_base_path() );

	for(Set<String>::Element *E=npb.front();E;E=E->next()) {

		TreeItem *parent=root;
		String descr=E->get();
		if (base) {
			NodePath np = E->get();

			if (np.get_property()!=StringName()) {
				Node *n = base->get_node(np);
				Skeleton *s = n->cast_to<Skeleton>();
				if (s) {

					String skelbase = E->get().substr(0,E->get().find(":"));


					int bidx = s->find_bone(np.get_property());

					if (bidx!=-1) {
						int bparent = s->get_bone_parent(bidx);
						//
						if (bparent!=-1) {


							String bpn = skelbase+":"+s->get_bone_name(bparent);
							if (pm.has(bpn)) {
								parent=pm[bpn];
								descr=np.get_property();
							}
						} else {

							if (pm.has(skelbase)) {
								parent=pm[skelbase];

							}
						}
					}
				}
			}
		}

		TreeItem *it = filter->create_item(parent);
		it->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
		it->set_text(0,descr);
		it->set_metadata(0,NodePath(E->get()));
		it->set_editable(0,true);
		if (anim_tree->node_get_type(edited_node)==AnimationTreePlayer::NODE_ONESHOT) {
			it->set_checked(0, anim_tree->oneshot_node_is_path_filtered(edited_node,E->get()));
		} else if (anim_tree->node_get_type(edited_node)==AnimationTreePlayer::NODE_BLEND2) {
			it->set_checked(0, anim_tree->blend2_node_is_path_filtered(edited_node,E->get()));
		}
		pm[E->get()]=it;
	}


}
Пример #16
0
void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_value) {
#define SET_FROM_STRUCT(m_type)                                                               \
	{                                                                                         \
		GDMonoMarshal::M_##m_type from = MARSHALLED_OUT(m_type, p_value.operator ::m_type()); \
		mono_field_set_value(p_object, mono_field, &from);                                    \
	}

#define SET_FROM_ARRAY(m_type)                                                                   \
	{                                                                                            \
		MonoArray *managed = GDMonoMarshal::m_type##_to_mono_array(p_value.operator ::m_type()); \
		mono_field_set_value(p_object, mono_field, &managed);                                    \
	}

	switch (type.type_encoding) {
		case MONO_TYPE_BOOLEAN: {
			MonoBoolean val = p_value.operator bool();
			mono_field_set_value(p_object, mono_field, &val);
		} break;

		case MONO_TYPE_CHAR: {
			int16_t val = p_value.operator unsigned short();
			mono_field_set_value(p_object, mono_field, &val);
		} break;

		case MONO_TYPE_I1: {
			int8_t val = p_value.operator signed char();
			mono_field_set_value(p_object, mono_field, &val);
		} break;
		case MONO_TYPE_I2: {
			int16_t val = p_value.operator signed short();
			mono_field_set_value(p_object, mono_field, &val);
		} break;
		case MONO_TYPE_I4: {
			int32_t val = p_value.operator signed int();
			mono_field_set_value(p_object, mono_field, &val);
		} break;
		case MONO_TYPE_I8: {
			int64_t val = p_value.operator int64_t();
			mono_field_set_value(p_object, mono_field, &val);
		} break;

		case MONO_TYPE_U1: {
			uint8_t val = p_value.operator unsigned char();
			mono_field_set_value(p_object, mono_field, &val);
		} break;
		case MONO_TYPE_U2: {
			uint16_t val = p_value.operator unsigned short();
			mono_field_set_value(p_object, mono_field, &val);
		} break;
		case MONO_TYPE_U4: {
			uint32_t val = p_value.operator unsigned int();
			mono_field_set_value(p_object, mono_field, &val);
		} break;
		case MONO_TYPE_U8: {
			uint64_t val = p_value.operator uint64_t();
			mono_field_set_value(p_object, mono_field, &val);
		} break;

		case MONO_TYPE_R4: {
			float val = p_value.operator float();
			mono_field_set_value(p_object, mono_field, &val);
		} break;

		case MONO_TYPE_R8: {
			double val = p_value.operator double();
			mono_field_set_value(p_object, mono_field, &val);
		} break;

		case MONO_TYPE_STRING: {
			MonoString *mono_string = GDMonoMarshal::mono_string_from_godot(p_value);
			mono_field_set_value(p_object, mono_field, mono_string);
		} break;

		case MONO_TYPE_VALUETYPE: {
			GDMonoClass *tclass = type.type_class;

			if (tclass == CACHED_CLASS(Vector2)) {
				SET_FROM_STRUCT(Vector2);
				break;
			}

			if (tclass == CACHED_CLASS(Rect2)) {
				SET_FROM_STRUCT(Rect2);
				break;
			}

			if (tclass == CACHED_CLASS(Transform2D)) {
				SET_FROM_STRUCT(Transform2D);
				break;
			}

			if (tclass == CACHED_CLASS(Vector3)) {
				SET_FROM_STRUCT(Vector3);
				break;
			}

			if (tclass == CACHED_CLASS(Basis)) {
				SET_FROM_STRUCT(Basis);
				break;
			}

			if (tclass == CACHED_CLASS(Quat)) {
				SET_FROM_STRUCT(Quat);
				break;
			}

			if (tclass == CACHED_CLASS(Transform)) {
				SET_FROM_STRUCT(Transform);
				break;
			}

			if (tclass == CACHED_CLASS(AABB)) {
				SET_FROM_STRUCT(AABB);
				break;
			}

			if (tclass == CACHED_CLASS(Color)) {
				SET_FROM_STRUCT(Color);
				break;
			}

			if (tclass == CACHED_CLASS(Plane)) {
				SET_FROM_STRUCT(Plane);
				break;
			}

			if (mono_class_is_enum(tclass->get_mono_ptr())) {
				MonoType *enum_basetype = mono_class_enum_basetype(tclass->get_mono_ptr());
				switch (mono_type_get_type(enum_basetype)) {
					case MONO_TYPE_BOOLEAN: {
						MonoBoolean val = p_value.operator bool();
						mono_field_set_value(p_object, mono_field, &val);
						break;
					}
					case MONO_TYPE_CHAR: {
						uint16_t val = p_value.operator unsigned short();
						mono_field_set_value(p_object, mono_field, &val);
						break;
					}
					case MONO_TYPE_I1: {
						int8_t val = p_value.operator signed char();
						mono_field_set_value(p_object, mono_field, &val);
						break;
					}
					case MONO_TYPE_I2: {
						int16_t val = p_value.operator signed short();
						mono_field_set_value(p_object, mono_field, &val);
						break;
					}
					case MONO_TYPE_I4: {
						int32_t val = p_value.operator signed int();
						mono_field_set_value(p_object, mono_field, &val);
						break;
					}
					case MONO_TYPE_I8: {
						int64_t val = p_value.operator int64_t();
						mono_field_set_value(p_object, mono_field, &val);
						break;
					}
					case MONO_TYPE_U1: {
						uint8_t val = p_value.operator unsigned char();
						mono_field_set_value(p_object, mono_field, &val);
						break;
					}
					case MONO_TYPE_U2: {
						uint16_t val = p_value.operator unsigned short();
						mono_field_set_value(p_object, mono_field, &val);
						break;
					}
					case MONO_TYPE_U4: {
						uint32_t val = p_value.operator unsigned int();
						mono_field_set_value(p_object, mono_field, &val);
						break;
					}
					case MONO_TYPE_U8: {
						uint64_t val = p_value.operator uint64_t();
						mono_field_set_value(p_object, mono_field, &val);
						break;
					}
					default: {
						ERR_EXPLAIN(String() + "Attempted to convert Variant to a managed enum value of unmarshallable base type.");
						ERR_FAIL();
					}
				}

				break;
			}

			ERR_EXPLAIN(String() + "Attempted to set the value of a field of unmarshallable type: " + tclass->get_name());
			ERR_FAIL();
		} break;

		case MONO_TYPE_ARRAY:
		case MONO_TYPE_SZARRAY: {
			MonoArrayType *array_type = mono_type_get_array_type(type.type_class->get_mono_type());

			if (array_type->eklass == CACHED_CLASS_RAW(MonoObject)) {
				SET_FROM_ARRAY(Array);
				break;
			}

			if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) {
				SET_FROM_ARRAY(PoolByteArray);
				break;
			}

			if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) {
				SET_FROM_ARRAY(PoolIntArray);
				break;
			}

			if (array_type->eklass == REAL_T_MONOCLASS) {
				SET_FROM_ARRAY(PoolRealArray);
				break;
			}

			if (array_type->eklass == CACHED_CLASS_RAW(String)) {
				SET_FROM_ARRAY(PoolStringArray);
				break;
			}

			if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) {
				SET_FROM_ARRAY(PoolVector2Array);
				break;
			}

			if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) {
				SET_FROM_ARRAY(PoolVector3Array);
				break;
			}

			if (array_type->eklass == CACHED_CLASS_RAW(Color)) {
				SET_FROM_ARRAY(PoolColorArray);
				break;
			}

			ERR_EXPLAIN(String() + "Attempted to convert Variant to a managed array of unmarshallable element type.");
			ERR_FAIL();
		} break;

		case MONO_TYPE_CLASS: {
			GDMonoClass *type_class = type.type_class;

			// GodotObject
			if (CACHED_CLASS(GodotObject)->is_assignable_from(type_class)) {
				MonoObject *managed = GDMonoUtils::unmanaged_get_managed(p_value.operator Object *());
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}

			if (CACHED_CLASS(NodePath) == type_class) {
				MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator NodePath());
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}

			if (CACHED_CLASS(RID) == type_class) {
				MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator RID());
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}

			if (CACHED_CLASS(Dictionary) == type_class) {
				MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator Dictionary(), CACHED_CLASS(Dictionary));
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}

			if (CACHED_CLASS(Array) == type_class) {
				MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator Array(), CACHED_CLASS(Array));
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}

			ERR_EXPLAIN(String() + "Attempted to set the value of a field of unmarshallable type: " + type_class->get_name());
			ERR_FAIL();
		} break;

		case MONO_TYPE_OBJECT: {
			// Variant
			switch (p_value.get_type()) {
				case Variant::BOOL: {
					MonoBoolean val = p_value.operator bool();
					mono_field_set_value(p_object, mono_field, &val);
				} break;
				case Variant::INT: {
					int32_t val = p_value.operator signed int();
					mono_field_set_value(p_object, mono_field, &val);
				} break;
				case Variant::REAL: {
#ifdef REAL_T_IS_DOUBLE
					double val = p_value.operator double();
					mono_field_set_value(p_object, mono_field, &val);
#else
					float val = p_value.operator float();
					mono_field_set_value(p_object, mono_field, &val);
#endif
				} break;
				case Variant::STRING: {
					MonoString *mono_string = GDMonoMarshal::mono_string_from_godot(p_value);
					mono_field_set_value(p_object, mono_field, mono_string);
				} break;
				case Variant::VECTOR2: {
					SET_FROM_STRUCT(Vector2);
				} break;
				case Variant::RECT2: {
					SET_FROM_STRUCT(Rect2);
				} break;
				case Variant::VECTOR3: {
					SET_FROM_STRUCT(Vector3);
				} break;
				case Variant::TRANSFORM2D: {
					SET_FROM_STRUCT(Transform2D);
				} break;
				case Variant::PLANE: {
					SET_FROM_STRUCT(Plane);
				} break;
				case Variant::QUAT: {
					SET_FROM_STRUCT(Quat);
				} break;
				case Variant::AABB: {
					SET_FROM_STRUCT(AABB);
				} break;
				case Variant::BASIS: {
					SET_FROM_STRUCT(Basis);
				} break;
				case Variant::TRANSFORM: {
					SET_FROM_STRUCT(Transform);
				} break;
				case Variant::COLOR: {
					SET_FROM_STRUCT(Color);
				} break;
				case Variant::NODE_PATH: {
					MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator NodePath());
					mono_field_set_value(p_object, mono_field, managed);
				} break;
				case Variant::_RID: {
					MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator RID());
					mono_field_set_value(p_object, mono_field, managed);
				} break;
				case Variant::OBJECT: {
					MonoObject *managed = GDMonoUtils::unmanaged_get_managed(p_value.operator Object *());
					mono_field_set_value(p_object, mono_field, managed);
					break;
				}
				case Variant::DICTIONARY: {
					MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator Dictionary(), CACHED_CLASS(Dictionary));
					mono_field_set_value(p_object, mono_field, managed);
				} break;
				case Variant::ARRAY: {
					MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator Array(), CACHED_CLASS(Array));
					mono_field_set_value(p_object, mono_field, managed);
				} break;
				case Variant::POOL_BYTE_ARRAY: {
					SET_FROM_ARRAY(PoolByteArray);
				} break;
				case Variant::POOL_INT_ARRAY: {
					SET_FROM_ARRAY(PoolIntArray);
				} break;
				case Variant::POOL_REAL_ARRAY: {
					SET_FROM_ARRAY(PoolRealArray);
				} break;
				case Variant::POOL_STRING_ARRAY: {
					SET_FROM_ARRAY(PoolStringArray);
				} break;
				case Variant::POOL_VECTOR2_ARRAY: {
					SET_FROM_ARRAY(PoolVector2Array);
				} break;
				case Variant::POOL_VECTOR3_ARRAY: {
					SET_FROM_ARRAY(PoolVector3Array);
				} break;
				case Variant::POOL_COLOR_ARRAY: {
					SET_FROM_ARRAY(PoolColorArray);
				} break;
				default: break;
			}
		} break;

		case MONO_TYPE_GENERICINST: {
			MonoReflectionType *reftype = mono_type_get_object(SCRIPTS_DOMAIN, type.type_class->get_mono_type());

			MonoException *exc = NULL;

			GDMonoUtils::IsDictionaryGenericType type_is_dict = CACHED_METHOD_THUNK(MarshalUtils, IsDictionaryGenericType);
			MonoBoolean is_dict = type_is_dict((MonoObject *)reftype, (MonoObject **)&exc);
			UNLIKELY_UNHANDLED_EXCEPTION(exc);

			if (is_dict) {
				MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator Dictionary(), type.type_class);
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}

			exc = NULL;

			GDMonoUtils::IsArrayGenericType type_is_array = CACHED_METHOD_THUNK(MarshalUtils, IsArrayGenericType);
			MonoBoolean is_array = type_is_array((MonoObject *)reftype, (MonoObject **)&exc);
			UNLIKELY_UNHANDLED_EXCEPTION(exc);

			if (is_array) {
				MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator Array(), type.type_class);
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}
		} break;

		default: {
			ERR_PRINTS(String() + "Attempted to set the value of a field of unexpected type encoding: " + itos(type.type_encoding));
		} break;
	}

#undef SET_FROM_ARRAY_AND_BREAK
#undef SET_FROM_STRUCT_AND_BREAK
}
void EditorPropertyRootMotion::_node_clear() {

	emit_signal("property_changed", get_edited_property(), NodePath());
	update_property();
}
Пример #18
0
NodePath BakedLightmapData::get_user_path(int p_user) const {

	ERR_FAIL_INDEX_V(p_user, users.size(), NodePath());
	return users[p_user].path;
}
Пример #19
0
void GDAPI godot_node_path_new_copy(godot_node_path *r_dest, const godot_node_path *p_src) {
	NodePath *dest = (NodePath *)r_dest;
	const NodePath *src = (const NodePath *)p_src;
	memnew_placement(dest, NodePath(*src));
}
Пример #20
0
World::World(WindowFramework* windowFramework)
    : m_windowFramework(windowFramework),
      m_title(),
      m_inst1(),
      m_inst2(),
      m_inst3(),
      m_inst4(),
      m_altCam(),
      m_teapot(),
      m_teapotInterval(),
      m_bufferViewer(NULL)
      // m_tvMen
{
    // Note: set background color here
    m_windowFramework->get_graphics_output()->get_active_display_region(0)->
    set_clear_color(Colorf(0, 0, 0, 1));

    // Post the instructions.
    m_title = add_title("Panda3D: Tutorial - Using Render-to-Texture");
    m_inst1 = add_instructions(0.95,"ESC: Quit");
    m_inst2 = add_instructions(0.90,"Up/Down: Zoom in/out on the Teapot");
    m_inst3 = add_instructions(0.85,"Left/Right: Move teapot left/right");
    m_inst4 = add_instructions(0.80,"V: View the render-to-texture results");

    //we get a handle to the default window
    PT(GraphicsOutput) mainWindow = m_windowFramework->get_graphics_output();

    // we now get buffer thats going to hold the texture of our new scene
    PT(GraphicsOutput) altBuffer = mainWindow->make_texture_buffer(
                                       "hello", 256, 256);

    // now we have to setup a new scene graph to make this scene
    NodePath altRender("new render");

    // this takes care of setting up the camera properly
    m_altCam = m_windowFramework->make_camera();
    // Note: set the size and shape of the "film" within the lens equal to the
    //       buffer of our new scene
    DCAST(Camera, m_altCam.node())->get_lens()->set_film_size(
        altBuffer->get_x_size(), altBuffer->get_y_size());
    // Note: make a DisplayRegion for the camera
    PT(DisplayRegion) dr = altBuffer->make_display_region(0, 1, 0, 1);
    dr->set_sort(0);
    dr->set_camera(m_altCam);
    m_altCam.reparent_to(altRender);
    m_altCam.set_pos(0, -10, 0);

    // get the teapot and rotates it for a simple animation
    const NodePath& models =
        m_windowFramework->get_panda_framework()->get_models();
    m_teapot = m_windowFramework->load_model(models, "../models/teapot");
    m_teapot.reparent_to(altRender);
    m_teapot.set_pos(0, 0, -1);

    const bool bakeInStart = true;
    const bool fluid = false;
    m_teapotInterval = new CLerpNodePathInterval("teapotInterval", 1.5,
            CLerpInterval::BT_no_blend, bakeInStart, fluid, m_teapot, NodePath());
    m_teapotInterval->set_start_hpr(m_teapot.get_hpr());
    m_teapotInterval->set_end_hpr(LVecBase3f(m_teapot.get_h()+360,
                                  m_teapot.get_p()+360,
                                  m_teapot.get_r()+360));
    m_teapotInterval->loop();

    // put some lighting on the teapot
    PT(DirectionalLight) dlight = new DirectionalLight("dlight");
    PT(AmbientLight) alight = new AmbientLight("alight");
    NodePath dlnp = altRender.attach_new_node(dlight);
    NodePath alnp = altRender.attach_new_node(alight);
    dlight->set_color(Colorf(0.8, 0.8, 0.5, 1));
    alight->set_color(Colorf(0.2, 0.2, 0.2, 1));
    dlnp.set_hpr(0, -60, 0);
    altRender.set_light(dlnp);
    altRender.set_light(alnp);

    // Panda contains a built-in viewer that lets you view the results of
    // your render-to-texture operations.  This code configures the viewer.

    WORLD_DEFINE_KEY("v", "toggleBufferViewer", toggle_buffer_viewer);
    m_bufferViewer = new CBufferViewer(m_windowFramework);
    m_bufferViewer->set_position(CBufferViewer::CP_llcorner);
    m_bufferViewer->set_card_size(1.0, 0.0);

    // Create the tv-men. Each TV-man will display the
    // offscreen-texture on his TV screen.
    make_tv_man(-5, 30,  1, altBuffer->get_texture(), 0.9);
    make_tv_man( 5, 30,  1, altBuffer->get_texture(), 1.4);
    make_tv_man( 0, 23, -3, altBuffer->get_texture(), 2.0);
    make_tv_man(-5, 20, -6, altBuffer->get_texture(), 1.1);
    make_tv_man( 5, 18, -5, altBuffer->get_texture(), 1.7);

    WORLD_DEFINE_KEY("escape", "exit", quit);
    WORLD_DEFINE_KEY("arrow_up", "zoomIn", zoom_in);
    WORLD_DEFINE_KEY("arrow_down", "zoomOut", zoom_out);
    WORLD_DEFINE_KEY("arrow_left", "moveLeft", move_left);
    WORLD_DEFINE_KEY("arrow_right", "moveRight", move_right);

    WORLD_ADD_TASK("worldAsyncTask", async_task);
}
Пример #21
0
void GDMonoField::set_value(MonoObject *p_object, const Variant &p_value) {
#define SET_FROM_STRUCT_AND_BREAK(m_type)                \
	{                                                    \
		const m_type &val = p_value.operator m_type();   \
		MARSHALLED_OUT(m_type, val, raw);                \
		mono_field_set_value(p_object, mono_field, raw); \
		break;                                           \
	}

#define SET_FROM_PRIMITIVE(m_type)                        \
	{                                                     \
		m_type val = p_value.operator m_type();           \
		mono_field_set_value(p_object, mono_field, &val); \
		break;                                            \
	}

#define SET_FROM_ARRAY_AND_BREAK(m_type)                                                       \
	{                                                                                          \
		MonoArray *managed = GDMonoMarshal::m_type##_to_mono_array(p_value.operator m_type()); \
		mono_field_set_value(p_object, mono_field, &managed);                                  \
		break;                                                                                 \
	}

	switch (type.type_encoding) {
		case MONO_TYPE_BOOLEAN: {
			SET_FROM_PRIMITIVE(bool);
		} break;

		case MONO_TYPE_I1: {
			SET_FROM_PRIMITIVE(signed char);
		} break;
		case MONO_TYPE_I2: {
			SET_FROM_PRIMITIVE(signed short);
		} break;
		case MONO_TYPE_I4: {
			SET_FROM_PRIMITIVE(signed int);
		} break;
		case MONO_TYPE_I8: {
			SET_FROM_PRIMITIVE(int64_t);
		} break;

		case MONO_TYPE_U1: {
			SET_FROM_PRIMITIVE(unsigned char);
		} break;
		case MONO_TYPE_U2: {
			SET_FROM_PRIMITIVE(unsigned short);
		} break;
		case MONO_TYPE_U4: {
			SET_FROM_PRIMITIVE(unsigned int);
		} break;
		case MONO_TYPE_U8: {
			SET_FROM_PRIMITIVE(uint64_t);
		} break;

		case MONO_TYPE_R4: {
			SET_FROM_PRIMITIVE(float);
		} break;

		case MONO_TYPE_R8: {
			SET_FROM_PRIMITIVE(double);
		} break;

		case MONO_TYPE_STRING: {
			MonoString *mono_string = GDMonoMarshal::mono_string_from_godot(p_value);
			mono_field_set_value(p_object, mono_field, mono_string);
		} break;

		case MONO_TYPE_VALUETYPE: {
			GDMonoClass *tclass = type.type_class;

			if (tclass == CACHED_CLASS(Vector2))
				SET_FROM_STRUCT_AND_BREAK(Vector2);

			if (tclass == CACHED_CLASS(Rect2))
				SET_FROM_STRUCT_AND_BREAK(Rect2);

			if (tclass == CACHED_CLASS(Transform2D))
				SET_FROM_STRUCT_AND_BREAK(Transform2D);

			if (tclass == CACHED_CLASS(Vector3))
				SET_FROM_STRUCT_AND_BREAK(Vector3);

			if (tclass == CACHED_CLASS(Basis))
				SET_FROM_STRUCT_AND_BREAK(Basis);

			if (tclass == CACHED_CLASS(Quat))
				SET_FROM_STRUCT_AND_BREAK(Quat);

			if (tclass == CACHED_CLASS(Transform))
				SET_FROM_STRUCT_AND_BREAK(Transform);

			if (tclass == CACHED_CLASS(AABB))
				SET_FROM_STRUCT_AND_BREAK(AABB);

			if (tclass == CACHED_CLASS(Color))
				SET_FROM_STRUCT_AND_BREAK(Color);

			if (tclass == CACHED_CLASS(Plane))
				SET_FROM_STRUCT_AND_BREAK(Plane);

			if (mono_class_is_enum(tclass->get_raw()))
				SET_FROM_PRIMITIVE(signed int);

			ERR_EXPLAIN(String() + "Attempted to set the value of a field of unmarshallable type: " + tclass->get_name());
			ERR_FAIL();
		} break;

		case MONO_TYPE_ARRAY:
		case MONO_TYPE_SZARRAY: {
			MonoArrayType *array_type = mono_type_get_array_type(GDMonoClass::get_raw_type(type.type_class));

			if (array_type->eklass == CACHED_CLASS_RAW(MonoObject))
				SET_FROM_ARRAY_AND_BREAK(Array);

			if (array_type->eklass == CACHED_CLASS_RAW(uint8_t))
				SET_FROM_ARRAY_AND_BREAK(PoolByteArray);

			if (array_type->eklass == CACHED_CLASS_RAW(int32_t))
				SET_FROM_ARRAY_AND_BREAK(PoolIntArray);

			if (array_type->eklass == REAL_T_MONOCLASS)
				SET_FROM_ARRAY_AND_BREAK(PoolRealArray);

			if (array_type->eklass == CACHED_CLASS_RAW(String))
				SET_FROM_ARRAY_AND_BREAK(PoolStringArray);

			if (array_type->eklass == CACHED_CLASS_RAW(Vector2))
				SET_FROM_ARRAY_AND_BREAK(PoolVector2Array);

			if (array_type->eklass == CACHED_CLASS_RAW(Vector3))
				SET_FROM_ARRAY_AND_BREAK(PoolVector3Array);

			if (array_type->eklass == CACHED_CLASS_RAW(Color))
				SET_FROM_ARRAY_AND_BREAK(PoolColorArray);

			ERR_EXPLAIN(String() + "Attempted to convert Variant to a managed array of unmarshallable element type.");
			ERR_FAIL();
		} break;

		case MONO_TYPE_CLASS: {
			GDMonoClass *type_class = type.type_class;

			// GodotObject
			if (CACHED_CLASS(GodotObject)->is_assignable_from(type_class)) {
				MonoObject *managed = GDMonoUtils::unmanaged_get_managed(p_value.operator Object *());
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}

			if (CACHED_CLASS(NodePath) == type_class) {
				MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator NodePath());
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}

			if (CACHED_CLASS(RID) == type_class) {
				MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator RID());
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}

			ERR_EXPLAIN(String() + "Attempted to set the value of a field of unmarshallable type: " + type_class->get_name());
			ERR_FAIL();
		} break;

		case MONO_TYPE_OBJECT: {
			// Variant
			switch (p_value.get_type()) {
				case Variant::BOOL: {
					SET_FROM_PRIMITIVE(bool);
				} break;
				case Variant::INT: {
					SET_FROM_PRIMITIVE(int);
				} break;
				case Variant::REAL: {
#ifdef REAL_T_IS_DOUBLE
					SET_FROM_PRIMITIVE(double);
#else
					SET_FROM_PRIMITIVE(float);
#endif
				} break;
				case Variant::STRING: {
					MonoString *mono_string = GDMonoMarshal::mono_string_from_godot(p_value);
					mono_field_set_value(p_object, mono_field, mono_string);
				} break;
				case Variant::VECTOR2: SET_FROM_STRUCT_AND_BREAK(Vector2);
				case Variant::RECT2: SET_FROM_STRUCT_AND_BREAK(Rect2);
				case Variant::VECTOR3: SET_FROM_STRUCT_AND_BREAK(Vector3);
				case Variant::TRANSFORM2D: SET_FROM_STRUCT_AND_BREAK(Transform2D);
				case Variant::PLANE: SET_FROM_STRUCT_AND_BREAK(Plane);
				case Variant::QUAT: SET_FROM_STRUCT_AND_BREAK(Quat);
				case Variant::AABB: SET_FROM_STRUCT_AND_BREAK(AABB);
				case Variant::BASIS: SET_FROM_STRUCT_AND_BREAK(Basis);
				case Variant::TRANSFORM: SET_FROM_STRUCT_AND_BREAK(Transform);
				case Variant::COLOR: SET_FROM_STRUCT_AND_BREAK(Color);
				case Variant::NODE_PATH: {
					MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator NodePath());
					mono_field_set_value(p_object, mono_field, managed);
				} break;
				case Variant::_RID: {
					MonoObject *managed = GDMonoUtils::create_managed_from(p_value.operator RID());
					mono_field_set_value(p_object, mono_field, managed);
				} break;
				case Variant::OBJECT: {
					MonoObject *managed = GDMonoUtils::unmanaged_get_managed(p_value.operator Object *());
					mono_field_set_value(p_object, mono_field, managed);
					break;
				}
				case Variant::DICTIONARY: {
					MonoObject *managed = GDMonoMarshal::Dictionary_to_mono_object(p_value.operator Dictionary());
					mono_field_set_value(p_object, mono_field, managed);
				} break;
				case Variant::ARRAY: SET_FROM_ARRAY_AND_BREAK(Array);
				case Variant::POOL_BYTE_ARRAY: SET_FROM_ARRAY_AND_BREAK(PoolByteArray);
				case Variant::POOL_INT_ARRAY: SET_FROM_ARRAY_AND_BREAK(PoolIntArray);
				case Variant::POOL_REAL_ARRAY: SET_FROM_ARRAY_AND_BREAK(PoolRealArray);
				case Variant::POOL_STRING_ARRAY: SET_FROM_ARRAY_AND_BREAK(PoolStringArray);
				case Variant::POOL_VECTOR2_ARRAY: SET_FROM_ARRAY_AND_BREAK(PoolVector2Array);
				case Variant::POOL_VECTOR3_ARRAY: SET_FROM_ARRAY_AND_BREAK(PoolVector3Array);
				case Variant::POOL_COLOR_ARRAY: SET_FROM_ARRAY_AND_BREAK(PoolColorArray);
#undef SET_FROM_ARRAY_AND_BREAK
				default: break;
			}
		} break;

		case MONO_TYPE_GENERICINST: {
			if (CACHED_RAW_MONO_CLASS(Dictionary) == type.type_class->get_raw()) {
				MonoObject *managed = GDMonoMarshal::Dictionary_to_mono_object(p_value.operator Dictionary());
				mono_field_set_value(p_object, mono_field, managed);
				break;
			}
		} break;

		default: {
			ERR_PRINTS(String() + "Attempted to set the value of a field of unexpected type encoding: " + itos(type.type_encoding));
		} break;
	}

#undef SET_FROM_STRUCT_AND_BREAK
#undef SET_FROM_PRIMITIVE
}
Пример #22
0
Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {

	uint32_t type = f->get_32();
	print_bl("find property of type: " + itos(type));

	switch (type) {

		case VARIANT_NIL: {

			r_v = Variant();
		} break;
		case VARIANT_BOOL: {

			r_v = bool(f->get_32());
		} break;
		case VARIANT_INT: {

			r_v = int(f->get_32());
		} break;
		case VARIANT_INT64: {

			r_v = int64_t(f->get_64());
		} break;
		case VARIANT_REAL: {

			r_v = f->get_real();
		} break;
		case VARIANT_DOUBLE: {

			r_v = f->get_double();
		} break;
		case VARIANT_STRING: {

			r_v = get_unicode_string();
		} break;
		case VARIANT_VECTOR2: {

			Vector2 v;
			v.x = f->get_real();
			v.y = f->get_real();
			r_v = v;

		} break;
		case VARIANT_RECT2: {

			Rect2 v;
			v.position.x = f->get_real();
			v.position.y = f->get_real();
			v.size.x = f->get_real();
			v.size.y = f->get_real();
			r_v = v;

		} break;
		case VARIANT_VECTOR3: {

			Vector3 v;
			v.x = f->get_real();
			v.y = f->get_real();
			v.z = f->get_real();
			r_v = v;
		} break;
		case VARIANT_PLANE: {

			Plane v;
			v.normal.x = f->get_real();
			v.normal.y = f->get_real();
			v.normal.z = f->get_real();
			v.d = f->get_real();
			r_v = v;
		} break;
		case VARIANT_QUAT: {
			Quat v;
			v.x = f->get_real();
			v.y = f->get_real();
			v.z = f->get_real();
			v.w = f->get_real();
			r_v = v;

		} break;
		case VARIANT_AABB: {

			AABB v;
			v.position.x = f->get_real();
			v.position.y = f->get_real();
			v.position.z = f->get_real();
			v.size.x = f->get_real();
			v.size.y = f->get_real();
			v.size.z = f->get_real();
			r_v = v;

		} break;
		case VARIANT_MATRIX32: {

			Transform2D v;
			v.elements[0].x = f->get_real();
			v.elements[0].y = f->get_real();
			v.elements[1].x = f->get_real();
			v.elements[1].y = f->get_real();
			v.elements[2].x = f->get_real();
			v.elements[2].y = f->get_real();
			r_v = v;

		} break;
		case VARIANT_MATRIX3: {

			Basis v;
			v.elements[0].x = f->get_real();
			v.elements[0].y = f->get_real();
			v.elements[0].z = f->get_real();
			v.elements[1].x = f->get_real();
			v.elements[1].y = f->get_real();
			v.elements[1].z = f->get_real();
			v.elements[2].x = f->get_real();
			v.elements[2].y = f->get_real();
			v.elements[2].z = f->get_real();
			r_v = v;

		} break;
		case VARIANT_TRANSFORM: {

			Transform v;
			v.basis.elements[0].x = f->get_real();
			v.basis.elements[0].y = f->get_real();
			v.basis.elements[0].z = f->get_real();
			v.basis.elements[1].x = f->get_real();
			v.basis.elements[1].y = f->get_real();
			v.basis.elements[1].z = f->get_real();
			v.basis.elements[2].x = f->get_real();
			v.basis.elements[2].y = f->get_real();
			v.basis.elements[2].z = f->get_real();
			v.origin.x = f->get_real();
			v.origin.y = f->get_real();
			v.origin.z = f->get_real();
			r_v = v;
		} break;
		case VARIANT_COLOR: {

			Color v;
			v.r = f->get_real();
			v.g = f->get_real();
			v.b = f->get_real();
			v.a = f->get_real();
			r_v = v;

		} break;

		case VARIANT_NODE_PATH: {

			Vector<StringName> names;
			Vector<StringName> subnames;
			bool absolute;

			int name_count = f->get_16();
			uint32_t subname_count = f->get_16();
			absolute = subname_count & 0x8000;
			subname_count &= 0x7FFF;
			if (ver_format < FORMAT_VERSION_NO_NODEPATH_PROPERTY) {
				subname_count += 1; // has a property field, so we should count it as well
			}

			for (int i = 0; i < name_count; i++)
				names.push_back(_get_string());
			for (uint32_t i = 0; i < subname_count; i++)
				subnames.push_back(_get_string());

			NodePath np = NodePath(names, subnames, absolute);

			r_v = np;

		} break;
		case VARIANT_RID: {

			r_v = f->get_32();
		} break;
		case VARIANT_OBJECT: {

			uint32_t objtype = f->get_32();

			switch (objtype) {

				case OBJECT_EMPTY: {
					//do none

				} break;
				case OBJECT_INTERNAL_RESOURCE: {
					uint32_t index = f->get_32();
					String path = res_path + "::" + itos(index);
					RES res = ResourceLoader::load(path);
					if (res.is_null()) {
						WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data());
					}
					r_v = res;

				} break;
				case OBJECT_EXTERNAL_RESOURCE: {
					//old file format, still around for compatibility

					String exttype = get_unicode_string();
					String path = get_unicode_string();

					if (path.find("://") == -1 && path.is_rel_path()) {
						// path is relative to file being loaded, so convert to a resource path
						path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
					}

					if (remaps.find(path)) {
						path = remaps[path];
					}

					RES res = ResourceLoader::load(path, exttype);

					if (res.is_null()) {
						WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data());
					}
					r_v = res;

				} break;
				case OBJECT_EXTERNAL_RESOURCE_INDEX: {
					//new file format, just refers to an index in the external list
					int erindex = f->get_32();

					if (erindex < 0 || erindex >= external_resources.size()) {
						WARN_PRINT("Broken external resource! (index out of size)");
						r_v = Variant();
					} else {

						String exttype = external_resources[erindex].type;
						String path = external_resources[erindex].path;

						if (path.find("://") == -1 && path.is_rel_path()) {
							// path is relative to file being loaded, so convert to a resource path
							path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path));
						}

						RES res = ResourceLoader::load(path, exttype);

						if (res.is_null()) {
							WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data());
						}
						r_v = res;
					}

				} break;
				default: {

					ERR_FAIL_V(ERR_FILE_CORRUPT);
				} break;
			}

		} break;
		case VARIANT_DICTIONARY: {

			uint32_t len = f->get_32();
			Dictionary d; //last bit means shared
			len &= 0x7FFFFFFF;
			for (uint32_t i = 0; i < len; i++) {
				Variant key;
				Error err = parse_variant(key);
				ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT);
				Variant value;
				err = parse_variant(value);
				ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT);
				d[key] = value;
			}
			r_v = d;
		} break;
		case VARIANT_ARRAY: {

			uint32_t len = f->get_32();
			Array a; //last bit means shared
			len &= 0x7FFFFFFF;
			a.resize(len);
			for (uint32_t i = 0; i < len; i++) {
				Variant val;
				Error err = parse_variant(val);
				ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT);
				a[i] = val;
			}
			r_v = a;

		} break;
		case VARIANT_RAW_ARRAY: {

			uint32_t len = f->get_32();

			PoolVector<uint8_t> array;
			array.resize(len);
			PoolVector<uint8_t>::Write w = array.write();
			f->get_buffer(w.ptr(), len);
			_advance_padding(len);
			w = PoolVector<uint8_t>::Write();
			r_v = array;

		} break;
		case VARIANT_INT_ARRAY: {

			uint32_t len = f->get_32();

			PoolVector<int> array;
			array.resize(len);
			PoolVector<int>::Write w = array.write();
			f->get_buffer((uint8_t *)w.ptr(), len * 4);
#ifdef BIG_ENDIAN_ENABLED
			{
				uint32_t *ptr = (uint32_t *)w.ptr();
				for (int i = 0; i < len; i++) {

					ptr[i] = BSWAP32(ptr[i]);
				}
			}

#endif
			w = PoolVector<int>::Write();
			r_v = array;
		} break;
		case VARIANT_REAL_ARRAY: {

			uint32_t len = f->get_32();

			PoolVector<real_t> array;
			array.resize(len);
			PoolVector<real_t>::Write w = array.write();
			f->get_buffer((uint8_t *)w.ptr(), len * sizeof(real_t));
#ifdef BIG_ENDIAN_ENABLED
			{
				uint32_t *ptr = (uint32_t *)w.ptr();
				for (int i = 0; i < len; i++) {

					ptr[i] = BSWAP32(ptr[i]);
				}
			}

#endif

			w = PoolVector<real_t>::Write();
			r_v = array;
		} break;
		case VARIANT_STRING_ARRAY: {

			uint32_t len = f->get_32();
			PoolVector<String> array;
			array.resize(len);
			PoolVector<String>::Write w = array.write();
			for (uint32_t i = 0; i < len; i++)
				w[i] = get_unicode_string();
			w = PoolVector<String>::Write();
			r_v = array;

		} break;
		case VARIANT_VECTOR2_ARRAY: {

			uint32_t len = f->get_32();

			PoolVector<Vector2> array;
			array.resize(len);
			PoolVector<Vector2>::Write w = array.write();
			if (sizeof(Vector2) == 8) {
				f->get_buffer((uint8_t *)w.ptr(), len * sizeof(real_t) * 2);
#ifdef BIG_ENDIAN_ENABLED
				{
					uint32_t *ptr = (uint32_t *)w.ptr();
					for (int i = 0; i < len * 2; i++) {

						ptr[i] = BSWAP32(ptr[i]);
					}
				}

#endif

			} else {
				ERR_EXPLAIN("Vector2 size is NOT 8!");
				ERR_FAIL_V(ERR_UNAVAILABLE);
			}
			w = PoolVector<Vector2>::Write();
			r_v = array;

		} break;
		case VARIANT_VECTOR3_ARRAY: {

			uint32_t len = f->get_32();

			PoolVector<Vector3> array;
			array.resize(len);
			PoolVector<Vector3>::Write w = array.write();
			if (sizeof(Vector3) == 12) {
				f->get_buffer((uint8_t *)w.ptr(), len * sizeof(real_t) * 3);
#ifdef BIG_ENDIAN_ENABLED
				{
					uint32_t *ptr = (uint32_t *)w.ptr();
					for (int i = 0; i < len * 3; i++) {

						ptr[i] = BSWAP32(ptr[i]);
					}
				}

#endif

			} else {
				ERR_EXPLAIN("Vector3 size is NOT 12!");
				ERR_FAIL_V(ERR_UNAVAILABLE);
			}
			w = PoolVector<Vector3>::Write();
			r_v = array;

		} break;
		case VARIANT_COLOR_ARRAY: {

			uint32_t len = f->get_32();

			PoolVector<Color> array;
			array.resize(len);
			PoolVector<Color>::Write w = array.write();
			if (sizeof(Color) == 16) {
				f->get_buffer((uint8_t *)w.ptr(), len * sizeof(real_t) * 4);
#ifdef BIG_ENDIAN_ENABLED
				{
					uint32_t *ptr = (uint32_t *)w.ptr();
					for (int i = 0; i < len * 4; i++) {

						ptr[i] = BSWAP32(ptr[i]);
					}
				}

#endif

			} else {
				ERR_EXPLAIN("Color size is NOT 16!");
				ERR_FAIL_V(ERR_UNAVAILABLE);
			}
			w = PoolVector<Color>::Write();
			r_v = array;
		} break;
#ifndef DISABLE_DEPRECATED
		case VARIANT_IMAGE: {
			uint32_t encoding = f->get_32();
			if (encoding == IMAGE_ENCODING_EMPTY) {
				r_v = Ref<Image>();
				break;
			} else if (encoding == IMAGE_ENCODING_RAW) {
				uint32_t width = f->get_32();
				uint32_t height = f->get_32();
				uint32_t mipmaps = f->get_32();
				uint32_t format = f->get_32();
				const uint32_t format_version_shift = 24;
				const uint32_t format_version_mask = format_version_shift - 1;

				uint32_t format_version = format >> format_version_shift;

				const uint32_t current_version = 0;
				if (format_version > current_version) {

					ERR_PRINT("Format version for encoded binary image is too new");
					return ERR_PARSE_ERROR;
				}

				Image::Format fmt = Image::Format(format & format_version_mask); //if format changes, we can add a compatibility bit on top

				uint32_t datalen = f->get_32();

				PoolVector<uint8_t> imgdata;
				imgdata.resize(datalen);
				PoolVector<uint8_t>::Write w = imgdata.write();
				f->get_buffer(w.ptr(), datalen);
				_advance_padding(datalen);
				w = PoolVector<uint8_t>::Write();

				Ref<Image> image;
				image.instance();
				image->create(width, height, mipmaps, fmt, imgdata);
				r_v = image;

			} else {
				//compressed
				PoolVector<uint8_t> data;
				data.resize(f->get_32());
				PoolVector<uint8_t>::Write w = data.write();
				f->get_buffer(w.ptr(), data.size());
				w = PoolVector<uint8_t>::Write();

				Ref<Image> image;

				if (encoding == IMAGE_ENCODING_LOSSY && Image::lossy_unpacker) {

					image = Image::lossy_unpacker(data);
				} else if (encoding == IMAGE_ENCODING_LOSSLESS && Image::lossless_unpacker) {

					image = Image::lossless_unpacker(data);
				}
				_advance_padding(data.size());

				r_v = image;
			}

		} break;
Пример #23
0
void LegIKController::solve_leg_ik(const float p_delta) {
	
	if(skeleton == NULL)
		return;
	
	Transform root_bone_transform = skeleton->get_global_transform() * skeleton->get_bone_global_pose(root_bone);
	
	if (ik_on && ik_valid) {
		if(dss == NULL) {
			if (root == NULL) {
				root = static_cast<Spatial *>(get_node(NodePath("..")));
				if (root == NULL)
					return;
			}

			dss = PhysicsServer::get_singleton()->space_get_direct_state(root->get_world()->get_space());
			if(dss == NULL);
				return;
		};
				
		root_global_transform = root->get_global_transform();
				
		Transform skeleton_affine_inverse = skeleton->get_global_transform().affine_inverse();

		Transform left_foot_local_transform = skeleton->get_bone_global_pose(left_ankle);
		Transform right_foot_local_transform = skeleton->get_bone_global_pose(right_ankle);
		
		Transform left_foot_transform = skeleton->get_global_transform() * left_foot_local_transform;
		Transform right_foot_transform = skeleton->get_global_transform() * right_foot_local_transform;
		
		Transform left_calf_transform = skeleton->get_global_transform() * skeleton->get_bone_global_pose(left_knee);
		Transform right_calf_transform = skeleton->get_global_transform() * skeleton->get_bone_global_pose(right_knee);
		
		Transform left_thigh_transform = skeleton->get_global_transform() * skeleton->get_bone_global_pose(left_leg);
		Transform right_thigh_transform = skeleton->get_global_transform() * skeleton->get_bone_global_pose(right_leg);
		
		root_offset = root_bone_transform.origin.y - root_global_transform.origin.y;
		ankle_height_L = left_foot_transform.origin.y - root_global_transform.origin.y;
		ankle_height_R = right_foot_transform.origin.y - root_global_transform.origin.y;
		
		targeted_left_ground.y += (left_foot_local_transform.origin.y - prev_left_ground.y);
		targeted_right_ground.y += (right_foot_local_transform.origin.y - prev_right_ground.y);
					
		prev_left_ground = left_foot_local_transform.origin;
		prev_right_ground = right_foot_local_transform.origin;
		
		// Default feet targets.
		Vector3 left_ground = left_foot_transform.origin;
		Vector3 right_ground = right_foot_transform.origin;
		Vector3 original_left_ground = left_foot_transform.origin;
		Vector3 original_right_ground = right_foot_transform.origin;
		
		float animation_delta = left_ground.y - right_ground.y;
		if (animation_delta < -animation_offset) {
			left_foot_down = true;
			right_foot_down = false;
		} else if (animation_delta > animation_offset) {
			left_foot_down = false;
			right_foot_down = true;
		} else {
			left_foot_down = true;
			right_foot_down = true;
		}
		
		float ray_distance = 0.0;
	 
		if ((!left_foot_down) && (right_foot_down)) {
			ray_distance = left_calf_length + ankle_height_L;
		} else {
			ray_distance = left_calf_length + left_leg_full_length;
		}

		// Left
		if (ray_distance > 0) {
			Vector3 from = left_foot_transform.origin + Vector3(0, left_calf_length, 0);
			Vector3 to = from + (-Vector3(0, 1, 0) * ray_distance);
			
			PhysicsDirectSpaceState::RayResult result_foot;
			if (dss->intersect_ray(from, to, result_foot, ray_exclusion_array, 1, 15)) {
				Transform left_toe_transform = skeleton->get_global_transform() * skeleton->get_bone_global_pose(left_toe);
				
				float original_y = from.y;
				from = left_toe_transform.origin + Vector3(0, left_calf_length, 0);
				from.y = original_y;
				to = from + (-Vector3(0, 1, 0) * ray_distance);
				
				PhysicsDirectSpaceState::RayResult result_toe;
				if (dss->intersect_ray(from, to, result_toe, ray_exclusion_array, 1, 15)) {
					if (result_toe.position.y - result_foot.position.y > 0.001) {
						left_ground = result_toe.position + Vector3(0, ankle_height_L, 0);
					} else {
						left_ground = result_foot.position + Vector3(0, ankle_height_L, 0);
					}
				} else {
					left_ground = result_foot.position + Vector3(0, ankle_height_L, 0);
				}
			}
		}

		if ((left_foot_down) && (!right_foot_down)) {
			ray_distance = right_calf_length + ankle_height_R;
		} else {
			ray_distance = right_calf_length + right_leg_full_length;
		}
		
		// Right
		if (ray_distance > 0) {
			Vector3 from = right_foot_transform.origin + Vector3(0, right_calf_length, 0);
			Vector3 to = from + (-Vector3(0, 1, 0) * ray_distance);
			
			PhysicsDirectSpaceState::RayResult result_foot;
			if (dss->intersect_ray(from, to, result_foot, ray_exclusion_array, 1, 15)) {
				Transform right_toe_transform = skeleton->get_global_transform() * skeleton->get_bone_global_pose(right_toe);

				float original_y = from.y;
				from = right_toe_transform.origin + Vector3(0, right_calf_length, 0);
				from.y = original_y;
				to = from + (-Vector3(0, 1, 0) * ray_distance);

				PhysicsDirectSpaceState::RayResult result_toe;
				if (dss->intersect_ray(from, to, result_toe, ray_exclusion_array, 1, 15)) {
					if (result_toe.position.y - result_foot.position.y > 0.001) {
						right_ground = result_toe.position + Vector3(0, ankle_height_R, 0);
					} else {
						right_ground = result_foot.position + Vector3(0, ankle_height_R, 0);
					}
				} else {
					right_ground = result_foot.position + Vector3(0, ankle_height_R, 0);
				}
			}
		}

		if (left_ground.y < right_ground.y) {
			target_height = left_ground.y - ankle_height_L + root_offset;
		} else {
			target_height = right_ground.y - ankle_height_R + root_offset;
		}
		
		target_height = Math::lerp(prev_target_height, target_height, p_delta * ik_body_reposition_rate);
		
		float height_diff = target_height - root_bone_transform.origin.y;
		
		root_bone_transform.origin.y = target_height;
		skeleton->set_bone_global_pose(root_bone, skeleton_affine_inverse * root_bone_transform);
		
		prev_target_height = root_bone_transform.origin.y;

		if((!left_foot_down) && (right_foot_down) && (left_ground == original_left_ground))
			left_ground.y += height_diff;
		
		if((left_foot_down) && (!right_foot_down) && (right_ground == original_right_ground))
			right_ground.y += height_diff;
		
		targeted_left_ground.x = left_ground.x;
		targeted_left_ground.z = left_ground.z;
		
		targeted_right_ground.x = right_ground.x;
		targeted_right_ground.z = right_ground.z;
		
		targeted_left_ground.y = Math::lerp(targeted_left_ground.y, left_ground.y, p_delta * ik_feet_reposition_rate);
		targeted_right_ground.y = Math::lerp(targeted_right_ground.y, right_ground.y, p_delta * ik_feet_reposition_rate);

		LegIK::solve_leg_ik(skeleton, left_leg, left_knee, left_ankle, targeted_left_ground);
		LegIK::solve_leg_ik(skeleton, right_leg, right_knee, right_ankle, targeted_right_ground);
	} else {
		prev_target_height = root_bone_transform.origin.y;
	}
}
Пример #24
0
Node* SceneTreeDock::instance(const String& p_file) {

	Node *parent = scene_tree->get_selected();
	if (!parent || !edited_scene) {

		current_option=-1;
		//accept->get_cancel()->hide();
		accept->get_ok()->set_text("Ok :( ");
		accept->set_text("No parent to instance a child at.");
		accept->popup_centered_minsize();
		return NULL;
	};

	ERR_FAIL_COND_V(!parent,NULL);

	Node*instanced_scene=NULL;
	Ref<PackedScene> sdata = ResourceLoader::load(p_file);
	if (sdata.is_valid())
		instanced_scene=sdata->instance(true);


	if (!instanced_scene) {

		current_option=-1;
		//accept->get_cancel()->hide();
		accept->get_ok()->set_text("Ugh");
		accept->set_text(String("Error loading scene from ")+p_file);
		accept->popup_centered_minsize();
		return NULL;
	}

	// If the scene hasn't been saved yet a cyclical dependency cannot exist.
	if (edited_scene->get_filename()!="") {

		if (_cyclical_dependency_exists(edited_scene->get_filename(), instanced_scene)) {

			accept->get_ok()->set_text("Ok");
			accept->set_text(String("Cannot instance the scene '")+p_file+String("' because the current scene exists within one of its' nodes."));
			accept->popup_centered_minsize();
			return NULL;
		}
	}

	//instanced_scene->generate_instance_state();
	instanced_scene->set_filename( Globals::get_singleton()->localize_path(p_file) );

	editor_data->get_undo_redo().create_action("Instance Scene");
	editor_data->get_undo_redo().add_do_method(parent,"add_child",instanced_scene);
	editor_data->get_undo_redo().add_do_method(instanced_scene,"set_owner",edited_scene);
	editor_data->get_undo_redo().add_do_method(editor_selection,"clear");
	editor_data->get_undo_redo().add_do_method(editor_selection,"add_node",instanced_scene);
	editor_data->get_undo_redo().add_do_reference(instanced_scene);
	editor_data->get_undo_redo().add_undo_method(parent,"remove_child",instanced_scene);


	String new_name = parent->validate_child_name(instanced_scene->get_name());
	ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
	editor_data->get_undo_redo().add_do_method(sed,"live_debug_instance_node",edited_scene->get_path_to(parent),p_file,new_name);
	editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(edited_scene->get_path_to(parent))+"/"+new_name));

	editor_data->get_undo_redo().commit_action();


	return instanced_scene;

}
Пример #25
0
World::World(WindowFramework* windowFrameworkPtr)
   : m_windowFrameworkPtr(windowFrameworkPtr)
   {
   // preconditions
   if(m_windowFrameworkPtr == NULL)
      {
      nout << "ERROR: World::World(WindowFramework* windowFrameworkPtr) parameter windowFrameworkPtr cannot be NULL." << endl;
      return;
      }

   m_keyMap.resize(K_keys);
   m_keyMap[K_left     ] = false;
   m_keyMap[K_right    ] = false;
   m_keyMap[K_forward  ] = false;
   m_keyMap[K_cam_left ] = false;
   m_keyMap[K_cam_right] = false;
   m_windowFrameworkPtr->set_background_type(WindowFramework::BT_black);

   // Post the instructions

   m_titleNp = add_title("Panda3D Tutorial: Roaming Ralph (Walking on Uneven Terrain)");
   m_inst1Np = add_instructions(0.95, "[ESC]: Quit");
   m_inst2Np = add_instructions(0.90, "[Left Arrow]: Rotate Ralph Left");
   m_inst3Np = add_instructions(0.85, "[Right Arrow]: Rotate Ralph Right");
   m_inst4Np = add_instructions(0.80, "[Up Arrow]: Run Ralph Forward");
   m_inst6Np = add_instructions(0.70, "[A]: Rotate Camera Left");
   m_inst7Np = add_instructions(0.65, "[S]: Rotate Camera Right");

   // Set up the environment
   //
   // This environment model contains collision meshes.  If you look
   // in the egg file, you will see the following:
   //
   //    <Collide> { Polyset keep descend }
   //
   // This tag causes the following mesh to be converted to a collision
   // mesh -- a mesh which is optimized for collision, not rendering.
   // It also keeps the original mesh, so there are now two copies ---
   // one optimized for rendering, one for collisions.

   NodePath modelsNp = m_windowFrameworkPtr->get_panda_framework()->get_models();
   m_environNp = m_windowFrameworkPtr->load_model(modelsNp, "../models/world");
   NodePath renderNp = m_windowFrameworkPtr->get_render();
   m_environNp.reparent_to(renderNp);
   m_environNp.set_pos(0,0,0);

   // Create the main character, Ralph
   LPoint3f ralphStartPos = m_environNp.find("**/start_point").get_pos();
   CActor::AnimMap ralphAnims;
   ralphAnims["../models/ralph-run"].push_back("run");
   ralphAnims["../models/ralph-walk"].push_back("walk");
   m_ralph.load_actor(m_windowFrameworkPtr,
                      "../models/ralph",
                      &ralphAnims,
                      PartGroup::HMF_ok_wrong_root_name|
                      PartGroup::HMF_ok_anim_extra|
                      PartGroup::HMF_ok_part_extra);
   m_ralph.reparent_to(renderNp);
   m_ralph.set_scale(0.2);
   m_ralph.set_pos(ralphStartPos);

   // Create a floater object.  We use the "floater" as a temporary
   // variable in a variety of calculations.

   m_floaterNp = NodePath("floater");
   m_floaterNp.reparent_to(renderNp);

   // Accept the control keys for movement and rotation
   m_windowFrameworkPtr->enable_keyboard();
   m_windowFrameworkPtr->get_panda_framework()->define_key("escape"        , "sysExit"    , sys_exit                        , NULL);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_left"    , "left"       , call_set_key<K_left     , true >, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_right"   , "right"      , call_set_key<K_right    , true >, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_up"      , "forward"    , call_set_key<K_forward  , true >, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("a"             , "cam-left"   , call_set_key<K_cam_left , true >, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("s"             , "cam-right"  , call_set_key<K_cam_right, true >, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_left-up" , "leftUp"     , call_set_key<K_left     , false>, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_right-up", "rightUp"    , call_set_key<K_right    , false>, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("arrow_up-up"   , "forwardUp"  , call_set_key<K_forward  , false>, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("a-up"          , "cam-leftUp" , call_set_key<K_cam_left , false>, this);
   m_windowFrameworkPtr->get_panda_framework()->define_key("s-up"          , "cam-rightUp", call_set_key<K_cam_right, false>, this);

   PT(GenericAsyncTask) taskPtr = new GenericAsyncTask("moveTask", call_move, this);
   if(taskPtr != NULL)
      {
      AsyncTaskManager::get_global_ptr()->add(taskPtr);
      }

   // Game state variables
   m_isMoving = false;

   // Set up the camera

   // Note: no need to disable the mouse in C++
   NodePath cameraNp = m_windowFrameworkPtr->get_camera_group();
   cameraNp.set_pos(m_ralph.get_x(), m_ralph.get_y()+10, 2);

   // We will detect the height of the terrain by creating a collision
   // ray and casting it downward toward the terrain.  One ray will
   // start above ralph's head, and the other will start above the camera.
   // A ray may hit the terrain, or it may hit a rock or a tree.  If it
   // hits the terrain, we can detect the height.  If it hits anything
   // else, we rule that the move is illegal.

   NodePath ralphGroundColNp;
   m_ralphGroundRayPtr = new CollisionRay();
   if(m_ralphGroundRayPtr != NULL)
      {
      m_ralphGroundRayPtr->set_origin(0, 0, 1000);
      m_ralphGroundRayPtr->set_direction(0, 0, -1);
      m_ralphGroundColPtr = new CollisionNode("ralphRay");
      if(m_ralphGroundColPtr != NULL)
         {
         m_ralphGroundColPtr->add_solid(m_ralphGroundRayPtr);
         m_ralphGroundColPtr->set_from_collide_mask(BitMask32::bit(0));
         m_ralphGroundColPtr->set_into_collide_mask(BitMask32::all_off());
         ralphGroundColNp = m_ralph.attach_new_node(m_ralphGroundColPtr);
         m_ralphGroundHandlerPtr = new CollisionHandlerQueue();
         if(m_ralphGroundHandlerPtr != NULL)
            {
            m_collisionTraverser.add_collider(ralphGroundColNp, m_ralphGroundHandlerPtr);
            }
         }
      }

   NodePath camGroundColNp;
   m_camGroundRayPtr = new CollisionRay();
   if(m_camGroundRayPtr != NULL)
      {
      m_camGroundRayPtr->set_origin(0, 0, 1000);
      m_camGroundRayPtr->set_direction(0, 0, -1);
      m_camGroundColPtr = new CollisionNode("camRay");
      if(m_camGroundColPtr != NULL)
         {
         m_camGroundColPtr->add_solid(m_camGroundRayPtr);
         m_camGroundColPtr->set_from_collide_mask(BitMask32::bit(0));
         m_camGroundColPtr->set_into_collide_mask(BitMask32::all_off());
         camGroundColNp = cameraNp.attach_new_node(m_camGroundColPtr);
         m_camGroundHandlerPtr = new CollisionHandlerQueue();
         if(m_camGroundHandlerPtr != NULL)
            {
            m_collisionTraverser.add_collider(camGroundColNp, m_camGroundHandlerPtr);
            }
         }
      }

   // Uncomment this line to see the collision rays
   //ralphGroundColNp.show();
   //camGroundColNp.show();

   // Uncomment this line to show a visual representation of the
   // collisions occuring
   //m_collisionTraverser.show_collisions(renderNp);

   // Create some lighting
   PT(AmbientLight) ambientLightPtr = new AmbientLight("ambientLight");
   if(ambientLightPtr != NULL)
      {
      ambientLightPtr->set_color(Colorf(.3, .3, .3, 1));
      renderNp.set_light(renderNp.attach_new_node(ambientLightPtr));
      }
   PT(DirectionalLight) directionalLightPtr = new DirectionalLight("directionalLightPtr");
   if(directionalLightPtr != NULL)
      {
      directionalLightPtr->set_direction(LVecBase3f(-5, -5, -5));
      directionalLightPtr->set_color(Colorf(1, 1, 1, 1));
      directionalLightPtr->set_specular_color(Colorf(1, 1, 1, 1));
      renderNp.set_light(renderNp.attach_new_node(directionalLightPtr));
      }
   }
Пример #26
0
SceneStringNames::SceneStringNames() {

	_estimate_cost = StaticCString::create("_estimate_cost");
	_compute_cost = StaticCString::create("_compute_cost");

	resized = StaticCString::create("resized");
	dot = StaticCString::create(".");
	doubledot = StaticCString::create("..");
	draw = StaticCString::create("draw");
	_draw = StaticCString::create("_draw");
	hide = StaticCString::create("hide");
	visibility_changed = StaticCString::create("visibility_changed");
	input_event = StaticCString::create("input_event");
	shader = StaticCString::create("shader");
	shader_unshaded = StaticCString::create("shader/unshaded");
	shading_mode = StaticCString::create("shader/shading_mode");
	tree_entered = StaticCString::create("tree_entered");
	tree_exiting = StaticCString::create("tree_exiting");
	tree_exited = StaticCString::create("tree_exited");
	ready = StaticCString::create("ready");
	item_rect_changed = StaticCString::create("item_rect_changed");
	size_flags_changed = StaticCString::create("size_flags_changed");
	minimum_size_changed = StaticCString::create("minimum_size_changed");
	sleeping_state_changed = StaticCString::create("sleeping_state_changed");

	finished = StaticCString::create("finished");
	emission_finished = StaticCString::create("emission_finished");
	animation_finished = StaticCString::create("animation_finished");
	animation_changed = StaticCString::create("animation_changed");
	animation_started = StaticCString::create("animation_started");

	mouse_entered = StaticCString::create("mouse_entered");
	mouse_exited = StaticCString::create("mouse_exited");

	focus_entered = StaticCString::create("focus_entered");
	focus_exited = StaticCString::create("focus_exited");

	sort_children = StaticCString::create("sort_children");

	body_shape_entered = StaticCString::create("body_shape_entered");
	body_entered = StaticCString::create("body_entered");
	body_shape_exited = StaticCString::create("body_shape_exited");
	body_exited = StaticCString::create("body_exited");

	area_shape_entered = StaticCString::create("area_shape_entered");
	area_shape_exited = StaticCString::create("area_shape_exited");

	_body_inout = StaticCString::create("_body_inout");
	_area_inout = StaticCString::create("_area_inout");

	idle = StaticCString::create("idle");
	iteration = StaticCString::create("iteration");
	update = StaticCString::create("update");
	updated = StaticCString::create("updated");

	_get_gizmo_geometry = StaticCString::create("_get_gizmo_geometry");
	_can_gizmo_scale = StaticCString::create("_can_gizmo_scale");

	_physics_process = StaticCString::create("_physics_process");
	_process = StaticCString::create("_process");

	_enter_tree = StaticCString::create("_enter_tree");
	_exit_tree = StaticCString::create("_exit_tree");
	_enter_world = StaticCString::create("_enter_world");
	_exit_world = StaticCString::create("_exit_world");
	_ready = StaticCString::create("_ready");

	_update_scroll = StaticCString::create("_update_scroll");
	_update_xform = StaticCString::create("_update_xform");

	_clips_input = StaticCString::create("_clips_input");

	_proxgroup_add = StaticCString::create("_proxgroup_add");
	_proxgroup_remove = StaticCString::create("_proxgroup_remove");

	grouped = StaticCString::create("grouped");
	ungrouped = StaticCString::create("ungrouped");

	screen_entered = StaticCString::create("screen_entered");
	screen_exited = StaticCString::create("screen_exited");

	viewport_entered = StaticCString::create("viewport_entered");
	viewport_exited = StaticCString::create("viewport_exited");

	camera_entered = StaticCString::create("camera_entered");
	camera_exited = StaticCString::create("camera_exited");

	_body_enter_tree = StaticCString::create("_body_enter_tree");
	_body_exit_tree = StaticCString::create("_body_exit_tree");

	_area_enter_tree = StaticCString::create("_area_enter_tree");
	_area_exit_tree = StaticCString::create("_area_exit_tree");

	_input = StaticCString::create("_input");
	_input_event = StaticCString::create("_input_event");

	gui_input = StaticCString::create("gui_input");
	_gui_input = StaticCString::create("_gui_input");

	_unhandled_input = StaticCString::create("_unhandled_input");
	_unhandled_key_input = StaticCString::create("_unhandled_key_input");

	changed = StaticCString::create("changed");
	_shader_changed = StaticCString::create("_shader_changed");

	_spatial_editor_group = StaticCString::create("_spatial_editor_group");
	_request_gizmo = StaticCString::create("_request_gizmo");

	offset = StaticCString::create("offset");
	unit_offset = StaticCString::create("unit_offset");
	rotation_mode = StaticCString::create("rotation_mode");
	rotate = StaticCString::create("rotate");
	h_offset = StaticCString::create("h_offset");
	v_offset = StaticCString::create("v_offset");

	transform_pos = StaticCString::create("position");
	transform_rot = StaticCString::create("rotation_degrees");
	transform_scale = StaticCString::create("scale");

	_update_remote = StaticCString::create("_update_remote");
	_update_pairs = StaticCString::create("_update_pairs");

	_get_minimum_size = StaticCString::create("_get_minimum_size");

	area_entered = StaticCString::create("area_entered");
	area_exited = StaticCString::create("area_exited");

	has_point = StaticCString::create("has_point");

	line_separation = StaticCString::create("line_separation");

	get_drag_data = StaticCString::create("get_drag_data");
	drop_data = StaticCString::create("drop_data");
	can_drop_data = StaticCString::create("can_drop_data");

	_im_update = StaticCString::create("_im_update");
	_queue_update = StaticCString::create("_queue_update");

	baked_light_changed = StaticCString::create("baked_light_changed");
	_baked_light_changed = StaticCString::create("_baked_light_changed");

	_mouse_enter = StaticCString::create("_mouse_enter");
	_mouse_exit = StaticCString::create("_mouse_exit");

	_pressed = StaticCString::create("_pressed");
	_toggled = StaticCString::create("_toggled");

	frame_changed = StaticCString::create("frame_changed");

	playback_speed = StaticCString::create("playback/speed");
	playback_active = StaticCString::create("playback/active");
	autoplay = StaticCString::create("autoplay");
	blend_times = StaticCString::create("blend_times");
	speed = StaticCString::create("speed");

	node_configuration_warning_changed = StaticCString::create("node_configuration_warning_changed");

	output = StaticCString::create("output");

	path_pp = NodePath("..");

	_default = StaticCString::create("default");

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

		mesh_materials[i] = "material/" + itos(i);
	}

	_mesh_changed = StaticCString::create("_mesh_changed");

	parameters_base_path = "parameters/";

	tracks_changed = "tracks_changed";
}
Пример #27
0
void GDTokenizerText::_advance() {

	if (error_flag) {
		//parser broke
		_make_error(last_error);
		return;
	}

	if (code_pos>=len) {
		_make_token(TK_EOF);
		return;
	}
#define GETCHAR(m_ofs) ((m_ofs+code_pos)>=len?0:_code[m_ofs+code_pos])
#define INCPOS(m_amount) { code_pos+=m_amount; column+=m_amount; }
	while (true) {


		bool is_node_path  = false;
		StringMode string_mode=STRING_DOUBLE_QUOTE;

		switch(GETCHAR(0)) {
			case 0:
				_make_token(TK_EOF);
				break;
			case '\\':
				INCPOS(1);
				if (GETCHAR(0)=='\r') {
					INCPOS(1);
				}

				if (GETCHAR(0)!='\n') {
					_make_error("Expected newline after '\\'.");
					return;
				}

				INCPOS(1);

				while(GETCHAR(0)==' ' || GETCHAR(0)=='\t') {
					INCPOS(1);
				}

				continue;
			case '\t':
			case '\r':
			case ' ':
				INCPOS(1);
				continue;
			case '\n': {
				line++;
				INCPOS(1);
				column=0;
				int i=0;
				while(GETCHAR(i)==' ' || GETCHAR(i)=='\t') {
					i++;
				}

				_make_newline(i);
				return;
			}
#if 1 //py style tokenizer
			case '#': { // line comment skip

				while(GETCHAR(0)!='\n') {
					code_pos++;
					if (GETCHAR(0)==0) { //end of file
						//_make_error("Unterminated Comment");
						_make_token(TK_EOF);
						return;
					}
				}
				INCPOS(1);
				column=0;
				line++;
				int i=0;
				while(GETCHAR(i)==' ' || GETCHAR(i)=='\t') {
					i++;
				}
				_make_newline(i);
				return;

			} break;
#endif
			case '/': {

				switch(GETCHAR(1)) {
#if 0 // c style tokenizer
					case '*': { // block comment
						int pos = code_pos+2;
						int new_line=line;
						int new_col=column+2;

						while(true) {
							if (_code[pos]=='0') {
								_make_error("Unterminated Comment");
								code_pos=pos;
								return;
							}
							if (_code[pos]=='*' && _code[pos+1]=='/') {
								new_col+=2;
								pos+=2; //compensate
								break;
							} else if (_code[pos]=='\n') {
								new_line++;
								new_col=0;
							} else {
								new_col++;
							}
							pos++;
						}

						column=new_col;
						line=new_line;
						code_pos=pos;
						continue;

					} break;
					case '/': { // line comment skip

						while(GETCHAR(0)!='\n') {
							code_pos++;
							if (GETCHAR(0)==0) { //end of file
								_make_error("Unterminated Comment");
								return;
							}
						}
						INCPOS(1);
						column=0;
						line++;
						continue;

					} break;
#endif
					case '=': { // diveq

						_make_token(TK_OP_ASSIGN_DIV);
						INCPOS(1);

					} break;
					default:
						_make_token(TK_OP_DIV);

				}
			} break;
			case '=': {
				if (GETCHAR(1)=='=') {
					_make_token(TK_OP_EQUAL);
					INCPOS(1);

				} else
					_make_token(TK_OP_ASSIGN);

			} break;
			case '<': {
				if (GETCHAR(1)=='=') {

					_make_token(TK_OP_LESS_EQUAL);
					INCPOS(1);
				} else if (GETCHAR(1)=='<') {
					if (GETCHAR(2)=='=') {
						_make_token(TK_OP_ASSIGN_SHIFT_LEFT);
						INCPOS(1);
					} else {
						_make_token(TK_OP_SHIFT_LEFT);
					}
					INCPOS(1);
				} else
					_make_token(TK_OP_LESS);

			} break;
			case '>': {
				if (GETCHAR(1)=='=') {
					_make_token(TK_OP_GREATER_EQUAL);
					INCPOS(1);
				} else if (GETCHAR(1)=='>') {
					if (GETCHAR(2)=='=') {
						_make_token(TK_OP_ASSIGN_SHIFT_RIGHT);
						INCPOS(1);

					} else {
						_make_token(TK_OP_SHIFT_RIGHT);
					}
					INCPOS(1);
				} else {
					_make_token(TK_OP_GREATER);
				}

			} break;
			case '!': {
				if (GETCHAR(1)=='=') {
					_make_token(TK_OP_NOT_EQUAL);
					INCPOS(1);
				} else {
					_make_token(TK_OP_NOT);
				}

			} break;
			//case '"' //string - no strings in shader
			//case '\'' //string - no strings in shader
			case '{':
				_make_token(TK_CURLY_BRACKET_OPEN);
				break;
			case '}':
				_make_token(TK_CURLY_BRACKET_CLOSE);
				break;
			case '[':
				_make_token(TK_BRACKET_OPEN);
				break;
			case ']':
				_make_token(TK_BRACKET_CLOSE);
				break;
			case '(':
				_make_token(TK_PARENTHESIS_OPEN);
				break;
			case ')':
				_make_token(TK_PARENTHESIS_CLOSE);
				break;
			case ',':
				_make_token(TK_COMMA);
				break;
			case ';':
				_make_token(TK_SEMICOLON);
				break;
			case '?':
				_make_token(TK_QUESTION_MARK);
				break;
			case ':':
				_make_token(TK_COLON); //for methods maybe but now useless.
				break;
			case '^': {
				if (GETCHAR(1)=='=') {
					_make_token(TK_OP_ASSIGN_BIT_XOR);
					INCPOS(1);
				} else {
					_make_token(TK_OP_BIT_XOR);
				}

			} break;
			case '~':
				_make_token(TK_OP_BIT_INVERT);
				break;
			case '&': {
				if (GETCHAR(1)=='&') {

					_make_token(TK_OP_AND);
					INCPOS(1);
				} else if (GETCHAR(1)=='=') {
					_make_token(TK_OP_ASSIGN_BIT_AND);
					INCPOS(1);
				} else {
					_make_token(TK_OP_BIT_AND);
				}
			} break;
			case '|': {
				if (GETCHAR(1)=='|') {

					_make_token(TK_OP_OR);
					INCPOS(1);
				} else if (GETCHAR(1)=='=') {
					_make_token(TK_OP_ASSIGN_BIT_OR);
					INCPOS(1);
				} else {
					_make_token(TK_OP_BIT_OR);
				}
			} break;
			case '*': {

				if (GETCHAR(1)=='=') {
					_make_token(TK_OP_ASSIGN_MUL);
					INCPOS(1);
				} else {
					_make_token(TK_OP_MUL);
				}
			} break;
			case '+': {

				if (GETCHAR(1)=='=') {
					_make_token(TK_OP_ASSIGN_ADD);
					INCPOS(1);
				//}  else if (GETCHAR(1)=='+') {
				//	_make_token(TK_OP_PLUS_PLUS);
				//	INCPOS(1);
				} else {
					_make_token(TK_OP_ADD);
				}

			} break;
			case '-': {

				if (GETCHAR(1)=='=') {
					_make_token(TK_OP_ASSIGN_SUB);
					INCPOS(1);
				//}  else if (GETCHAR(1)=='-') {
				//	_make_token(TK_OP_MINUS_MINUS);
				//	INCPOS(1);
				} else {
					_make_token(TK_OP_SUB);
				}
			} break;
			case '%': {

				if (GETCHAR(1)=='=') {
					_make_token(TK_OP_ASSIGN_MOD);
					INCPOS(1);
				} else {
					_make_token(TK_OP_MOD);
				}
			} break;
			case '@':
				if( CharType(GETCHAR(1))!='"' && CharType(GETCHAR(1))!='\'' ) {
					_make_error("Unexpected '@'");
					return;
				}
				INCPOS(1);
				is_node_path=true;
				
			case '\'':
			case '"': {
	
				if (GETCHAR(0)=='\'')
					string_mode=STRING_SINGLE_QUOTE;
																	
																	
				int i=1;
				if (string_mode==STRING_DOUBLE_QUOTE && GETCHAR(i)=='"' && GETCHAR(i+1)=='"') {
					i+=2;
					string_mode=STRING_MULTILINE;

				}


				String str;
				while(true) {
					if (CharType(GETCHAR(i))==0) {

						_make_error("Unterminated String");
						return;
					} else if( string_mode==STRING_DOUBLE_QUOTE && CharType(GETCHAR(i))=='"' ) {
						break;
					} else if( string_mode==STRING_SINGLE_QUOTE && CharType(GETCHAR(i))=='\'' ) {
						break;
					} else if( string_mode==STRING_MULTILINE && CharType(GETCHAR(i))=='\"' &&  CharType(GETCHAR(i+1))=='\"' && CharType(GETCHAR(i+2))=='\"') {
						i+=2;
						break;
					} else if( string_mode!=STRING_MULTILINE && CharType(GETCHAR(i))=='\n') {
						_make_error("Unexpected EOL at String.");
						return;

					} else if (CharType(GETCHAR(i))=='\\') {
						//escaped characters...
						i++;
						CharType next = GETCHAR(i);
						if (next==0) {
							_make_error("Unterminated String");
							return;
						}
						CharType res=0;

						switch(next) {

							case 'a': res=7; break;
							case 'b': res=8; break;
							case 't': res=9; break;
							case 'n': res=10; break;
							case 'v': res=11; break;
							case 'f': res=12; break;
							case 'r': res=13; break;
							case '\'': res='\''; break;
							case '\"': res='\"'; break;
							case '\\': res='\\'; break;
							case '/': res='/'; break; //wtf

							case 'u': {
								//hexnumbarh - oct is deprecated
								i+=1;
								for(int j=0;j<4;j++) {
									CharType c = GETCHAR(i+j);
									if (c==0) {
										_make_error("Unterminated String");
										return;
									}
									if (!((c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F'))) {

										_make_error("Malformed hex constant in string");
										return;
									}
									CharType v;
									if (c>='0' && c<='9') {
										v=c-'0';
									} else if (c>='a' && c<='f') {
										v=c-'a';
										v+=10;
									} else if (c>='A' && c<='F') {
										v=c-'A';
										v+=10;
									} else {
										ERR_PRINT("BUG");
										v=0;
									}

									res<<=4;
									res|=v;


								}
								i+=3;

							} break;
							default: {

								_make_error("Invalid escape sequence");
								return;
							} break;
						}

						str+=res;

					} else {
						str+=CharType(GETCHAR(i));
					}
					i++;
				}
				INCPOS(i);

				if (is_node_path) {
					_make_constant(NodePath(str));
				} else {
					_make_constant(str);
				}

			} break;
			case 0xFFFF: {
				_make_token(TK_CURSOR);
			} break;
			default: {

				if (_is_number(GETCHAR(0)) || (GETCHAR(0)=='.' && _is_number(GETCHAR(1)))) {
					// parse number
					bool period_found=false;
					bool exponent_found=false;
					bool hexa_found=false;
					bool sign_found=false;

					String str;
					int i=0;

					while(true) {
						if (GETCHAR(i)=='.') {
							if (period_found || exponent_found) {
                                _make_error("Invalid numeric constant at '.'");
								return;
							}
							period_found=true;
						} else if (GETCHAR(i)=='x') {
                            if (hexa_found || str.length()!=1 || !( (i==1 && str[0]=='0') || (i==2 && str[1]=='0' && str[0]=='-') ) ) {
                                _make_error("Invalid numeric constant at 'x'");
								return;
							}
							hexa_found=true;
                        } else if (!hexa_found && GETCHAR(i)=='e') {
							if (hexa_found || exponent_found) {
                                _make_error("Invalid numeric constant at 'e'");
								return;
							}
							exponent_found=true;
						} else if (_is_number(GETCHAR(i))) {
							//all ok
						} else if (hexa_found && _is_hex(GETCHAR(i))) {

						} else if ((GETCHAR(i)=='-' || GETCHAR(i)=='+') && exponent_found) {
							if (sign_found) {
                                _make_error("Invalid numeric constant at '-'");
								return;
							}
							sign_found=true;
						} else
							break;

						str+=CharType(GETCHAR(i));
						i++;
					}

                    if (!( _is_number(str[str.length()-1]) || (hexa_found && _is_hex(str[str.length()-1])))) {
                        _make_error("Invalid numeric constant: "+str);
						return;
					}

					INCPOS(str.length());
                    if (hexa_found) {
                        int val = str.hex_to_int();
                        _make_constant(val);
                    } else if (period_found) {
						real_t val = str.to_double();
						//print_line("*%*%*%*% to convert: "+str+" result: "+rtos(val));
						_make_constant(val);
                    } else {
						int val = str.to_int();
						_make_constant(val);

					}

					return;
				}

				if (GETCHAR(0)=='.') {
					//parse period
					_make_token(TK_PERIOD);
					break;
				}

				if (_is_text_char(GETCHAR(0))) {
					// parse identifier
					String str;
					str+=CharType(GETCHAR(0));

					int i=1;
					while(_is_text_char(GETCHAR(i))) {
						str+=CharType(GETCHAR(i));
						i++;
					}

					bool identifier=false;

					if (str=="null") {
						_make_constant(Variant());

					} else if (str=="true") {
						_make_constant(true);

					} else if (str=="false") {
						_make_constant(false);
					} else {

						bool found=false;

						struct _bit { Variant::Type type; const char *text;};
						//built in types

						static const  _bit type_list[]={
							//types
							{Variant::BOOL,"bool"},
							{Variant::INT,"int"},
							{Variant::REAL,"float"},
							{Variant::STRING,"String"},
							{Variant::VECTOR2,"vec2"},
							{Variant::VECTOR2,"Vector2"},
							{Variant::RECT2,"Rect2"},
							{Variant::MATRIX32,"Matrix32"},
							{Variant::MATRIX32,"mat32"},
							{Variant::VECTOR3,"vec3"},
							{Variant::VECTOR3,"Vector3"},
							{Variant::_AABB,"AABB"},
							{Variant::_AABB,"Rect3"},
							{Variant::PLANE,"Plane"},
							{Variant::QUAT,"Quat"},
							{Variant::MATRIX3,"mat3"},
							{Variant::MATRIX3,"Matrix3"},
							{Variant::TRANSFORM,"trn"},
							{Variant::TRANSFORM,"Transform"},
							{Variant::COLOR,"Color"},
							{Variant::IMAGE,"Image"},
							{Variant::_RID,"RID"},
							{Variant::OBJECT,"Object"},
							{Variant::INPUT_EVENT,"InputEvent"},
							{Variant::NODE_PATH,"NodePath"},
							{Variant::DICTIONARY,"dict"},
							{Variant::DICTIONARY,"Dictionary"},
							{Variant::ARRAY,"Array"},
							{Variant::RAW_ARRAY,"RawArray"},
							{Variant::INT_ARRAY,"IntArray"},
							{Variant::REAL_ARRAY,"FloatArray"},
							{Variant::STRING_ARRAY,"StringArray"},
							{Variant::VECTOR2_ARRAY,"Vector2Array"},
							{Variant::VECTOR3_ARRAY,"Vector3Array"},
							{Variant::COLOR_ARRAY,"ColorArray"},
							{Variant::VARIANT_MAX,NULL},
						};

						{


							int idx=0;

							while(type_list[idx].text) {

								if (str==type_list[idx].text) {
									_make_type(type_list[idx].type);
									found=true;
									break;
								}
								idx++;
							}
						}

						if (!found) {

							//built in func?

							for(int i=0;i<GDFunctions::FUNC_MAX;i++) {

								if (str==GDFunctions::get_func_name(GDFunctions::Function(i))) {

									_make_built_in_func(GDFunctions::Function(i));
									found=true;
									 break;
								}
							}

							//keywor
						}

						if (!found) {


							struct _kws { Token token; const char *text;};

							static const  _kws keyword_list[]={
								//ops
								{TK_OP_IN,"in"},
								{TK_OP_NOT,"not"},
								{TK_OP_OR,"or"},
								{TK_OP_AND,"and"},
								//func
								{TK_PR_FUNCTION,"func"},
								{TK_PR_FUNCTION,"function"},
								{TK_PR_CLASS,"class"},
								{TK_PR_EXTENDS,"extends"},
								{TK_PR_TOOL,"tool"},
								{TK_PR_STATIC,"static"},
								{TK_PR_EXPORT,"export"},
								{TK_PR_SETGET,"setget"},
								{TK_PR_VAR,"var"},
								{TK_PR_PRELOAD,"preload"},
								{TK_PR_ASSERT,"assert"},
								{TK_PR_YIELD,"yield"},
								{TK_PR_CONST,"const"},
								//controlflow
								{TK_CF_IF,"if"},
								{TK_CF_ELIF,"elif"},
								{TK_CF_ELSE,"else"},
								{TK_CF_FOR,"for"},
								{TK_CF_WHILE,"while"},
								{TK_CF_DO,"do"},
								{TK_CF_SWITCH,"switch"},
								{TK_CF_BREAK,"break"},
								{TK_CF_CONTINUE,"continue"},
								{TK_CF_RETURN,"return"},
								{TK_CF_PASS,"pass"},
								{TK_SELF,"self"},
								{TK_ERROR,NULL}
							};

							int idx=0;
							found=false;

							while(keyword_list[idx].text) {

								if (str==keyword_list[idx].text) {
									_make_token(keyword_list[idx].token);
									found=true;
									break;
								}
								idx++;
							}
						}

						if (!found)
							identifier=true;
					}


					if (identifier) {
						_make_identifier(str);
					}
					INCPOS(str.length());
					return;
				}

				_make_error("Unknown character");
				return;

			} break;
		}

		INCPOS(1);
		break;
	}

}
Пример #28
0
void SceneTreeDock::_node_reparent(NodePath p_path,bool p_node_only) {


	Node *node = scene_tree->get_selected();
	ERR_FAIL_COND(!node);
	ERR_FAIL_COND(node==edited_scene);
	Node *new_parent = scene_root->get_node(p_path);
	ERR_FAIL_COND(!new_parent);

	Node *validate=new_parent;
	while(validate) {

		if (editor_selection->is_selected(validate)) {
			ERR_EXPLAIN("Selection changed at some point.. can't reparent");
			ERR_FAIL();
			return;
		}
		validate=validate->get_parent();
	}

	//ok all valid

	List<Node*> selection = editor_selection->get_selected_node_list();

	if (selection.empty())
		return; //nothing to reparent

	//sort by tree order, so re-adding is easy
	selection.sort_custom<Node::Comparator>();

	editor_data->get_undo_redo().create_action("Reparent Node");

	List<Pair<NodePath,NodePath> > path_renames;

	for(List<Node*>::Element *E=selection.front();E;E=E->next()) {

		//no undo for now, sorry
		Node *node = E->get();

		fill_path_renames(node,new_parent,&path_renames);

		List<Node*> owned;
		node->get_owned_by(node->get_owner(),&owned);
		Array owners;
		for(List<Node*>::Element *E=owned.front();E;E=E->next()) {

			owners.push_back(E->get());
		}



		editor_data->get_undo_redo().add_do_method(node->get_parent(),"remove_child",node);
		editor_data->get_undo_redo().add_do_method(new_parent,"add_child",node);

		ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
		String new_name = new_parent->validate_child_name(node->get_name());
		editor_data->get_undo_redo().add_do_method(sed,"live_debug_reparent_node",edited_scene->get_path_to(node),edited_scene->get_path_to(new_parent),new_name,-1);
		editor_data->get_undo_redo().add_undo_method(sed,"live_debug_reparent_node",NodePath(String(edited_scene->get_path_to(new_parent))+"/"+new_name),edited_scene->get_path_to(node->get_parent()),node->get_name(),node->get_index());


		editor_data->get_undo_redo().add_do_method(this,"_set_owners",edited_scene,owners);

		if (editor->get_animation_editor()->get_root()==node)
			editor_data->get_undo_redo().add_do_method(editor->get_animation_editor(),"set_root",node);

		editor_data->get_undo_redo().add_undo_method(new_parent,"remove_child",node);

	}

	//add and move in a second step.. (so old order is preserved)



	for(List<Node*>::Element *E=selection.front();E;E=E->next()) {

		Node *node = E->get();

		List<Node*> owned;
		node->get_owned_by(node->get_owner(),&owned);
		Array owners;
		for(List<Node*>::Element *E=owned.front();E;E=E->next()) {

			owners.push_back(E->get());
		}

		int child_pos = node->get_position_in_parent();

		editor_data->get_undo_redo().add_undo_method(node->get_parent(),"add_child",node);
		editor_data->get_undo_redo().add_undo_method(node->get_parent(),"move_child",node,child_pos);
		editor_data->get_undo_redo().add_undo_method(this,"_set_owners",edited_scene,owners);
		if (editor->get_animation_editor()->get_root()==node)
			editor_data->get_undo_redo().add_undo_method(editor->get_animation_editor(),"set_root",node);

	}

	perform_node_renames(NULL,&path_renames);

	editor_data->get_undo_redo().commit_action();
	//node->set_owner(owner);
}
Пример #29
0
MeshInstance::MeshInstance() {
	skeleton_path = NodePath("..");
}
Пример #30
0
void SceneTreeDock::perform_node_renames(Node* p_base,List<Pair<NodePath,NodePath> > *p_renames, Map<Ref<Animation>, Set<int> > *r_rem_anims) {

	Map<Ref<Animation>, Set<int> > rem_anims;

	if (!r_rem_anims)
		r_rem_anims=&rem_anims;

	if (!bool(EDITOR_DEF("animation/autorename_animation_tracks",true)))
		return;

	if (!p_base) {

		p_base=edited_scene;
	}

	if (!p_base)
		return;


	if (p_base->cast_to<AnimationPlayer>()) {

		AnimationPlayer *ap=p_base->cast_to<AnimationPlayer>();
		List<StringName> anims;
		ap->get_animation_list(&anims);
		Node *root = ap->get_node(ap->get_root());


		if (root) {


			NodePath root_path=root->get_path();
			NodePath new_root_path=root_path;


			for(List<Pair<NodePath,NodePath> >::Element* E=p_renames->front();E;E=E->next()) {

				if (E->get().first==root_path) {
					new_root_path=E->get().second;
					break;
				}
			}

			if (new_root_path!=NodePath()) {
				//will not be erased

				for(List<StringName>::Element *E=anims.front();E;E=E->next()) {

					Ref<Animation> anim=ap->get_animation(E->get());
					if (!r_rem_anims->has(anim)) {
						r_rem_anims->insert(anim,Set<int>());
						Set<int> &ran = r_rem_anims->find(anim)->get();
						for(int i=0;i<anim->get_track_count();i++)
							ran.insert(i);
					}

					Set<int> &ran = r_rem_anims->find(anim)->get();

					if (anim.is_null())
						continue;

					for(int i=0;i<anim->get_track_count();i++) {

						NodePath track_np=anim->track_get_path(i);
						Node *n = root->get_node(track_np);
						if (!n) {
							continue;
						}

						NodePath old_np = n->get_path();

						if (!ran.has(i))
							continue; //channel was removed

						for(List<Pair<NodePath,NodePath> >::Element* E=p_renames->front();E;E=E->next()) {

							if (E->get().first==old_np) {


								if (E->get().second==NodePath()) {
									//will be erased

									int idx=0;
									Set<int>::Element *EI=ran.front();
									ERR_FAIL_COND(!EI); //bug
									while(EI->get()!=i) {
										idx++;
										EI=EI->next();
										ERR_FAIL_COND(!EI); //another bug

									}

									editor_data->get_undo_redo().add_do_method(anim.ptr(),"remove_track",idx);
									editor_data->get_undo_redo().add_undo_method(anim.ptr(),"add_track",anim->track_get_type(i),idx);
									editor_data->get_undo_redo().add_undo_method(anim.ptr(),"track_set_path",idx,track_np);
									editor_data->get_undo_redo().add_undo_method(anim.ptr(),"track_set_interpolation_type",idx,anim->track_get_interpolation_type(i));
									for(int j=0;j<anim->track_get_key_count(i);j++) {

										editor_data->get_undo_redo().add_undo_method(anim.ptr(),"track_insert_key",idx,anim->track_get_key_time(i,j),anim->track_get_key_value(i,j),anim->track_get_key_transition(i,j));
									}

									ran.erase(i); //byebye channel

								} else {
									//will be renamed
									NodePath rel_path = new_root_path.rel_path_to(E->get().second);

									NodePath new_path = NodePath( rel_path.get_names(), track_np.get_subnames(), false, track_np.get_property() );
									if (new_path==track_np)
										continue; //bleh
									editor_data->get_undo_redo().add_do_method(anim.ptr(),"track_set_path",i,new_path);
									editor_data->get_undo_redo().add_undo_method(anim.ptr(),"track_set_path",i,track_np);
								}
							}
						}
					}
				}
			}
		}
	}


	for(int i=0;i<p_base->get_child_count();i++)
		perform_node_renames(p_base->get_child(i),p_renames,r_rem_anims);

}