Example #1
0
   bool
   StringParser::WildcardMatchNoCase(const String &sWildcard, const String &sString)
   {
      String sLowerWild = sWildcard;
      String sLowerStr = sString;

      sLowerWild.ToLower();
      sLowerStr.ToLower();

      return WildcardMatch(sLowerWild, sLowerStr);
   }
Example #2
0
TextureUnit ParseTextureUnitName(String name)
{
    name = name.ToLower().Trimmed();

    TextureUnit unit = (TextureUnit)GetStringListIndex(name.CString(), textureUnitNames, MAX_TEXTURE_UNITS);
    if (unit == MAX_TEXTURE_UNITS)
    {
        // Check also for shorthand names
        if (name == "diff")
            unit = TU_DIFFUSE;
        else if (name == "albedo")
            unit = TU_DIFFUSE;
        else if (name == "norm")
            unit = TU_NORMAL;
        else if (name == "spec")
            unit = TU_SPECULAR;
        else if (name == "env")
            unit = TU_ENVIRONMENT;
        // Finally check for specifying the texture unit directly as a number
        else if (name.Length() < 3)
            unit = (TextureUnit)Clamp(ToInt(name), 0, MAX_TEXTURE_UNITS - 1);
    }

    if (unit == MAX_TEXTURE_UNITS)
        LOGERROR("Unknown texture unit name " + name);

    return unit;
}
Example #3
0
unsigned Technique::GetPassIndex(const String& passName)
{
    // Initialize built-in pass indices on first call
    if (passIndices.Empty())
    {
        basePassIndex = passIndices["base"] = 0;
        alphaPassIndex = passIndices["alpha"] = 1;
        materialPassIndex = passIndices["material"] = 2;
        deferredPassIndex = passIndices["deferred"] = 3;
        lightPassIndex = passIndices["light"] = 4;
        litBasePassIndex = passIndices["litbase"] = 5;
        litAlphaPassIndex = passIndices["litalpha"] = 6;
        shadowPassIndex = passIndices["shadow"] = 7;
    }

    String nameLower = passName.ToLower();
    HashMap<String, unsigned>::Iterator i = passIndices.Find(nameLower);
    if (i != passIndices.End())
        return i->second_;
    else
    {
        unsigned newPassIndex = passIndices.Size();
        passIndices[nameLower] = newPassIndex;
        return newPassIndex;
    }
}
Example #4
0
void FilterUtility::CheckPermission(const ApiUser::Ptr& user, const String& permission, Expression **permissionFilter)
{
	if (permissionFilter)
		*permissionFilter = NULL;

	if (permission.IsEmpty())
		return;

	bool foundPermission = false;
	String requiredPermission = permission.ToLower();

	Array::Ptr permissions = user->GetPermissions();
	if (permissions) {
		ObjectLock olock(permissions);
		BOOST_FOREACH(const Value& item, permissions) {
			String permission;
			Function::Ptr filter;
			if (item.IsObjectType<Dictionary>()) {
				Dictionary::Ptr dict = item;
				permission = dict->Get("permission");
				filter = dict->Get("filter");
			} else
				permission = item;

			permission = permission.ToLower();

			if (!Utility::Match(permission, requiredPermission))
				continue;

			foundPermission = true;

			if (filter && permissionFilter) {
				std::vector<Expression *> args;
				args.push_back(new GetScopeExpression(ScopeLocal));
				FunctionCallExpression *fexpr = new FunctionCallExpression(new IndexerExpression(MakeLiteral(filter), MakeLiteral("call")), args);

				if (!*permissionFilter)
					*permissionFilter = fexpr;
				else
					*permissionFilter = new LogicalOrExpression(*permissionFilter, fexpr);
			}
		}
	}
Example #5
0
void Technique::RemovePass(const String& name)
{
    HashMap<String, unsigned>::ConstIterator i = passIndices.Find(name.ToLower());
    if (i == passIndices.End())
        return;
    else if (i->second_ < passes_.Size() && passes_[i->second_].Get())
    {
        passes_[i->second_].Reset();
        SetMemoryUse((unsigned)(sizeof(Technique) + GetNumPasses() * sizeof(Pass)));
    }
}
Example #6
0
   bool 
   TLD::IsTLD(const String &sName)
   {
      String sTmp = sName;

      sTmp.ToLower();

      if (tld_.find(sName) != tld_.end())
         return true;
      else
         return false;
   }
Example #7
0
Pass::Pass(const String& name) :
    blendMode_(BLEND_REPLACE),
    cullMode_(MAX_CULLMODES),
    depthTestMode_(CMP_LESSEQUAL),
    lightingMode_(LIGHTING_UNLIT),
    shadersLoadedFrameNumber_(0),
    depthWrite_(true),
    isDesktop_(false)
{
    name_ = name.ToLower();
    index_ = Technique::GetPassIndex(name_);

    // Guess default lighting mode from pass name
    if (index_ == Technique::basePassIndex || index_ == Technique::alphaPassIndex || index_ == Technique::materialPassIndex ||
        index_ == Technique::deferredPassIndex)
        lightingMode_ = LIGHTING_PERVERTEX;
    else if (index_ == Technique::lightPassIndex || index_ == Technique::litBasePassIndex || index_ == Technique::litAlphaPassIndex)
        lightingMode_ = LIGHTING_PERPIXEL;
}
Example #8
0
   bool 
   TLD::GetDomainNameFromHost(String &sHost, bool &bIsIPAddress)
   {
      bIsIPAddress = false;

      // Start at the end.
      std::vector<String> vecParts = StringParser::SplitString(sHost, ".");

      int iParts = vecParts.size();

      if (iParts < 2)
         return false;

      // Check if it's an IP address
      if (iParts == 4 && StringParser::IsValidIPAddress(sHost))
      {
         sHost = vecParts[3] + "." + vecParts[2] + "." + vecParts[1] + "." + vecParts[0];
         bIsIPAddress = true;
         return true;
      }

      // It's not an IP address.
      String sTwoLast = vecParts[iParts-2] + "." + vecParts[iParts-1];
      sTwoLast.ToLower();

      if (!IsTLD(sTwoLast))
         sHost = sTwoLast;
      else
      {
         if (iParts == 2)
            return false;

         sHost = vecParts[iParts-3] + "." + vecParts[iParts-2] + "." + vecParts[iParts-1];
      }

      return true;      
   }
void AssetRefListener::HandleAssetRefChange(AssetAPI *assetApi, String assetRef, const String& assetType)
{
    // Disconnect from any previous transfer we might be listening to
    if (!currentTransfer.Expired())
    {
        IAssetTransfer* current = currentTransfer.Get();
        current->Succeeded.Disconnect(this, &AssetRefListener::OnTransferSucceeded);
        current->Failed.Disconnect(this, &AssetRefListener::OnTransferFailed);
        currentTransfer.Reset();
    }
    
    assert(assetApi);

    // Store AssetAPI ptr for later signal hooking.
    if (!myAssetAPI)
        myAssetAPI = assetApi;

    // If the ref is empty, don't go any further as it will just trigger the LogWarning below.
    assetRef = assetRef.Trimmed();
    if (assetRef.Empty())
    {
        asset = AssetPtr();
        return;
    }
    currentWaitingRef = "";

    // Resolve the protocol for generated:// assets. These assets are never meant to be
    // requested from AssetAPI, they cannot be fetched from anywhere. They can only be either
    // loaded or we must wait for something to load/create them.
    String protocolPart = "";
    assetApi->ParseAssetRef(assetRef, &protocolPart);
    if (protocolPart.ToLower() == "generated")
    {
        AssetPtr loadedAsset = assetApi->FindAsset(assetRef);
        if (loadedAsset.Get() && loadedAsset->IsLoaded())
        {
            // Asset is loaded, emit Loaded with 1 msec delay to preserve the logic
            // that HandleAssetRefChange won't emit anything itself as before.
            // Otherwise existing connection can break/be too late after calling this function.
            asset = loadedAsset;
            assetApi->GetFramework()->Frame()->DelayedExecute(0.0f).Connect(this, &AssetRefListener::EmitLoaded);
            return;
        }
        else
        {
            // Wait for it to be created.
            currentWaitingRef = assetRef;
            myAssetAPI->AssetCreated.Connect(this, &AssetRefListener::OnAssetCreated);
        }
    }
    else
    {
        // This is not a generated asset, request normally from asset api.
        AssetTransferPtr transfer = assetApi->RequestAsset(assetRef, assetType);
        if (!transfer)
        {
            LogWarning("AssetRefListener::HandleAssetRefChange: Asset request for asset \"" + assetRef + "\" failed.");
            return;
        }
        currentWaitingRef = assetRef;

        transfer->Succeeded.Connect(this, &AssetRefListener::OnTransferSucceeded);
        transfer->Failed.Connect(this, &AssetRefListener::OnTransferFailed);

        currentTransfer = transfer;
    }
    
    // Disconnect from the old asset's load signal
    if (asset)
        asset->Loaded.Disconnect(this, &AssetRefListener::OnAssetLoaded);
    asset = AssetPtr();
}
Example #10
0
void StartRoom::RoomStart()
{
	std::cout << " " << std::endl;



	String string = " ";
	StartRoom room;

	std::cout << "Welcome to Start Room										type 'help' if you need assistence" << std::endl;
	std::cout << "There is a door infront of you, it seems to be unlocked" << std::endl;
	std::cout << "What will you do" << std::endl;

	while (true)
	{
		string.ReadFromConsole();
		string.ToLower();



		std::cout << std::endl;


		if (string.EqualTo("north") == true)
		{
			room.NextRoom();

		}
		else if (string.EqualTo("south") == true)
		{
			std::cout << "There is a wall in your way" << std::endl;
		}
		else if (string.EqualTo("east") == true)
		{
			std::cout << "There is a wall in your way" << std::endl;
		}
		else if (string.EqualTo("west") == true)
		{
			std::cout << "There is a wall in your way" << std::endl;
		}
		else if (string.EqualTo("look") == true)
		{
			std::cout << "you see and empty room with a door infront of you" << std::endl;
		}
		else if (string.EqualTo("map") == true)
		{
			room.Map(1);
			std::cout << std::endl;
		}
		else if (string.EqualTo("help") == true)
		{
			std::cout << "         Help Menu" << std::endl;
			std::cout << "       --------------" << std::endl;
			std::cout << "     help = Help Menu" << std::endl;
			std::cout << "     look = search the Room" << std::endl;
			std::cout << "      map = Show Map" << std::endl;
			std::cout << " go north = Travel North" << std::endl;
			std::cout << " go south = Travel South" << std::endl;
			std::cout << " go east  = Travel East" << std::endl;
			std::cout << " go west  = Travel West" << std::endl;
			std::cout << " " << std::endl;
		}
		else
			std::cout << "failed" << std::endl;

		system("pause");
		system("cls");
	}



}
Example #11
0
void HttpRequest::AddHeader(const String& key, const String& value)
{
	ASSERT(m_State == HttpRequestStart || m_State == HttpRequestHeaders);
	Headers->Set(key.ToLower(), value);
}
void Run(const Vector<String>& arguments)
{
    if (arguments.Size() < 1)
    {
        ErrorExit(
            "Usage: ShaderCompiler <definitionfile> [outputpath] [options]\n\n"
            "Options:\n"
            "-t<VS|PS>  Compile only vertex or pixel shaders, by default compile both\n"
            "-v<name>   Compile only the shader variation with name\n"
            "-d<define> Add a define. Add SM3 to compile for Shader Model 3\n\n"
            "If output path is not specified, shader binaries will be output into the same\n"
            "directory as the definition file. Specify a wildcard to compile multiple\n"
            "shaders."
        );
    }
    
    String path, file, extension;
    SplitPath(arguments[0], path, file, extension);
    inDir_ = AddTrailingSlash(path);
    if (arguments.Size() > 1 && arguments[1][0] != '-')
        outDir_ = AddTrailingSlash(arguments[1]);
    else
        outDir_ = inDir_;
    
    for (unsigned i = 1; i < arguments.Size(); ++i)
    {
        if (arguments[i][0] == '-' && arguments[i].Length() > 1)
        {
            char option = arguments[i][1];
            String arg = arguments[i].Substring(2);
            
            switch (option)
            {
            case 'd':
                {
                    Vector<String> nameAndValue = arg.Split('=');
                    if (nameAndValue.Size() == 2)
                    {
                        defines_.Push(nameAndValue[0]);
                        defineValues_.Push(nameAndValue[1]);
                        if (nameAndValue[0] == "SM3" && ToInt(nameAndValue[1]) > 0)
                            useSM3_ = true;
                    }
                    else
                    {
                        defines_.Push(arg);
                        defineValues_.Push("1");
                        if (arg == "SM3")
                            useSM3_ = true;
                    }
                }
                break;
                
            case 't':
                if (arg.ToLower() == "vs")
                {
                    compileVS_ = true;
                    compilePS_ = false;
                }
                else if (arg.ToLower() == "ps")
                {
                    compileVS_ = false;
                    compilePS_ = true;
                }
                break;
                
            case 'v':
                compileVariation_ = true;
                variationName_ = arg;
                break;
            }
        }
    }
    
    if (!file.StartsWith("*"))
        CompileShader(arguments[0]);
    else
    {
        Vector<String> shaderFiles;
        fileSystem_->ScanDir(shaderFiles, inDir_, file + extension, SCAN_FILES, false);
        for (unsigned i = 0; i < shaderFiles.Size(); ++i)
            CompileShader(inDir_ + shaderFiles[i]);
    }
}
Example #13
0
void ConsoleInput::HandleInput(const String& input)
{
    String inputLower = input.ToLower().Trimmed();
    if (inputLower.Empty())
    {
        Print("Empty input given!");
        return;
    }

    if (inputLower == "quit" || inputLower == "exit")
        engine_->Exit();
    else if (gameOn_)
    {
        // Game is on
        if (inputLower == "help")
            Print("The following commands are available: 'eat', 'hide', 'wait', 'score', 'quit'.");
        else if (inputLower == "score")
            Print("You have survived " + String(numTurns_) + " turns.");
        else if (inputLower == "eat")
        {
            if (foodAvailable_)
            {
                Print("You eat several pieces of fish food.");
                foodAvailable_ = false;
                eatenLastTurn_ = true;
                hunger_ -= (hunger_ > 3) ? 2 : 1;
                if (hunger_ < 0)
                {
                    EndGame("You have killed yourself by over-eating!");
                    return;
                }
                else
                    Print("You are now " + String(hungerLevels[hunger_]) + ".");
            }
            else
                Print("There is no food available.");

            Advance();
        }
        else if (inputLower == "wait")
        {
            Print("Time passes...");
            Advance();
        }
        else if (inputLower == "hide")
        {
            if (urhoThreat_ > 0)
            {
                bool evadeSuccess = hunger_ > 2 || Random() < 0.5f;
                if (evadeSuccess)
                {
                    Print("You hide behind the thick bottom vegetation, until Urho grows bored.");
                    urhoThreat_ = -2;
                }
                else
                    Print("Your movements are too slow; you are unable to hide from Urho.");
            }
            else
                Print("There is nothing to hide from.");

            Advance();
        }
        else
            Print("Cannot understand the input '" + input + "'.");
    }
    else
    {
        // Game is over, wait for (y)es or (n)o reply
        if (inputLower[0] == 'y')
            StartGame();
        else if (inputLower[0] == 'n')
            engine_->Exit();
        else
            Print("Please answer 'y' or 'n'.");
    }
}
Example #14
0
PerfdataValue::Ptr PerfdataValue::Parse(const String& perfdata)
{
	size_t eqp = perfdata.FindLastOf('=');

	if (eqp == String::NPos)
		BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid performance data value: " + perfdata));

	String label = perfdata.SubStr(0, eqp);

	if (label.GetLength() > 2 && label[0] == '\'' && label[label.GetLength() - 1] == '\'')
		label = label.SubStr(1, label.GetLength() - 2);

	size_t spq = perfdata.FindFirstOf(' ', eqp);

	if (spq == String::NPos)
		spq = perfdata.GetLength();

	String valueStr = perfdata.SubStr(eqp + 1, spq - eqp - 1);

	size_t pos = valueStr.FindFirstNotOf("+-0123456789.e");

	double value = Convert::ToDouble(valueStr.SubStr(0, pos));

	std::vector<String> tokens = valueStr.Split(";");

	bool counter = false;
	String unit;
	Value warn, crit, min, max;

	if (pos != String::NPos)
		unit = valueStr.SubStr(pos, tokens[0].GetLength() - pos);

	unit = unit.ToLower();

	double base = 1.0;

	if (unit == "us") {
		base /= 1000.0 * 1000.0;
		unit = "seconds";
	} else if (unit == "ms") {
		base /= 1000.0;
		unit = "seconds";
	} else if (unit == "s") {
		unit = "seconds";
	} else if (unit == "tb") {
		base *= 1024.0 * 1024.0 * 1024.0 * 1024.0;
		unit = "bytes";
	} else if (unit == "gb") {
		base *= 1024.0 * 1024.0 * 1024.0;
		unit = "bytes";
	} else if (unit == "mb") {
		base *= 1024.0 * 1024.0;
		unit = "bytes";
	} else if (unit == "kb") {
		base *= 1024.0;
		unit = "bytes";
	} else if (unit == "b") {
		unit = "bytes";
	} else if (unit == "%") {
		unit = "percent";
	} else if (unit == "c") {
		counter = true;
		unit = "";
	} else if (unit != "") {
		BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid performance data unit: " + unit));
	}

	warn = ParseWarnCritMinMaxToken(tokens, 1, "warning");
	crit = ParseWarnCritMinMaxToken(tokens, 2, "critical");
	min = ParseWarnCritMinMaxToken(tokens, 3, "minimum");
	max = ParseWarnCritMinMaxToken(tokens, 4, "maximum");

	value = value * base;

	if (!warn.IsEmpty())
		warn = warn * base;

	if (!crit.IsEmpty())
		crit = crit * base;

	if (!min.IsEmpty())
		min = min * base;

	if (!max.IsEmpty())
		max = max * base;

	return new PerfdataValue(label, value, counter, unit, warn, crit, min, max);
}
Example #15
0
bool Technique::HasPass(const String& name) const
{
    HashMap<String, unsigned>::ConstIterator i = passIndices.Find(name.ToLower());
    return i != passIndices.End() ? HasPass(i->second_) : false;
}