예제 #1
0
void ServerConfigurationImpl::load(const CL_String &p_configFile)
{
	try {
		cl_log_event(LOG_DEBUG, "loading configuration from %1", p_configFile);

		CL_File file(
				p_configFile,
				CL_File::open_existing,
				CL_File::access_read
		);


		CL_DomDocument document(file);
		CL_DomElement root = document.get_document_element();

		if (root.named_item("server").is_null()) {
			// no configuration at all
			return;
		}

		CL_DomElement server = root.named_item("server").to_element();

		m_level = server.select_string("level");
		m_port = server.select_int("port");

		if (m_level.length() == 0) {
			cl_log_event(LOG_ERROR, "%1: level not set", CONFIG_FILE);
			exit(1);
		}

		if (m_port <= 0 || m_port > 0xFFFF) {
			cl_log_event(LOG_ERROR, "%1: invalid port value", CONFIG_FILE);
			exit(1);
		}

//		// read all elements
//		CL_DomNode cur = server.get_first_child();
//		while (cur.is_element()) {
//
//			if (cur.get_node_name() == "port") {
//				m_port = CL_StringHelp::local8_to_int
//						(cur.to_element().get_text()
//				);
//				cl_log_event(LOG_DEBUG, "Port set to %1", m_port);
//			}
//
//			cur = cur.get_next_sibling();
//		}


	} catch (CL_Exception e) {
		cl_log_event(LOG_ERROR, e.message);
	}
}
void CL_Collada_Effect_Texture_Impl::load_texture(CL_DomElement &profile_element, CL_DomElement &newparam_element, CL_DomElement &sampler2d_element, std::vector<CL_Collada_Image> &library_images)
{
	sid = newparam_element.get_attribute("sid");

	CL_DomElement source_element = sampler2d_element.named_item("source").to_element();
	if (source_element.is_null())
		throw CL_Exception("source is missing");

	CL_String source_name = source_element.get_text();

	// Find the corresponding surface
	CL_DomElement surface_element;
	CL_DomNode cur_child(profile_element.get_first_child());
	while (!cur_child.is_null())
	{
			if(cur_child.get_node_name() == "newparam")
			{
				CL_DomElement newparam_element = cur_child.to_element();
				CL_String new_sid = newparam_element.get_attribute("sid");
				if (new_sid == source_name)
				{
					surface_element = newparam_element.named_item("surface").to_element();
					if (!surface_element.is_null())
						break;	// Found match
				}
			}
			cur_child = cur_child.get_next_sibling();
	}

	if (surface_element.is_null())
		throw CL_Exception("Cannot find the corresponding surface");

	CL_DomElement init_from_element = surface_element.named_item("init_from").to_element();
	if (init_from_element.is_null())
		throw CL_Exception("Only init_from surfaces are supported");

	CL_String image_name = init_from_element.get_text();

	unsigned int size = library_images.size();
	for (unsigned int cnt=0; cnt < size; cnt++)
	{
		if (library_images[cnt].get_id() == image_name)
		{
			image = library_images[cnt];
			break;
		}
	}
	if (image.is_null())
		throw CL_Exception("Cannot find requested image in the image library");

}
예제 #3
0
void CL_Collada_Material_Impl::load_material(CL_DomElement &material_element, std::vector<CL_Collada_Effect> &effects)
{
	id = material_element.get_attribute("id");

	CL_DomElement instance_effect_element = material_element.named_item("instance_effect").to_element();
	if (instance_effect_element.is_null())
		throw CL_Exception("Only instance_effect materials are supported");

	CL_String url = instance_effect_element.get_attribute("url");
	url = url.substr(1);	// Remove the initial '#' symbol

	std::vector<CL_Collada_Effect>::size_type size, cnt;
	size = effects.size();
	for (cnt=0; cnt< size; cnt++)
	{
		if (effects[cnt].get_id() == url)
		{
			effect = effects[cnt];
			break;
		}
	}

	if (effect.is_null())
		throw CL_Exception("Unable to find effect");

}
예제 #4
0
void CL_Collada_Triangles_Impl::load_polylist(CL_DomElement &polylist_element, bool contains_vcount, std::vector<CL_Collada_Source> &sources, CL_Collada_Vertices &vertices, std::vector<CL_Collada_Material> &library_materials)
{
	name = polylist_element.get_attribute("name");

	// Find material	
	if (polylist_element.has_attribute("material"))
	{
		CL_String material_name = polylist_element.get_attribute("material");

			std::vector<CL_Collada_Material>::size_type size, cnt;
			size = library_materials.size();
			for (cnt=0; cnt< size; cnt++)
			{
				if (library_materials[cnt].get_id() == material_name)
				{
					material = library_materials[cnt];
					break;
				}
			}
	
		if (material.is_null())
			throw CL_Exception("Unable to find material");

	}

	triangle_count = polylist_element.get_attribute_int("count", 0);

	load_inputs(polylist_element, sources, vertices);

	if (contains_vcount)
	{
		CL_DomElement vcount_element = polylist_element.named_item("vcount").to_element();
		if (!vcount_element.is_null())
			validate_vcount(vcount_element);
	}

	CL_DomElement primitive_element = polylist_element.named_item("p").to_element();
	if (!primitive_element.is_null())
		load_primitive(primitive_element);
}
예제 #5
0
void Level::loadFromFile(const CL_String& p_filename)
{
	assert(!m_loaded && "level is already loaded");

	try {
		CL_File file(p_filename, CL_File::open_existing, CL_File::access_read);


		CL_DomDocument document(file);
		const CL_DomElement root = document.get_document_element();

		// load meta element
		const CL_DomNode metaNode = root.named_item("meta");
		loadMetaElement(metaNode);

		// gets level's content
		const CL_DomNode contentNode = root.named_item("content");

		// load sand
		const CL_DomNode sandNode = contentNode.named_item("sand");
		loadSandElement(sandNode);

		// load track
		const CL_DomNode trackNode = contentNode.named_item("track");
		loadTrackElement(trackNode);

		// load track bounds
		const CL_DomNode boundsNode = contentNode.named_item("bounds");
		loadBoundsElement(boundsNode);

		file.close();
		m_loaded = true;

	} catch (CL_Exception e) {
		CL_Console::write_line(e.message);
	}

}
void ReferenceFunction::parse_memberdef(CL_DomElement memberdef)
{
	CL_DomElement element_name = memberdef.named_item("name").to_element();
	if (element_name.is_null() || element_name.get_text() != name)
		return;

	CL_String type, type_formatted, definition, argsstring;
	std::vector<CL_String> cur_params;

	CL_DomNode cur_node;
	for (cur_node = memberdef.get_first_child(); !cur_node.is_null(); cur_node = cur_node.get_next_sibling())
	{
		CL_DomElement cur_element = cur_node.to_element();
		if (cur_element.is_null()) continue;

		CL_String tag_name = cur_element.get_tag_name();
		
		if (tag_name == "type")
		{
			type = cur_element.get_text();
			type_formatted = ReferenceDocs::get_formatted(cur_element);
		}
		else if (tag_name == "definition")
		{
			definition = CL_StringHelp::trim(ReferenceDocs::escape_code(cur_element.get_text()));
		}
		else if (tag_name == "argsstring")
		{
			argsstring = cur_element.get_text();
		}
		else if (tag_name == "param")
		{
			CL_String param_type = ReferenceDocs::get_formatted(cur_element.named_item("type").to_element());
			CL_String param_name = cur_element.named_item("declname").to_element().get_text();
			CL_String param_defval = ReferenceDocs::get_formatted(cur_element.named_item("defval").to_element());
			
			CL_String param_text = param_type + " " + param_name;
			if (!param_defval.empty())
				param_text += CL_String(" = ") + param_defval;
			cur_params.push_back(param_text);
		}
		else if (tag_name == "briefdescription")
		{
			brief_description = ReferenceDocs::get_formatted(cur_element);
		}
		else if (tag_name == "detaileddescription")
		{
			detailed_description = ReferenceDocs::get_formatted(cur_element);
			get_params_list(cur_element);
		}
	}

	CL_String cur_declaration;
	cur_declaration += cl_format("\t%1(", definition);
	for (unsigned int index_params = 0; index_params < cur_params.size(); index_params++)
	{
		if (index_params > 0)
			cur_declaration += ",";
		cur_declaration += cl_format("\n\t\t%1", cur_params[index_params]);
	}
	cur_declaration += ");\n";

	if (!declaration.empty())
		declaration += "\n";
	declaration += cur_declaration;
}