Пример #1
0
void  NULLVC::receive_data_from_comm_port( BYTE *recvBuf, int recvLen, void *scope)
{
    NULLVC *myThis = (NULLVC *)scope;
    DWORD time = GetTickCount();
    BitStream bstream(recvBuf, MaxHeaderSize);

    if(!myThis)
        return;

    log_file.log("NULLVC::receive_data_from_comm_port: %lx bytes, state %lx",recvLen,myThis->getState());
    // is it a game info packet?
    if(!bstream.readFlag())
    {
        myThis->mySession->onReceive(NULL, myThis->addressString, recvBuf, recvLen);
    }
    else
    {
        myThis->receivePacket(recvBuf, recvLen, time);
        if(myThis->getState() == VC::Unbound)
        {
            log_file.log("NULLVC::Unbound VC in receive_data_from_comm_port");
            myThis->deleteVC();
        }
    }
}
Пример #2
0
static void test_buffer(skiatest::Reporter* reporter) {
    SkRandom rand;
    SkAutoMalloc am(MAX_SIZE * 2);
    char* storage = (char*)am.get();
    char* storage2 = storage + MAX_SIZE;

    random_fill(rand, storage, MAX_SIZE);

    for (int sizeTimes = 0; sizeTimes < 100; sizeTimes++) {
        int size = rand.nextU() % MAX_SIZE;
        if (size == 0) {
            size = MAX_SIZE;
        }
        for (int times = 0; times < 100; times++) {
            int bufferSize = 1 + (rand.nextU() & 0xFFFF);
            SkMemoryStream mstream(storage, size);
            SkBufferStream bstream(&mstream, bufferSize);

            int bytesRead = 0;
            while (bytesRead < size) {
                int s = 17 + (rand.nextU() & 0xFFFF);
                int ss = bstream.read(storage2, s);
                REPORTER_ASSERT(reporter, ss > 0 && ss <= s);
                REPORTER_ASSERT(reporter, bytesRead + ss <= size);
                REPORTER_ASSERT(reporter,
                                memcmp(storage + bytesRead, storage2, ss) == 0);
                bytesRead += ss;
            }
            REPORTER_ASSERT(reporter, bytesRead == size);
        }
    }
}
Пример #3
0
 void encodeDynamicVector(float *buffer, size_t componentsCount, size_t count, const GLTFConverterContext& converterContext) {
     GLTFOutputStream *outputStream = converterContext._compressionOutputStream;
     Real max[32];
     Real min[32];
     O3DGCStreamType streamType = converterContext.compressionMode == "ascii" ? O3DGC_STREAM_TYPE_ASCII : O3DGC_STREAM_TYPE_BINARY;
     
     DynamicVector dynamicVector;
     dynamicVector.SetVectors(buffer);
     dynamicVector.SetDimVector(componentsCount);
     dynamicVector.SetMax(max);
     dynamicVector.SetMin(min);
     dynamicVector.SetNVector(count);
     dynamicVector.SetStride(componentsCount);
     dynamicVector.ComputeMinMax(O3DGC_SC3DMC_MAX_SEP_DIM);//O3DGC_SC3DMC_MAX_ALL_DIMS        
     DVEncodeParams params;
     
     params.SetQuantBits(componentsCount == 1 ? 11 : 17); //HACK, if that's 1 component it is the TIME and 10 bits is OK
     params.SetStreamType(streamType);
     
     DynamicVectorEncoder encoder;
     encoder.SetStreamType(streamType);
     Timer timer;
     timer.Tic();
     BinaryStream bstream(componentsCount * count * 16);
     encoder.Encode(params, dynamicVector, bstream);
     timer.Toc();
     outputStream->write((const char*)bstream.GetBuffer(), bstream.GetSize());
     
     /*
     if (componentsCount == 4) {
         DynamicVector  dynamicVector1;
         DynamicVectorDecoder decoder;
         decoder.DecodeHeader(dynamicVector1, bstream);
         dynamicVector1.SetStride(dynamicVector1.GetDimVector());
         
         std::vector<Real> oDV;
         std::vector<Real> oDVMin;
         std::vector<Real> oDVMax;
         oDV.resize(dynamicVector1.GetNVector() * dynamicVector1.GetDimVector());
         oDVMin.resize(dynamicVector1.GetDimVector());
         oDVMax.resize(dynamicVector1.GetDimVector());
         dynamicVector1.SetVectors(& oDV[0]);
         dynamicVector1.SetMin(& oDVMin[0]);
         dynamicVector1.SetMax(& oDVMax[0]);
         decoder.DecodePlayload(dynamicVector1, bstream);
         
         float* dbuffer = (float*)dynamicVector1.GetVectors();
         
         printf("****dump axis-angle. Axis[3] / Angle[1]\n");
         for (int i = 0 ; i < count ; i++) {
             int offset = i * 4;
             printf("[raw]%f %f %f %f [10bits]%f %f %f %f\n",
                    buffer[offset+0],buffer[offset+1],buffer[offset+2],buffer[offset+3],
                    dbuffer[offset+0],dbuffer[offset+1],dbuffer[offset+2],dbuffer[offset+3]);
         }
     }
     */
 }
inline void get_pid_str(pid_str_t &pid_str, OS_process_id_t pid)
{
   bufferstream bstream(pid_str, sizeof(pid_str));
   bstream << pid << std::ends;
}
Пример #5
0
    void stringtable::update(const uint32_t& entries, const std::string& data) const {
        // create bitstream for data field
        bitstream bstream(data);

        // if true, list contains no names only updates
        const uint32_t full = bstream.read(1);

        // index for consecutive incrementing
        int32_t index = -1;

        // key history for key deltas
        std::vector<std::string> keys;

        // read all the entries in the string table
        for (uint32_t i = 0; i < entries; ++i) {
            char key[STRINGTABLE_MAX_KEY_SIZE] = {'\0'};
            char value[STRINGTABLE_MAX_VALUE_SIZE] = {'\0'};

            const bool increment = bstream.read(1);
            if (increment) {
                ++index;
            } else {
                index = bstream.read(std::ceil(log2(maxEntries)));
            }

            // read name
            const bool hasName = bstream.read(1);
            if (hasName) {
                if (full && bstream.read(1)) {
                    // this should never happen because we cant reference the entry from this point onwards
                    BOOST_THROW_EXCEPTION( stringtableKeyMissing() );
                    return;
                }

                // check for key delta
                const bool substring = bstream.read(1);
                if (substring) {
                    // read substring
                    const uint32_t sIndex = bstream.read(5);  // index of substr in keyhistory
                    const uint32_t sLength = bstream.read(5); // prefix length to new key

                    if (sIndex >= STRINGTABLE_KEY_HISTORY || sLength >= STRINGTABLE_MAX_KEY_SIZE)
                        BOOST_THROW_EXCEPTION( stringtableMalformedSubstring()
                            << (EArgT<1, uint32_t>::info(sIndex))
                            << (EArgT<1, uint32_t>::info(sLength))
                        );

                    keys[sIndex].copy(key, sLength, 0);
                    bstream.readString(key + sLength, STRINGTABLE_MAX_KEY_SIZE - sLength);
                } else {
                    bstream.readString(reinterpret_cast<char*>(&key), STRINGTABLE_MAX_KEY_SIZE);
                }

                // check the key history
                if (keys.size() >= STRINGTABLE_KEY_HISTORY)
                    detail::pop_front(keys);

                keys.push_back(std::string(key));
            }

            // read value
            const bool hasValue = bstream.read(1);
            uint32_t length = 0;
            if (hasValue) {
                uint32_t valsize = 0;
                if (userDataFixed) {
                    length = userDataSize;
                    valsize = userDataSizeBits;
                } else {
                    length = bstream.read(14);
                    valsize = length * 8;
                }

                if (length > STRINGTABLE_MAX_VALUE_SIZE)
                    BOOST_THROW_EXCEPTION( stringtableValueOverflow()
                        << (EArgT<1, uint32_t>::info(length))
                    );

                bstream.readBits((char*)&value, valsize);
            }

            // insert entry
            std::string k(key);
            std::string v(value, length);

            if (hasName && db.hasKey(k)) {
                db.set(std::move(k), std::move(v));
            } else if (hasName) {
                db.insert(storage::entry_type{std::move(k), index, std::move(v)});
            } else if (hasValue && db.hasIndex(index)) {
                db.set(index, std::move(v));
            } else {
                db.insert(storage::entry_type{"anonymous", index, std::move(v)});
            }
        }
    }
Пример #6
0
    void encodeOpen3DGCMesh(shared_ptr <GLTFMesh> mesh,
                            shared_ptr<JSONObject> floatAttributeIndexMapping,
                            const GLTFConverterContext& converterContext)
    {
        o3dgc::SC3DMCEncodeParams params;
        o3dgc::IndexedFaceSet <unsigned short> ifs;

        //setup options
        int qcoord    = 12;
        int qtexCoord = 10;
        int qnormal   = 10;
        int qcolor   = 10;
        int qWeights = 8;
        
        GLTFOutputStream *outputStream = converterContext._compressionOutputStream;
        size_t bufferOffset = outputStream->length();
        
        O3DGCSC3DMCPredictionMode floatAttributePrediction = O3DGC_SC3DMC_PARALLELOGRAM_PREDICTION;
        
        unsigned int nFloatAttributes = 0;
        
        PrimitiveVector primitives = mesh->getPrimitives();
        unsigned int primitivesCount =  (unsigned int)primitives.size();
        unsigned int allIndicesCount = 0;
        unsigned int allTrianglesCount = 0;
        
        std::vector <unsigned int> trianglesPerPrimitive;
        
        //First run through primitives to gather the number of indices and infer the number of triangles.
        for (unsigned int i = 0 ; i < primitivesCount ; i++) {
            shared_ptr<GLTF::GLTFPrimitive> primitive = primitives[i];
            shared_ptr <GLTF::GLTFIndices> uniqueIndices = primitive->getUniqueIndices();
            unsigned int indicesCount = (unsigned int)(uniqueIndices->getCount());
            //FIXME: assumes triangles, but we are guarded from issues by canEncodeOpen3DGCMesh
            allIndicesCount += indicesCount;
            trianglesPerPrimitive.push_back(indicesCount / 3);
        }
        
        //Then we setup the matIDs array and at the same time concatenate all triangle indices
        unsigned long *primitiveIDs = (unsigned long*)malloc(sizeof(unsigned long) * (allIndicesCount / 3));
        unsigned long *primitiveIDsPtr = primitiveIDs;
        unsigned short* allConcatenatedIndices = (unsigned short*)malloc(allIndicesCount * sizeof(unsigned short));
        unsigned short* allConcatenatedIndicesPtr = allConcatenatedIndices;
        
        for (unsigned int i = 0 ; i < trianglesPerPrimitive.size() ; i++) {
            unsigned int trianglesCount = trianglesPerPrimitive[i];
            for (unsigned int j = 0 ; j < trianglesCount ; j++) {
                primitiveIDsPtr[j] = i;
            }
            primitiveIDsPtr += trianglesCount;
            allTrianglesCount += trianglesCount;
            shared_ptr<GLTF::GLTFPrimitive> primitive = primitives[i];
            shared_ptr <GLTF::GLTFIndices> uniqueIndices = primitive->getUniqueIndices();
            unsigned int indicesCount = (unsigned int)(uniqueIndices->getCount());
            unsigned int* indicesPtr = (unsigned int*)uniqueIndices->getBufferView()->getBufferDataByApplyingOffset();
            for (unsigned int j = 0 ; j < indicesCount ; j++) {
                allConcatenatedIndicesPtr[j] = indicesPtr[j];
            }
            allConcatenatedIndicesPtr += indicesCount;
        }
        
        //FIXME:Open3DGC SetNCoordIndex is not a good name here (file against o3dgc)
        ifs.SetNCoordIndex(allTrianglesCount);
        ifs.SetCoordIndex((unsigned short * const ) allConcatenatedIndices);
        ifs.SetIndexBufferID(primitiveIDs);
        
        size_t vertexCount = 0;
        
        std::vector <GLTF::Semantic> semantics = mesh->allSemantics();
        for (unsigned int i = 0 ; i < semantics.size() ; i ++) {
            GLTF::Semantic semantic  = semantics[i];
            
            size_t attributesCount = mesh->getMeshAttributesCountForSemantic(semantic);
            
            for (size_t j = 0 ; j < attributesCount ; j++) {
                shared_ptr <GLTFMeshAttribute> meshAttribute = mesh->getMeshAttribute(semantic, j);
                vertexCount = meshAttribute->getCount();
                size_t componentsPerAttribute = meshAttribute->getComponentsPerAttribute();
                char *buffer = (char*)meshAttribute->getBufferView()->getBufferDataByApplyingOffset();
                switch (semantic) {
                    case POSITION:
                        params.SetCoordQuantBits(qcoord);
                        params.SetCoordPredMode(floatAttributePrediction);
                        ifs.SetNCoord(vertexCount);
                        ifs.SetCoord((Real * const)buffer);
                        break;
                    case NORMAL:
                        params.SetNormalQuantBits(qnormal);
                        params.SetNormalPredMode(O3DGC_SC3DMC_SURF_NORMALS_PREDICTION);
                        ifs.SetNNormal(vertexCount);
                        ifs.SetNormal((Real * const)buffer);
                        break;
                    case TEXCOORD:
                        params.SetFloatAttributeQuantBits(nFloatAttributes, qtexCoord);
                        params.SetFloatAttributePredMode(nFloatAttributes, floatAttributePrediction);
                        ifs.SetNFloatAttribute(nFloatAttributes, vertexCount);
                        ifs.SetFloatAttributeDim(nFloatAttributes, componentsPerAttribute);
                        ifs.SetFloatAttributeType(nFloatAttributes, O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_TEXCOORD);
                        ifs.SetFloatAttribute(nFloatAttributes, (Real * const)buffer);
                        floatAttributeIndexMapping->setUnsignedInt32(meshAttribute->getID(), nFloatAttributes);
                        nFloatAttributes++;
                        break;
                    case COLOR:
                        params.SetFloatAttributeQuantBits(nFloatAttributes, qcolor);
                        params.SetFloatAttributePredMode(nFloatAttributes, floatAttributePrediction);
                        ifs.SetNFloatAttribute(nFloatAttributes, vertexCount);
                        ifs.SetFloatAttributeDim(nFloatAttributes, componentsPerAttribute);
                        ifs.SetFloatAttributeType(nFloatAttributes, O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_COLOR);
                        ifs.SetFloatAttribute(nFloatAttributes, (Real * const)buffer);
                        floatAttributeIndexMapping->setUnsignedInt32(meshAttribute->getID(), nFloatAttributes);
                        nFloatAttributes++;
                        break;
                    case WEIGHT:
                        params.SetFloatAttributeQuantBits(nFloatAttributes, qWeights);
                        params.SetFloatAttributePredMode(nFloatAttributes, O3DGC_SC3DMC_DIFFERENTIAL_PREDICTION);
                        ifs.SetNFloatAttribute(nFloatAttributes, vertexCount);
                        ifs.SetFloatAttributeDim(nFloatAttributes, componentsPerAttribute);
                        ifs.SetFloatAttributeType(nFloatAttributes, O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_WEIGHT);
                        ifs.SetFloatAttribute(nFloatAttributes, (Real * const)buffer);
                        floatAttributeIndexMapping->setUnsignedInt32(meshAttribute->getID(), nFloatAttributes);
                        nFloatAttributes++;
                        break;
                    case JOINT:
                        /*
                         params.SetIntAttributePredMode(nIntAttributes, O3DGC_SC3DMC_DIFFERENTIAL_PREDICTION);
                         ifs.SetNIntAttribute(nIntAttributes, jointIDs.size() / numJointsPerVertex);
                         ifs.SetIntAttributeDim(nIntAttributes, numJointsPerVertex);
                         ifs.SetIntAttributeType(nIntAttributes, O3DGC_IFS_INT_ATTRIBUTE_TYPE_JOINT_ID);
                         ifs.SetIntAttribute(nIntAttributes, (long * const ) & (jointIDs[0]));
                         nIntAttributes++;
                         */
                        params.SetFloatAttributeQuantBits(nFloatAttributes, 10);
                        params.SetFloatAttributePredMode(nFloatAttributes, O3DGC_SC3DMC_PARALLELOGRAM_PREDICTION);
                        ifs.SetNFloatAttribute(nFloatAttributes, vertexCount);
                        ifs.SetFloatAttributeDim(nFloatAttributes, componentsPerAttribute);
                        ifs.SetFloatAttributeType(nFloatAttributes, O3DGC_IFS_FLOAT_ATTRIBUTE_TYPE_UNKOWN);
                        ifs.SetFloatAttribute(nFloatAttributes, (Real * const)buffer);
                        floatAttributeIndexMapping->setUnsignedInt32(meshAttribute->getID(), nFloatAttributes);
                        nFloatAttributes++;
                        break;
                    default:
                        break;
                }
            }
        }
        
        params.SetNumFloatAttributes(nFloatAttributes);
        ifs.SetNumFloatAttributes(nFloatAttributes);
        shared_ptr<JSONObject> compressionObject = static_pointer_cast<JSONObject>(mesh->getExtensions()->createObjectIfNeeded("Open3DGC-compression"));
        
        ifs.ComputeMinMax(O3DGC_SC3DMC_MAX_ALL_DIMS);
        BinaryStream bstream(vertexCount * 8);
        SC3DMCEncoder <unsigned short> encoder;
        shared_ptr<JSONObject> compressedData(new JSONObject());
        compressedData->setInt32("verticesCount", vertexCount);
        compressedData->setInt32("indicesCount", allIndicesCount);
        //Open3DGC binary is disabled
        params.SetStreamType(converterContext.compressionMode == "binary" ? O3DGC_STREAM_TYPE_BINARY : O3DGC_STREAM_TYPE_ASCII);
#if DUMP_O3DGC_OUTPUT
        static int dumpedId = 0;
        COLLADABU::URI outputURI(converterContext.outputFilePath.c_str());
        std::string outputFilePath = outputURI.getPathDir() + GLTFUtils::toString(dumpedId) + ".txt";
        dumpedId++;
        SaveIFS(outputFilePath, ifs);
#endif
        encoder.Encode(params, ifs, bstream);
        
        compressedData->setString("mode", converterContext.compressionMode);
        compressedData->setUnsignedInt32("count", bstream.GetSize());
        compressedData->setUnsignedInt32("type", converterContext.profile->getGLenumForString("UNSIGNED_BYTE"));
        compressedData->setUnsignedInt32("byteOffset", bufferOffset);
        compressedData->setValue("floatAttributesIndexes", floatAttributeIndexMapping);
        
        compressionObject->setValue("compressedData", compressedData);
        
        //testDecode(mesh, bstream);
        outputStream->write((const char*)bstream.GetBuffer(0), bstream.GetSize());
        
        if (ifs.GetCoordIndex()) {
            free(ifs.GetCoordIndex());
        }
        
        if (primitiveIDs) {
            free(primitiveIDs);
        }
    }