Updated main loop to use a while loop instead, added full try{}catch()

block. Added proper threading on displays and force updating of fields.
secondmonitor
sigonasr2 4 years ago
parent 6eee74a868
commit f6c627f3c1
  1. BIN
      DivaBot/DivaBot.jar
  2. 8
      DivaBot/calibration_data.txt
  3. BIN
      DivaBot/capture.png
  4. BIN
      DivaBot/capture_2.png
  5. BIN
      DivaBot/capture_3.png
  6. BIN
      DivaBot/capture_4.png
  7. BIN
      DivaBot/capture_5.png
  8. 2
      DivaBot/config.txt
  9. 4
      DivaBot/src/sig/Calibrator.java
  10. 32
      DivaBot/src/sig/Display.java
  11. 10
      DivaBot/src/sig/DrawCanvas.java
  12. 31
      DivaBot/src/sig/MyRobot.java

Binary file not shown.

@ -1,4 +1,4 @@
768
504
1548
940
746
577
1527
1014

Binary file not shown.

Before

Width:  |  Height:  |  Size: 531 KiB

After

Width:  |  Height:  |  Size: 536 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 531 KiB

After

Width:  |  Height:  |  Size: 535 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 530 KiB

After

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 530 KiB

After

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 528 KiB

After

Width:  |  Height:  |  Size: 529 KiB

@ -1,4 +1,4 @@
DISPLAYDATA -16776961*-13369549*100*Gungsuh*600*90*300*Song Title (Japanese+Romanized)*176*136*~-16776961*-13369549*24*Gulim*400*40*300*Overall Rating|Song Title (Romanized)|FC Count*176*240*
DISPLAYDATA -16776961*-13369549*100*Gungsuh*600*90*5000*Song Title (Japanese+Romanized)*176*136*~-16776961*-13369549*24*Gulim*400*40*300*Overall Rating|Song Title (Romanized)|FC Count*176*240*~-16776961*-13369549*24*Gulim*400*40*300*Best Play*0*0*
LAST_HEIGHT 40
WIDTH 1127
HEIGHT 765

@ -63,6 +63,8 @@ public class Calibrator{
MyRobot.FRAME.setCursor(Cursor.getDefaultCursor());
Overlay.started=false;
MyRobot.FRAME.setAlwaysOnTop(false);
Overlay.OVERLAY.setVisible(true);
if (((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))<=16/9f-0.04||
((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))>=16/9f+0.04) {
int dialogResult = JOptionPane.showConfirmDialog (null, "Could not detect Megamix properly!\n\nYour calibration cut a bit "+((((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))<=16/9f-0.04)?"more":"less")+" than expected. Do you want to try selecting a more accurate region?","Warning",JOptionPane.YES_NO_OPTION);
@ -74,7 +76,7 @@ public class Calibrator{
return;
}
}
Overlay.OVERLAY.setVisible(true);
MyRobot.FRAME.setAlwaysOnTop(true);
// failed=CalibrationStage3(p);
// if (failed) {return;}

@ -20,6 +20,8 @@ public class Display {
int width=200;
int height=48;
int delay=10000;
long nextUpdateTime = System.currentTimeMillis();
boolean forceUpdate=false;
String[] labels;
String currentText;
int cycle=0;
@ -101,10 +103,17 @@ public class Display {
public void run() {
try {
while (!deleted) {
if (System.currentTimeMillis()>nextUpdateTime) {
if (!forceUpdate) {
AdvanceCycle();
}
updateFont();
currentText=interpretLabel(labels[cycle]);
MyRobot.p.repaint();
Thread.sleep(delay);
nextUpdateTime=System.currentTimeMillis()+delay;
forceUpdate=false;
}
Thread.sleep(50);
}
} catch (InterruptedException e) {
e.printStackTrace();
@ -205,19 +214,40 @@ public class Display {
return (data.songname + " - " + ((data.romanizedname.length()>0)?(data.romanizedname.equalsIgnoreCase(data.englishname))?data.romanizedname:data.romanizedname+" ("+data.englishname+")":data.englishname)) + " by "+data.artist;
}
case "Play Count":{
if (data.plays>0) {
return Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":"");
} else {
return "No Plays";
}
}
case "Pass/Play Count":{
if (data.plays>0) {
return Integer.toString(data.passes) + "/" + Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":"");
}
else {
return "No Plays";
}
}
case "Pass/Play Count (+%)":{
if (data.plays>0) {
return (data.passes)+"/"+(data.plays)+" play"+((data.plays!=1)?"s":"")+" "+"("+((int)(Math.floor(((float)data.passes)/data.plays*100)))+"% pass rate)";
} else {
return "No Plays";
}
}
case "FC Count":{
if (data.plays>0) {
return data.fcCount +" FC"+(data.fcCount==1?"":"s");
} else {
return "No Plays";
}
}
case "FC Count (+%)":{
if (data.plays>0) {
return data.fcCount +" FC"+(data.fcCount==1?"":"s")+" "+((int)(Math.floor(((float)data.fcCount)/data.plays*100)))+"% FC rate";
} else {
return "No Plays";
}
}
default:{
return string;

@ -80,7 +80,7 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
boolean targetBuffer=false;
static Color background = new Color(170,170,170);
public static HashMap<String,String> configData = new HashMap<String,String>();
List<Display> displays = new ArrayList<Display>();
static List<Display> displays = new ArrayList<Display>();
public static Display selectedDisplay = null;
public static Display draggedDisplay = null;
DrawCanvas() throws FontFormatException, IOException {
@ -103,6 +103,13 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
t.start();
}
public static void refreshAllLabels() {
for (Display d : displays) {
d.forceUpdate=true;
d.nextUpdateTime=System.currentTimeMillis()-1;
}
}
public void pullData(final String songname,final String difficulty) {
this.songname=(songname.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(songname.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":songname);
this.difficulty=difficulty;
@ -162,6 +169,7 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
}
scrollX = 0;*/
MyRobot.p.repaint();
MyRobot.p.refreshAllLabels();
}
}
} catch (JSONException | IOException e) {

@ -162,7 +162,7 @@ public class MyRobot{
public static String USERNAME = "";
public static String AUTHTOKEN = "";
public static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
public static long lastmainlooptime = 0;
public static void main(String[] args) throws JSONException, IOException, FontFormatException {
@ -266,22 +266,33 @@ public class MyRobot{
}
void BotMain() {
lastmainlooptime=System.currentTimeMillis();
while (true) {
try {
RunMainLoop();
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void RunMainLoop() {
try {
try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/"+USERNAME);
p.lastRating = p.overallrating;
if (obj.has("rating")) {
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
}
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Timer t = new Timer();
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
if (CALIBRATION_MODE) {
if (MyRobot.calibrating) {
MyRobot.calibrating=false;
@ -302,6 +313,7 @@ public class MyRobot{
if (selectedSong!=null && difficulty!=null) {
if (!prevSongTitle.equalsIgnoreCase(selectedSong.title) || !prevDifficulty.equalsIgnoreCase(difficulty)) {
System.out.println("On Song Select Screen: Current Song-"+selectedSong.title+" Diff:"+difficulty);
MyRobot.p.refreshAllLabels();
p.pullData(selectedSong.title,difficulty);
prevSongTitle=selectedSong.title;
prevDifficulty=difficulty;
@ -466,7 +478,7 @@ public class MyRobot{
}
MYROBOT.refreshScreen();
}
} catch (IOException | InterruptedException e) {
}catch(Exception e) {
e.printStackTrace();
}
}
@ -572,11 +584,6 @@ public class MyRobot{
}
}
},
0,
50);
}
void go() throws FontFormatException, IOException {
initialize();
p = new DrawCanvas();

Loading…
Cancel
Save