From ec8e276f68a269a8afc3fc16ba01bf82770ecb7a Mon Sep 17 00:00:00 2001 From: jwinterm Date: Sun, 17 Jan 2016 12:57:43 -0800 Subject: [PATCH] Got rid of libgdx timers. --- .gitignore | 7 + .../lightwallet/screens/AbstractScreen.java | 22 +-- .../jw/lightwallet/screens/MainScreen.java | 125 ++++++++++-------- .../com/jw/lightwallet/utils/StringToTx.java | 5 + 4 files changed, 99 insertions(+), 60 deletions(-) create mode 100644 core/src/com/jw/lightwallet/utils/StringToTx.java diff --git a/.gitignore b/.gitignore index 47454ee..7b5b3b9 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,10 @@ build/ ## OS Specific .DS_Store + +## log files +desktop/simplewallet.log +desktop/m* +desktop/lightwallet.conf + + diff --git a/core/src/com/jw/lightwallet/screens/AbstractScreen.java b/core/src/com/jw/lightwallet/screens/AbstractScreen.java index fa8d23a..29bcdc2 100644 --- a/core/src/com/jw/lightwallet/screens/AbstractScreen.java +++ b/core/src/com/jw/lightwallet/screens/AbstractScreen.java @@ -12,15 +12,19 @@ public class AbstractScreen implements Screen { protected int w; protected int h; protected float aspect; - protected float accumulator; + protected float accum5s; + protected float accum10s; + protected float accum60s; public AbstractScreen (final LightWallet game) { - this.game = game; - this.font = new BitmapFont(Gdx.files.internal("fonts/bauchaomaicha.fnt")); - this.w = Gdx.graphics.getWidth(); - this.h = Gdx.graphics.getHeight(); - this.aspect = w/h; - this.accumulator = 0; + this.game = game; + this.font = new BitmapFont(Gdx.files.internal("fonts/bauchaomaicha.fnt")); + this.w = Gdx.graphics.getWidth(); + this.h = Gdx.graphics.getHeight(); + this.aspect = w/h; + this.accum5s = 0; + this.accum10s = 0; + this.accum60s = 0; } @Override @@ -33,7 +37,9 @@ public class AbstractScreen implements Screen { public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - accumulator = accumulator + delta; + accum5s = accum5s + delta; + accum10s = accum10s + delta; + accum60s = accum60s + delta; } @Override diff --git a/core/src/com/jw/lightwallet/screens/MainScreen.java b/core/src/com/jw/lightwallet/screens/MainScreen.java index 670bff0..4dbf1ec 100644 --- a/core/src/com/jw/lightwallet/screens/MainScreen.java +++ b/core/src/com/jw/lightwallet/screens/MainScreen.java @@ -6,6 +6,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; +import java.util.ArrayList; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; @@ -59,23 +60,22 @@ public class MainScreen extends AbstractScreen { HistoryView historyview; // Timers - Timer daemontimer; - Timer walletsavetimer; - Timer balancetimer; + boolean fivesectimer; + boolean tensectimer; + boolean sixtysectimer; // Wallet thread and queue stuff Process wp; BufferedReader wr; AtomicQueue wq; + ArrayList txlist; public MainScreen(final LightWallet game) { super(game); - - daemontimer = new Timer(); - walletsavetimer = new Timer(); + wq = new AtomicQueue(1000); - balancetimer = new Timer(); + txlist = new ArrayList(); Skin uiSkin = new Skin(Gdx.files.internal("skin/uiskin.json")); @@ -155,7 +155,69 @@ public class MainScreen extends AbstractScreen { public void show() { super.show(); + launchsimplewallet(); + } + + + public void render(float delta) { + super.render(delta); + + stage.draw(); + stage.act(delta); + updatetimers(delta); + runtasks(); + update(); + + } + + + public void dispose() { + super.dispose(); + } + + + @Override + public void hide() { + // TODO Auto-generated method stub + super.hide(); + wp.destroy(); + } + + public void updatetimers(float delta) { + if (accum5s > 5) { fivesectimer = true; } + if (accum10s > 10) { tensectimer = true; } + if (accum60s > 60) { sixtysectimer = true; } + } + + public void runtasks() { + if (fivesectimer == true) { + // Timer task to check balance from simplewallet + balancerpc.getinfo(balancevalues); + fivesectimer = false; + accum5s = 0; + } + if (tensectimer == true) { + // Timer task to get network info from daemon + daemonrpc.getinfo(daemonvalues); + daemonview.Update(daemonvalues); + tensectimer = false; + accum10s = 0; + } + if (sixtysectimer == true) { + // Timer task to try and save wallet every minute + walletsaverpc.trysave(walletsavevalues); + dumptx(); + sixtysectimer = false; + accum60s = 0; + } + } + + public void update() { + + } + + public void launchsimplewallet() { new Thread(new Runnable() { @Override public void run() { @@ -186,41 +248,9 @@ public class MainScreen extends AbstractScreen { }); } }).start(); - - // Timer task to get network info from daemon - daemontimer.scheduleTask(new Timer.Task() { - @Override - public void run() { - daemonrpc.getinfo(daemonvalues); - daemonview.Update(daemonvalues); - } - }, 1f, 10f); - - // Timer task to check balance from simplewallet - balancetimer.scheduleTask(new Timer.Task() { - @Override - public void run() { - balancerpc.getinfo(balancevalues); - } - }, 1f, 5f); - - // Timer task to try and save wallet every minute - walletsavetimer.scheduleTask(new Timer.Task() { - @Override - public void run() { - walletsaverpc.trysave(walletsavevalues); - } - }, 60f, 60f); - } - - public void render(float delta) { - super.render(delta); - - stage.draw(); - stage.act(delta); - + public void readwalletqueue () { // Poll wallet thread and check block height and if transaction data is in output String queuepoll = wq.poll(); // Gdx.app.log(LightWallet.LOG, "Queue result: " + queuepoll); @@ -235,6 +265,7 @@ public class MainScreen extends AbstractScreen { } else if (queuepoll != null && queuepoll.contains("money")) { PrintWriter txout; + txlist.add(queuepoll); try { txout = new PrintWriter(new BufferedWriter(new FileWriter(game.walletvalues.getName() + "tx.txt", true))); txout.println(queuepoll); @@ -247,18 +278,8 @@ public class MainScreen extends AbstractScreen { } catch (NullPointerException e){e.printStackTrace();} } - - public void dispose() { - super.dispose(); - } - - - @Override - public void hide() { - // TODO Auto-generated method stub - super.hide(); - wp.destroy(); + public void dumptx() { + } - } diff --git a/core/src/com/jw/lightwallet/utils/StringToTx.java b/core/src/com/jw/lightwallet/utils/StringToTx.java new file mode 100644 index 0000000..cc859d7 --- /dev/null +++ b/core/src/com/jw/lightwallet/utils/StringToTx.java @@ -0,0 +1,5 @@ +package com.jw.lightwallet.utils; + +public class StringToTx { + +}