diff options
Diffstat (limited to 'same-android/src/main')
-rw-r--r-- | same-android/src/main/java/com/orbekk/GameView.java | 26 | ||||
-rw-r--r-- | same-android/src/main/java/com/orbekk/HelloAndroidActivity.java | 8 |
2 files changed, 27 insertions, 7 deletions
diff --git a/same-android/src/main/java/com/orbekk/GameView.java b/same-android/src/main/java/com/orbekk/GameView.java index 4accd7a..edb41cb 100644 --- a/same-android/src/main/java/com/orbekk/GameView.java +++ b/same-android/src/main/java/com/orbekk/GameView.java @@ -3,6 +3,10 @@ package com.orbekk; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.orbekk.same.State.Component; +import com.orbekk.same.ClientService; +import com.orbekk.same.ClientServiceImpl; + import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; @@ -15,6 +19,7 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback { private GameThread thread; static class GameThread extends Thread { + private Logger logger = LoggerFactory.getLogger(getClass()); private int height = 0; private int width = 0; private float posX; @@ -23,10 +28,13 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback { private Context context; private Paint background; private Paint paint; + private ClientServiceImpl client; - public GameThread(SurfaceHolder holder, Context context) { + public GameThread(SurfaceHolder holder, Context context, + ClientServiceImpl client) { this.holder = holder; this.context = context; + this.client = client; posX = 100; posY = 100; paint = new Paint(); @@ -60,17 +68,27 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback { } } - private void setPosition(float x, float y) { + private synchronized void setPosition(float x, float y) { posX = x; posY = y; run(); + long rev = 0; + Component c = client.getState("position"); + if (c != null) { + rev = c.getRevision(); + } + + if (client.sendStateUpdate("position", this.posX + "," + this.posY, + rev + 1)) { + logger.warn("Unable to set state."); + } } } - public GameView(Context context) { + public GameView(Context context, ClientServiceImpl client) { super(context); getHolder().addCallback(this); - thread = new GameThread(getHolder(), context); + thread = new GameThread(getHolder(), context, client); } @Override diff --git a/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java b/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java index cc90a3a..9df93d9 100644 --- a/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java +++ b/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java @@ -2,6 +2,7 @@ package com.orbekk; import com.orbekk.net.Broadcaster; import com.orbekk.same.ClientApp; +import com.orbekk.same.ClientServiceImpl; import android.app.Activity; import android.os.Bundle; @@ -26,15 +27,16 @@ public class HelloAndroidActivity extends Activity { Log.i(TAG, "onCreate"); // setContentView(R.layout.main); - setContentView(new GameView(this)); + ClientApp client = new ClientApp(); + ClientServiceImpl client_ = client.getClient(10015, "ClientNetwork", + "http://10.0.0.6:10010/"); + setContentView(new GameView(this, client_)); // Broadcast broadcast = new Broadcast(this); // broadcast.sendBroadcast("Broadcast test".getBytes(), 10010); // Broadcaster broadcaster = new Broadcaster(); // Log.i(TAG, "Broadcast success: " + broadcaster.sendBroadcast(10010, "Broadcast test from Android".getBytes())); // -// ClientApp client = new ClientApp(); -// client.run(10015, "ClientNetwork", "http://10.0.0.6:10010/"); } @Override |