Beispiel #1
0
Variant ToVectorVariant(const String& source)
{
    return ToVectorVariant(source.CString());
}
Beispiel #2
0
bool FileWatcher::StartWatching(const String& pathName, bool watchSubDirs)
{
    if (!fileSystem_)
    {
        LOGERROR("No FileSystem, can not start watching");
        return false;
    }
    
    // Stop any previous watching
    StopWatching();
    
#if defined(ENABLE_FILEWATCHER)
#if defined(WIN32)
    String nativePath = GetNativePath(RemoveTrailingSlash(pathName));
    
    dirHandle_ = (void*)CreateFileW(
        WString(nativePath).CString(),
        FILE_LIST_DIRECTORY,
        FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE,
        0,
        OPEN_EXISTING,
        FILE_FLAG_BACKUP_SEMANTICS,
        0);
    
    if (dirHandle_ != INVALID_HANDLE_VALUE)
    {
        path_ = AddTrailingSlash(pathName);
        watchSubDirs_ = watchSubDirs;
        Start();
        
        LOGDEBUG("Started watching path " + pathName);
        return true;
    }
    else
    {
        LOGERROR("Failed to start watching path " + pathName);
        return false;
    }
#elif defined(__linux__)
    int flags = IN_CREATE|IN_DELETE|IN_MODIFY|IN_MOVED_FROM|IN_MOVED_TO;
    int handle = inotify_add_watch(watchHandle_, pathName.CString(), flags);

    if (handle < 0)
    {
        LOGERROR("Failed to start watching path " + pathName);
        return false;
    }
    else
    {
        // Store the root path here when reconstructed with inotify later
        dirHandle_[handle] = "";
        path_ = AddTrailingSlash(pathName);
        watchSubDirs_ = watchSubDirs;

        if (watchSubDirs_)
        {
            Vector<String> subDirs;
            fileSystem_->ScanDir(subDirs, pathName, "*", SCAN_DIRS, true);

            for (unsigned i = 0; i < subDirs.Size(); ++i)
            {
                String subDirFullPath = AddTrailingSlash(path_ + subDirs[i]);

                // Don't watch ./ or ../ sub-directories
                if (!subDirFullPath.EndsWith("./"))
                {
                    handle = inotify_add_watch(watchHandle_, subDirFullPath.CString(), flags);
                    if (handle < 0)
                        LOGERROR("Failed to start watching subdirectory path " + subDirFullPath);
                    else
                    {
                        // Store sub-directory to reconstruct later from inotify
                        dirHandle_[handle] = AddTrailingSlash(subDirs[i]);
                    }
                }
            }
        }
        Start();

        LOGDEBUG("Started watching path " + pathName);
        return true;
    }
#elif defined(__APPLE__) && !defined(IOS)
    if (!supported_)
    {
        LOGERROR("Individual file watching not supported by this OS version, can not start watching path " + pathName);
        return false;        
    }
    
    watcher_ = CreateFileWatcher(pathName.CString(), watchSubDirs);
    if (watcher_)
    {
        path_ = AddTrailingSlash(pathName);
        watchSubDirs_ = watchSubDirs;
        Start();
        
        LOGDEBUG("Started watching path " + pathName);
        return true;
    }
    else
    {
        LOGERROR("Failed to start watching path " + pathName);
        return false;
    }
#else
    LOGERROR("FileWatcher not implemented, can not start watching path " + pathName);
    return false;
#endif
#else
    LOGDEBUG("FileWatcher feature not enabled");
    return false;
#endif
}
Beispiel #3
0
Vector4 ToVector4(const String& source, bool allowMissingCoords)
{
    return ToVector4(source.CString(), allowMissingCoords);
}
Beispiel #4
0
bool XPathQuery::SetVariable(const String& name, const String& value)
{
    return SetVariable(name.CString(), value.CString());
}
Beispiel #5
0
bool XMLElement::RemoveAttribute(const String& name)
{
    return RemoveAttribute(name.CString());
}
Beispiel #6
0
void StringToBuffer(PODVector<unsigned char>& dest, const String& source)
{
    StringToBuffer(dest, source.CString());
}
Beispiel #7
0
bool ToBool(const String& source)
{
    return ToBool(source.CString());
}
Beispiel #8
0
float ToFloat(const String& source)
{
    return ToFloat(source.CString());
}
Beispiel #9
0
double ToDouble(const String& source)
{
    return ToDouble(source.CString());
}
Beispiel #10
0
int ToInt(const String& source, int base)
{
    return ToInt(source.CString(), base);
}
Beispiel #11
0
unsigned ToUInt(const String& source, int base)
{
    return ToUInt(source.CString(), base);
}
void LuaScriptInstance::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
{
    if (attr.ptr_ != (void*)0xffffffff)
    {
        Serializable::OnSetAttribute(attr, src);
        return;
    }

    if (scriptObjectRef_ == LUA_REFNIL)
        return;

    String name = attr.name_;
    unsigned length = name.Length();
    if (name.Back() == '_')
        length -= 1;

    int top = lua_gettop(luaState_);

    String functionName = String("Set") + name.Substring(0, 1).ToUpper() + name.Substring(1, length - 1);
    WeakPtr<LuaFunction> function = GetScriptObjectFunction(functionName);
    // If set function exist
    if (function)
    {
        if (function->BeginCall(this))
        {
            function->PushVariant(src);
            function->EndCall();
        }
    }
    else
    {
        lua_rawgeti(luaState_, LUA_REGISTRYINDEX, scriptObjectRef_);
        lua_pushstring(luaState_, name.CString());

        switch (attr.type_)
        {
        case VAR_BOOL:
            lua_pushboolean(luaState_, src.GetBool());
            break;
        case VAR_FLOAT:
            lua_pushnumber(luaState_, src.GetFloat());
            break;
        case VAR_STRING:
            tolua_pushurho3dstring(luaState_, src.GetString());
            break;
        case VAR_VECTOR2:
            tolua_pushusertype(luaState_, (void*)&(src.GetVector2()), "Vector2");
            break;
        case VAR_VECTOR3:
            tolua_pushusertype(luaState_, (void*)&(src.GetVector3()), "Vector3");
            break;
        case VAR_VECTOR4:
            tolua_pushusertype(luaState_, (void*)&(src.GetVector4()), "Vector4");
            break;
        case VAR_QUATERNION:
            tolua_pushusertype(luaState_, (void*)&(src.GetQuaternion()), "Quaternion");
            break;
        case VAR_COLOR:
            tolua_pushusertype(luaState_, (void*)&(src.GetColor()), "Color");
            break;
        case VAR_INTRECT:
            tolua_pushusertype(luaState_, (void*)&(src.GetIntRect()), "IntRect");
            break;
        case VAR_INTVECTOR2:
            tolua_pushusertype(luaState_, (void*)&(src.GetIntVector2()), "IntVector2");
            break;
        default:
            LOGERROR("Unsupported data type");
            lua_settop(luaState_, top);
            return;
        }
        lua_settable(luaState_, -3);
    }

    lua_settop(luaState_, top);
}
void LuaScriptInstance::OnGetAttribute(const AttributeInfo& attr, Variant& dest) const
{
    if (attr.ptr_ != (void*)0xffffffff)
    {
        Serializable::OnGetAttribute(attr, dest);
        return;
    }

    if (scriptObjectRef_ == LUA_REFNIL)
        return;

    String name = attr.name_;
    unsigned length = name.Length();
    if (name.Back() == '_')
        length -= 1;

    int top = lua_gettop(luaState_);

    String functionName = String("Get") + name.Substring(0, 1).ToUpper() + name.Substring(1, length - 1);
    WeakPtr<LuaFunction> function = GetScriptObjectFunction(functionName);
    // If get function exist
    if (function)
    {
        if (function->BeginCall(this))
            function->EndCall(1);
    }
    else
    {
        lua_rawgeti(luaState_, LUA_REGISTRYINDEX, scriptObjectRef_);
        lua_pushstring(luaState_, name.CString());
        lua_gettable(luaState_, -2);
    }

    switch (attr.type_)
    {
    case VAR_BOOL:
        dest = lua_toboolean(luaState_, -1) != 0;
        break;
    case VAR_FLOAT:
        dest = (float)lua_tonumber(luaState_, -1);
        break;
    case VAR_STRING:
        dest = tolua_tourho3dstring(luaState_, -1, "");
        break;
    case VAR_VECTOR2:
        dest = *((Vector2*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_VECTOR3:
        dest = *((Vector3*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_VECTOR4:
        dest = *((Vector4*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_QUATERNION:
        dest = *((Quaternion*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_COLOR:
        dest = *((Color*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_INTRECT:
        dest = *((IntRect*)tolua_tousertype(luaState_, -1, 0));
        break;
    case VAR_INTVECTOR2:
        dest = *((IntVector2*)tolua_tousertype(luaState_, -1, 0));
        break;
    default:
        LOGERROR("Unsupported data type");
        return;
    }

    lua_settop(luaState_, top);
}
Beispiel #14
0
bool Technique::BeginLoad(Deserializer& source)
{
    passes_.Clear();
    cloneTechniques_.Clear();

    SetMemoryUse(sizeof(Technique));

    SharedPtr<XMLFile> xml(new XMLFile(context_));
    if (!xml->Load(source))
        return false;

    XMLElement rootElem = xml->GetRoot();
    if (rootElem.HasAttribute("desktop"))
        isDesktop_ = rootElem.GetBool("desktop");

    String globalVS = rootElem.GetAttribute("vs");
    String globalPS = rootElem.GetAttribute("ps");
    String globalVSDefines = rootElem.GetAttribute("vsdefines");
    String globalPSDefines = rootElem.GetAttribute("psdefines");
    // End with space so that the pass-specific defines can be appended
    if (!globalVSDefines.Empty())
        globalVSDefines += ' ';
    if (!globalPSDefines.Empty())
        globalPSDefines += ' ';

    XMLElement passElem = rootElem.GetChild("pass");
    while (passElem)
    {
        if (passElem.HasAttribute("name"))
        {
            Pass* newPass = CreatePass(passElem.GetAttribute("name"));

            if (passElem.HasAttribute("desktop"))
                newPass->SetIsDesktop(passElem.GetBool("desktop"));

            // Append global defines only when pass does not redefine the shader
            if (passElem.HasAttribute("vs"))
            {
                newPass->SetVertexShader(passElem.GetAttribute("vs"));
                newPass->SetVertexShaderDefines(passElem.GetAttribute("vsdefines"));
            }
            else
            {
                newPass->SetVertexShader(globalVS);
                newPass->SetVertexShaderDefines(globalVSDefines + passElem.GetAttribute("vsdefines"));
            }
            if (passElem.HasAttribute("ps"))
            {
                newPass->SetPixelShader(passElem.GetAttribute("ps"));
                newPass->SetPixelShaderDefines(passElem.GetAttribute("psdefines"));
            }
            else
            {
                newPass->SetPixelShader(globalPS);
                newPass->SetPixelShaderDefines(globalPSDefines + passElem.GetAttribute("psdefines"));
            }

            newPass->SetVertexShaderDefineExcludes(passElem.GetAttribute("vsexcludes"));
            newPass->SetPixelShaderDefineExcludes(passElem.GetAttribute("psexcludes"));

            if (passElem.HasAttribute("lighting"))
            {
                String lighting = passElem.GetAttributeLower("lighting");
                newPass->SetLightingMode((PassLightingMode)GetStringListIndex(lighting.CString(), lightingModeNames,
                    LIGHTING_UNLIT));
            }

            if (passElem.HasAttribute("blend"))
            {
                String blend = passElem.GetAttributeLower("blend");
                newPass->SetBlendMode((BlendMode)GetStringListIndex(blend.CString(), blendModeNames, BLEND_REPLACE));
            }

            if (passElem.HasAttribute("cull"))
            {
                String cull = passElem.GetAttributeLower("cull");
                newPass->SetCullMode((CullMode)GetStringListIndex(cull.CString(), cullModeNames, MAX_CULLMODES));
            }

            if (passElem.HasAttribute("depthtest"))
            {
                String depthTest = passElem.GetAttributeLower("depthtest");
                if (depthTest == "false")
                    newPass->SetDepthTestMode(CMP_ALWAYS);
                else
                    newPass->SetDepthTestMode((CompareMode)GetStringListIndex(depthTest.CString(), compareModeNames, CMP_LESS));
            }

            if (passElem.HasAttribute("depthwrite"))
                newPass->SetDepthWrite(passElem.GetBool("depthwrite"));
        }
        else
            URHO3D_LOGERROR("Missing pass name");

        passElem = passElem.GetNext("pass");
    }

    return true;
}
Beispiel #15
0
Matrix3 ToMatrix3(const String& source)
{
    return ToMatrix3(source.CString());
}
Beispiel #16
0
Color ToColor(const String& source)
{
    return ToColor(source.CString());
}
Beispiel #17
0
Matrix4 ToMatrix4(const String& source)
{
    return ToMatrix4(source.CString());
}
Beispiel #18
0
Rect ToRect(const String& source)
{
    return ToRect(source.CString());
}
Beispiel #19
0
unsigned GetStringListIndex(const String& value, const String* strings, unsigned defaultIndex, bool caseSensitive)
{
    return GetStringListIndex(value.CString(), strings, defaultIndex, caseSensitive);
}
Beispiel #20
0
Quaternion ToQuaternion(const String& source)
{
    return ToQuaternion(source.CString());
}
Beispiel #21
0
bool XPathQuery::SetVariable(const String& name, float value)
{
    if (!variables_)
        variables_ = new pugi::xpath_variable_set();
    return variables_->set(name.CString(), value);
}
Beispiel #22
0
Vector2 ToVector2(const String& source)
{
    return ToVector2(source.CString());
}
Beispiel #23
0
bool XMLElement::RemoveChildren(const String& name)
{
    return RemoveChildren(name.CString());
}
Beispiel #24
0
Vector3 ToVector3(const String& source)
{
    return ToVector3(source.CString());
}
Beispiel #25
0
bool XMLElement::SetAttribute(const String& value)
{
    return SetAttribute(value.CString());
}
Beispiel #26
0
void RenderPathCommand::Load(const XMLElement& element)
{
    type_ = (RenderCommandType)GetStringListIndex(element.GetAttributeLower("type").CString(), commandTypeNames, CMD_NONE);
    tag_ = element.GetAttribute("tag");
    if (element.HasAttribute("enabled"))
        enabled_ = element.GetBool("enabled");
    if (element.HasAttribute("metadata"))
        metadata_ = element.GetAttribute("metadata");

    switch (type_)
    {
    case CMD_CLEAR:
        if (element.HasAttribute("color"))
        {
            clearFlags_ |= CLEAR_COLOR;
            if (element.GetAttributeLower("color") == "fog")
                useFogColor_ = true;
            else
                clearColor_ = element.GetColor("color");
        }
        if (element.HasAttribute("depth"))
        {
            clearFlags_ |= CLEAR_DEPTH;
            clearDepth_ = element.GetFloat("depth");
        }
        if (element.HasAttribute("stencil"))
        {
            clearFlags_ |= CLEAR_STENCIL;
            clearStencil_ = (unsigned)element.GetInt("stencil");
        }
        break;

    case CMD_SCENEPASS:
        pass_ = element.GetAttribute("pass");
        sortMode_ =
            (RenderCommandSortMode)GetStringListIndex(element.GetAttributeLower("sort").CString(), sortModeNames, SORT_FRONTTOBACK);
        if (element.HasAttribute("marktostencil"))
            markToStencil_ = element.GetBool("marktostencil");
        if (element.HasAttribute("vertexlights"))
            vertexLights_ = element.GetBool("vertexlights");
        break;

    case CMD_FORWARDLIGHTS:
        pass_ = element.GetAttribute("pass");
        if (element.HasAttribute("uselitbase"))
            useLitBase_ = element.GetBool("uselitbase");
        break;

    case CMD_LIGHTVOLUMES:
    case CMD_QUAD:
        vertexShaderName_ = element.GetAttribute("vs");
        pixelShaderName_ = element.GetAttribute("ps");

        if (type_ == CMD_QUAD && element.HasAttribute("blend"))
        {
            String blend = element.GetAttributeLower("blend");
            blendMode_ = ((BlendMode)GetStringListIndex(blend.CString(), blendModeNames, BLEND_REPLACE));
        }
        break;

    case CMD_SENDEVENT:
        eventName_ = element.GetAttribute("name");
        break;

    default:
        break;
    }

    // By default use 1 output, which is the viewport
    outputs_.Resize(1);
    outputs_[0] = MakePair(String("viewport"), FACE_POSITIVE_X);
    if (element.HasAttribute("output"))
        outputs_[0].first_ = element.GetAttribute("output");
    if (element.HasAttribute("face"))
        outputs_[0].second_ = (CubeMapFace)element.GetInt("face");
    if (element.HasAttribute("depthstencil"))
        depthStencilName_ = element.GetAttribute("depthstencil");
    // Check for defining multiple outputs
    XMLElement outputElem = element.GetChild("output");
    while (outputElem)
    {
        unsigned index = (unsigned)outputElem.GetInt("index");
        if (index < MAX_RENDERTARGETS)
        {
            if (index >= outputs_.Size())
                outputs_.Resize(index + 1);
            outputs_[index].first_ = outputElem.GetAttribute("name");
            outputs_[index].second_ = outputElem.HasAttribute("face") ? (CubeMapFace)outputElem.GetInt("face") : FACE_POSITIVE_X;
        }
        outputElem = outputElem.GetNext("output");
    }

    // Shader compile flags & parameters
    vertexShaderDefines_ = element.GetAttribute("vsdefines");
    pixelShaderDefines_ = element.GetAttribute("psdefines");
    XMLElement parameterElem = element.GetChild("parameter");
    while (parameterElem)
    {
        String name = parameterElem.GetAttribute("name");
        shaderParameters_[name] = Material::ParseShaderParameterValue(parameterElem.GetAttribute("value"));
        parameterElem = parameterElem.GetNext("parameter");
    }

    // Texture bindings
    XMLElement textureElem = element.GetChild("texture");
    while (textureElem)
    {
        TextureUnit unit = TU_DIFFUSE;
        if (textureElem.HasAttribute("unit"))
            unit = ParseTextureUnitName(textureElem.GetAttribute("unit"));
        if (unit < MAX_TEXTURE_UNITS)
        {
            String name = textureElem.GetAttribute("name");
            textureNames_[unit] = name;
        }

        textureElem = textureElem.GetNext("texture");
    }
}