Пример #1
0
void Sound::Load_Stream(const String& fileName) 
{
	if(fileName.Count()) return;

	name = fileName;

	FMOD_RESULT s_result = FMOD_OK;

	if(sound != nullptr)
	{
		s_result = FMOD_Sound_Release(sound);
		check_error(s_result);
	}

    s_result = FMOD_System_CreateSound(fmodSystem, fileName.Data(),
		FMOD_SOFTWARE | FMOD_UNICODE | FMOD_CREATESTREAM, nullptr, &sound);
	check_error(s_result);

	switch(type)
	{
		case MUSIC:
			FMOD_Sound_SetSoundGroup(sound, musicGroup);
			break;

		case SOUND_EFFECT:
			FMOD_Sound_SetSoundGroup(sound, noiseGroup);
			break;
	}
}
Пример #2
0
std::vector<Tigre::String> Tigre::String::explode(String delimitador) {
    std::vector<Tigre::String> result;
    int last_push = 0;

    for (int i=0; i < this->value.size() && i+delimitador.Count()-1 < this->value.size(); i++) {
        if(this->value.substr(i, delimitador.Count()) == delimitador){
            result.push_back(this->value.substr(last_push, i-last_push));
            last_push = i+delimitador.Count();
        }
    }

    if(last_push < this->value.size()){
        result.push_back(this->value.substr(last_push, this->value.size()-last_push));
    }

    return result;
}
Пример #3
0
void Tigre::String::replace(String valor_a, String valor_b) {
    String result = "";

    std::vector<Tigre::String> peaces = this->explode(valor_a);

    for(int i=0; i < peaces.size(); i++){
        if(i+1 < peaces.size()) {
            result += peaces[i] + valor_b;
        } else {
            if(this->value.substr(this->value.size()-valor_a.Count(), valor_a.Count() ) != valor_a){
                result += peaces[i];
            } else {
                result += peaces[i] + valor_b;
            }
        }
    }
    this->value = result.value;
}
Пример #4
0
/// Finds appropriate CSV delimiter in given string. Usually highest occurrance of the following ('\t;,')
char FindCSVDelimiter(String csvString)
{
	String tokens(";,\t");
	int maxDelim = 0, maxCount = 0;
	for (int i = 0; i < tokens.Length(); ++i)
	{
		char delim = tokens.CharAt(i);
		int count = csvString.Count(delim);
		if (count > maxCount)
		{
			maxCount = count;
			maxDelim = delim;
		}
	}
	return maxDelim;
}
Пример #5
0
	void Execute()
	{
		if (CurrentVote.Voting)
		{
			Player->PrintToClient(PRINT_HIGH, "Vote already in progress.");
			return;
		}

		if (ArgCount() != 3)
		{
			Player->PrintToClient (PRINT_HIGH, "Use \"players\" to check the player IDs for kick-by-ID. Syntax:\n  vote ban/kick n:id\n  vote ban/kick p:playerName\n\n  Example: vote ban/kick n:8\n  Example: vote ban/kick p:Paril\n");
			return;
		}

		String str = ArgGets(2);

		if (str.Count() < 3 ||
			str[1] != ':' ||
			(str[0] != 'p' && str[0] != 'n'))
		{
			Player->PrintToClient (PRINT_HIGH, "Syntax error. Type \"vote ban\" or \"vote kick\" to see syntax.\n");
			return;
		}

		int playerToKick = -1;

		if (str[0] == 'p')
		{
			String playerName = str.Substring(2).ToLower();

			if (playerName.IsNullOrEmpty())	
			{
				Player->PrintToClient (PRINT_HIGH, "Syntax error. Type \"vote ban\" or \"vote kick\" to see syntax.\n");
				return;
			}

			for (int i = 1; i <= Game.MaxClients; ++i)
			{
				if (entity_cast<CPlayerEntity>(Game.Entities[i].Entity)->Client.Persistent.Name.Clone().ToLower() == playerName)
				{
					if (playerToKick != -1)
					{
						Player->PrintToClient (PRINT_HIGH, "Multiple players exist by that name. Type \"vote ban\" or \"vote kick\" to see how to ban by player number instead.\n");
						return;
					}

					playerToKick = i;
				}
			}

			if (playerToKick == -1)
			{
				Player->PrintToClient (PRINT_HIGH, "Player does not exist.\n");
				return;
			}
		}
		else
		{
			String playerNum = str.Substring(2);

			for (size_t i = 0; i < playerNum.Count(); ++i)
			{
				if (playerNum[i] < '0' || playerNum[i] > '9')
				{
					Player->PrintToClient (PRINT_HIGH, "Invalid player number.\n");
					return;
				}
			}

			playerToKick = atoi(str.Substring(2).CString());

			if (playerToKick <= 0 || playerToKick > Game.MaxClients)
			{
				Player->PrintToClient (PRINT_HIGH, "Invalid player number.\n");
				return;
			}
		}

		CVoteKickBanData *voteData = QNew(TAG_GENERIC) CVoteKickBanData(ban, playerToKick);
		CurrentVote.StartVote(voteType, voteData, Player->Client.Persistent.Name);
	}
Пример #6
0
	SharedPtr<Resource> LevelLoader::Load(Stream& source)
	{
		String line;
		List<String> list;

		SharedPtr<TextReader> reader(new TextReader(&source));

		line = reader->ReadLine();
		list = line.Split(' ');
		if (list.Count() < 2)
			return SharedPtr<Resource>::EMPTY;

		const Vector2i size(list[0].ToInt(), list[1].ToInt());
		auto data = _context->NewObject<Level>();
		auto cache = _context->GetModule<ResourceCache>();

		List<SharedPtr<Model>> prefabs;
		prefabs.Add(SharedPtr<Model>(cache->Load<Model>("Data/Models/floor.obj")));
		prefabs.Add(SharedPtr<Model>(cache->Load<Model>("Data/Models/wall.obj")));

		bool** map = new bool*[size.x];
		for (int x = 0; x < size.x; x++)
			map[x] = new bool[size.y];

		for (int y = 0; y < size.y; y++)
		{
			line = reader->ReadLine();
			if (line.Count() != size.x)
			{
				for (int x = 0; x < size.x; x++)
					map[x][y] = false;

				continue;
			}

			for (int x = 0; x < size.x; x++)
				map[x][y] = line[x] == '#';
		}

		for (int x = 0; x < size.x; x++)
		for (int y = 0; y < size.y; y++)
		{
			const Vector2i index(x / LevelChunk::SIDE, y / LevelChunk::SIDE);
			const Vector2i pos(x - index.x * LevelChunk::SIDE, y - index.y * LevelChunk::SIDE);
			auto chunk = data->GetChunk(index);

			auto& cell = chunk->GetCell(pos);
			cell.Clear();

			if (map[x][y])
				continue;

			cell.SetFloor(0);

			if (x > 0 && map[x - 1][y])
				cell.SetWall(DIR_WEST, 1);
			if (x + 1 < size.x && map[x + 1][y])
				cell.SetWall(DIR_EAST, 1);
			if (y > 0 && map[x][y - 1])
				cell.SetWall(DIR_NORTH, 1);
			if (y + 1 < size.y && map[x][y + 1])
				cell.SetWall(DIR_SOUTH, 1);
		}

		for (int x = 0; x < size.x; x++)
			delete[] map[x];
		delete[] map;

		data->SetPrefabs(prefabs);
		return DynamicCast<Resource>(data);
	}