Skip to content

Commit

Permalink
Fix freeze on Reset + code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
ricdays committed Mar 26, 2016
1 parent 83c31dc commit f3cb025
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 108 deletions.
6 changes: 3 additions & 3 deletions mslrb2015/Button.pde
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static Button buttonFromEnum(ButtonsEnum btn)
return null;
}

void bevent(char group, int pos) {
void buttonEvent(char group, int pos) {

ButtonsEnum clickedButton = null;
Button clickBtn = null;
Expand Down Expand Up @@ -192,7 +192,7 @@ void bevent(char group, int pos) {
StateMachine.Update(clickedButton, btnOn);

if(soundMaxTime != null && clickedButton.isStart())
lastPlayMillis = millis();
lastPlayMillis = mainApplet.millis();
else
lastPlayMillis = 0;

Expand All @@ -214,4 +214,4 @@ void bevent(char group, int pos) {
}
}
}
}
}
44 changes: 17 additions & 27 deletions mslrb2015/Comms.pde
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
public static void serverEvent(MyServer whichServer, Client whichClient) {
try {
if (whichServer.equals(BaseStationServer)) {
Log.logMessage("New BaseStationClient @ "+whichClient.ip());
Log.logMessage("New BaseStation @ "+whichClient.ip());
}
else if (whichServer.equals(scoreClients.scoreServer)) {
Log.logMessage("New ScoreClient @ " + whichClient.ip());
}
else if (mslRemote != null && mslRemote.server != null && whichServer != null && whichServer.equals(mslRemote.server)) {
Log.logMessage("New RemoteControl @ " + whichClient.ip());
Log.logMessage("New Remote @ " + whichClient.ip());
}
}catch(Exception e){}
}
Expand Down Expand Up @@ -382,11 +382,6 @@ public static final char COMM_DROPPED_BALL = 'N';
// repair Commands
public static final char COMM_REPAIR_OUT_MAGENTA = 'o'; //exits field
public static final char COMM_REPAIR_OUT_CYAN = 'O';
//public static final char COMM_REPAIR_IN_MAGENTA = 'i';
//public static final char COMM_REPAIR_IN_CYAN = 'I';

// public static final char COMM_CANCEL = 'x'; //not used
// public static final String COMM_RECONNECT_STRING = "Reconnect"; //not used

//free: fFHlmMnqQvVxX
//------------------------------------------------------
Expand All @@ -399,16 +394,15 @@ void comms_initDescriptionDictionary() {
Description.set("N", "Drop Ball");
Description.set("h", "Halftime");
Description.set("e", "End Game");
Description.set("z", "Game Over"); //NEW 2015CAMBADA
Description.set("Z", "Reset Game"); //NEW 2015CAMBADA
Description.set("W", "Welcome"); //NEW 2015CAMBADA
Description.set("w", "Request World State"); //NEW 2015CAMBADA
Description.set("U", "Test Mode on"); //NEW 2015CAMBADA ?
Description.set("u", "Test Mode off"); //NEW 2015CAMBADA ?
Description.set("z", "Game Over");
Description.set("Z", "Reset Game");
Description.set("W", "Welcome");
Description.set("U", "Test Mode on");
Description.set("u", "Test Mode off");
Description.set("1", "1st half");
Description.set("2", "2nd half");
Description.set("3", "Overtime 1st half"); //NEW 2015CAMBADA
Description.set("4", "Overtime 2nd half"); //NEW 2015CAMBADA
Description.set("3", "Overtime 1st half");
Description.set("4", "Overtime 2nd half");
Description.set("L", "Park");

Description.set("K", "CYAN Kickoff");
Expand All @@ -418,13 +412,11 @@ void comms_initDescriptionDictionary() {
Description.set("C", "CYAN Corner");
Description.set("P", "CYAN Penalty Kick");
Description.set("A", "CYAN Goal+");
Description.set("D", "CYAN Goal-");
Description.set("D", "CYAN Goal-");
Description.set("O", "CYAN Repair Out");
// Description.set("I", "CYAN Repair In");
Description.set("R", "CYAN Red Card"); //NEW 2015CAMBADA
Description.set("Y", "CYAN Yellow Card"); //NEW 2015CAMBADA
// Description.set("J", "CYAN Double Yellow in"); //NEW 2015CAMBADA
Description.set("B","CYAN Double Yellow"); //NEW 2015CAMBADA
Description.set("R", "CYAN Red Card");
Description.set("Y", "CYAN Yellow Card");
Description.set("B", "CYAN Double Yellow");

Description.set("k", "MAGENTA Kickoff");
Description.set("f", "MAGENTA Freekick");
Expand All @@ -435,9 +427,7 @@ void comms_initDescriptionDictionary() {
Description.set("a", "MAGENTA Goal+");
Description.set("d", "MAGENTA Goal-");
Description.set("o", "MAGENTA Repair Out");
// Description.set("i", "MAGENTA Repair In");
Description.set("r", "MAGENTA Red Card"); //NEW 2015CAMBADA
Description.set("y", "MAGENTA Yellow Card"); //NEW 2015CAMBADA
// Description.set("j", "MAGENTA Double Yellow in"); //NEW 2015CAMBADA
Description.set("b","MAGENTA Double Yellow"); //NEW 2015CAMBADA
}
Description.set("r", "MAGENTA Red Card");
Description.set("y", "MAGENTA Yellow Card");
Description.set("b", "MAGENTA Double Yellow");
}
4 changes: 2 additions & 2 deletions mslrb2015/MSLRemote.pde
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class MSLRemote

char group = 'C';

bevent(group, pos);
buttonEvent(group, pos);

}
}
Expand All @@ -262,4 +262,4 @@ class MSLRemote
println("Invalid JSON received from MSL Remote.");
}
}
}
}
59 changes: 5 additions & 54 deletions mslrb2015/StateMachine.pde
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ static class StateMachine

public static void reset()
{
try {
send_to_basestation("" + COMM_RESET);

needUpdate = false;
btnCurrent = ButtonsEnum.BTN_ILLEGAL;
btnPrev = ButtonsEnum.BTN_ILLEGAL;
Expand All @@ -341,10 +344,9 @@ static class StateMachine

Log.createLog();

send_to_basestation("" + COMM_RESET);

BaseStationServer.stop();
BaseStationServer = new MyServer(mainApplet, Config.basestationServerPort);
} catch(Exception e) {}
}

public static boolean isHalf()
Expand Down Expand Up @@ -385,55 +387,4 @@ static class StateMachine

void StateMachineCheck() {
StateMachine.StateMachineRefresh();
}

//==============
void checkpopup() {
/*if (bCommoncmds[5].isActive()) checkresetpopup(); //"RESET"
else if (bCommoncmds[4].isActive()) checkendhalfpopup(); //"ENDHALF"
else if (StateMachine.GetCurrentGameState() == GameStateEnum.GS_PREGAME) checkteampopup();*/
}

void checkresetpopup() { //RESET
//if (bPopup[0].isActive()) resetgame(); //popup yes
if (bPopup[0].isActive() || bPopup[1].isActive()) {
bCommoncmds[5].enable(); //reset
Popup.close();
}
//else println("outside click...");
}

void checkteampopup(){
if (bPopup[0].isActive()) {
println("cyan - " + teamselect.getString("shortname8"));
teamA.shortName=teamselect.getString("shortname8");
teamA.longName=teamselect.getString("longame24");
teamA.unicastIP = teamselect.getString("UnicastAddr");
teamA.multicastIP = teamselect.getString("MulticastAddr");
Popup.close();
}
else if (bPopup[1].isActive()) {
println("magenta - " + teamselect.getString("shortname8"));
teamB.shortName=teamselect.getString("shortname8");
teamB.longName=teamselect.getString("longame24");
teamB.unicastIP = teamselect.getString("UnicastAddr");
teamB.multicastIP = teamselect.getString("MulticastAddr");
Popup.close();
}
//else println("outside click...");
}

void checkflags() {
teamA.checkflags();
teamB.checkflags();
}

void doubleyellowtimercheck() {
if (teamA.DoubleYellowCardCount>0) teamA.setDoubleYellowOutRemain();
if (teamB.DoubleYellowCardCount>0) teamB.setDoubleYellowOutRemain();
}

void doubleyellowtimercheckresume() {
if (teamA.DoubleYellowCardCount>0) teamA.resumeDoubleYellowOutRemain();
if (teamB.DoubleYellowCardCount>0) teamB.resumeDoubleYellowOutRemain();
}
}
9 changes: 4 additions & 5 deletions mslrb2015/SystemEvents.pde
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void mousePressed() {
if (bCommoncmds[i].isEnabled()) {
bCommoncmds[i].checkhover();
if (bCommoncmds[i].HOVER==true) {
bevent('C', i);
buttonEvent('C', i);
break;
}
}
Expand All @@ -34,14 +34,14 @@ void mousePressed() {
if (bTeamAcmds[i].isEnabled()) {
bTeamAcmds[i].checkhover();
if (bTeamAcmds[i].HOVER==true) {
bevent('A', i);
buttonEvent('A', i);
break;
}
}
if (bTeamBcmds[i].isEnabled()) {
bTeamBcmds[i].checkhover();
if (bTeamBcmds[i].HOVER==true) {
bevent('B', i);
buttonEvent('B', i);
break;
}
}
Expand Down Expand Up @@ -84,5 +84,4 @@ void keyPressed() {
Popup.close();
}

}

}
4 changes: 4 additions & 0 deletions mslrb2015/Team.pde
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ class Team {
this.newPenaltyKick=false;
for (int i=0; i<5; i++)
r[i].reset();

if(this.connectedClient != null && this.connectedClient.active())
this.connectedClient.stop();
this.connectedClient = null;

this.firstWorldState = true;
}

Expand Down
25 changes: 8 additions & 17 deletions mslrb2015/mslrb2015.pde
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Table teamstable;
public static TableRow teamselect;
public static long updateScoreClientslasttime=0;
public static long tstartTime=0, tsplitTime=0, tprevsplitTime=0;
public static boolean TESTMODE=false, stopsplittimer=true, BACKGROUNDon=true, VOICECOACH=false, REMOTECONTROLENABLE=false;
public static boolean TESTMODE=false, stopsplittimer=true, VOICECOACH=false, REMOTECONTROLENABLE=false;
public static char LastKickOff='.';
public static String[] Last5cmds= { ".", ".", ".", ".", "." };
public static String LogFileName;
Expand All @@ -73,11 +73,10 @@ public PImage backgroundImage;
public PImage rcfLogo;

// Sounds
AudioChannel soundMaxTime;
public static AudioChannel soundMaxTime;
public static long lastPlayMillis = 0;

public static PApplet mainApplet = null;
//static long ctr = 0;

/**************************************************************************************************************************
* This the Processing setup() function
Expand Down Expand Up @@ -109,10 +108,6 @@ void setup() {
Config.Load(this, "config.json"); // Load config file
Log.init(this); // Init Log module
comms_initDescriptionDictionary(); // Initializes the dictionary for communications with the basestations


//setbackground(); // Load background
//backgroundImage=get();

scoreClients = new ScoreClients(this, Config.scoreServerPort); // Load score clients server
BaseStationServer = new MyServer(this, Config.basestationServerPort); // Load basestations server
Expand All @@ -134,6 +129,8 @@ void setup() {
Ess.start(this); // start up Ess
if(Config.sounds_maxTime.length() > 0) {
soundMaxTime = new AudioChannel(dataPath("sounds/" + Config.sounds_maxTime));
}else{
soundMaxTime = null;
}
}

Expand All @@ -153,9 +150,8 @@ void setup() {
**************************************************************************************************************************/
void draw() {

if (BACKGROUNDon) background(backgroundImage);
else background(48);

background(backgroundImage);

long t1=getGameTime();
long t2=getSplitTime();
gametime=nf(int((t1/1000)/60), 2)+":"+nf(int((t1/1000)%60), 2);
Expand All @@ -176,19 +172,14 @@ void draw() {
bTeamBcmds[i].update();
}

// ctr ++;
// println ("Update : ", ctr);
teamA.updateUI();
teamB.updateUI();

for (int i = 0; i < bSlider.length; i++)
bSlider[i].update();

// Check scheduled state change
StateMachineCheck();

// Refresh buttons
RefreshButonStatus1();
StateMachineCheck(); // Check scheduled state change
RefreshButonStatus1(); // Refresh buttons

fill(255);
textAlign(CENTER, CENTER);
Expand Down

0 comments on commit f3cb025

Please sign in to comment.