Variant ValueAnimation::SubstractAndMultiply(const Variant& value1, const Variant& value2, float t) const { switch (valueType_) { case VAR_FLOAT: return (value1.GetFloat() - value2.GetFloat()) * t; case VAR_VECTOR2: return (value1.GetVector2() - value2.GetVector2()) * t; case VAR_VECTOR3: return (value1.GetVector3() - value2.GetVector3()) * t; case VAR_VECTOR4: return (value1.GetVector4() - value2.GetVector4()) * t; case VAR_QUATERNION: return (value1.GetQuaternion() - value2.GetQuaternion()) * t; case VAR_COLOR: return (value1.GetColor() - value2.GetColor()) * t; case VAR_DOUBLE: return (value1.GetDouble() - value2.GetDouble()) * t; default: ATOMIC_LOGERROR("Invalid value type for spline interpolation's subtract and multiply operation"); return Variant::EMPTY; } }
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; } }
Variant Spline::LinearInterpolation(const Variant& lhs, const Variant& rhs, float t) const { switch (lhs.GetType()) { case VAR_FLOAT: return Lerp(lhs.GetFloat(), rhs.GetFloat(), t); case VAR_VECTOR2: return lhs.GetVector2().Lerp(rhs.GetVector2(), t); case VAR_VECTOR3: return lhs.GetVector3().Lerp(rhs.GetVector3(), t); case VAR_VECTOR4: return lhs.GetVector4().Lerp(rhs.GetVector4(), t); case VAR_COLOR: return lhs.GetColor().Lerp(rhs.GetColor(), t); default: return Variant::EMPTY; } }
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; } }
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); }
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; } }