Ejemplo n.º 1
0
void CrowdManager::SetObstacleAvoidanceTypesAttr(const VariantVector& value)
{
    if (!crowd_)
        return;

    unsigned index = 0;
    unsigned obstacleAvoidanceType = 0;
    numObstacleAvoidanceTypes_ = index < value.Size() ? Min(value[index++].GetUInt(), (unsigned)DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS) : 0;

    while (obstacleAvoidanceType < numObstacleAvoidanceTypes_)
    {
        if (index + 10 <= value.Size())
        {
            dtObstacleAvoidanceParams params;
            params.velBias = value[index++].GetFloat();
            params.weightDesVel = value[index++].GetFloat();
            params.weightCurVel = value[index++].GetFloat();
            params.weightSide = value[index++].GetFloat();
            params.weightToi = value[index++].GetFloat();
            params.horizTime = value[index++].GetFloat();
            params.gridSize = (unsigned char)value[index++].GetUInt();
            params.adaptiveDivs = (unsigned char)value[index++].GetUInt();
            params.adaptiveRings = (unsigned char)value[index++].GetUInt();
            params.adaptiveDepth = (unsigned char)value[index++].GetUInt();
            crowd_->setObstacleAvoidanceParams(obstacleAvoidanceType, &params);
        }
        ++obstacleAvoidanceType;
    }
}
Ejemplo n.º 2
0
void AnimationController::SetNodeAnimationStatesAttr(const VariantVector& value)
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    nodeAnimationStates_.Clear();
    unsigned index = 0;
    unsigned numStates = index < value.Size() ? value[index++].GetUInt() : 0;
    // Prevent negative or overly large value being assigned from the editor
    if (numStates > M_MAX_INT)
        numStates = 0;
    if (numStates > MAX_NODE_ANIMATION_STATES)
        numStates = MAX_NODE_ANIMATION_STATES;

    nodeAnimationStates_.Reserve(numStates);
    while (numStates--)
    {
        if (index + 2 < value.Size())
        {
            // Note: null animation is allowed here for editing
            const ResourceRef& animRef = value[index++].GetResourceRef();
            SharedPtr<AnimationState> newState(new AnimationState(GetNode(), cache->GetResource<Animation>(animRef.name_)));
            nodeAnimationStates_.Push(newState);

            newState->SetLooped(value[index++].GetBool());
            newState->SetTime(value[index++].GetFloat());
        }
        else
        {
            // If not enough data, just add an empty animation state
            SharedPtr<AnimationState> newState(new AnimationState(GetNode(), 0));
            nodeAnimationStates_.Push(newState);
        }
    }
}
Ejemplo n.º 3
0
void CrowdManager::SetQueryFilterTypesAttr(const VariantVector& value)
{
    if (!crowd_)
        return;

    unsigned index = 0;
    unsigned queryFilterType = 0;
    numQueryFilterTypes_ = index < value.Size() ? Min(value[index++].GetUInt(), (unsigned)DT_CROWD_MAX_QUERY_FILTER_TYPE) : 0;

    while (queryFilterType < numQueryFilterTypes_)
    {
        if (index + 3 <= value.Size())
        {
            dtQueryFilter* filter = crowd_->getEditableFilter(queryFilterType);
            assert(filter);
            filter->setIncludeFlags((unsigned short)value[index++].GetUInt());
            filter->setExcludeFlags((unsigned short)value[index++].GetUInt());
            unsigned prevNumAreas = numAreas_[queryFilterType];
            numAreas_[queryFilterType] = Min(value[index++].GetUInt(), (unsigned)DT_MAX_AREAS);

            // Must loop through based on previous number of areas, the new area cost (if any) can only be set in the next attribute get/set iteration
            if (index + prevNumAreas <= value.Size())
            {
                for (unsigned i = 0; i < prevNumAreas; ++i)
                    filter->setAreaCost(i, value[index++].GetFloat());
            }
        }
        ++queryFilterType;
    }
}
Ejemplo n.º 4
0
void StaticModelGroup::SetNodeIDsAttr(const VariantVector& value)
{
    // Just remember the node IDs. They need to go through the SceneResolver, and we actually find the nodes during
    // ApplyAttributes()
    if (value.Size())
    {
        nodeIDsAttr_.Clear();
        
        unsigned index = 0;
        unsigned numInstances = value[index++].GetUInt();
        // Prevent crash on entering negative value in the editor
        if (numInstances > M_MAX_INT)
            numInstances = 0;
        
        nodeIDsAttr_.Push(numInstances);
        while (numInstances--)
        {
            // If vector contains less IDs than should, fill the rest with zeroes
            if (index < value.Size())
                nodeIDsAttr_.Push(value[index++].GetUInt());
            else
                nodeIDsAttr_.Push(0);
        }
    }
    else
    {
        nodeIDsAttr_.Clear();
        nodeIDsAttr_.Push(0);
    }
    nodeIDsDirty_ = true;
}
Ejemplo n.º 5
0
void AnimationController::SetAnimationsAttr(VariantVector value)
{
    animations_.Clear();
    animations_.Reserve(value.Size() / 5);  // Incomplete data is discarded
    unsigned index = 0;
    while (index + 4 < value.Size())    // Prevent out-of-bound index access
    {
        AnimationControl newControl;
        newControl.hash_ = value[index++].GetStringHash();
        newControl.speed_ = value[index++].GetFloat();
        newControl.targetWeight_ = value[index++].GetFloat();
        newControl.fadeTime_ = value[index++].GetFloat();
        newControl.autoFadeTime_ = value[index++].GetFloat();
        animations_.Push(newControl);
    }
}
Ejemplo n.º 6
0
bool Serializer::WriteVariantVector(const VariantVector& value)
{
    bool success = true;
    success &= WriteVLE(value.Size());
    for (VariantVector::ConstIterator i = value.Begin(); i != value.End(); ++i)
        success &= WriteVariant(*i);
    return success;
}
Ejemplo n.º 7
0
void Cursor::SetShapesAttr(const VariantVector& value)
{
    if (!value.Size())
        return;

    for (VariantVector::ConstIterator i = value.Begin(); i != value.End(); ++i)
    {
        VariantVector shapeVector = i->GetVariantVector();
        if (shapeVector.Size() >= 4)
        {
            String shape = shapeVector[0].GetString();
            ResourceRef ref = shapeVector[1].GetResourceRef();
            IntRect imageRect = shapeVector[2].GetIntRect();
            IntVector2 hotSpot = shapeVector[3].GetIntVector2();

            DefineShape(shape, GetSubsystem<ResourceCache>()->GetResource<Image>(ref.name_), imageRect, hotSpot);
        }
    }
}
Ejemplo n.º 8
0
void AnimatedModel::SetAnimationStatesAttr(const VariantVector& value)
{
    auto* cache = GetSubsystem<ResourceCache>();
    RemoveAllAnimationStates();
    unsigned index = 0;
    unsigned numStates = index < value.Size() ? value[index++].GetUInt() : 0;
    // Prevent negative or overly large value being assigned from the editor
    if (numStates > M_MAX_INT)
        numStates = 0;
    if (numStates > MAX_ANIMATION_STATES)
        numStates = MAX_ANIMATION_STATES;

    animationStates_.Reserve(numStates);
    while (numStates--)
    {
        if (index + 5 < value.Size())
        {
            // Note: null animation is allowed here for editing
            const ResourceRef& animRef = value[index++].GetResourceRef();
            SharedPtr<AnimationState> newState(new AnimationState(this, cache->GetResource<Animation>(animRef.name_)));
            animationStates_.Push(newState);

            newState->SetStartBone(skeleton_.GetBone(value[index++].GetString()));
            newState->SetLooped(value[index++].GetBool());
            newState->SetWeight(value[index++].GetFloat());
            newState->SetTime(value[index++].GetFloat());
            newState->SetLayer((unsigned char)value[index++].GetInt());
        }
        else
        {
            // If not enough data, just add an empty animation state
            SharedPtr<AnimationState> newState(new AnimationState(this, nullptr));
            animationStates_.Push(newState);
        }
    }

    if (animationStates_.Size())
    {
        MarkAnimationDirty();
        MarkAnimationOrderDirty();
    }
}
Ejemplo n.º 9
0
void Cursor::SetShapesAttr(VariantVector value)
{
    unsigned index = 0;
    if (!value.Size())
        return;

    unsigned numShapes = value[index++].GetUInt();
    while (numShapes-- && (index + 4) <= value.Size())
    {
        CursorShape shape = (CursorShape)GetStringListIndex(value[index++].GetString().CString(), shapeNames, CS_MAX_SHAPES);
        if (shape != CS_MAX_SHAPES)
        {
            ResourceRef ref = value[index++].GetResourceRef();
            IntRect imageRect = value[index++].GetIntRect();
            IntVector2 hotSpot = value[index++].GetIntVector2();
            DefineShape(shape, GetSubsystem<ResourceCache>()->GetResource<Image>(ref.name_), imageRect, hotSpot);
        }
        else
            index += 3;
    }
}
Ejemplo n.º 10
0
void BillboardSet::SetBillboardsAttr(const VariantVector& value)
{
    unsigned index = 0;
    unsigned numBillboards = index < value.Size() ? value[index++].GetUInt() : 0;
    SetNumBillboards(numBillboards);

    // Dealing with old billboard format
    if (value.Size() == billboards_.Size() * 6 + 1)
    {
        for (PODVector<Billboard>::Iterator i = billboards_.Begin(); i != billboards_.End() && index < value.Size(); ++i)
        {
            i->position_ = value[index++].GetVector3();
            i->size_ = value[index++].GetVector2();
            Vector4 uv = value[index++].GetVector4();
            i->uv_ = Rect(uv.x_, uv.y_, uv.z_, uv.w_);
            i->color_ = value[index++].GetColor();
            i->rotation_ = value[index++].GetFloat();
            i->enabled_ = value[index++].GetBool();
        }
    }
    // New billboard format
    else
    {
        for (PODVector<Billboard>::Iterator i = billboards_.Begin(); i != billboards_.End() && index < value.Size(); ++i)
        {
            i->position_ = value[index++].GetVector3();
            i->size_ = value[index++].GetVector2();
            Vector4 uv = value[index++].GetVector4();
            i->uv_ = Rect(uv.x_, uv.y_, uv.z_, uv.w_);
            i->color_ = value[index++].GetColor();
            i->rotation_ = value[index++].GetFloat();
            i->direction_ = value[index++].GetVector3();
            i->enabled_ = value[index++].GetBool();
        }
    }

    Commit();
}
Ejemplo n.º 11
0
void StaticModel::SetGeometryEnabledAttr(const VariantVector& value)
{
    if (!value.Size() || value.Size() != geometryData_.Size())
    {
        geometryDisabled_ = false;
        geometryEnabled_.Clear();
        return;
    }

    bool init = !geometryEnabled_.Size();

    geometryEnabled_ = value;

    for (unsigned i = 0; i < geometryData_.Size(); i++)
    {
        geometryData_[i].enabled_ = geometryEnabled_[i].GetBool();
        if (!geometryData_[i].enabled_)
            geometryDisabled_ = true;
        if (init)
            geometryData_[i].batchGeometry_ = 0;
    }

}
Ejemplo n.º 12
0
void RaycastVehicle::SetWheelDataAttr(const VariantVector& value)
{
    if (!vehicleData_)
    {
        URHO3D_LOGERROR("RaycastVehicle: vehicleData doesn't exist");
        return;
    }
    if (value.Size() < 2)
    {
        URHO3D_LOGERROR("RaycastVehicle: Incorrect vehicleData");
        return;
    }

    loadedWheelData_ = value;
}
Ejemplo n.º 13
0
void ParticleEmitter::SetTextureFramesAttr(VariantVector value)
{
    unsigned index = 0;
    unsigned numFrames = index < value.Size() ? value[index++].GetUInt() : 0;
    // Prevent negative value being assigned from the editor
    if (numFrames > M_MAX_INT)
        numFrames = 0;
    
    textureFrames_.Resize(numFrames);
    for (Vector<TextureFrame>::Iterator i = textureFrames_.Begin(); i < textureFrames_.End() && index < value.Size(); ++i)
    {
        i->uv_ = value[index++].GetVector4();
        i->time_ = value[index++].GetFloat();
    }
}
Ejemplo n.º 14
0
void ParticleEmitter::SetColorsAttr(VariantVector value)
{
    unsigned index = 0;
    unsigned numColors = index < value.Size() ? value[index++].GetUInt() : 0;
    // Prevent negative value being assigned from the editor
    if (numColors > M_MAX_INT)
        numColors = 0;
    
    colorFrames_.Resize(numColors);
    for (Vector<ColorFrame>::Iterator i = colorFrames_.Begin(); i < colorFrames_.End() && index < value.Size(); ++i)
    {
        i->color_ = value[index++].GetColor();
        i->time_ = value[index++].GetFloat();
    }
}
Ejemplo n.º 15
0
void ParticleEmitter::SetParticlesAttr(VariantVector value)
{
    unsigned index = 0;
    SetNumParticles(index < value.Size() ? value[index++].GetUInt() : 0);
    
    for (PODVector<Particle>::Iterator i = particles_.Begin(); i != particles_.End() && index < value.Size(); ++i)
    {
        i->velocity_ = value[index++].GetVector3();
        i->size_ = value[index++].GetVector2();
        i->timer_ = value[index++].GetFloat();
        i->timeToLive_ = value[index++].GetFloat();
        i->scale_ = value[index++].GetFloat();
        i->rotationSpeed_ = value[index++].GetFloat();
        i->colorIndex_ = value[index++].GetInt();
        i->texIndex_ = value[index++].GetInt();
    }
}
Ejemplo n.º 16
0
void BillboardSet::SetBillboardsAttr(VariantVector value)
{
    unsigned index = 0;
    unsigned numBillboards = index < value.Size() ? value[index++].GetUInt() : 0;
    SetNumBillboards(numBillboards);
    
    for (PODVector<Billboard>::Iterator i = billboards_.Begin(); i != billboards_.End() && index < value.Size(); ++i)
    {
        i->position_ = value[index++].GetVector3();
        i->size_ = value[index++].GetVector2();
        Vector4 uv = value[index++].GetVector4();
        i->uv_ = Rect(uv.x_, uv.y_, uv.z_, uv.w_);
        i->color_ = value[index++].GetColor();
        i->rotation_ = value[index++].GetFloat();
        i->enabled_ = value[index++].GetBool();
    }
    
    Commit();
}
Ejemplo n.º 17
0
VariantVector RaycastVehicle::GetWheelDataAttr() const
{
    VariantVector ret;
    ret.Reserve(GetNumWheels() * 22 + 1);
    ret.Push(GetNumWheels());
    for (int i = 0; i < GetNumWheels(); i++)
    {
        Node* wNode = GetWheelNode(i);
        int node_id = wNode->GetID();
        URHO3D_LOGDEBUG("RaycastVehicle: Saving node id = " + String(node_id));
        ret.Push(node_id);
        ret.Push(GetWheelDirection(i));
        ret.Push(GetWheelAxle(i));
        ret.Push(GetWheelRestLength(i));
        ret.Push(GetWheelRadius(i));
        ret.Push(IsFrontWheel(i));
        ret.Push(GetSteeringValue(i));
        ret.Push(GetWheelConnectionPoint(i));
        ret.Push(origRotation_[i]);
        ret.Push(GetWheelSkidInfoCumulative(i));
        ret.Push(GetWheelSideSlipSpeed(i));
        ret.Push(WheelIsGrounded(i));
        ret.Push(GetContactPosition(i));
        ret.Push(GetContactNormal(i));       // 14
        ret.Push(GetWheelSuspensionStiffness(i));
        ret.Push(GetWheelDampingRelaxation(i));
        ret.Push(GetWheelDampingCompression(i));
        ret.Push(GetWheelFrictionSlip(i));
        ret.Push(GetWheelRollInfluence(i));
        ret.Push(GetEngineForce(i));
        ret.Push(GetBrake(i));
        ret.Push(GetWheelSkidInfo(i));
    }
    URHO3D_LOGDEBUG("RaycastVehicle: saved items: " + String(ret.Size()));
    URHO3D_LOGDEBUG("maxSideSlipSpeed_ value save: " + String(maxSideSlipSpeed_));
    return ret;
}
Ejemplo n.º 18
0
void ScriptFile::SetParameters(asIScriptContext* context, asIScriptFunction* function, const VariantVector& parameters)
{
    unsigned paramCount = function->GetParamCount();
    for (unsigned i = 0; i < parameters.Size() && i < paramCount; ++i)
    {
        int paramType = function->GetParamTypeId(i);
        
        switch (paramType)
        {
        case asTYPEID_BOOL:
            context->SetArgByte(i, (unsigned char)parameters[i].GetBool());
            break;
            
        case asTYPEID_INT8:
        case asTYPEID_UINT8:
            context->SetArgByte(i, parameters[i].GetInt());
            break;
            
        case asTYPEID_INT16:
        case asTYPEID_UINT16:
            context->SetArgWord(i, parameters[i].GetInt());
            break;
            
        case asTYPEID_INT32:
        case asTYPEID_UINT32:
            context->SetArgDWord(i, parameters[i].GetInt());
            break;
            
        case asTYPEID_FLOAT:
            context->SetArgFloat(i, parameters[i].GetFloat());
            break;
            
        default:
            if (paramType & asTYPEID_APPOBJECT)
            {
                switch (parameters[i].GetType())
                {
                case VAR_VECTOR2:
                    context->SetArgObject(i, (void*)&parameters[i].GetVector2());
                    break;
                    
                case VAR_VECTOR3:
                    context->SetArgObject(i, (void*)&parameters[i].GetVector3());
                    break;
                    
                case VAR_VECTOR4:
                    context->SetArgObject(i, (void*)&parameters[i].GetVector4());
                    break;
                    
                case VAR_QUATERNION:
                    context->SetArgObject(i, (void*)&parameters[i].GetQuaternion());
                    break;
                    
                case VAR_STRING:
                    context->SetArgObject(i, (void*)&parameters[i].GetString());
                    break;
                    
                case VAR_VOIDPTR:
                    context->SetArgObject(i, parameters[i].GetVoidPtr());
                    break;
                    
                case VAR_PTR:
                    context->SetArgObject(i, (void*)parameters[i].GetPtr());
                    break;
                    
                default:
                    break;
                }
            }
            break;
        }
    }
}
Ejemplo n.º 19
0
void JSONValue::SetVariantVector(const VariantVector& variantVector, Context* context)
{
    SetType(JSON_ARRAY);
    for (unsigned i = 0; i < variantVector.Size(); ++i)
        (*this)[i].SetVariant(variantVector[i]);
}
Ejemplo n.º 20
0
void AnimatedModel::SetBonesEnabledAttr(const VariantVector& value)
{
    Vector<Bone>& bones = skeleton_.GetModifiableBones();
    for (unsigned i = 0; i < bones.Size() && i < value.Size(); ++i)
        bones[i].animated_ = value[i].GetBool();
}