Ejemplo n.º 1
0
	void Scene::load(stream::InputStream<stream::SerializationEndian> &strm)
	{
		PROFILE;
		int engineMajor, engineMinor, enginePatch;

		strm.read(engineMajor);
		strm.read(engineMinor);
		strm.read(enginePatch);

		if (engineMajor != ENGINE_VERSION_MAJOR || engineMinor != ENGINE_VERSION_MINOR || enginePatch != ENGINE_VERSION_PATCH)
		{
			LOG_ERROR("Invalid version number on scene file, aborting load. Engine: " << ENGINE_VERSION_MAJOR << "." << ENGINE_VERSION_MINOR << "." << ENGINE_VERSION_PATCH << " File: " << engineMajor << "." << engineMinor << "." << enginePatch);
			return;
		}

		//Loading happens in two steps.
		//a) build the scene data as it is in the stream
		//b) Refresh Handle pointers
		//c) Refresh resources

		unsigned entityCount;

		strm.read(entityCount);

		for (unsigned i = 0; i < entityCount; ++i)
		{
			Entity *ent = rtti::dynamicCast<Entity>(rtti::RTTI::generateSerializable("Entity", getContextData()));

			ent->load(strm);

			entities.push_back(ent);
		}
	}
Ejemplo n.º 2
0
        size_t refill(const Stream::InputStream & is, size_t readPossible)
        {
            if (!canFit(readPossible))
                readPossible = total - available();
            if (readPossible <= 0) return 0;

            // Move the data that was consumed out of buffer
            if (consumed)
            {
                memmove((uint8*)buffer, &((uint8*)buffer)[consumed], fill - consumed);
                fill -= consumed;
            }
            consumed = 0;

            uint64 ret = is.read(&((uint8*)buffer)[fill], readPossible);
            if (ret != (uint64)-1) fill += (size_t)ret;
            return (size_t)ret;
        }
Ejemplo n.º 3
0
    bool BSCLib::compressStream(Stream::OutputStream & outStream, const Stream::InputStream & inStream, const uint32 amountToProcess, const bool lastCall)
    {
        if (!memBuffer || !outBuffer) return setError(NotEnoughMemory);
        // If we were decompressing, let's change that
        if (decHeader.valid) { resizeBuffer(); decHeader.valid = false; }
        // Detect end of buffer
        // Try to be smart, else try to read as much as possible
        uint64 inSize = amountToProcess ? min((uint64)amountToProcess, inStream.fullSize()) : inStream.fullSize();
        if (inSize == 0)
        {
            if (!dataSize && !memBuffer->available()) return true;
            // Need to process the remaining block, if any
            if (!processBlock(outStream)) return false;
            // End of stream, let's rewind and write the header
            if (outStream.setPosition(0))
            {
                uint32 nBlocks = (uint32)((dataSize + getBufferSize() - 1) / getBufferSize());
                PUSH(&nBlocks, sizeof(nBlocks));
                dataSize = 0;
                headerWritten = false;
            }
            return true;
        }

        // Check if we need to write the number of blocks now (or not)
        if (!headerWritten)
        {
            // Safety first
            if (dataSize == 0 && !outStream.setPosition(outStream.currentPosition()))
            {
                // If you don't provide the input size and the output stream can not be rewind to save
                // the header in the end, then it'll not work.
                Assert(dataSize == 0 && outStream.setPosition(outStream.currentPosition()));
                return false;
            }

            uint32 nBlocks = (uint32)((-dataSize + getBufferSize() - 1) / getBufferSize()); //blockSize > 0 ? (uint32)((inSize + blockSize - 1) / blockSize) : 0;
            PUSH(&nBlocks, sizeof(nBlocks));
            dataSize = 0;
            headerWritten = true;
        }

        // Check if we can cache the data to avoid small compression block
        if (!lastCall && memBuffer->canFit(inSize))
        {   // Accumulate the input stream
            return memBuffer->refill(inStream, inSize) == inSize;
        }

        while ((int64)inSize > 0)
        {
            // Read as much as possible to the memory buffer, and save that
            size_t readSize = memBuffer->available();
            if (!memBuffer->full())
            {
                readSize = memBuffer->refill(inStream, inSize);
                inSize -= (uint64)readSize;
            }
            if (memBuffer->available() >= getBufferSize() || lastCall)
            {
                if (!processBlock(outStream)) return false;
            }
        }
        return setError(Success);
    }
Ejemplo n.º 4
0
	void Handle::load(stream::InputStream<stream::SerializationEndian> &strm)
	{
		strm.read(id);
		ptr = manager->getHandle(id);
	}