Advertisement
Guest User

MapAndreas for Shoebill

a guest
May 31st, 2014
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.nio.MappedByteBuffer;
  5. import java.nio.channels.FileChannel;
  6.  
  7. public class MapAndreas
  8. {
  9.     private MappedByteBuffer mappedByteBuffer;
  10.  
  11.  
  12.     public MapAndreas(File mapAndreadData) throws IOException
  13.     {
  14.         FileInputStream in = new FileInputStream(mapAndreadData);
  15.         FileChannel fileChannel = in.getChannel();
  16.  
  17.         mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
  18.         fileChannel.close();
  19.         in.close();
  20.     }
  21.  
  22.     public void close()
  23.     {
  24.         if (mappedByteBuffer == null) return;
  25.         synchronized (mappedByteBuffer)
  26.         {
  27.             mappedByteBuffer = null;
  28.         }
  29.     }
  30.  
  31.     public float findZ(float x, float y)
  32.     {
  33.         if (mappedByteBuffer == null) return 0.0f;
  34.         if (x < -3000.0f || x > 3000.0f || y > 3000.0f || y < -3000.0f) return 0.0f;
  35.  
  36.         synchronized (mappedByteBuffer)
  37.         {
  38.             int gridX = ((int) x) + 3000;
  39.             int gridY = (((int) y) - 3000) * -1;
  40.             int dataPos = (gridY * 6000) + gridX;
  41.  
  42.             mappedByteBuffer.position(dataPos);
  43.  
  44.             int ch1 = Byte.toUnsignedInt(mappedByteBuffer.get()), ch2 = Byte.toUnsignedInt(mappedByteBuffer.get());
  45.             return ((float) ((ch2 << 8) + (ch1))) / 100.0f;
  46.         }
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement