Hey guys
I'm using Tiled (mapeditor.org) for the mapping in my game and I have made a few maps, and started implementing them in my game. The first thing I had to do was decode them from base64, then gunzip the string.

Now I am on the last step and I don't understand what they are telling me to do.

Finally, you can read 4 bytes at a time for each GID from the beginning of the data stream until the end.

and they give out some C++ code too but I don't understand it and I have never used the shift operators.

const int gid = data[i] |
              data[i + 1] << 8 |
              data[i + 2] << 16 |
              data[i + 3] << 24;

Here is a link to the wiki site Im working off of.

I'm no C++ guru, but I'm pretty sure the shift operator works the same as in Java. Basically a left shift of 1 is like multiplying by 2 to the power of 1 (ie 2), so a left shift of 8 is like multiplying by 2 to the power of 8 (ie 256 or 1 byte).

What your code is actually doing is converting an array of 1's and 0's to a numeric 32-bit integer (32 bits = 4 bytes). It does this by adding the bytes together. The first byte starts at position 0 in the bit array, so no shift is necessary. The second byte starts at position 256 in the bit array, so we need to left-shift by a power of 8 in order to calculate the numbers that this byte represents. Similarly for the other two bytes...

Ah okay thanks for the reply! I get it now, (I think) now if you could give me one more hand.

I am outputting the correct data but not enough

Here is my code

//Saves the retrieved data to an array
					layerData[s] = ((Node) fstNm.item(0)).getNodeValue();
					//changes the recorded string to a byte array
					byte[] buffer = decode(layerData[s].getBytes());
					//puts the byte array into a inputStream
					ByteArrayInputStream byteStream = new ByteArrayInputStream(buffer);
					//Sends array GZIP input stream
					GZIPInputStream gis = new GZIPInputStream(byteStream);
					//reads input stream into buffer array
					int bytesRead = gis.read(buffer, 0, buffer.length);
					
					int i = 0;
					System.out.println("Buffer Length:"+buffer.length);
					while( i < buffer.length/4){
						int gid = buffer[i] |
			              buffer[i + 1] << 8 |
			              buffer[i + 2] << 16 |
			              buffer[i + 3] << 24;
						System.out.println("GID: "+gid);
						i+=4;
					}
					System.out.println("EOS");

and the output:

Buffer Length:42
GID: 12571
GID: 12571
GID: 12571
EOS
Buffer Length:83
GID: 1
GID: 2
GID: 3
GID: 4
GID: 5
EOS

and here is a version of the map that is not compressed out in base 64 (I wanna use the compression because this version of the map is 30 times the size of the other map)
http://pastebin.com/zXJgBmdJ

There are suppose to be a WHOLE lot more in each category!

Thanks PO

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.