Пример #1
0
	void PropertyChangeAction::SetProperties(Vector<DataNode>& values)
	{
		Vector<SceneEditableObject*> objects = objectsIds.Select<SceneEditableObject*>([](SceneUID id) { 
			return o2Scene.GetEditableObjectByID(id); });

		const Type* componentType = nullptr;
		String finalPropertyPath = propertyPath;
		if (propertyPath.StartsWith("component:"))
		{
			int c = ((String)"component:").Length();

			String typeName = propertyPath.SubStr(c, propertyPath.Find('/', c));

			c += typeName.Length() + 1;
			finalPropertyPath.Erase(0, c);

			componentType = o2Reflection.GetType(typeName);
		}

		int i = 0;
		for (auto object : objects)
		{
			if (!object)
			{
				continue;
				i++;
			}

			FieldInfo* fi = nullptr;
			void* ptr = nullptr;

			if (componentType)
			{
				if (Actor* actor = dynamic_cast<Actor*>(object))
				{
					Component* component = actor->GetComponent(componentType);
					if (component)
						ptr = component->GetType().GetFieldPtr(component, finalPropertyPath, fi);
				}
			}
			else
			{
				auto objectType = dynamic_cast<const ObjectType*>(&object->GetType());
				if (objectType)
				{
					void* realTypeObject = objectType->DynamicCastFromIObject(dynamic_cast<IObject*>(object));
					ptr = objectType->GetFieldPtr(realTypeObject, finalPropertyPath, fi);
				}
			}

			if (fi && ptr)
				fi->Deserialize(ptr, values[i]);

			object->OnChanged();

			i++;
		}
	}
Пример #2
0
// TODO CURRENT
int Labyrinth::LoadMap(String filename)
{
    ResourceCache *cache = GetSubsystem<ResourceCache>();
    
    File *file = new File(context_, filename, Urho3D::FILE_READ);
    String sMap = file->ReadString();
    String n;
    
    
    //Vector<String> sMap.Split('\n');
    
    // TODO
    /*int player01Spawn, player02Spawn, player03Spawn, player04Spawn;
    
    int s = sMap.Find("Player01Spawn=");
    int e = sMap.Find("Map");
    
    
     coordinates;
    coordinates = sMap.Split(',');
    for (int ; i < sMap.Capacity(); i++)
    {
	if (sMap[i] == 'j');
    }
    
    sMap.Find("Player02Spawn=");
    sMap.Find("Player03Spawn=");
    sMap.Find("Player04Spawn=");*/

    unsigned int s = sMap.Find("Map=");
    sMap.Erase(0, s + 4);


    /*for (int i = 0; i < sMap.Capacity(); i++)
    {
	char c = sMap[i];
	if (isdigit(c))
	{
	        n += c;
	}
	else if(c == ' ')
	{
	    StringToNumbersVector(n);
	}
    }*/
    map_ = StringToNumbersVector(sMap);
}
Пример #3
0
void ExtractValue (String& code, String& out, const String& var, const char* def = 0)
{
	uint start = code.Find(var);
	uint length = code.GetLength();

	if (start < length)
	{
		uint offset = start + var.GetLength();

		// Skip up to the equals sign
		while (offset < length && code[offset] != '=') ++offset;

		if (offset < length)
		{
			++offset;
			uint end = offset;
			while (end < length && code[end] != ';') ++end;

			if (end < length)
			{
				// Get the value of this variable
				code.GetTrimmed(out, offset, end);

				// Skip the ';' character
				++end;

				// Trim the line so it can be removed cleanly
				//while (start > 0 && code[start-1] == '\t') --start;
				while (end < length && code[end] < 33) ++end;

				// Erase this segment
				code.Erase(start, end);
				return;
			}
		}
	}
	out = def;
}
Пример #4
0
bool CHttpClient::ParseHeaders(String& strBuffer, int& iBufferSize)
{
	// Find the header size, testing code, but should work
	mg_request_info info;
	
	char* buf = new char[iBufferSize];
	memcpy(buf, strBuffer.C_String(), iBufferSize);
	parse_http_response(buf, strBuffer.GetLength(), &info);
	
	String buf_header;
	int iHeaderSize = 0;
	for(int i = 0; i < info.num_headers; ++i)
	{
		buf_header.AppendF("%s: %s\r\n", info.http_headers[i].name, info.http_headers[i].value);
	}

	iHeaderSize = buf_header.GetLength();
	iHeaderSize += (info.request_method != NULL ? strlen(info.request_method) : 0) + (info.uri != NULL ? strlen(info.uri) : 0) + (info.http_version != NULL ? strlen(info.http_version) : 0) + strlen("\r\n\r\n\r\n");
	iBufferSize -= iHeaderSize;
	strBuffer.Erase(0, iHeaderSize);
	m_headerMap["HeaderSize"] = iHeaderSize;


	// ADAMIX/JENKSTA: commented out this code because doesn't work properly. Are we really need to parse headers?

	/*// Ignore all initial whitespace
	unsigned int uiWhiteSpace = 0;

	for(unsigned int i = 0; i < (unsigned int)iBufferSize; i++)
	{
		// Is this whitespace?
		if(strBuffer[i] == ' ')
		{
			// Increment the whitespace amount
			uiWhiteSpace++;
			continue;
		}

		// Finished
		break;
	}

	// Remove whitespace
	if(uiWhiteSpace > 0)
		strBuffer.Erase(0, uiWhiteSpace);

	// Ignore the version, status code and status message
	// TODO: Use this information?
	// Will be in format 'HTTP/1.0 200 OK\r\n'
	unsigned int uiIgnore = strBuffer.Find("\r\n");

	if(uiIgnore == String::nPos)
		return false;

	strBuffer.Erase(0, (uiIgnore + 2));
	iBufferSize -= (uiIgnore + 2);

	// Find all headers
	unsigned int uiContentLength = String::nPos;
	unsigned int uiNameSplit;
	unsigned int uiValueSplit;

	while((uiNameSplit = strBuffer.Find(": ")) != String::nPos)
	{
		// Do we have a content length?
		if(uiContentLength != String::nPos)
		{
			// Get the content start
			unsigned int uiContentStart = (iBufferSize - uiContentLength);

			// Is the find over the content start?
			if(uiNameSplit >= uiContentStart)
				break;
		}

		// Find the value end
		uiValueSplit = strBuffer.Find("\r\n");

		// Did we not find a value end?
		if(uiValueSplit == String::nPos)
			return false;

		// Get the header name
		String strName = strBuffer.SubStr(0, uiNameSplit);

		// If this is an accept-ranges header get the value from the next header
		// jenksta: not sure if this is right, but this is how it works with 'accept-ranges: bytes'
		// in mongoose
		if(!strName.ICompare("accept-ranges"))
		{
			// Find the value end
			uiValueSplit = strBuffer.Find("\r\n", (uiValueSplit + 2));

			// Did we not find a value end?
			if(uiValueSplit == String::nPos)
				return false;
		}

		// Get the header value
		String strValue = strBuffer.SubStr((uiNameSplit + 2), (uiValueSplit - (uiNameSplit + 2)));

		// Add the header to the header map
		m_headerMap[strName] = strValue;

		// Erase the header from the buffer
		strBuffer.Erase(0, (uiValueSplit + 2));
		iBufferSize -= (uiValueSplit + 2);

		// Is this the content length header?
		if(!strName.ICompare("content-length"))
		{
			// Set the content length
			uiContentLength = strValue.ToInteger();
		}
	}

	// Did we not get any headers?
	if(m_headerMap.empty())
		return false;
	*/
	// Success
	return true;
}
Пример #5
0
void CommandLineData::Set(const wchar_t* cmdLine)
{
	String cmd = cmdLine;
	
	// Check length
	if(!cmd.GetLength())
		return;

	// Trim spaces
	cmd.TrimAll();

	// Check if entire string was just spaces
	if(!cmd.GetLength())
		return;

	// Quote monitoring
	bool quote = true;

	// Check for unmached quotes
	for(unsigned long i = 0; i < cmd.GetLength(); ++i)
	{
		if(cmd[i] == L'"')
			quote = !quote;
	}

	// Check if ok
	if(!quote)
		return;

	// Clear old vars
	Clear();

	quote = false;

	String varName;
	String varValue;

	bool value = false;

	// Split the string
	while(cmd.GetLength())
	{
		if(cmd[0] == L'"')
		{
			quote = !quote;

			cmd.Erase(0);
		}
		else if(cmd[0] == L'=' && !value)
		{
			value = true;

			cmd.Erase(0);
		}
		else if(iswspace(cmd[0]))
		{
			if(quote)
			{
				if(value)
					varValue += cmd[0];
				else
					varName += cmd[0];
			}
			else if(cmd.GetLength())
			{
				// Add var
				value = false;

				AddVar(varName,varValue);

				varName.Erase();
				varValue.Erase();
			}

			cmd.Erase(0);
		}
		else
		{
			if(value)
				varValue += cmd[0];
			else
				varName += cmd[0];

			cmd.Erase(0);
		}
	}

	if(varName.GetLength())
	{
		// Add var
		value = false;

		AddVar(varName,varValue);

		varName.Erase();
		varValue.Erase();
	}
}
Пример #6
0
ROCKETCORE_API void EMPStringTests()
{
	std::string ss = "test";
	String es = "test";

	es = "hello";
	es.Resize(100);
	es.Erase(4);
	es.Erase(2,100);
	es += "y";

	String sub1 = es.Replace("lo", "l");
	sub1 = sub1.Replace("h", "!");

	EMPTime start;

	{
		// Create a few free buffers
		String tempstring("buffer");
		String tempstring1("buffer1");
		String tempstring2("buffer2");
	}	

	start = SYSClock::GetRealTime();
	for (int i = 0; i < 100000; i++)
	{
		std::string str("test");	
	}
	Log::Message(LC_CORE, Log::LT_ALWAYS, "SS Assign Short: %f", SYSClock::GetRealTime() - start);
	
	start = SYSClock::GetRealTime();	
	for (int i = 0; i < 100000; i++)
	{
		String str("test");
	}
	Log::Message(LC_CORE, Log::LT_ALWAYS, "ES Assign Short: %f", SYSClock::GetRealTime() - start);

	start = SYSClock::GetRealTime();
	for (int i = 0; i < 100000; i++)
	{
		std::string str("test this really long string that won't fit in a local buffer");	
	}
	Log::Message(LC_CORE, Log::LT_ALWAYS, "SS Assign Long: %f", SYSClock::GetRealTime() - start);
	
	start = SYSClock::GetRealTime();	
	for (int i = 0; i < 100000; i++)
	{
		String str("test this really long string that won't fit in a local buffer");
	}
	Log::Message(LC_CORE, Log::LT_ALWAYS, "ES Assign Long: %f", SYSClock::GetRealTime() - start);

	start = SYSClock::GetRealTime();
	for (int i = 0; i < 100000; i++)
	{
		if (ss == "hello")
		{
			int bob = 10;
		}
	}
	Log::Message(LC_CORE, Log::LT_ALWAYS, "SS Compare: %f (char*)", SYSClock::GetRealTime() - start);

	std::string compare = "hello";
	start = SYSClock::GetRealTime();
	for (int i = 0; i < 100000; i++)
	{
		if (ss == compare)
		{
			int bob = 10;
		}
	}
	Log::Message(LC_CORE, Log::LT_ALWAYS, "SS Compare: %f (std::string)", SYSClock::GetRealTime() - start);

	start = SYSClock::GetRealTime();
	for (int i = 0; i < 100000; i++)
	{
		if (es == "hello")
		{
			int bob = 10;
		}
	}
	Log::Message(LC_CORE, Log::LT_ALWAYS, "ES Compare: %f (char*)", SYSClock::GetRealTime() - start);
	
	String oes = es;
	start = SYSClock::GetRealTime();
	for (int i = 0; i < 100000; i++)
	{
		if (es == oes)
		{
			int bob = 10;
		}
	}
	Log::Message(LC_CORE, Log::LT_ALWAYS, "ES Compare: %f (String)", SYSClock::GetRealTime() - start);

	start = SYSClock::GetRealTime();
	std::string ss_concat = "hello";
	for (int i = 0; i < 100000; i++)
	{
		ss_concat += "y";
	}
	Log::Message(LC_CORE, Log::LT_ALWAYS, "SS +=: %f", SYSClock::GetRealTime() - start);

	String es_concat = "hello";
	start = SYSClock::GetRealTime();
	for (int i = 0; i < 100000; i++)
	{
		if (i == 1016)
		{
			int bob = 10;
		}
		es_concat += "y";
	}
	Log::Message(LC_CORE, Log::LT_ALWAYS, "ES +=: %f", SYSClock::GetRealTime() - start);

	const char* x1 = "bob";
	String s;
	String t;
	String u;
	s = "hello";
	t = "hell";
	u = "hello";
	if (s == t)
	{
		int bob = 10;
	}
	if (s == u)
	{
		int bob = 10;
	}

	t = s + u;
	if (t == "hellohello")
	{
		int bob = 10;
	}
	if (t == "x")
	{
		int bob = 10;
	}

	t += u;


	size_t x = s.Find("e");
	size_t y = s.Find("z");
	
	String sub = t.Replace("lo", "l");
	sub = sub.Replace("h", "!");

	sub.FormatString(128, "%s", "hello");
	int bob = 10;
}