Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.nio.MappedByteBuffer;
- import java.nio.channels.FileChannel;
- public class MapAndreas
- {
- private MappedByteBuffer mappedByteBuffer;
- public MapAndreas(File mapAndreadData) throws IOException
- {
- FileInputStream in = new FileInputStream(mapAndreadData);
- FileChannel fileChannel = in.getChannel();
- mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
- fileChannel.close();
- in.close();
- }
- public void close()
- {
- if (mappedByteBuffer == null) return;
- synchronized (mappedByteBuffer)
- {
- mappedByteBuffer = null;
- }
- }
- public float findZ(float x, float y)
- {
- if (mappedByteBuffer == null) return 0.0f;
- if (x < -3000.0f || x > 3000.0f || y > 3000.0f || y < -3000.0f) return 0.0f;
- synchronized (mappedByteBuffer)
- {
- int gridX = ((int) x) + 3000;
- int gridY = (((int) y) - 3000) * -1;
- int dataPos = (gridY * 6000) + gridX;
- mappedByteBuffer.position(dataPos);
- int ch1 = Byte.toUnsignedInt(mappedByteBuffer.get()), ch2 = Byte.toUnsignedInt(mappedByteBuffer.get());
- return ((float) ((ch2 << 8) + (ch1))) / 100.0f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement