Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fthielke committed Oct 3, 2015
1 parent 77d9e64 commit d228d27
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions build.xml
Expand Up @@ -20,6 +20,7 @@
<target name="compile">
<delete dir="${classes.dir}" quiet="true" />
<mkdir dir="${classes.dir}"/>
<!-- debug flags: debug="true" debuglevel="lines,vars,source" -->
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" source="1.7" target="1.7" encoding="utf-8">
<compilerarg value="-Xlint:-options"/> <!-- ignore nagging about missing bootstrap class path -->
<compilerarg value="-Xlint:unchecked"/>
Expand Down
18 changes: 11 additions & 7 deletions src/teamcomm/data/RobotState.java
Expand Up @@ -70,7 +70,9 @@ public void registerMessage(final SPLStandardMessage message) {
playerNumber = (int) message.playerNum;
}
lastMessageTimestamp = System.currentTimeMillis();
recentMessageTimestamps.addFirst(lastMessageTimestamp);
synchronized (recentMessageTimestamps) {
recentMessageTimestamps.addFirst(lastMessageTimestamp);
}
messageCount++;

for (final RobotStateEventListener listener : listeners.getListeners(RobotStateEventListener.class)) {
Expand Down Expand Up @@ -103,14 +105,16 @@ public SPLStandardMessage getLastMessage() {
* @return number of messages per second
*/
public double getMessagesPerSecond() {
final ListIterator<Long> it = recentMessageTimestamps.listIterator(recentMessageTimestamps.size());
synchronized (recentMessageTimestamps) {
final ListIterator<Long> it = recentMessageTimestamps.listIterator(recentMessageTimestamps.size());

final long curTime = System.currentTimeMillis();
while (curTime - it.previous() > AVERAGE_CALCULATION_TIME) {
it.remove();
}
final long curTime = System.currentTimeMillis();
while (curTime - it.previous() > AVERAGE_CALCULATION_TIME) {
it.remove();
}

return recentMessageTimestamps.size() > 0 ? (recentMessageTimestamps.size() * 1000.0 / Math.max(1000, curTime - recentMessageTimestamps.getLast())) : 0;
return recentMessageTimestamps.size() > 0 ? (recentMessageTimestamps.size() * 1000.0 / Math.max(1000, curTime - recentMessageTimestamps.getLast())) : 0;
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/teamcomm/gui/RobotPanel.java
Expand Up @@ -76,6 +76,7 @@ public void run() {
setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(getForeground()), robot.getAddress(), TitledBorder.CENTER, TitledBorder.TOP));
setLayout(new OverlayLayout(robotPanel));
setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
setMaximumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));

foregroundPanel.setLayout(new BoxLayout(foregroundPanel, BoxLayout.Y_AXIS));
foregroundPanel.setOpaque(false);
Expand Down

0 comments on commit d228d27

Please sign in to comment.