#include "xphyspreset.h"

XPhysPreset::XPhysPreset()
    : XAsset()
    , mName()
    , mType(0)
    , mMass(0)
    , mBounce(0)
    , mFriction(0)
    , mBulletForceScale(0)
    , mExplosiveForceScale(0)
    , mSndAliasPrefix()
    , mPiecesSpreadFraction(0)
    , mPiecesUpwardVelocity(0)
    , mTempDefaultToCylinder(false)
{
    SetType(ASSET_TYPE_PHYSPRESET);
    SetName("Phys Preset");
}

XPhysPreset::~XPhysPreset()
{
    
}

void XPhysPreset::ParseData(XDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        mName.ParsePtr(aStream, false);

        *aStream
            >> mType
            >> mMass;


        quint32 rawTemp;
        *aStream >> rawTemp;
        memcpy(&mBounce, &rawTemp, sizeof(mBounce));
        *aStream >> rawTemp;
        memcpy(&mFriction, &rawTemp, sizeof(mFriction));
        *aStream >> rawTemp;
        memcpy(&mBulletForceScale, &rawTemp, sizeof(mBulletForceScale));
        *aStream >> rawTemp;
        memcpy(&mExplosiveForceScale, &rawTemp, sizeof(mExplosiveForceScale));

        mSndAliasPrefix.ParsePtr(aStream, false);


        *aStream >> rawTemp;
        memcpy(&mPiecesSpreadFraction, &rawTemp, sizeof(mPiecesSpreadFraction));
        *aStream >> rawTemp;
        memcpy(&mPiecesUpwardVelocity, &rawTemp, sizeof(mPiecesUpwardVelocity));

        *aStream >> mTempDefaultToCylinder;

        mName.ParseData(aStream);
        mSndAliasPrefix.ParseData(aStream);
    }
}

void XPhysPreset::Clear()
{
    mName.Clear();
    mType = 0;
    mMass = 0;
    mBounce = 0;
    mFriction = 0;
    mBulletForceScale = 0;
    mExplosiveForceScale = 0;
    mSndAliasPrefix.Clear();
    mPiecesSpreadFraction = 0;
    mPiecesUpwardVelocity = 0;
    mTempDefaultToCylinder = false;
}
