Permalink
Browse files

cleanup sending of control package

  • Loading branch information...
1 parent ab9c22f commit 1a6b96fd8d3e7ab16745ee5c5ac858d64cfa60a5 @jonasb committed Apr 7, 2012
Showing with 13 additions and 15 deletions.
  1. +13 −15 src/se/forskningsavd/Communicator.java
@@ -126,34 +126,32 @@ public void run() {
return;
}
+ final ByteBuffer buffer = ByteBuffer.allocate(1024);
+ buffer.order(ByteOrder.LITTLE_ENDIAN);
float rotationCumulative = 0;
float cameraAngleCumulative = 0;
while (mRunning) {
- byte kb = 0;
- if (mNavigator.left)
- kb |= 1;
- if (mNavigator.right)
- kb |= 1 << 1;
- if (mNavigator.up)
- kb |= 1 << 2;
- if (mNavigator.down)
- kb |= 1 << 3;
- //TODO reuse buffer/modify the data
- final ByteBuffer buffer = ByteBuffer.allocate(1024);
- buffer.order(ByteOrder.LITTLE_ENDIAN);
+ buffer.clear();
buffer.put("CTRL".getBytes());
buffer.put(mTrustServer);
buffer.put(mTrustClient);
buffer.put((byte) 0); //padding
buffer.put((byte) 0); //padding
-
rotationCumulative += mNavigator.rotation * 20;
- cameraAngleCumulative += mNavigator.cameraAngle * 10;
-
buffer.putInt(closestZero(rotationCumulative)); //mx
+ cameraAngleCumulative += mNavigator.cameraAngle * 10;
buffer.putInt(closestZero(cameraAngleCumulative)); //my
buffer.putInt((int) (mNavigator.moveX * 128)); //dx -1..1 -> -127..127
buffer.putInt((int) (mNavigator.moveY * 128)); //dy -1..1 -> -127..127
+ byte kb = 0;
+ if (mNavigator.left)
+ kb |= 1;
+ if (mNavigator.right)
+ kb |= 1 << 1;
+ if (mNavigator.up)
+ kb |= 1 << 2;
+ if (mNavigator.down)
+ kb |= 1 << 3;
buffer.put(kb);
buffer.put((byte) 0); //padding
buffer.put((byte) 0); //padding

0 comments on commit 1a6b96f

Please sign in to comment.