Advertisement
spacechase0

Map Data

Jan 8th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. // Assuming size.x and size.y are 4 bytes, and heightmap.getHeight( ix, iy ) is 1 byte
  2.  
  3. // Writing
  4. buffer.writeInt( size.x );
  5. buffer.writeInt( size.y );
  6.  
  7. for ( int ix = 0; ix < size.x; ++ix )
  8. {
  9.     for ( int iy = 0; iy < size.y; ++iy )
  10.     {
  11.         byte height = heightmap.getHeight( ix, iy );
  12.         buffer.writeByte( height );
  13.     }
  14. }
  15.  
  16. // Reading
  17. size.x = buffer.readInt();
  18. size.y = buffer.readInt();
  19.  
  20. for ( int ix = 0; ix < size.x; ++ix )
  21. {
  22.     for ( int iy = 0; iy < size.y; ++iy )
  23.     {
  24.         byte height = buffer.readByte();
  25.         heightmap.setHeight( ix, iy, height );
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement