Exemplo n.º 1
0
plServerGuid plServerGuid::FromString(const plString& str) {
    plServerGuid guid;
    for (size_t i=0; i<8; i++) {
        char x = str[(2*i)  ];
        char y = str[(2*i)+1];
        if (x >= '0' && x <= '9')
            guid[i] = x - '0';
        else if (x >= 'A' && x <= 'F')
            guid[i] = (x - 'A') + 10;
        else if (x >= 'a' && x <= 'f')
            guid[i] = (x - 'a') + 10;
        else
            throw hsBadParamException(__FILE__, __LINE__, "Bad hex character");

        guid[i] <<= 4;
        if (y >= '0' && y <= '9')
            guid[i] += y - '0';
        else if (y >= 'A' && y <= 'F')
            guid[i] += (y - 'A') + 10;
        else if (y >= 'a' && y <= 'f')
            guid[i] += (y - 'a') + 10;
        else
            throw hsBadParamException(__FILE__, __LINE__, "Bad hex character");
    }
    return guid;
}
Exemplo n.º 2
0
void plVaultStore::ImportFile(const char* filename) {
    hsStream* S;
    if (plEncryptedStream::IsFileEncrypted(filename)) {
        S = new plEncryptedStream();
        ((plEncryptedStream*)S)->open(filename, fmRead, plEncryptedStream::kEncAuto);
    } else {
        S = new hsFileStream();
        ((hsFileStream*)S)->open(filename, fmRead);
    }

    if (S->readByte() != 1) {
        delete S;
        throw hsBadParamException(__FILE__, __LINE__, "Incorrect Vault File Version");
    }

    hsBitVector fileFields;
    fileFields.read(S);
    if (fileFields[0]) {
        if (S->readByte() != 3) {
            delete S;
            throw hsBadParamException(__FILE__, __LINE__, "Incorrect Vault Version");
        }

        hsBitVector vaultFields;
        vaultFields.read(S);
        if (vaultFields[0]) {
            fLastNodeID = S->readInt();
        }
        if (vaultFields[2]) {
            size_t numNodes = S->readInt();
            for (size_t i=0; i<numNodes; i++) {
                plVaultNode node;
                node.read(S);
                fNodes[node.getNodeID()] = node;
            }
            if (numNodes > 0)
                fFirstNodeID = fNodes.begin()->first;
        }
        if (vaultFields[1]) {
            size_t numRefs = S->readInt();
            for (size_t i=0; i<numRefs; i++) {
                plVaultNodeRef ref;
                ref.read(S);
                fNodeRefs.push_back(ref);
            }
        }
    }

    delete S;
}
Exemplo n.º 3
0
pfSizedStream::pfSizedStream(hsStream* S, uint32_t len)
        : fBase(S), fLength(len) {
    if (S != NULL) {
        ver = S->getVer();

        fBegin = S->pos();

        if (S->size() - fBegin < len) {
            throw hsBadParamException(__FILE__, __LINE__, "Stream too small");
        }
    } else {
        throw hsBadParamException(__FILE__, __LINE__, "Null Stream");
    }
}
Exemplo n.º 4
0
void plStateDataRecord::read(hsStream* S, plResManager* mgr) {
    fFlags = S->readShort();
    if (S->readByte() != kIOVersion || fDescriptor == NULL)
        throw hsBadParamException(__FILE__, __LINE__);

    for (size_t i=0; i<fDescriptor->getNumVars(); i++)
        fAllVars[i]->SetFromDefault();

    size_t num = plSDL::VariableLengthRead(S, fDescriptor->getNumVars());
    bool all = (num == fVarsList.getSize());
    for (size_t i=0; i<num; i++) {
        size_t idx;
        if (!all)
            idx = plSDL::VariableLengthRead(S, fDescriptor->getNumVars());
        else
            idx = i;
        fVarsList[idx]->read(S, mgr);
        fVarsList[idx]->setDirty();
    }

    num = plSDL::VariableLengthRead(S, fDescriptor->getNumVars());
    all = (num == fSDVarsList.getSize());
    for (size_t i=0; i<num; i++) {
        size_t idx;
        if (!all)
            idx = plSDL::VariableLengthRead(S, fDescriptor->getNumVars());
        else
            idx = i;
        fSDVarsList[idx]->read(S, mgr);
        fSDVarsList[idx]->setDirty();
    }
}
Exemplo n.º 5
0
void plPythonParameter::read(hsStream* S, plResManager* mgr) {
    fID = S->readInt();
    fValueType = PlasmaToMapped(S->readInt(), S->getVer());
    if (fValueType > kNone || fValueType == 0)
        throw hsBadParamException(__FILE__, __LINE__);

    int size = 0;
    switch (fValueType) {
    case kInt:
        fIntValue = S->readInt();
        return;
    case kBoolean:
        fBoolValue = (S->readInt() != 0);
        return;
    case kFloat:
        fFloatValue = S->readFloat();
        return;
    case kString:
    case kAnimationName:
    case kGlobalSDLVar:
    case kSubtitle:
        size = S->readInt();
        if (size == 0) {
            fStrValue = "";
            return;
        }
        fStrValue = S->readStr(size);
        return;
    case kNone:
        return;
    default:
        fObjKey = mgr->readKey(S);
        return;
    }
}
Exemplo n.º 6
0
void plSimpleParticleGenerator::write(hsStream* S, plResManager* mgr) {
    S->writeFloat(fGenLife);
    S->writeFloat(fPartLifeMin);
    S->writeFloat(fPartLifeMax);
    S->writeFloat(fParticlesPerSecond);

    if (fInitPos.size() != fInitPitch.size() || fInitPos.size() != fInitYaw.size()) {
        throw hsBadParamException(__FILE__, __LINE__,
                "Init Position, Pitch and Yaw array sizes must match");
    }

    uint32_t count = static_cast<uint32_t>(fInitPos.size());
    S->writeInt(count);
    for (uint32_t i = 0; i < count; ++i) {
        fInitPos[i].write(S);
        S->writeFloat(fInitPitch[i]);
        S->writeFloat(fInitYaw[i]);
    }

    S->writeFloat(fAngleRange);
    S->writeFloat(fVelMin);
    S->writeFloat(fVelMax);
    S->writeFloat(fXSize);
    S->writeFloat(fYSize);
    S->writeFloat(fScaleMin);
    S->writeFloat(fScaleMax);
    S->writeFloat(fPartMassRange);
    S->writeFloat(fPartRadsPerSecRange);
}
Exemplo n.º 7
0
void plGenericPhysical::write(hsStream* S, plResManager* mgr) {
    plSynchedObject::write(S, mgr);

    PhysType wtype;
    if (S->getVer().isUniversal()) {
        wtype = fInternalType;
        S->writeInt(wtype);
    } else if (S->getVer().isNewPlasma()) {
        wtype = kPhysODE;
    } else if (S->getVer().isLive()) {
        wtype = kPhysX;
    } else {
        wtype = kPhysHavok;
    }

    switch (wtype) {
    case kPhysODE:
        IWriteODEPhysical(S, mgr);
        break;
    case kPhysX:
        IWritePXPhysical(S, mgr);
        break;
    case kPhysHavok:
        IWriteHKPhysical(S, mgr);
        break;
    default:
        throw hsBadParamException(__FILE__, __LINE__, "Physics type");
    }
}
Exemplo n.º 8
0
/* plDDPixelFormat */
void plDDSurface::plDDPixelFormat::read(hsStream* S) {
    if (S->readInt() != DDPF_SIZE)
        throw hsBadParamException(__FILE__, __LINE__, "Invalid DDPIXELFORMAT size");

    fFlags = S->readInt();
    fFourCC = S->readInt();
    fBitDepth = S->readInt();
    fRBitMask = S->readInt();
    fGBitMask = S->readInt();
    fBBitMask = S->readInt();
    fAlphaBitMask = S->readInt();

    if (((fFlags & DDPF_FOURCC) != 0) && (fFourCC != FOURCC_DXT1
        && fFourCC != FOURCC_DXT3 && fFourCC != FOURCC_DXT5))
        throw hsBadParamException(__FILE__, __LINE__, "Unsupported DXT compression type");
}
Exemplo n.º 9
0
void plGenericPhysical::read(hsStream* S, plResManager* mgr) {
    plSynchedObject::read(S, mgr);

    if (S->getVer().isUniversal())
        fInternalType = (PhysType)S->readInt();
    else if (S->getVer().isNewPlasma())
        fInternalType = kPhysODE;
    else if (S->getVer().isLive())
        fInternalType = kPhysX;
    else
        fInternalType = kPhysHavok;

    switch (fInternalType) {
    case kPhysODE:
        IReadODEPhysical(S, mgr);
        break;
    case kPhysX:
        IReadPXPhysical(S, mgr);
        break;
    case kPhysHavok:
        IReadHKPhysical(S, mgr);
        break;
    default:
        throw hsBadParamException(__FILE__, __LINE__, "Physics type");
    }
}
Exemplo n.º 10
0
void plBitmap::setConfig(ColorFormat format) {
    switch (format) {
    case kRGB8888:
        fPixelSize = 32;
        fSpace = kDirectSpace;
        fFlags = kAlphaChannelFlag;
        break;
    case kRGB4444:
        fPixelSize = 16;
        fSpace = kDirectSpace;
        fFlags = kAlphaChannelFlag;
        break;
    case kRGB1555:
        fPixelSize = 16;
        fSpace = kDirectSpace;
        fFlags = kAlphaBitFlag;
        break;
    case kInten8:
        fPixelSize = 8;
        fSpace = kGraySpace;
        fFlags = 0;
        break;
    case kAInten88:
        fPixelSize = 16;
        fSpace = kGraySpace;
        fFlags = kAlphaChannelFlag;
        break;
    default:
        throw hsBadParamException(__FILE__, __LINE__, "Invalid pixel configuration");
    }
}
Exemplo n.º 11
0
long pnRC4Socket::peek(void* buf, size_t size)
{
    if (!fEncrypted)
        return pnSocket::peek(buf, size);

    throw hsBadParamException(__FILE__, __LINE__, "Cannot peek on an encrypted socket");
}
Exemplo n.º 12
0
void plOneTimeParticleGenerator::IPrcWrite(pfPrcHelper* prc) {
    prc->startTag("GeneratorParams");
    prc->writeParam("XSize", fXSize);
    prc->writeParam("YSize", fYSize);
    prc->writeParam("ScaleMin", fScaleMin);
    prc->writeParam("ScaleMax", fScaleMax);
    prc->writeParam("RadsPerSecond", fPartRadsPerSecRange);
    prc->endTag(true);

    if (fPosition.size() != fDirection.size()) {
        throw hsBadParamException(__FILE__, __LINE__,
                "Position and Direction array sizes must match");
    }

    prc->writeSimpleTag("ParticleSources");
    for (size_t i = 0; i < fPosition.size(); ++i) {
        prc->writeSimpleTag("Source");
        prc->writeSimpleTag("Position");
        fPosition[i].prcWrite(prc);
        prc->closeTag();
        prc->writeSimpleTag("Direction");
        fDirection[i].prcWrite(prc);
        prc->closeTag();
        prc->closeTag();  // Source
    }
    prc->closeTag();
}
Exemplo n.º 13
0
void plMD5Hash::fromHex(const char* hex) {
    HashConvert hc;

    if (strlen(hex) != 32)
        throw hsBadParamException(__FILE__, __LINE__, "Invalid hex string");
    for (size_t i=0; i<16; i++) {
        int ch1 = charToHex(hex[(2*i)    ]);
        int ch2 = charToHex(hex[(2*i) + 1]);
        if (ch1 == -1 || ch2 == -1)
            throw hsBadParamException(__FILE__, __LINE__, "Invalid hex string");
        hc.hash8[i] = ((ch1 << 4) & 0xF0) | (ch2 & 0x0F);
    }

    fHash[0] = LESWAP32(hc.hash32[0]);
    fHash[1] = LESWAP32(hc.hash32[1]);
    fHash[2] = LESWAP32(hc.hash32[2]);
    fHash[3] = LESWAP32(hc.hash32[3]);
}
Exemplo n.º 14
0
void plLeafController::IReadUruController(hsStream* S) {
    switch (ClassIndex()) {
    case kEaseController:
        if (S->readInt() != 0) {
            AllocKeys(S->readInt(), hsKeyFrame::kScalarKeyFrame);
            for (size_t i=0; i<fKeys.getSize(); i++)
                fKeys[i]->read(S, fType);
        } else {
            AllocKeys(0, 0);
        }
        break;
    case kMatrix33Controller:
        AllocKeys(S->readInt(), hsKeyFrame::kMatrix33KeyFrame);
        for (size_t i=0; i<fKeys.getSize(); i++)
            fKeys[i]->read(S, fType);
        break;
    case kMatrix44Controller:
        AllocKeys(S->readInt(), hsKeyFrame::kMatrix44KeyFrame);
        for (size_t i=0; i<fKeys.getSize(); i++)
            fKeys[i]->read(S, fType);
        break;
    case kPoint3Controller:
        if (S->readInt() != 0) {
            AllocKeys(S->readInt(), hsKeyFrame::kPoint3KeyFrame);
            for (size_t i=0; i<fKeys.getSize(); i++)
                fKeys[i]->read(S, fType);
        } else {
            AllocKeys(0, 0);
        }
        break;
    case kQuatController:
        AllocKeys(S->readInt(), hsKeyFrame::kQuatKeyFrame);
        for (size_t i=0; i<fKeys.getSize(); i++)
            fKeys[i]->read(S, fType);
        break;
    case kScalarController:
        if (S->readInt() != 0) {
            AllocKeys(S->readInt(), hsKeyFrame::kScalarKeyFrame);
            for (size_t i=0; i<fKeys.getSize(); i++)
                fKeys[i]->read(S, fType);
        } else {
            AllocKeys(0, 0);
        }
        break;
    case kScaleValueController:
        AllocKeys(S->readInt(), hsKeyFrame::kScaleKeyFrame);
        for (size_t i=0; i<fKeys.getSize(); i++)
            fKeys[i]->read(S, fType);
        break;
    default:
        plString err = plString::Format("Unexpected class type [%04X]", ClassIndex());
        throw hsBadParamException(__FILE__, __LINE__, err);
    }

    if (fKeys.getSize() > 0)
        fType = fKeys[0]->getType();
}
Exemplo n.º 15
0
void plLeafController::IWriteUruController(hsStream* S) {
    switch (ClassIndex()) {
    case kEaseController:
        if (fKeys.getSize() == 0) {
            S->writeInt(0);
        } else {
            S->writeInt(1);
            S->writeInt(fKeys.getSize());
            for (size_t i=0; i<fKeys.getSize(); i++)
                fKeys[i]->write(S);
        }
        break;
    case kMatrix33Controller:
        S->writeInt(fKeys.getSize());
        for (size_t i=0; i<fKeys.getSize(); i++)
            fKeys[i]->write(S);
        break;
    case kMatrix44Controller:
        S->writeInt(fKeys.getSize());
        for (size_t i=0; i<fKeys.getSize(); i++)
            fKeys[i]->write(S);
        break;
    case kPoint3Controller:
        if (fKeys.getSize() == 0) {
            S->writeInt(0);
        } else {
            S->writeInt(1);
            S->writeInt(fKeys.getSize());
            for (size_t i=0; i<fKeys.getSize(); i++)
                fKeys[i]->write(S);
        }
        break;
    case kQuatController:
        S->writeInt(fKeys.getSize());
        for (size_t i=0; i<fKeys.getSize(); i++)
            fKeys[i]->write(S);
        break;
    case kScalarController:
        if (fKeys.getSize() == 0) {
            S->writeInt(0);
        } else {
            S->writeInt(1);
            S->writeInt(fKeys.getSize());
            for (size_t i=0; i<fKeys.getSize(); i++)
                fKeys[i]->write(S);
        }
        break;
    case kScaleValueController:
        S->writeInt(fKeys.getSize());
        for (size_t i=0; i<fKeys.getSize(); i++)
            fKeys[i]->write(S);
        break;
    default:
        plString err = plString::Format("Unexpected class type [%04X]", ClassIndex());
        throw hsBadParamException(__FILE__, __LINE__, err);
    }
}
Exemplo n.º 16
0
void plUoid::prcParse(const pfPrcTag* tag) {
    if (tag->getName() != "plKey")
        throw hsBadParamException(__FILE__, __LINE__, "Tag name mismatch");

    objName = tag->getParam("Name", "");
    classType = plFactory::ClassIndex(tag->getParam("Type", ""));
    location.prcParse(tag);
    loadMask.prcParse(tag);
    cloneID = tag->getParam("CloneID", "0").toUint();
    clonePlayerID = tag->getParam("ClonePlayerID", "0").toUint();
}
Exemplo n.º 17
0
void plGenericPhysical::IWriteHKPhysical(hsStream* S, plResManager* mgr) {

    unsigned int memGroup = plHKSimDefs::setMemGroup(this);
    unsigned int repGroup = plHKSimDefs::setRepGroup(this);
    unsigned int colGroup = plHKSimDefs::setColGroup(this);


    fPos.write(S);
    S->writeFloat(fRot.W);
    S->writeFloat(fRot.X);
    S->writeFloat(fRot.Y);
    S->writeFloat(fRot.Z);

    S->writeFloat(fMass);
    S->writeFloat(fFriction);
    S->writeFloat(fRestitution);

    if (fBounds == plSimDefs::kCylinderBounds) {
        throw hsBadParamException(__FILE__, __LINE__,
                "Invalid Bounds type");
    }
    S->writeInt(fBounds);

    S->writeInt(memGroup);
    S->writeInt(repGroup);
    S->writeInt(colGroup);

    S->writeBool(fDisableReport);
    S->writeBool(fDisableCollide);

    if (fBounds == plSimDefs::kHullBounds) {
        S->writeInt(fVerts.size());
        for (size_t i=0; i<fVerts.size(); i++)
            fVerts[i].write(S);
    } else if (fBounds == plSimDefs::kSphereBounds) {
        fOffset.write(S);
        S->writeFloat(fRadius);
    } else {    // Box, Proxy, Explicit
        S->writeInt(fVerts.size());
        for (size_t i=0; i<fVerts.size(); i++)
            fVerts[i].write(S);
        S->writeInt(fIndices.size() / 3);
        for (size_t i=0; i<fIndices.size(); i++)
            S->writeShort(fIndices[i]);
    }

    mgr->writeKey(S, fObjectKey);
    fProps.write(S);
    mgr->writeKey(S, fSceneNode);
    S->writeInt(fLOSDBs);
    mgr->writeKey(S, fSubWorld);
    mgr->writeKey(S, fSoundGroup);
}
Exemplo n.º 18
0
void plDDSurface::write(hsStream* S) {
    if (fDataSize != calcTotalBufferSize()) {
        plDebug::Debug("Data format does not match buffer size: %d, %d",
                       fDataSize, calcTotalBufferSize());
    }

    S->write(4, "DDS ");
    S->writeInt(DDSD2_SIZE);

    S->writeInt(fFlags);
    S->writeInt(fHeight);
    S->writeInt(fWidth);
    S->writeInt(fLinearSize);
    S->writeInt(fBackBufferCount);
    S->writeInt(fMipmapCount);
    S->writeInt(fAlphaDepth);
    S->writeInt(0);                 // Reserved
    S->writeInt(0);                 // lpSurface
    fCKDestOverlay.write(S);
    fCKDestBlt.write(S);
    fCKSrcOverlay.write(S);
    fCKSrcBlt.write(S);

    switch (fFlags & (DDSD_FVF | DDSD_PIXELFORMAT)) {
    case 0:
    case DDSD_PIXELFORMAT:
        fPixelFormat.write(S);
        break;
    case DDSD_FVF:
        S->writeInt(fFVF);
        S->writeInt(0);     // Ignored
        S->writeInt(0);
        S->writeInt(0);
        S->writeInt(0);
        S->writeInt(0);
        S->writeInt(0);
        S->writeInt(0);
        break;
    default:
        throw hsBadParamException(__FILE__, __LINE__, "DDSURFACEDESC may not have both DDSD_PIXELFORMAT and DDSD_FVF");
    }

    S->writeInt(fCaps);
    S->writeInt(fCaps2);
    S->writeInt(fCaps3);
    S->writeInt(fCaps4);
    S->writeInt(fTextureStage);

    if (fDataBuffer != NULL)
        S->write(fDataSize, fDataBuffer);
}
Exemplo n.º 19
0
void plDDSurface::plDDPixelFormat::write(hsStream* S) {
    if (((fFlags & DDPF_FOURCC) != 0) && (fFourCC != FOURCC_DXT1
        && fFourCC != FOURCC_DXT3 && fFourCC != FOURCC_DXT5))
        throw hsBadParamException(__FILE__, __LINE__, "Unsupported DXT compression type");

    S->writeInt(DDPF_SIZE);
    S->writeInt(fFlags);
    S->writeInt(fFourCC);
    S->writeInt(fBitDepth);
    S->writeInt(fRBitMask);
    S->writeInt(fGBitMask);
    S->writeInt(fBBitMask);
    S->writeInt(fAlphaBitMask);
}
Exemplo n.º 20
0
void plStateDescriptor::read(hsStream* S) {
    if (S->readByte() != 1)
        throw hsBadParamException(__FILE__, __LINE__, "Bad plStateDescriptor IO Version");
    fName = S->readSafeStr();
    fVersion = S->readShort();

    clearVariables();
    fVariables.resize(S->readShort());
    for (size_t i=0; i<fVariables.size(); i++) {
        fVariables[i] = new plVarDescriptor();
        S->readBool();  // Redundant - tells us whether this is an SDVar or a SimpleVar
        fVariables[i]->read(S);
    }
}
Exemplo n.º 21
0
void plKeyData::setObj(class hsKeyedObject* obj) {
    if (obj == fObjPtr)
        return;

    if (fObjPtr != NULL && !fObjPtr->isStub())
        throw hsBadParamException(__FILE__, __LINE__, "Trying to change already loaded object");

    fObjPtr = obj;

    if (obj && !obj->isStub()) {
        for (auto it = fCallbacks.begin(); it != fCallbacks.end(); it++)
            (*it)(obj);

        fCallbacks.clear();
    }
}
Exemplo n.º 22
0
void plMipmap::Create(unsigned int width, unsigned int height, unsigned char numLevels,
                      unsigned char compType, ColorFormat format, unsigned char dxtLevel) {
    delete[] fImageData;
    delete[] fJPEGData;
    delete[] fJAlphaData;

    if (compType == kDirectXCompression && dxtLevel == kDXTError)
        throw hsBadParamException(__FILE__, __LINE__, "DXT Type must be set for DirectX textures");

    fCompressionType = compType;
    if (compType == kUncompressed || compType == kJPEGCompression) {
        setConfig(format);
        fUncompressedInfo.fType = format;
    } else {
        fPixelSize = 32;
        fSpace = kDirectSpace;
        fDXInfo.fCompressionType = dxtLevel;
        if (dxtLevel == kDXT1) {
            fDXInfo.fBlockSize = 8;
            fFlags = kAlphaBitFlag;
        } else {
            fDXInfo.fBlockSize = 16;
            fFlags = kAlphaChannelFlag;
        }
    }

    fWidth = width;
    fHeight = height;
    fStride = (fPixelSize * fWidth) / 8;

    if (fWidth == 0 || fHeight == 0) {
        fLevelData.clear();
        fTotalSize = 0;
        fImageData = NULL;
        fJPEGData = NULL;
        fJAlphaData = NULL;
        return;
    }

    if (numLevels == 0) {
        numLevels = 1;
        while (width > 1 || height > 1) {
            width = (width > 1) ? width >> 1 : 1;
            height = (height > 1) ? height >> 1 : 1;
            numLevels++;
        }
    }
Exemplo n.º 23
0
void hsThread::start() {
    hsThread_WIN32* _this = (hsThread_WIN32*)fThreadData;

    _this->fMutex.lock();
    if ((_this->fState & kStateRunning) != 0) {
        _this->fMutex.unlock();
        throw hsBadParamException(__FILE__, __LINE__, "Thread already running!");
    }

    _this->fState |= kStateRunning;
    _this->fThreadHandle = CreateThread(NULL, 0, &s_threadstart, this, 0, NULL);
    if (_this->fThreadHandle == NULL) {
        _this->fState = (_this->fState & ~kStateRunning) | kStateFinished;
        fFinishCondition.signal();
    }
    _this->fMutex.unlock();
}
Exemplo n.º 24
0
size_t plDDSurface::calcBufferSize(unsigned int width, unsigned int height) const {
    if ((fFlags & DDSD_HEIGHT) == 0 || (fFlags & DDSD_WIDTH) == 0)
        return 0;
    if ((fFlags & DDSD_PIXELFORMAT) == 0)
        throw hsBadParamException(__FILE__, __LINE__, "Surface has no pixel format descriptor");

    size_t stride, blocks;
    if ((fPixelFormat.fFlags & DDPF_FOURCC) != 0) {
        stride = (fPixelFormat.fFourCC == FOURCC_DXT1) ? 8 : 16;
        blocks = ((width+3)/4) * ((height+3)/4);
    } else {
        stride = ((fPixelFormat.fBitCount * width) + 7) / 8;
        blocks = height;
    }

    return stride * blocks;
}
Exemplo n.º 25
0
void plParticleSystem::read(hsStream* S, plResManager* mgr) {
    plModifier::read(S, mgr);

    fMaterial = mgr->readKey(S);
    setAmbientCtl(plController::Convert(mgr->ReadCreatable(S)));
    setDiffuseCtl(plController::Convert(mgr->ReadCreatable(S)));
    setOpacityCtl(plController::Convert(mgr->ReadCreatable(S)));
    setWidthCtl(plController::Convert(mgr->ReadCreatable(S)));
    setHeightCtl(plController::Convert(mgr->ReadCreatable(S)));

    fXTiles = S->readInt();
    fYTiles = S->readInt();
    fMaxTotalParticles = S->readInt();
    fMaxEmitters = S->readInt();
    fPreSim = S->readFloat();
    fAccel.read(S);
    fDrag = S->readFloat();
    fWindMult = S->readFloat();
    fNumValidEmitters = S->readInt();

    for (auto emi = fEmitters.begin(); emi != fEmitters.end(); ++emi)
        delete *emi;
    fEmitters.resize(fMaxEmitters);
    if (fNumValidEmitters > fMaxEmitters)
        throw hsBadParamException(__FILE__, __LINE__);
    for (size_t i=0; i<fNumValidEmitters; i++)
        fEmitters[i] = plParticleEmitter::Convert(mgr->ReadCreatable(S));
    for (size_t i=fNumValidEmitters; i<fMaxEmitters; i++)
        fEmitters[i] = NULL;

    fForces.resize(S->readInt());
    for (size_t i=0; i<fForces.size(); i++)
        fForces[i] = mgr->readKey(S);
    fEffects.resize(S->readInt());
    for (size_t i=0; i<fEffects.size(); i++)
        fEffects[i] = mgr->readKey(S);
    fConstraints.resize(S->readInt());
    for (size_t i=0; i<fConstraints.size(); i++)
        fConstraints[i] = mgr->readKey(S);

    fPermaLights.resize(S->readInt());
    for (size_t i=0; i<fPermaLights.size(); i++)
        fPermaLights[i] = mgr->readKey(S);
}
Exemplo n.º 26
0
void plOneTimeParticleGenerator::write(hsStream* S, plResManager* mgr) {
    uint32_t count = static_cast<uint32_t>(fPosition.size());
    S->writeInt(count);
    S->writeFloat(fXSize);
    S->writeFloat(fYSize);
    S->writeFloat(fScaleMin);
    S->writeFloat(fScaleMax);
    S->writeFloat(fPartRadsPerSecRange);

    if (fPosition.size() != fDirection.size()) {
        throw hsBadParamException(__FILE__, __LINE__,
                "Position and Direction array sizes must match");
    }

    for (uint32_t i = 0; i < count; ++i) {
        fPosition[i].write(S);
        fDirection[i].write(S);
    }
}
Exemplo n.º 27
0
/* plVarDescriptor */
void plVarDescriptor::read(hsStream* S) {
    if (S->readByte() != 3)
        throw hsBadParamException(__FILE__, __LINE__, "Bad plVarDescriptor IO Version");

    fName = S->readSafeStr();
    size_t len = S->readShort();
    fDisplay = S->readStr(len);
    fCount = S->readInt();
    fType = (plVarDescriptor::Type)S->readByte();
    fDefault = S->readSafeStr();
    fFlags = S->readInt();

    if (fType == kStateDescriptor) {
        fStateDescType = S->readSafeStr();
        fStateDescVer = S->readShort();
    } else {
        S->readShort();     // Atomic count
        S->readByte();      // Atomic type
    }
}
Exemplo n.º 28
0
void plSimpleParticleGenerator::IPrcWrite(pfPrcHelper* prc) {
    prc->startTag("ParticleParams");
    prc->writeParam("GenLife", fGenLife);
    prc->writeParam("PartLifeMin", fPartLifeMin);
    prc->writeParam("PartLifeMax", fPartLifeMax);
    prc->writeParam("ParticlesPerSecond", fParticlesPerSecond);
    prc->writeParam("ParticleMass", fPartMassRange);
    prc->writeParam("RadsPerSecond", fPartRadsPerSecRange);
    prc->endTag(true);

    prc->startTag("GeneratorParams");
    prc->writeParam("AngleRange", fAngleRange);
    prc->writeParam("VelMin", fVelMin);
    prc->writeParam("VelMax", fVelMax);
    prc->writeParam("XSize", fXSize);
    prc->writeParam("YSize", fYSize);
    prc->writeParam("ScaleMin", fScaleMin);
    prc->writeParam("ScaleMax", fScaleMax);
    prc->endTag(true);

    if (fInitPos.size() != fInitPitch.size() || fInitPos.size() != fInitYaw.size()) {
        throw hsBadParamException(__FILE__, __LINE__,
                "Init Position, Pitch and Yaw array sizes must match");
    }

    prc->writeSimpleTag("ParticleSources");
    for (size_t i = 0; i < fInitPos.size(); ++i) {
        prc->startTag("Source");
        prc->writeParam("Pitch", fInitPitch[i]);
        prc->writeParam("Yaw", fInitYaw[i]);
        prc->endTag();
        fInitPos[i].prcWrite(prc);
        prc->closeTag();
    }
    prc->closeTag();
}
Exemplo n.º 29
0
void plDrawableSpans::read(hsStream* S, plResManager* mgr) {
    hsKeyedObject::read(S, mgr);

    fProps = S->readInt();
    fCriteria = S->readInt();
    fRenderLevel = S->readInt();

    fMaterials.setSize(S->readInt());
    for (size_t i=0; i<fMaterials.getSize(); i++)
        fMaterials[i] = mgr->readKey(S);

    for (size_t i=0; i<fSpans.getSize(); i++)
        delete fSpans[i];

    fIcicles.setSize(S->readInt());
    for (size_t i=0; i<fIcicles.getSize(); i++) {
        fIcicles[i] = new plIcicle();
        fIcicles[i]->read(S);
    }

    if (!S->getVer().isHexIsle()) {
        if (S->readInt() != 0)
            throw hsBadParamException(__FILE__, __LINE__, "Unsupported field count > 0");
    }

    fSpans.setSizeNull(S->readInt());
    fSpanSourceIndices.setSizeNull(fSpans.getSize());
    for (size_t i=0; i<fSpanSourceIndices.getSize(); i++) {
        fSpanSourceIndices[i] = S->readInt();
        if ((fSpanSourceIndices[i] & kSpanTypeMask) == kSpanTypeIcicle)
            fSpans[i] = fIcicles[fSpanSourceIndices[i] & kSpanIDMask];
        else if ((fSpanSourceIndices[i] & kSpanTypeMask) == kSpanTypeParticleSpan)
            fSpans[i] = fParticleSpans[fSpanSourceIndices[i] & kSpanIDMask];
    }

    for (size_t i=0; i<fSpans.getSize(); i++)
        fSpans[i]->setFogEnvironment(mgr->readKey(S));

    if (fSpans.getSize() > 0) {
        fLocalBounds.read(S);
        fWorldBounds.read(S);
        fMaxWorldBounds.read(S);
    } else {
        fLocalBounds.setType(hsBounds3::kIsSphere);
        fWorldBounds.setType(hsBounds3::kIsSphere);
        fMaxWorldBounds.setType(hsBounds3::kIsSphere);
    }

    for (size_t i=0; i<fSpans.getSize(); i++) {
        if (fSpans[i]->getProps() & plSpan::kPropHasPermaLights) {
            size_t count = S->readInt();
            for (size_t j=0; j<count; j++)
                fSpans[i]->addPermaLight(mgr->readKey(S));
        }
        if (fSpans[i]->getProps() & plSpan::kPropHasPermaProjs) {
            size_t count = S->readInt();
            for (size_t j=0; j<count; j++)
                fSpans[i]->addPermaProj(mgr->readKey(S));
        }
    }

    fSourceSpans.setSizeNull(S->readInt());
    if (fSourceSpans.getSize() > 0 && !S->getVer().isUniversal())
        plDebug::Debug("Reading deprecated SourceSpans");
    for (size_t i=0; i<fSourceSpans.getSize(); i++) {
        fSourceSpans[i].reset(new plGeometrySpan());
        fSourceSpans[i]->read(S);
        if (fSpans[i]->getMaterialIdx() == 0xFFFFFFFF)
            fSourceSpans[i]->setMaterial(NULL);
        else
            fSourceSpans[i]->setMaterial(fMaterials[fSpans[i]->getMaterialIdx()]);
        fSourceSpans[i]->setFogEnvironment(fSpans[i]->getFogEnvironment());
    }

    size_t xformCount = S->readInt();
    fLocalToWorlds.setSize(xformCount);
    fWorldToLocals.setSize(xformCount);
    fLocalToBones.setSize(xformCount);
    fBoneToLocals.setSize(xformCount);
    for (size_t i=0; i<xformCount; i++) {
        fLocalToWorlds[i].read(S);
        fWorldToLocals[i].read(S);
        fLocalToBones[i].read(S);
        fBoneToLocals[i].read(S);
    }

    fDIIndices.setSize(S->readInt());
    for (size_t i=0; i<fDIIndices.getSize(); i++) {
        fDIIndices[i].fFlags = S->readInt();
        fDIIndices[i].fIndices.setSize(S->readInt());
        for (size_t j=0; j<(fDIIndices[i].fIndices.getSize()); j++)
            fDIIndices[i].fIndices[j] = S->readInt();
    }

    for (size_t i=0; i<fGroups.getSize(); i++)
        delete fGroups[i];
    fGroups.setSizeNull(S->readInt());
    for (size_t i=0; i<fGroups.getSize(); i++) {
        fGroups[i] = new plGBufferGroup(0);
        fGroups[i]->read(S);
    }

    setSpaceTree(plSpaceTree::Convert(mgr->ReadCreatable(S)));
    fSceneNode = mgr->readKey(S);
}
Exemplo n.º 30
0
void plClothingItem::IPrcParse(const pfPrcTag* tag, plResManager* mgr) {
    if (tag->getName() == "ClothingName") {
        fItemName = tag->getParam("value", "");
    } else if (tag->getName() == "ClosetOptions") {
        fGroup = tag->getParam("Group", "0").to_uint();
        fType = tag->getParam("Type", "0").to_uint();
        fTileset = tag->getParam("Tileset", "0").to_uint();
        fSortOrder = tag->getParam("SortOrder", "0").to_uint();
    } else if (tag->getName() == "Description") {
        fDescription = "";
        std::list<ST::string> descTokens = tag->getContents();
        for (auto tok = descTokens.begin(); tok != descTokens.end(); ++tok)
            fDescription += *tok + " ";
    } else if (tag->getName() == "CustomText") {
        fCustomText = tag->getParam("value", "");
    } else if (tag->getName() == "Icon") {
        if (tag->hasChildren())
            fIcon = mgr->prcParseKey(tag->getFirstChild());
    } else if (tag->getName() == "Elements") {
        clearElements();
        fElementNames.resize(tag->countChildren());
        fTextures.resize(fElementNames.size());
        const pfPrcTag* child = tag->getFirstChild();
        for (size_t i=0; i<fElementNames.size(); i++) {
            if (child->getName() != "Element")
                throw pfPrcTagException(__FILE__, __LINE__, child->getName());
            fElementNames[i] = child->getParam("Name", "");
            fTextures[i] = new plKey[10];
            size_t nSubChildren = child->countChildren();
            const pfPrcTag* subChild = child->getFirstChild();
            for (size_t j=0; j<nSubChildren; j++) {
                plKey k = mgr->prcParseKey(subChild);
                if (j < kLayerMax)
                    fTextures[i][j] = k;
                else
                    plDebug::Warning("Throwing away key {}", k.toString());
                subChild = subChild->getNextSibling();
            }
            child = child->getNextSibling();
        }
    } else if (tag->getName() == "Meshes") {
        size_t nMeshes = tag->countChildren();
        if (nMeshes != kNumLODLevels)
            throw hsBadParamException(__FILE__, __LINE__);
        const pfPrcTag* child = tag->getFirstChild();
        for (size_t i=0; i<kNumLODLevels; i++) {
            fMeshes[i] = mgr->prcParseKey(child);
            child = child->getNextSibling();
        }
    } else if (tag->getName() == "Accessory") {
        if (tag->hasChildren())
            fAccessory = mgr->prcParseKey(tag->getFirstChild());
    } else if (tag->getName() == "DefaultTints") {
        const pfPrcTag* child = tag->getFirstChild();
        while (child != NULL) {
            if (child->getName() == "Tint1") {
                fDefaultTint1[0] = child->getParam("red", "0").to_uint();
                fDefaultTint1[1] = child->getParam("green", "0").to_uint();
                fDefaultTint1[2] = child->getParam("blue", "0").to_uint();
            } else if (child->getName() == "Tint2") {
                fDefaultTint2[0] = child->getParam("red", "0").to_uint();
                fDefaultTint2[1] = child->getParam("green", "0").to_uint();
                fDefaultTint2[2] = child->getParam("blue", "0").to_uint();
            } else {
                throw pfPrcTagException(__FILE__, __LINE__, child->getName());
            }
            child = child->getNextSibling();
        }
    } else {
        hsKeyedObject::IPrcParse(tag, mgr);
    }
}