#include "xgfxcell.h"

XGfxCell::XGfxCell()
    : XAsset()
    , mMins()
    , mMaxs()
    , mAabbTreeCount(0)
    , mAabbTree()
    , mPortalCount(0)
    , mPortals()
    , mCullGroupCount(0)
    , mCullGroups()
    , mReflectionProbeCount(0)
    , mReflectionProbes()
{

}

XGfxCell::~XGfxCell()
{

}

void XGfxCell::ParseData(QDataStream *aStream)
{
    qint32 aabbTreePtr, portalsPtr, cullGroupsPtr, reflectionProbesPtr;
    *aStream
        >> mMins[0]
        >> mMins[1]
        >> mMins[2]
        >> mMaxs[0]
        >> mMaxs[1]
        >> mMaxs[2]
        >> mAabbTreeCount
        >> aabbTreePtr
        >> mPortalCount
        >> portalsPtr
        >> mCullGroupCount
        >> cullGroupsPtr
        >> mReflectionProbeCount
        >> reflectionProbesPtr;

    if (aabbTreePtr)
    {
        for (int i = 0; i < mAabbTreeCount; i++)
        {
            XGfxAabbTree newTree;
            newTree.ParseData(aStream);
            mAabbTree.append(newTree);
        }
    }

    if (portalsPtr)
    {
        for (int i = 0; i < mPortalCount; i++)
        {
            XGfxPortal newPortal;
            newPortal.ParseData(aStream);
            mPortals.append(newPortal);
        }
    }

    if (cullGroupsPtr)
    {
        for (int i = 0; i < mCullGroupCount; i++)
        {
            qint32 newCullGroup;
            *aStream >> newCullGroup;
            mCullGroups.append(newCullGroup);
        }
    }

    if (reflectionProbesPtr)
    {
        for (int i = 0; i < mReflectionProbeCount; i++)
        {
            quint8 newReflectionProbe;
            *aStream >> newReflectionProbe;
            mReflectionProbes.append(newReflectionProbe);
        }
    }
}

void XGfxCell::Clear()
{
    mMins = QVector3D();
    mMaxs = QVector3D();
    mAabbTreeCount = 0;
    mAabbTree.clear();
    mPortalCount = 0;
    mPortals.clear();
    mCullGroupCount = 0;
    mCullGroups.clear();
    mReflectionProbeCount = 0;
    mReflectionProbes.clear();
}
