コード例 #1
0
ファイル: variant.cpp プロジェクト: renokun/Aspen
Variant Variant::operator /(Variant var)
{
    VARIABLE_TYPE vtype = var.Typeof();

    switch(type)
        {
        case VAR_INT:
            switch(vtype)
                {
                case VAR_INT:
                    return Variant(i32 / var.GetInt());
                case VAR_DOUBLE:
                    return Variant(i32 / var.GetDouble());
                default:
                    throw(InvalidVariableTypeException("Tried to divide illegal value."));
                }
        case VAR_DOUBLE:
            switch(vtype)
                {
                case VAR_INT:
                    return Variant(d / var.GetInt());
                case VAR_DOUBLE:
                    return Variant(d / var.GetDouble());
                default:
                    throw(InvalidVariableTypeException("Tried to divide illegal value."));
                }
        default:
            throw(InvalidVariableTypeException("Tried to divide illegal value."));
        }
}
コード例 #2
0
ファイル: variant.cpp プロジェクト: renokun/Aspen
BOOL Variant::Compare(const Variant &var) const
{
    VARIABLE_TYPE vtype = var.Typeof();
    switch(type)
        {
        case VAR_STR:
            switch(vtype)
                {
                case VAR_STR:
                    return (str == var.GetStr()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare a string with an illegal value."));
                }
        case VAR_INT:
            switch(vtype)
                {
                case VAR_INT:
                    return (i32 == var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return (i32 == (int)var.GetDouble()?1:0);
                case VAR_BYTE:
                    return (i32 == var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare integer with an illegal type."));
                }
        case VAR_DOUBLE:
            switch(vtype)
                {
                case VAR_INT:
                    return ((int)d == var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return d==var.GetDouble();
                case VAR_BYTE:
                    return ((char)d == var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare double with an illegal type."));
                }
        case VAR_BYTE:
            switch(vtype)
                {
                case VAR_INT:
                    return (byte == var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return (byte == (char)var.GetDouble()?1:0);
                case VAR_BYTE:
                    return (byte == var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare byte with an illegal type."));
                }
        default:
            throw(InvalidVariableTypeException("Tried to compare with an illegal type."));
        }

    return false;
}
コード例 #3
0
ファイル: variant.cpp プロジェクト: renokun/Aspen
bool Variant::operator >(Variant var)
{
    VARIABLE_TYPE vtype = var.Typeof();
    switch(type)
        {
        case VAR_STR:
            switch(vtype)
                {
                case VAR_STR:
                    return (str > var.GetStr()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare a string with an illegal value."));
                }
        case VAR_INT:
            switch(vtype)
                {
                case VAR_INT:
                    return (i32 > var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return (i32 > var.GetDouble()?1:0);
                case VAR_BYTE:
                    return (i32 > var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare integer with an illegal type."));
                }
        case VAR_DOUBLE:
            switch(vtype)
                {
                case VAR_INT:
                    return (d > var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return (d > var.GetDouble()?1:0);
                case VAR_BYTE:
                    return (d > var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare double with an illegal type."));
                }
        case VAR_BYTE:
            switch(vtype)
                {
                case VAR_INT:
                    return (byte > var.GetInt()?1:0);
                case VAR_DOUBLE:
                    return (byte > var.GetDouble()?1:0);
                case VAR_BYTE:
                    return (byte > var.GetByte()?1:0);
                default:
                    throw(InvalidVariableTypeException("Tried to compare byte with an illegal type."));
                }
        default:
            throw(InvalidVariableTypeException("Tried to compare with an illegal type."));
        }
}
コード例 #4
0
ファイル: Graphics.cpp プロジェクト: TheComet93/Urho3D
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;
    }
}
コード例 #5
0
ファイル: test.cpp プロジェクト: erio-nk/MyCxxProgram2011
	void Test()
	{
		DBGTRACE(_T("--------------------------------------------------"));

		Properties props;

		props.AddProperty(_T("hoge"), 0);
		props.AddProperty(_T("fuga"), 1);
		
		props[_T("piyo")].SetString(_T("piyopiyo"));

		Variant* hoge = props.GetProperty(_T("hoge"));
		DBGTRACE(_T("hoge=%d"), hoge->GetInt());

		Variant* fuga = props.GetProperty(_T("fuga"));
		DBGTRACE(_T("fuga=%d"), fuga->GetInt());

		DBGTRACE(_T("piyo=%s"), props[_T("piyo")].GetString().c_str());
	}
コード例 #6
0
ファイル: variant.cpp プロジェクト: renokun/Aspen
Variant Variant::operator %(Variant var)
{
    if ((var.Typeof() == VAR_INT) && (type == VAR_INT))
        {
            return Variant(i32 % var.GetInt());
        }
    else
        {
            throw(InvalidVariableTypeException("Tried to get modulous of illegal value."));
        }
}
コード例 #7
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;
    }
}
コード例 #8
0
ファイル: variant.cpp プロジェクト: renokun/Aspen
Variant::Variant(const Variant& var)
{
    type = var.Typeof();
    switch(type)
        {
        case VAR_BYTE:
            byte = var.GetByte();
            break;
        case VAR_INT:
            i32=var.GetInt();
            break;
        case VAR_DOUBLE:
            d=var.GetDouble();
            break;
        case VAR_STR:
            str=var.GetStr();;
        case VAR_EMPTY:
        default:
            break;
        }
}
コード例 #9
0
ファイル: GameMain.cpp プロジェクト: nonconforme/FH
bool GameMain::Raycast(float maxDistance, Vector3& hitPos, Vector3& hitNormal, Drawable*& hitDrawable)
{
	hitDrawable = 0;

	Graphics* graphics = GetSubsystem<Graphics>();
	//Ray cameraRay = camera->GetScreenRay((float)graphics->GetWidth() * 0.5f, (float) graphics->GetHeight() * 0.5f);
	Ray ray = world.camera.camera_->GetScreenRay((float) 0.5f, (float) 0.5f);
	//Ray gunRay = Ray(gunNode_->GetWorldPosition(), gunNode_->GetWorldDirection());

	// Pick only geometry objects, not eg. zones or lights, only get the first (closest) hit
	PODVector<RayQueryResult> results;
	//RayOctreeQuery query(results, cameraRay, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY);
	RayOctreeQuery query(results, ray, RAY_TRIANGLE, maxDistance, DRAWABLE_GEOMETRY, 191);
		
	Octree* octree = scene_->GetComponent<Octree>();
	//octree->RaycastSingle(query);
	octree->Raycast(query);

	if (results.Size())
	{
		for (unsigned int i = 0; i < results.Size(); i++) 
		{
			RayQueryResult& result = results[i];

			Variant fx = result.node_->GetVar("fx");
			if (fx.GetInt() == 1) continue;

			hitPos = result.position_;
			hitNormal = result.normal_;
			hitDrawable = result.drawable_;

			return true;
		}			
	}

	return false;
}
コード例 #10
0
ファイル: Serializer.cpp プロジェクト: cleavetv/Urho3D
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;
    }
}
コード例 #11
0
ファイル: JSONValue.cpp プロジェクト: ElishaMcNutt/Clockwork
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();
    }
}
コード例 #12
0
ファイル: variant.cpp プロジェクト: renokun/Aspen
Variant Variant::operator +(Variant var)
{
    VARIABLE_TYPE vtype = var.Typeof();

    switch(type)
        {
//string
        case VAR_STR:
            switch(vtype)
                {
                case VAR_STR:
                    return Variant(str+var.GetStr());
                case VAR_BYTE:
                    return Variant(str+var.GetByte());
                case VAR_INT:
                    return Variant(str+std::to_string(var.GetInt()));
                case VAR_DOUBLE:
                    return Variant(str + std::to_string(var.GetDouble()));
                default:
                    throw(VariableEmptyException("Tried to add an empty variant to another variant."));
                }
//integer
        case VAR_INT:
            switch(vtype)
                {
                case VAR_INT:
                    return Variant(i32 + var.GetInt());
                case VAR_DOUBLE:
                    return Variant(i32 + var.GetDouble());
                case VAR_BYTE:
                    return Variant(i32 + var.GetByte());
                case VAR_STR:
                    throw(InvalidVariableTypeException("Tried to add a string to an integer."));
                default:
                    throw(VariableEmptyException("Tried to add an empty variant to another variant."));
                }
//double
        case VAR_DOUBLE:
            switch(vtype)
                {
                case VAR_DOUBLE:
                    return Variant(d + var.GetDouble());
                case VAR_INT:
                    return Variant(d + var.GetInt());
                case VAR_BYTE:
                    throw(InvalidVariableTypeException("Tried to add byte to double."));
                case VAR_STR:
                    throw(InvalidVariableTypeException("Tried to add a string to a double."));
                default:
                    throw(VariableEmptyException("Tried to add an empty variant to another variant."));
                }
//byte
        case VAR_BYTE:
            switch(vtype)
                {
                case VAR_INT:
                    return Variant(byte + var.GetInt());
                case VAR_BYTE:
                    return Variant(byte + var.GetByte());
                default:
                    throw(InvalidVariableTypeException("Tried to add byte to an illegal value."));
                }
        default:
            throw(InvalidVariableTypeException("Tried to add empty variable."));
        }
}