void CL_Collada_Triangles_Impl::validate_vcount(CL_DomElement &vcount_element)
{
	CL_String points = vcount_element.get_text();
	const CL_String::char_type *vcount_text = points.c_str();

	for (unsigned int cnt=0; cnt < triangle_count; cnt++)
	{
		if (!(*vcount_text))
			throw CL_Exception("VCount data count mismatch");

		int value = atoi(vcount_text);

		if (value != 3)
			throw CL_Exception("Only triangles are supported. Export your mesh as triangles please");

		while(*vcount_text)
		{
			if (*(vcount_text++) <= ' ')	// Find whitespace
				break;
		}

		while(*vcount_text)
		{
			if ((*vcount_text) > ' ')	// Find end of whitespace
				break;
			vcount_text++;
		}

	}
	if (*vcount_text)
			throw CL_Exception("VCount data count mismatch (end)");
}
void CL_Collada_Triangles_Impl::load_primitive(CL_DomElement &primitive_element)
{
	unsigned int count = stride * triangle_count * 3;

	primitive.resize(count);

	CL_String points = primitive_element.get_text();
	const CL_String::char_type *primitive_text = points.c_str();

	for (unsigned int cnt=0; cnt < count; cnt++)
	{
		if (!(*primitive_text))
			throw CL_Exception("Primitive data count mismatch");

		int value = atoi(primitive_text);
		primitive[cnt] = value;

		while(*primitive_text)
		{
			if (*(primitive_text++) <= ' ')	// Find whitespace
				break;
		}

		while(*primitive_text)
		{
			if ((*primitive_text) > ' ')	// Find end of whitespace
				break;
			primitive_text++;
		}

	}
	if (*primitive_text)
			throw CL_Exception("Primitive data count mismatch (end)");
}
CL_VirtualDirectoryListing CL_VirtualFileSystem::get_directory_listing(const CL_String &path_rel)
{
	CL_String path = CL_PathHelp::make_absolute(
		"/",
		path_rel,
		CL_PathHelp::path_type_virtual);

	// First see if its a mount point:
	int index, size;
	size = (int) impl->mounts.size();
	for (index = 0; index < size; index++)
	{
		if (impl->mounts[index].first == path.substr(0, impl->mounts[index].first.length()))
		{
			return impl->mounts[index].second.get_directory_listing( path.substr(impl->mounts[index].first.length(), path.length()));
		}
	}

	// Try open locally, if we got a file provider attached
	if (impl->provider)
	{
		return CL_VirtualDirectoryListing(
			impl->provider,
			CL_PathHelp::make_relative(
				"/",
				path,
				CL_PathHelp::path_type_virtual));		
	}
	else
		throw CL_Exception(cl_format("Unable to list directory: %1", path));

}
void CL_StringFormat::set_arg(int index, long unsigned int value, int min_length)
{
	CL_String t = CL_StringHelp::ull_to_text(value);
	if ((int) t.length() < min_length)
		t = CL_String(min_length-t.length(), '0') + t;
	set_arg(index, t);
}
Beispiel #5
0
void CL_TimeOfDay::FromStream (istream& s)
{
    CL_String rep;
    char c;
    long count = 0;
    char fill_char = s.fill ();
    
    while (s.get (c) && c == fill_char);
    if (!s.good() || s.eof()) {
        _numSecs = 0;
        return;
    }
    do {
        if (isalnum (c) || c == ':') {
            rep.Append (c);
            count++;
        }
        else
            break;
    } while (s.get (c));

    long n = ParseAndConvert (rep);
    if (n > 0) {
        if (!s.eof())
            s.putback (c);
        _numSecs = n;
    }
    else {
        s.seekg (s.tellg() - count, istream::cur);
        _numSecs = 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");

}
Beispiel #7
0
bool CL_PathHelp::is_absolute(const CL_String &path, PathType path_type)
{
	if (path_type == path_type_file)
	{
#ifdef WIN32
		if (path.length() < 3)
			return false;
		if (path[1] == ':' && (path[2] == '\\' || path[2] == '/'))
			return true;
		if (path[0] == '\\' && path[1] == '\\')
			return true;
		return false;
#else
		if (path.length() < 1)
			return false;
		if (path[0] == '/')
			return true;
		if (path[0] == '\\')
			return true;
		return false;
#endif
	}
	else
	{
		if (path.length() < 1)
			return false;
		if (path[0] == '/')
			return true;
		return false;
	}
}
Beispiel #8
0
CL_String CL_File::read_text(const CL_String &filename)
{
    CL_File file(filename);
    CL_String str;
    str.resize(file.get_size());
    file.read(str.data(), str.length());
    file.close();
    return str;
}
Beispiel #9
0
CL_String CL_PathHelp::remove_trailing_slash(const CL_String &path)
{
	if (path.empty())
		return path;

	if (path[path.length()-1] == '/' || path[path.length()-1] == '\\')
		return path.substr(0, path.length()-1);

	return path;
}
Beispiel #10
0
//конвертирование из CP-1251 в UTF-8
CL_String decode(const CL_String &str)
{
	//строка символов в текущей локали преобразовать в UCS-2 через MultiByteToWideChar,
	//а потом из UCS-2 в кланлибовский UTF-8 через CL_StringHelp::ucs2_to_text.
	CL_String16 result;
	int count = MultiByteToWideChar(1251, 0, str.c_str(), str.size(), NULL, 0);
	result.resize(count);
	MultiByteToWideChar(1251, 0, str.c_str(), str.size(), result.data(), count);
	
	return CL_StringHelp::ucs2_to_text(result);
}
void ReferenceIndex::save(const CL_StringRef &filename)
{
	CL_File index_file(filename, CL_File::create_always, CL_File::access_write);
	CL_String html =
		"<!-- clanlib header begin -->"
		"<HTML>"
		"<HEAD>"
		"<TITLE>Index - ClanLib Game SDK</TITLE>"
		"<STYLE TYPE=\"text/css\"><!--"
		"HTML BODY"
		"{"
		"        font-family: verdana, helvetica, sans-serif;"
		"        font-size: 12px;"
		"}"
		"H1 { font-size: 22px; }"
		"H2 { font-size: 18px; }"
		"H3 { font-size: 16px; }"
		"H4 { font-size: 14px; }"
		"P { font-size: 12px; }"
		"LI { font-size: 12px; }"
		".reflink:link { text-decoration: none; font-weight: bold; color: black; }"
		".reflink:visited { text-decoration: none; font-weight: bold; color: black; }"
		".reflink:active { text-decoration: none; font-weight: bold; color: black; }"
		".reflink:hover { text-decoration: underline; font-weight: bold; color: black; }"
		"--></STYLE>"
		"</HEAD>"
		"<body bgcolor=white text=black link=blue vlink=#800080>"
		"<center>"
		"<img src=\"http://clanlib.org/gfx/clanlib.png\">"
		"</center>"
		"<!-- clanlib header end -->"
		"<center>"
		"<p>"
//		"<a href=\"http://clanlib.org/docs.html\">Home</a> |"
		"<a href=\"classes.html\">All Classes</a> |"
		"<a href=\"modules.html\">Grouped Classes</a> |"
		"<a href=\"index.html\">Index</a>"
//		"<a href=\"search.html\">Search</a>"
		"</p>"
		"</center>"
		"<h1>Index</h1>";
	index_file.write(html.data(), html.length());

	html =
		"<!-- clanlib footer begin -->"
//		"<center><br><br><font color=\"#a0a0a0\">"
//		"Questions or comments, write to the <a href=\"http://clanlib.org/contact.html\">ClanLib mailing list</a>."
//		"</font></center>"
		"<!-- clanlib footer end -->"
		"</body>"
		"</html>";
	index_file.write(html.data(), html.length());
}
Beispiel #12
0
CL_String CL_PathHelp::get_fullname(
	const CL_String &fullpath,
	const CL_String &filename,
	const CL_String &extension,
	PathType path_type)
{
	if (!extension.empty() && extension[0] == '.')
		return add_trailing_slash(fullpath, path_type) + filename + extension;
	else if (!extension.empty())
		return add_trailing_slash(fullpath, path_type) + filename + "." + extension;
	else
		return add_trailing_slash(fullpath, path_type) + filename;
}
Beispiel #13
0
CL_String CL_PathHelp::get_fullname(
	const CL_String &location,
	const CL_String &basepath,
	const CL_String &filename,
	const CL_String &extension,
	PathType path_type)
{
	CL_String fullname = location;
	fullname += add_trailing_slash(basepath, path_type);
	fullname += filename;
	if (!extension.empty() && extension[0] == '.')
		fullname += extension;
	else if (!extension.empty())
		fullname += "." + extension;
	return fullname;
}
void CL_ImageProviderFactory::save(
	CL_PixelBuffer buffer,
	const CL_String &filename,
	CL_VirtualDirectory &directory,
	const CL_String &type_
	)
{
	CL_String type = type_;

	if (type.empty())
		type = CL_PathHelp::get_extension(filename, CL_PathHelp::path_type_virtual);
	
	if (types.find(type) == types.end()) throw CL_Exception("Unknown image provider type " + type);
	
	CL_ImageProviderType *factory = types[type];
	factory->save(buffer, filename, directory);
}
Beispiel #15
0
CL_String CL_DomElement::get_text() const
{
	CL_String str;
	if (has_child_nodes() == false)
		return str;

	CL_DomNode cur = get_first_child();
	while (!cur.is_null())
	{
		if (cur.is_text() || cur.is_cdata_section())
			str.append(cur.get_node_value());
		if (cur.is_element())
			str.append(cur.to_element().get_text());
		cur = cur.get_next_sibling();
	}
	return str;
}
Beispiel #16
0
bool CL_Directory::set_current(const CL_String &dir_name)
{
#ifdef WIN32
	return SetCurrentDirectory(CL_StringHelp::utf8_to_ucs2(dir_name).c_str()) == TRUE;
#else
	return chdir(dir_name.c_str()) == 0;
#endif
}
Beispiel #17
0
CL_String CL_PathHelp::get_extension(
	const CL_String &fullname,
	PathType path_type)
{
	CL_String filename = get_filename(fullname, path_type);
	CL_String::size_type pos = filename.find_last_of('.');
	if (pos == CL_String::npos)
		return CL_String();
#ifndef WIN32
	// Files beginning with a dot is not a filename extension in Unix.
	// This is different from Windows where it is considered the extension.
	if (path_type == path_type_file && pos == 0)
		return CL_String();
#endif
	if (path_type == path_type_virtual && pos == 0)
		return CL_String();
	return filename.substr(pos + 1);
}
Beispiel #18
0
long CL_TimeOfDay::ParseAndConvert (const CL_String& s)
{
    CL_String fld[4];
    short hour, min, sec;

    short n;
    if ((n = s.Split (fld, 4, ":")) == 2 || n == 3) {
        hour = (short) fld[0].AsLong ();
        min  = (short) fld[1].AsLong ();
        sec  = (short) fld[2].AsLong ();
    }
    else if (s.Split (fld, 4, ": ") == 3) {
        hour = (short) fld[0].AsLong ();
        min  = (short) fld[1].AsLong ();
        sec = 0;
        if (fld[2] == "pm")
            hour += 12;
    }
    else {
        // Assume that it's either four or six digits, and try to parse it.
        for (short i = 0; i < s.Size(); i++) {
            if (s[i] > '9' || s[i] < '0') {
                return -1;
            }
        }
        hour = (s[0]-'0')*10 + s[1]-'0';
        min  = (s[2]-'0')*10 + s[3]-'0';
        if (s.Size() == 6) {
            sec  = (s[4]-'0')*10 + s[5]-'0';
        }
        else
            sec = 0;
    }
    if (! (hour >= 0 && hour < 24) ) {
        return -1;
    }
    if (! (min >= 0 && min < 60) ) {
        return -1;
    }
    if (! (sec >= 0 && sec < 60) ) {
        return -1;
    }
    return (hour * 3600L + min * 60 + sec);
}    
CL_ResourceData_CollisionOutline::CL_ResourceData_CollisionOutline(CL_Resource &resource)
{
	CL_String filename = resource.get_element().get_attribute("file");
	int alpha_limit = CL_StringHelp::text_to_int( (resource.get_element().get_attribute("alpha_value", "128")));
	CL_String accuracy_str = resource.get_element().get_attribute("accuracy", "medium");
	CL_OutlineAccuracy accuracy;

	if(accuracy_str == "high")
		accuracy = accuracy_high;
	else if(accuracy_str == "medium")
		accuracy = accuracy_medium;
	else if(accuracy_str == "low")
		accuracy = accuracy_low;
	else if(accuracy_str == "poor")
		accuracy = accuracy_poor;
    else
		accuracy = accuracy_raw;

	CL_CollisionOutline_Generic *outline;

	if (filename.length() >= 3 && filename.substr(filename.length()-3, 3) == "out" )
	{
		outline = new CL_CollisionOutline_Generic(
			new CL_OutlineProviderFile(filename, resource.get_manager().get_directory(resource)), accuracy_raw);
	}
	else
	{
		CL_PixelBuffer pbuf = CL_ImageProviderFactory::load(filename, resource.get_manager().get_directory(resource), "");
		outline = new CL_CollisionOutline_Generic(
			new CL_OutlineProviderBitmap(pbuf, alpha_limit), accuracy );
	}

	CL_CollisionOutline *collision_outline_tmp = 
		new CL_CollisionOutline(outline->contours, outline->width, outline->height);
	collision_outline = *collision_outline_tmp;

	delete collision_outline_tmp;

	collision_outline.calculate_radius();
	
	delete outline;
}
Beispiel #20
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);
	}
}
Beispiel #21
0
void RaceScene::initializeOnline(const CL_String &p_hostname, int p_port)
{
	G_ASSERT(p_hostname.length() > 0);
	G_ASSERT(p_port > 0 && p_port <= 0xFFFF);

	if (!m_initialized) {
		m_logic = new Race::OnlineRaceLogic(p_hostname, p_port);
		initCommon();
	}

}
void CL_SpanLayout_Impl::add_text(const CL_String &more_text, const CL_Font &font, const CL_Colorf &color, int id)
{
	SpanObject object;
	object.type = object_text;
	object.start = text.length();
	object.end = object.start + more_text.length();
	object.font = font;
	object.color = color;
	object.id = id;
	objects.push_back(object);
	text += more_text;
}
Beispiel #23
0
CL_String CL_PathHelp::get_filename(
	const CL_String &fullname,
	PathType path_type)
{
	if (path_type == path_type_file)
	{
		CL_String::size_type pos = fullname.find_last_of("/\\");
		if (pos == CL_String::npos)
		{
#ifdef WIN32
			if (fullname.length() >= 2 && fullname[1] == ':')
				return fullname.substr(2);
#endif
			return fullname;
		}
		return fullname.substr(pos+1);
	}
	else
	{
		CL_String::size_type pos = fullname.find_last_of('/');
		if (pos == CL_String::npos)
			return fullname;
		return fullname.substr(pos+1);
	}
}
CL_String CL_CSSLayoutNode_Impl::escape_text(CL_String text)
{
	while (true)
	{
		CL_String::size_type pos = text.find('\r');
		if (pos == CL_String::npos)
			break;
		text.replace(pos, 1, "\\r");
	}
	while (true)
	{
		CL_String::size_type pos = text.find('\n');
		if (pos == CL_String::npos)
			break;
		text.replace(pos, 1, "\\n");
	}
	while (true)
	{
		CL_String::size_type pos = text.find('\t');
		if (pos == CL_String::npos)
			break;
		text.replace(pos, 1, "\\t");
	}
	return text;
}
Beispiel #25
0
std::vector<CL_String> CL_PathHelp::split_basepath(
	const CL_String &fullname,
	PathType path_type)
{
	CL_String basepath = get_basepath(fullname, path_type);
	std::vector<CL_String> result;
	if (path_type == path_type_file)
	{
		CL_String::size_type start_pos = 0, end_pos = 0;
		while (true)
		{
			end_pos = basepath.find_first_of("/\\", start_pos);

			if (end_pos == CL_String::npos)
			{
				if (start_pos != basepath.length())
					result.push_back(basepath.substr(start_pos));
				break;
			}

			result.push_back(basepath.substr(start_pos, end_pos - start_pos));
			start_pos = end_pos + 1;
		}
	}
	else
	{
		CL_String::size_type start_pos = 0, end_pos = 0;
		while (true)
		{
			end_pos = basepath.find_first_of('/', start_pos);
			if (end_pos == CL_String::npos)
			{
				if (start_pos != basepath.length())
					result.push_back(basepath.substr(start_pos));
				break;
			}

			result.push_back(basepath.substr(start_pos, end_pos - start_pos));
			start_pos = end_pos + 1;
		}
	}
	return result;
}
Beispiel #26
0
CL_String CL_PathHelp::get_basepath(
	const CL_String &fullname,
	PathType path_type)
{
	CL_String path = get_fullpath(fullname, path_type);
#ifdef WIN32
	if (path_type == path_type_file && path.length() >= 2)
	{
		if (path[1] == ':')
			return path.substr(2);

		if (path[0] == '\\' && path[1] == '\\')
		{
			CL_String::size_type pos = path.find_first_of("/\\", 2);
			if (pos == CL_String::npos)
				return CL_String();
			else
				return path.substr(pos);
		}
	}
#endif
	return path;
}
CL_IODevice CL_VirtualFileSystem::open_file(const CL_String &filename_rel,
	CL_File::OpenMode mode,
	unsigned int access,
	unsigned int share,
	unsigned int flags) const
{
	CL_String filename = CL_PathHelp::make_absolute(
		"/",
		filename_rel,
		CL_PathHelp::path_type_virtual);

	// First see if its a file for one of our mount points:
	int index, size;
	size = (int) impl->mounts.size();
	for (index = 0; index < size; index++)
	{
		if (impl->mounts[index].first == filename.substr(0, impl->mounts[index].first.length()))
		{
			return impl->mounts[index].second.open_file( filename.substr(impl->mounts[index].first.length(), filename.length()));
		}
	}

	// Try open locally, if we got a file provider attached
	if (impl->provider)
	{
		return impl->provider->open_file(
			CL_PathHelp::make_relative(
				"/",
				filename,
				CL_PathHelp::path_type_virtual), mode, access, share, flags);
	}
	else
	{
		throw CL_Exception(cl_format("Unable to open file: %1", filename));
	}
}
Beispiel #28
0
void RankingFindQueryImpl::submit()
{
	G_ASSERT(!m_playerId.empty() && "player id not set");

	m_parent->start();

	Game &game = Game::getInstance();
	Client &client = game.getNetworkConnection();
	RankingClient &rankingClient = client.getRankingClient();

	m_recvSlot =
			rankingClient.sig_entriesReceived.connect(
					this, &RankingFindQueryImpl::onEntriesReceived);

	m_token = rankingClient.findEntry(m_playerId);
}
Beispiel #29
0
void CL_TimeOfDay::operator= (const CL_String& s)
{
    if (!PrepareToChange())
        return;
    if (s.Size() == 0) {
        _numSecs = 0;
        Notify ();
        return;
    }
    long l = ParseAndConvert (s);
    if (l < 0) {
        // CL_Error::Warning ("CL_TimeOfDay::op= (const CL_String&): "
        //                    "Invalid form '%s'", (char*) s);
        _numSecs = 0;
    }
    else
        _numSecs = l;
    Notify ();
}
Beispiel #30
0
bool CL_Directory::create(const CL_String &dir_name)
{
	if (dir_name.empty())
		return false;

	// this will be a full path
	CL_String full_path; // calculate the full path

	#ifdef WIN32
		DWORD buff_len = ::GetFullPathName(CL_StringHelp::utf8_to_ucs2(dir_name).c_str(), 0, 0, 0);

		if (buff_len == 0)
			// can't calculate, return bad status
			return false;
		else
		{
			std::vector<TCHAR> buffer_vector;
			buffer_vector.resize(buff_len + 1);
			TCHAR *buffer = &(buffer_vector[0]);
			TCHAR *buffer_ptr_to_filename = 0;
			// Obtaining full path
			buff_len = ::GetFullPathName(CL_StringHelp::utf8_to_ucs2(dir_name).c_str(), buff_len, buffer, &buffer_ptr_to_filename);
			if (buff_len == 0)
				// can't obtain full path, return bad status
				return false;
			else
				// ok, save it
				full_path = buffer;
		}
	#else
		// TODO: add here Linux version of GetFullPathName
		full_path = dir_name;
	#endif

#ifdef WIN32
		return ::CreateDirectory(CL_StringHelp::utf8_to_ucs2(full_path).c_str(), NULL) != 0;
#else
		return ::mkdir(full_path.c_str(), 0755) == 0;
#endif
}