Ejemplo n.º 1
0
void Graphics::SetShaderParameter(StringHash param, const Variant& value)
{
    switch (value.GetType())
    {
    case VAR_BOOL:
        SetShaderParameter(param, value.GetBool());
        break;

    case VAR_INT:
        SetShaderParameter(param, value.GetInt());
        break;

    case VAR_FLOAT:
    case VAR_DOUBLE:
        SetShaderParameter(param, value.GetFloat());
        break;

    case VAR_VECTOR2:
        SetShaderParameter(param, value.GetVector2());
        break;

    case VAR_VECTOR3:
        SetShaderParameter(param, value.GetVector3());
        break;

    case VAR_VECTOR4:
        SetShaderParameter(param, value.GetVector4());
        break;

    case VAR_COLOR:
        SetShaderParameter(param, value.GetColor());
        break;

    case VAR_MATRIX3:
        SetShaderParameter(param, value.GetMatrix3());
        break;

    case VAR_MATRIX3X4:
        SetShaderParameter(param, value.GetMatrix3x4());
        break;

    case VAR_MATRIX4:
        SetShaderParameter(param, value.GetMatrix4());
        break;

    case VAR_BUFFER:
        {
            const PODVector<unsigned char>& buffer = value.GetBuffer();
            if (buffer.Size() >= sizeof(float))
                SetShaderParameter(param, reinterpret_cast<const float*>(&buffer[0]), buffer.Size() / sizeof(float));
        }
        break;

    default:
        // Unsupported parameter type, do nothing
        break;
    }
}
Ejemplo n.º 2
0
void PushVariant(duk_context* ctx, const Variant& variant)
{
    switch (variant.GetType())
    {
    case Urho3D::VAR_BOOL:
        duk_push_boolean(ctx, variant.GetBool() ? 1 : 0);
        break;
    
    case Urho3D::VAR_INT:
        duk_push_number(ctx, (duk_double_t)variant.GetInt());
        break;
    
    case Urho3D::VAR_FLOAT:
        duk_push_number(ctx, variant.GetFloat());
        break;
    
    case Urho3D::VAR_DOUBLE:
        duk_push_number(ctx, variant.GetFloat());
        break;
    
    case Urho3D::VAR_STRING:
        duk_push_string(ctx, variant.GetString().CString());
        break;
    
    case Urho3D::VAR_VECTOR2:
        PushValueObjectCopy<float2>(ctx, float2(variant.GetVector2()), float2_ID, float2_Finalizer);
        break;
    
    case Urho3D::VAR_VECTOR3:
        PushValueObjectCopy<float3>(ctx, float3(variant.GetVector3()), float3_ID, float3_Finalizer);
        break;
    
    case Urho3D::VAR_VECTOR4:
        PushValueObjectCopy<float4>(ctx, float4(variant.GetVector4()), float4_ID, float4_Finalizer);
        break;
    
    case Urho3D::VAR_QUATERNION:
        PushValueObjectCopy<Quat>(ctx, Quat(variant.GetQuaternion()), Quat_ID, Quat_Finalizer);
        break;
    
    default:
        /// \todo More types
        duk_push_null(ctx);
        break;
    }
}
Ejemplo n.º 3
0
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:
        {
            Vector2* value = new Vector2(src.GetVector2());
            tolua_pushusertype(luaState_, value, "Vector2");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_VECTOR3:
        {
            Vector3* value = new Vector3(src.GetVector3());
            tolua_pushusertype(luaState_, value, "Vector3");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_VECTOR4:
        {
            Vector4* value = new Vector4(src.GetVector4());
            tolua_pushusertype(luaState_, value, "Vector4");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_QUATERNION:
        {
            Quaternion* value = new Quaternion(src.GetQuaternion());
            tolua_pushusertype(luaState_, value, "Quaternion");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }

        break;
        case VAR_COLOR:
        {
            Color* value = new Color(src.GetColor());
            tolua_pushusertype(luaState_, value, "Color");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_INTRECT:
        {
            IntRect* value = new IntRect(src.GetIntRect());
            tolua_pushusertype(luaState_, value, "IntRect");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        case VAR_INTVECTOR2:
        {
            IntVector2* value = new IntVector2(src.GetIntVector2());
            tolua_pushusertype(luaState_, value, "IntVector2");
            tolua_register_gc(luaState_, lua_gettop(luaState_));
        }
        break;
        default:
            LOGERROR("Unsupported data type");
            lua_settop(luaState_, top);
            return;
        }

        lua_settable(luaState_, -3);
    }

    lua_settop(luaState_, top);
}
Ejemplo n.º 4
0
bool Serializer::WriteVariantData(const Variant& value)
{
    switch (value.GetType())
    {
    case VAR_NONE:
        return true;

    case VAR_INT:
        return WriteInt(value.GetInt());

    case VAR_BOOL:
        return WriteBool(value.GetBool());

    case VAR_FLOAT:
        return WriteFloat(value.GetFloat());

    case VAR_VECTOR2:
        return WriteVector2(value.GetVector2());

    case VAR_VECTOR3:
        return WriteVector3(value.GetVector3());

    case VAR_VECTOR4:
        return WriteVector4(value.GetVector4());

    case VAR_QUATERNION:
        return WriteQuaternion(value.GetQuaternion());

    case VAR_COLOR:
        return WriteColor(value.GetColor());

    case VAR_STRING:
        return WriteString(value.GetString());

    case VAR_BUFFER:
        return WriteBuffer(value.GetBuffer());

    // Serializing pointers is not supported. Write null
    case VAR_VOIDPTR:
    case VAR_PTR:
        return WriteUInt(0);

    case VAR_RESOURCEREF:
        return WriteResourceRef(value.GetResourceRef());

    case VAR_RESOURCEREFLIST:
        return WriteResourceRefList(value.GetResourceRefList());

    case VAR_VARIANTVECTOR:
        return WriteVariantVector(value.GetVariantVector());

    case VAR_VARIANTMAP:
        return WriteVariantMap(value.GetVariantMap());

    case VAR_INTRECT:
        return WriteIntRect(value.GetIntRect());

    case VAR_INTVECTOR2:
        return WriteIntVector2(value.GetIntVector2());

    case VAR_MATRIX3:
        return WriteMatrix3(value.GetMatrix3());

    case VAR_MATRIX3X4:
        return WriteMatrix3x4(value.GetMatrix3x4());

    case VAR_MATRIX4:
        return WriteMatrix4(value.GetMatrix4());

    default:
        return false;
    }
}
Ejemplo n.º 5
0
void JSONValue::SetVariantValue(const Variant& variant, Context* context)
{
    if (!IsNull())
    {
        LOGWARNING("JsonValue is not null");
    }

    switch (variant.GetType())
    {
    case VAR_BOOL:
        *this = variant.GetBool();
        return;
    
    case VAR_INT:
        *this = variant.GetInt();
        return;

    case VAR_FLOAT:
        *this = variant.GetFloat();
        return;

    case VAR_DOUBLE:
        *this = variant.GetDouble();
        return;

    case VAR_STRING:
        *this = variant.GetString();
        return;

    case VAR_VARIANTVECTOR:
        SetVariantVector(variant.GetVariantVector(), context);
        return;

    case VAR_VARIANTMAP:
        SetVariantMap(variant.GetVariantMap(), context);
        return;

    case VAR_RESOURCEREF:
        {
            if (!context)
            {
                LOGERROR("Context must not null for ResourceRef");
                return;
            }

            const ResourceRef& ref = variant.GetResourceRef();
            *this = String(context->GetTypeName(ref.type_)) + ";" + ref.name_;
        }
        return;

    case VAR_RESOURCEREFLIST:
        {
            if (!context)
            {
                LOGERROR("Context must not null for ResourceRefList");
                return;
            }

            const ResourceRefList& refList = variant.GetResourceRefList();
            String str(context->GetTypeName(refList.type_));
            for (unsigned i = 0; i < refList.names_.Size(); ++i)
            {
                str += ";";
                str += refList.names_[i];
            }
            *this = str;
        }
        return;

    case VAR_STRINGVECTOR:
        {
            const StringVector& vector = variant.GetStringVector();
            Resize(vector.Size());
            for (unsigned i = 0; i < vector.Size(); ++i)
                (*this)[i] = vector[i];
        }
        return;

    default:
        *this = variant.ToString();
    }
}