#include "xwater.h"

XWater::XWater()
    : XAsset()
    , mWritable()
    , mH0X()
    , mH0Y()
    , mWTerm()
    , mM(0)
    , mN(0)
    , mLx(0)
    , mLz(0)
    , mGravity(0)
    , mWindVel(0)
    , mWindDir(1)
    , mAmplitude(0)
    , mCodeConstant(4)
    , mImage()
{
    
}

XWater::~XWater()
{
    
}

void XWater::ParseData(QDataStream *aStream)
{
    mWritable.ParseData(aStream);

    qint32 h0xPtr, h0yPtr, wTermPtr;
    *aStream
        >> h0xPtr
        >> h0yPtr
        >> wTermPtr
        >> mM
        >> mN
        >> mLx
        >> mLz
        >> mGravity
        >> mWindVel
        >> mWindDir[0]
        >> mWindDir[1]
        >> mAmplitude
        >> mWindDir[0]
        >> mWindDir[1]
        >> mWindDir[2]
        >> mWindDir[3];

    mImage.ParsePtr(aStream, false);

    if (h0xPtr)
    {
        aStream->readRawData(mH0X.data(), 4 * mM * mN);
    }
    if (h0yPtr)
    {
        aStream->readRawData(mH0X.data(), 4 * mM * mN);
    }
    if (wTermPtr)
    {
        aStream->readRawData(mWTerm.data(), 4 * mM * mN);
    }

    mImage.ParseData(aStream);
}

void XWater::Clear()
{
    mWritable.Clear();
    mH0X = 0;
    mH0Y = 0;
    mWTerm = 0;
    mM = 0;
    mN = 0;
    mLx = 0;
    mLz = 0;
    mGravity = 0;
    mWindVel = 0;
    mWindDir.clear();
    mAmplitude = 0;
    mCodeConstant.clear();
    mImage.Clear();
}
