Example #1
0
		void Save(SpriteMap *sm, StreamWriter *f) {
			// Write TileTypes
			f->WriteShort((Short)sm->GetNumTileTypes());
			for (Short i = 0; i < (Short)sm->GetNumTileTypes(); i++) {
				const SpriteMapTileType &smtt = sm->GetTileType(i);
				f->WriteInt(smtt.mEntityTypeName.GetSizeInBytes());
				f->WriteString(smtt.mEntityTypeName, false);
				f->WriteInt(smtt.mSpriteName.GetSizeInBytes());
				f->WriteString(smtt.mSpriteName, false);
			}
			// Write Layers
			f->WriteInt(sm->GetNumLayers());
			for (Int i = 0; i < sm->GetNumLayers(); i++) {
				SpriteMapLayer *sml = sm->GetLayer(i);
				f->WriteInt(sml->GetName().GetSizeInBytes());
				f->WriteString(sml->GetName(), false);
				f->WriteInt(sml->GetChunkWidth());
				f->WriteInt(sml->GetChunkHeight());
				f->WriteInt(sml->GetDrawLayer());
				f->WriteVector2D(sml->GetCamera()->GetStartingOrigin());
				f->WriteFloat(sml->GetCamera()->GetStartingRotationDegrees());
				f->WriteFloat(sml->GetCamera()->GetStartingZoom());
				f->WriteFloat(sml->GetScrollMultiplier().mX);
				f->WriteFloat(sml->GetScrollMultiplier().mY);
				f->WriteFloat(sml->GetSpawnBounds().mOrigin.mX);
				f->WriteFloat(sml->GetSpawnBounds().mOrigin.mY);
				f->WriteFloat(sml->GetSpawnBounds().mSize.mX);
				f->WriteFloat(sml->GetSpawnBounds().mSize.mX);
				// Write Chunks
				f->WriteInt(sml->GetNumChunks());
				for (Int j = 0; j < sml->GetNumChunks(); j++) {
					const SpriteMapChunk &c = sml->GetChunk(j);
					Array<Short> compressedTiles;
					f->WriteInt(c.GetTileOffset().mX);
					f->WriteInt(c.GetTileOffset().mY);
					c.GetCompressedTiles(compressedTiles);
					f->WriteInt(compressedTiles.GetElementCount());
					f->Write((Byte*)&compressedTiles[0],
						compressedTiles.GetElementCount());
				}
			}
		}
Example #2
0
void StreamReader::ReadString(String *result, const String &delimiter) {
    Array<Char> retString;
    Array<Char> delString;
    String strDelimiter = delimiter;
    Char c;
    if (strDelimiter.IsEmpty()) {
        strDelimiter.Resize(1);
        strDelimiter.Append("\0");
    }
    while (true) {
        c = ReadByte();
        if (this->GetError())
            break;
        if (c == strDelimiter.GetData()[0]) {
            delString.Clear();
            delString.Append(c);
            for (Int i = 1; i < strDelimiter.GetSizeInBytes(); i++) {
                c = ReadByte();
                if (this->GetError()) {
                    for (Int j = 0; j < delString.GetElementCount(); j++)
                        retString.Append(delString[j]);
                    break;
                }
                delString.Append(c);
                if (c != strDelimiter.GetData()[i])
                    break;
            }
            if (strDelimiter.GetSizeInBytes() > delString.GetElementCount())
                for (Int i = 0; i < delString.GetElementCount(); i++)
                    retString.Append(delString[i]);
            else {
                if (memcmp(strDelimiter.GetData(),
                           delString.GetData(), delString.GetElementCount()))
                {
                    for (Int i = 0; i < delString.GetElementCount(); i++)
                        retString.Append(delString[i]);
                }
                else
                    break;
            }
        } else {
            retString.Append(c);
        }
    }
    result->Resize(retString.GetElementCount());
    memcpy((Char*)result->GetData(),
           retString.GetData(), retString.GetElementCount());
}