Пример #1
0
int RetrieveAttrValue(XMLNodePtr node, std::string const & attr_name, int default_value)
{
	XMLAttributePtr attr = node->Attrib(attr_name);
	if (attr)
	{
		return attr->ValueInt();
	}

	return default_value;
}
Пример #2
0
	int32_t XMLNode::AttribInt(std::string const & name, int32_t default_val)
	{
		XMLAttributePtr attr = this->Attrib(name);
		return attr ? attr->ValueInt() : default_val;
	}
Пример #3
0
	void Context::LoadCfg(std::string const & cfg_file)
	{
		int width = 800;
		int height = 600;
		ElementFormat color_fmt = EF_ARGB8;
		ElementFormat depth_stencil_fmt = EF_D16;
		int sample_count = 1;
		int sample_quality = 0;
		bool full_screen = false;
		int sync_interval = 0;
		int motion_frames = 0;
		bool hdr = false;
		bool ppaa = false;
		bool gamma = false;
		bool color_grading = false;
		int stereo_method = 0;
		float stereo_separation = 0;
		std::string graphics_options;

#ifdef KLAYGE_PLATFORM_WINDOWS
		std::string rf_name = "D3D11";
#else
		std::string rf_name = "OpenGL";
#endif
		std::string af_name = "OpenAL";
#ifdef KLAYGE_PLATFORM_WINDOWS
		std::string if_name = "DInput";
#else
		std::string if_name;
#endif
#ifdef KLAYGE_PLATFORM_WINDOWS
		std::string sf_name = "DShow";
#else
		std::string sf_name;
#endif
#ifdef KLAYGE_PLATFORM_WINDOWS
		std::string scf_name = "Python";
#else
		std::string scf_name;
#endif
		std::string sm_name;
		std::string adsf_name;

		ResIdentifierPtr file = ResLoader::Instance().Open(cfg_file);
		if (file)
		{
			XMLDocument cfg_doc;
			XMLNodePtr cfg_root = cfg_doc.Parse(file);

			XMLNodePtr context_node = cfg_root->FirstNode("context");
			XMLNodePtr graphics_node = cfg_root->FirstNode("graphics");

#ifdef KLAYGE_PLATFORM_WINDOWS
			XMLNodePtr rf_node = context_node->FirstNode("render_factory");
			if (rf_node)
			{
				rf_name = rf_node->Attrib("name")->ValueString();
			}
#endif

#ifdef KLAYGE_PLATFORM_WINDOWS
			XMLNodePtr af_node = context_node->FirstNode("audio_factory");
			if (af_node)
			{
				af_name = af_node->Attrib("name")->ValueString();
			}
#endif

#ifdef KLAYGE_PLATFORM_WINDOWS
			XMLNodePtr if_node = context_node->FirstNode("input_factory");
			if (if_node)
			{
				if_name = if_node->Attrib("name")->ValueString();
			}
#endif

#ifdef KLAYGE_PLATFORM_WINDOWS
			XMLNodePtr sf_node = context_node->FirstNode("show_factory");
			if (sf_node)
			{
				sf_name = sf_node->Attrib("name")->ValueString();
			}
#endif

#ifdef KLAYGE_PLATFORM_WINDOWS
			XMLNodePtr scf_node = context_node->FirstNode("script_factory");
			if (scf_node)
			{
				scf_name = scf_node->Attrib("name")->ValueString();
			}
#endif

			XMLNodePtr sm_node = context_node->FirstNode("scene_manager");
			if (sm_node)
			{
				sm_name = sm_node->Attrib("name")->ValueString();
			}

			XMLNodePtr adsf_node = context_node->FirstNode("audio_data_source_factory");
			if (adsf_node)
			{
				adsf_name = adsf_node->Attrib("name")->ValueString();
			}

			XMLNodePtr frame_node = graphics_node->FirstNode("frame");
			XMLAttributePtr attr;
			attr = frame_node->Attrib("width");
			if (attr)
			{
				width = attr->ValueInt();
			}
			attr = frame_node->Attrib("height");
			if (attr)
			{
				height = attr->ValueInt();
			}
			std::string color_fmt_str = "ARGB8";
			attr = frame_node->Attrib("color_fmt");
			if (attr)
			{
				color_fmt_str = attr->ValueString();
			}
			std::string depth_stencil_fmt_str = "D16";
			attr = frame_node->Attrib("depth_stencil_fmt");
			if (attr)
			{
				depth_stencil_fmt_str = attr->ValueString();
			}
			attr = frame_node->Attrib("fullscreen");
			if (attr)
			{
				std::string fs_str = attr->ValueString();
				if (("1" == fs_str) || ("true" == fs_str))
				{
					full_screen = true;
				}
				else
				{
					full_screen = false;
				}
			}

			if ("ARGB8" == color_fmt_str)
			{
				color_fmt = EF_ARGB8;
			}
			else if ("ABGR8" == color_fmt_str)
			{
				color_fmt = EF_ABGR8;
			}
			else if ("A2BGR10" == color_fmt_str)
			{
				color_fmt = EF_A2BGR10;
			}

			if ("D16" == depth_stencil_fmt_str)
			{
				depth_stencil_fmt = EF_D16;
			}
			else if ("D24S8" == depth_stencil_fmt_str)
			{
				depth_stencil_fmt = EF_D24S8;
			}
			else if ("D32F" == depth_stencil_fmt_str)
			{
				depth_stencil_fmt = EF_D32F;
			}

			XMLNodePtr sample_node = frame_node->FirstNode("sample");
			attr = sample_node->Attrib("count");
			if (attr)
			{
				sample_count = attr->ValueInt();
			}
			attr = sample_node->Attrib("quality");
			if (attr)
			{
				sample_quality = attr->ValueInt();
			}

			XMLNodePtr sync_interval_node = graphics_node->FirstNode("sync_interval");
			attr = sync_interval_node->Attrib("value");
			if (attr)
			{
				sync_interval = attr->ValueInt();
			}

			XMLNodePtr motion_blur_node = graphics_node->FirstNode("motion_blur");
			attr = motion_blur_node->Attrib("frames");
			if (attr)
			{
				motion_frames = attr->ValueInt();
			}

			XMLNodePtr hdr_node = graphics_node->FirstNode("hdr");
			attr = hdr_node->Attrib("value");
			if (attr)
			{
				std::string hdr_str = attr->ValueString();
				if (("1" == hdr_str) || ("true" == hdr_str))
				{
					hdr = true;
				}
				else
				{
					hdr = false;
				}
			}

			XMLNodePtr ppaa_node = graphics_node->FirstNode("ppaa");
			attr = hdr_node->Attrib("value");
			if (attr)
			{
				std::string ppaa_str = attr->ValueString();
				if (("1" == ppaa_str) || ("true" == ppaa_str))
				{
					ppaa = true;
				}
				else
				{
					ppaa = false;
				}
			}

			XMLNodePtr gamma_node = graphics_node->FirstNode("gamma");
			attr = gamma_node->Attrib("value");
			if (attr)
			{
				std::string gamma_str = attr->ValueString();
				if (("1" == gamma_str) || ("true" == gamma_str))
				{
					gamma = true;
				}
				else
				{
					gamma = false;
				}
			}

			XMLNodePtr color_grading_node = graphics_node->FirstNode("color_grading");
			attr = color_grading_node->Attrib("value");
			if (attr)
			{
				std::string color_grading_str = attr->ValueString();
				if (("1" == color_grading_str) || ("true" == color_grading_str))
				{
					color_grading = true;
				}
				else
				{
					color_grading = false;
				}
			}

			XMLNodePtr stereo_node = graphics_node->FirstNode("stereo");
			attr = stereo_node->Attrib("method");
			if (attr)
			{
				std::string method_str = attr->ValueString();
				if ("none" == method_str)
				{
					stereo_method = STM_None;
				}
				else if ("red_cyan" == method_str)
				{
					stereo_method = STM_ColorAnaglyph_RedCyan;
				}
				else if ("yellow_blue" == method_str)
				{
					stereo_method = STM_ColorAnaglyph_YellowBlue;
				}
				else if ("green_red" == method_str)
				{
					stereo_method = STM_ColorAnaglyph_GreenRed;
				}
				else if ("lcd_shutter" == method_str)
				{
					stereo_method = STM_LCDShutter;
				}
				else if ("hor_interlacing" == method_str)
				{
					stereo_method = STM_HorizontalInterlacing;
				}
				else if ("ver_interlacing" == method_str)
				{
					stereo_method = STM_VerticalInterlacing;
				}
				else if ("horizontal" == method_str)
				{
					stereo_method = STM_Horizontal;
				}
				else if ("vertical" == method_str)
				{
					stereo_method = STM_Vertical;
				}
				else
				{
					stereo_method = STM_ColorAnaglyph_RedCyan;
				}
			}
			else
			{
				stereo_method = STM_None;
			}
			attr = stereo_node->Attrib("separation");
			if (attr)
			{
				stereo_separation = attr->ValueFloat();
			}

			XMLNodePtr options_node = graphics_node->FirstNode("options");
			if (options_node)
			{
				attr = options_node->Attrib("str");
				if (attr)
				{
					graphics_options = attr->ValueString();
				}
			}
		}

		cfg_.render_factory_name = rf_name;
		cfg_.audio_factory_name = af_name;
		cfg_.input_factory_name = if_name;
		cfg_.show_factory_name = sf_name;
		cfg_.script_factory_name = scf_name;
		cfg_.scene_manager_name = sm_name;
		cfg_.audio_data_source_factory_name = adsf_name;

		cfg_.graphics_cfg.left = cfg_.graphics_cfg.top = 0;
		cfg_.graphics_cfg.width = width;
		cfg_.graphics_cfg.height = height;
		cfg_.graphics_cfg.color_fmt = color_fmt;
		cfg_.graphics_cfg.depth_stencil_fmt = depth_stencil_fmt;
		cfg_.graphics_cfg.sample_count = sample_count;
		cfg_.graphics_cfg.sample_quality = sample_quality;
		cfg_.graphics_cfg.full_screen = full_screen;
		cfg_.graphics_cfg.sync_interval = sync_interval;
		cfg_.graphics_cfg.motion_frames = motion_frames;
		cfg_.graphics_cfg.hdr = hdr;
		cfg_.graphics_cfg.ppaa = ppaa;
		cfg_.graphics_cfg.gamma = gamma;
		cfg_.graphics_cfg.color_grading = color_grading;
		cfg_.graphics_cfg.stereo_method = static_cast<StereoMethod>(stereo_method);
		cfg_.graphics_cfg.stereo_separation = stereo_separation;
		cfg_.graphics_cfg.options = graphics_options;

		cfg_.deferred_rendering = false;
	}
Пример #4
0
int32_t XMLNode::AttributeInt( const std::string& name , int32_t defaultVar  )
{
    XMLAttributePtr attr = Attribute(name);
    return attr ? attr->ValueInt() : defaultVar;
}
Пример #5
0
		void SubThreadStage()
		{
			ResIdentifierPtr psmm_input = ResLoader::Instance().Open(ps_desc_.res_name);

			KlayGE::XMLDocument doc;
			XMLNodePtr root = doc.Parse(psmm_input);

			{
				XMLNodePtr particle_node = root->FirstNode("particle");
				{
					XMLNodePtr alpha_node = particle_node->FirstNode("alpha");
					ps_desc_.ps_data->particle_alpha_from_tex = alpha_node->Attrib("from")->ValueString();
					ps_desc_.ps_data->particle_alpha_to_tex = alpha_node->Attrib("to")->ValueString();
				}
				{
					XMLNodePtr color_node = particle_node->FirstNode("color");
					{
						Color from;
						XMLAttributePtr attr = color_node->Attrib("from");
						if (attr)
						{
							std::vector<std::string> strs;
							boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" "));
							for (size_t i = 0; i < 3; ++ i)
							{
								if (i < strs.size())
								{
									boost::algorithm::trim(strs[i]);
									from[i] = static_cast<float>(atof(strs[i].c_str()));
								}
								else
								{
									from[i] = 0;
								}
							}
						}
						from.a() = 1;
						ps_desc_.ps_data->particle_color_from = from;

						Color to;
						attr = color_node->Attrib("to");
						if (attr)
						{
							std::vector<std::string> strs;
							boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" "));
							for (size_t i = 0; i < 3; ++ i)
							{
								if (i < strs.size())
								{
									boost::algorithm::trim(strs[i]);
									to[i] = static_cast<float>(atof(strs[i].c_str()));
								}
								else
								{
									to[i] = 0;
								}
							}
						}
						to.a() = 1;
						ps_desc_.ps_data->particle_color_to = to;
					}
				}
			}

			{
				XMLNodePtr emitter_node = root->FirstNode("emitter");

				XMLAttributePtr type_attr = emitter_node->Attrib("type");
				if (type_attr)
				{
					ps_desc_.ps_data->emitter_type = type_attr->ValueString();
				}
				else
				{
					ps_desc_.ps_data->emitter_type = "point";
				}

				XMLNodePtr freq_node = emitter_node->FirstNode("frequency");
				if (freq_node)
				{
					XMLAttributePtr attr = freq_node->Attrib("value");
					ps_desc_.ps_data->frequency = attr->ValueFloat();
				}

				XMLNodePtr angle_node = emitter_node->FirstNode("angle");
				if (angle_node)
				{
					XMLAttributePtr attr = angle_node->Attrib("value");
					ps_desc_.ps_data->angle = attr->ValueInt() * DEG2RAD;
				}

				XMLNodePtr pos_node = emitter_node->FirstNode("pos");
				if (pos_node)
				{
					float3 min_pos(0, 0, 0);
					XMLAttributePtr attr = pos_node->Attrib("min");
					if (attr)
					{
						std::vector<std::string> strs;
						boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" "));
						for (size_t i = 0; i < 3; ++ i)
						{
							if (i < strs.size())
							{
								boost::algorithm::trim(strs[i]);
								min_pos[i] = static_cast<float>(atof(strs[i].c_str()));
							}
							else
							{
								min_pos[i] = 0;
							}
						}
					}
					ps_desc_.ps_data->min_pos = min_pos;
			
					float3 max_pos(0, 0, 0);
					attr = pos_node->Attrib("max");
					if (attr)
					{
						std::vector<std::string> strs;
						boost::algorithm::split(strs, attr->ValueString(), boost::is_any_of(" "));
						for (size_t i = 0; i < 3; ++ i)
						{
							if (i < strs.size())
							{
								boost::algorithm::trim(strs[i]);
								max_pos[i] = static_cast<float>(atof(strs[i].c_str()));
							}
							else
							{
								max_pos[i] = 0;
							}
						}
					}			
					ps_desc_.ps_data->max_pos = max_pos;
				}

				XMLNodePtr vel_node = emitter_node->FirstNode("vel");
				if (vel_node)
				{
					XMLAttributePtr attr = vel_node->Attrib("min");
					ps_desc_.ps_data->min_vel = attr->ValueFloat();

					attr = vel_node->Attrib("max");
					ps_desc_.ps_data->max_vel = attr->ValueFloat();
				}

				XMLNodePtr life_node = emitter_node->FirstNode("life");
				if (life_node)
				{
					XMLAttributePtr attr = life_node->Attrib("min");
					ps_desc_.ps_data->min_life = attr->ValueFloat();

					attr = life_node->Attrib("max");
					ps_desc_.ps_data->max_life = attr->ValueFloat();
				}
			}

			{
				XMLNodePtr updater_node = root->FirstNode("updater");

				XMLAttributePtr type_attr = updater_node->Attrib("type");
				if (type_attr)
				{
					ps_desc_.ps_data->updater_type = type_attr->ValueString();
				}
				else
				{
					ps_desc_.ps_data->updater_type = "polyline";
				}

				if ("polyline" == ps_desc_.ps_data->updater_type)
				{
					for (XMLNodePtr node = updater_node->FirstNode("curve"); node; node = node->NextSibling("curve"))
					{
						std::vector<float2> xys;
						for (XMLNodePtr ctrl_point_node = node->FirstNode("ctrl_point"); ctrl_point_node; ctrl_point_node = ctrl_point_node->NextSibling("ctrl_point"))
						{
							XMLAttributePtr attr_x = ctrl_point_node->Attrib("x");
							XMLAttributePtr attr_y = ctrl_point_node->Attrib("y");

							xys.push_back(float2(attr_x->ValueFloat(), attr_y->ValueFloat()));
						}

						XMLAttributePtr attr = node->Attrib("name");
						size_t const name_hash = RT_HASH(attr->ValueString().c_str());
						if (CT_HASH("size_over_life") == name_hash)
						{
							ps_desc_.ps_data->size_over_life_ctrl_pts = xys;
						}
						else if (CT_HASH("mass_over_life") == name_hash)
						{
							ps_desc_.ps_data->mass_over_life_ctrl_pts = xys;
						}
						else if (CT_HASH("opacity_over_life") == name_hash)
						{
							ps_desc_.ps_data->opacity_over_life_ctrl_pts = xys;
						}
					}
				}
			}

			RenderFactory& rf = Context::Instance().RenderFactoryInstance();
			RenderDeviceCaps const & caps = rf.RenderEngineInstance().DeviceCaps();
			if (caps.multithread_res_creating_support)
			{
				this->MainThreadStage();
			}
		}