Skip to content

Commit

Permalink
Merge branch 'master' into java-17
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesbraun committed Sep 23, 2023
2 parents 0d87b06 + 0ec8e4d commit d1d7453
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 69 deletions.
17 changes: 1 addition & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@ jobs:
tar czf RoboViz.tar.gz bin/
- name: Create Release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create-release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`.
asset_path: ./RoboViz.tar.gz
asset_name: RoboViz.tar.gz
asset_content_type: application/tar+gzip
run: gh release create ${{ github.ref }} --title ${{ github.ref }} ./RoboViz.tar.gz
2 changes: 1 addition & 1 deletion jsgl/src/main/java/jsgl/jogl/model/ObjModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Face(String line, ObjMaterial material)
readVertexFormat(parts);
} else if (subparts.length == 2) {
readVertexTexCoordsFormat(parts);
} else if (subparts[1].equals("")) {
} else if (subparts[1].isEmpty()) {
readVertexNormalFormat(parts);
} else {
readVertexTexCoordsNormalFormat(parts);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/rv/comm/rcssserver/ILogfileReader.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package rv.comm.rcssserver;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;

public interface ILogfileReader
public interface ILogfileReader extends Closeable
{
interface LogfileListener
{
Expand Down Expand Up @@ -36,7 +37,7 @@ interface LogfileListener
* Closes any open file streams. If the logfile is already closed, this method is ignored. While
* closed, the logfile frames cannot be read.
*/
void close();
void close() throws IOException;

/**
* Moves the current frame ahead by one frame.
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/rv/comm/rcssserver/LogAnalyzerThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ public void run()
}
processFrame();

callback.finished(logfile.getNumFrames());
if (!aborted) {
callback.finished(logfile.getNumFrames());
}

try {
logfile.close();
} catch (IOException e) {
// Ignore exception
}
}

private void processFrame()
Expand Down Expand Up @@ -111,7 +119,9 @@ private void processGoals()
int frame = logfile.getCurrentFrame();
int goalWindowFrames = Math.round((1 / stepSize) * LogPlayer.GOAL_WINDOW_SECONDS);
int viewFrame = Math.max(0, frame - goalWindowFrames);
callback.goalFound(new Goal(frame, viewFrame, scoringTeam));
if (!aborted) {
callback.goalFound(new Goal(frame, viewFrame, scoringTeam));
}
}

lastScoreLeft = scoreLeft;
Expand Down Expand Up @@ -139,7 +149,9 @@ private void processStepSize()
// estimate total number of frames
float halfTime = world.getGameState().getHalfTime();
int numFrames = Math.round(((1 / stepSize) * halfTime) + numPauseFrames);
callback.stepSizeFound(stepSize, numFrames);
if (!aborted) {
callback.stepSizeFound(stepSize, numFrames);
}
this.stepSize = stepSize;
}

Expand Down
26 changes: 23 additions & 3 deletions src/main/java/rv/comm/rcssserver/LogPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,29 @@ private void startAnalyzerThread(File file)
logAnalyzer.abort();
}
logAnalyzer = new LogAnalyzerThread(file, new LogAnalyzerThread.ResultCallback() {
/*
A reference to the logfile reader is stored locally in the beginning of each callback.
This prevents a NullPointerException when logfile is suddenly set to null in another thread.
*/
@Override
public void stepSizeFound(float stepSize, int numFrames)
{
ILogfileReader logfileReader = logfile;
if (logfile == null) {
return;
}
foundStepSize = true;
SECONDS_PER_FRAME = stepSize;
logfile.setNumFrames(numFrames);
logfileReader.setNumFrames(numFrames);
}

@Override
public void goalFound(Goal goal)
{
ILogfileReader logfileReader = logfile;
if (logfile == null) {
return;
}
goals.add(goal);
analyzedFrames = goal.frame();
stateChanged();
Expand All @@ -430,8 +442,12 @@ public void goalFound(Goal goal)
@Override
public void finished(int numFrames)
{
ILogfileReader logfileReader = logfile;
if (logfile == null) {
return;
}
LogPlayer.this.logAnalyzed = true;
logfile.setNumFrames(numFrames);
logfileReader.setNumFrames(numFrames);
analyzedFrames = numFrames;
stateChanged();
}
Expand All @@ -447,7 +463,11 @@ public void stopLogPlayer()
logAnalyzer.abort();

if (logfile != null) {
logfile.close();
try {
logfile.close();
} catch (IOException e) {
// Ignore exception
}
logfile = null;
for (StateChangeListener l : listeners)
l.logfileChanged();
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/rv/comm/rcssserver/Logfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,9 @@ public void rewind() throws IOException
}

@Override
public void close()
public void close() throws IOException
{
try {
br.close();
} catch (Exception ex) {
}
br.close();
}

@Override
Expand Down Expand Up @@ -200,13 +197,6 @@ public void stepAnywhere(int frame) throws IOException
setCurrentFrame(frame);
}

@Override
protected void finalize() throws Throwable
{
super.finalize();
close();
}

@Override
public File getFile()
{
Expand Down Expand Up @@ -254,7 +244,7 @@ public String processDrawCmds(String line)
ByteBuffer buf = ByteBuffer.wrap(drawCmdBytes);

while (buf.hasRemaining()) {
Command cmd = null;
Command cmd;
try {
cmd = Command.parse(buf);
if (cmd != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void rewind() throws IOException
}

@Override
public void close()
public void close() throws IOException
{
decoratee.close();
buffer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,9 @@ public void rewind() throws IOException
}

@Override
public void close()
public void close() throws IOException
{
try {
raf.close();
} catch (Exception ex) {
}
raf.close();
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/rv/comm/rcssserver/ServerComm.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.apache.logging.log4j.Logger;
import org.magmaoffenburg.roboviz.configuration.Config.General;
import org.magmaoffenburg.roboviz.configuration.Config.Networking;
import org.magmaoffenburg.roboviz.util.DataTypes;
import org.magmaoffenburg.roboviz.util.Mode;
import rv.comm.drawing.DrawComm.DrawCommListener;
import rv.world.WorldModel;

Expand Down Expand Up @@ -217,7 +217,7 @@ private void writeToLogfile(String msg)
logfileOutput.write("\n");
}

public ServerComm(WorldModel world, DataTypes.Mode viewerMode)
public ServerComm(WorldModel world, Mode viewerMode)
{
this.world = world;

Expand All @@ -235,7 +235,7 @@ public ServerComm(WorldModel world, DataTypes.Mode viewerMode)
autoConnectTimer.start();
}

recordLogs = viewerMode != DataTypes.Mode.LOG && General.INSTANCE.getRecordLogs();
recordLogs = viewerMode != Mode.LOG && General.INSTANCE.getRecordLogs();
logfileDirectory = General.INSTANCE.getLogfileDirectory();
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/rv/world/WorldModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.magmaoffenburg.roboviz.configuration.Config;
import org.magmaoffenburg.roboviz.configuration.Config.TeamColors;
import org.magmaoffenburg.roboviz.rendering.CameraController;
import org.magmaoffenburg.roboviz.util.DataTypes;
import org.magmaoffenburg.roboviz.util.Mode;
import rv.comm.rcssserver.GameState;
import rv.comm.rcssserver.ISceneGraphItem;
import rv.comm.rcssserver.scenegraph.SceneGraph;
Expand Down Expand Up @@ -184,7 +184,7 @@ public Team getRightTeam()
return rightTeam;
}

public void init(GL glObj, ContentManager cm, DataTypes.Mode mode)
public void init(GL glObj, ContentManager cm, Mode mode)
{
this.cm = cm;
GL2 gl = glObj.getGL2();
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/magmaoffenburg/roboviz/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.magmaoffenburg.roboviz.configuration.Config.General
import org.magmaoffenburg.roboviz.etc.LookAndFeelController
import org.magmaoffenburg.roboviz.gui.MainWindow
import org.magmaoffenburg.roboviz.rendering.Renderer
import org.magmaoffenburg.roboviz.util.DataTypes.Mode
import org.magmaoffenburg.roboviz.util.Mode
import java.awt.EventQueue

class Main {
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/org/magmaoffenburg/roboviz/gui/MainWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.magmaoffenburg.roboviz.configuration.Config.Graphics
import org.magmaoffenburg.roboviz.gui.menus.*
import org.magmaoffenburg.roboviz.gui.windows.LogPlayerControlsPanel
import org.magmaoffenburg.roboviz.rendering.Renderer
import org.magmaoffenburg.roboviz.util.DataTypes
import org.magmaoffenburg.roboviz.util.Mode
import org.magmaoffenburg.roboviz.util.SwingUtils
import rv.comm.rcssserver.LogPlayer
import rv.comm.rcssserver.ServerComm
Expand Down Expand Up @@ -49,7 +49,7 @@ class MainWindow : JFrame(), ServerComm.ServerChangeListener, LogPlayer.StateCha
isVisible = true // set visible after everything is initialized
instance = this

if (Main.mode == DataTypes.Mode.LOG) {
if (Main.mode == Mode.LOG) {
initializeLogPlayerControls()
}
}
Expand Down Expand Up @@ -83,8 +83,8 @@ class MainWindow : JFrame(), ServerComm.ServerChangeListener, LogPlayer.StateCha
jMenuBar.removeAll()

when (Main.mode) {
DataTypes.Mode.LIVE -> initializeLiveMenu()
DataTypes.Mode.LOG -> initializeLogMenu()
Mode.LIVE -> initializeLiveMenu()
Mode.LOG -> initializeLogMenu()
}
}

Expand Down Expand Up @@ -165,8 +165,8 @@ class MainWindow : JFrame(), ServerComm.ServerChangeListener, LogPlayer.StateCha
SwingUtilities.updateComponentTreeUI(this)

when (Main.mode) {
DataTypes.Mode.LOG -> initializeLogPlayerControls()
DataTypes.Mode.LIVE -> logPlayerControls?.dispose()
Mode.LOG -> initializeLogPlayerControls()
Mode.LIVE -> logPlayerControls?.dispose()
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/org/magmaoffenburg/roboviz/rendering/Renderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.apache.logging.log4j.kotlin.logger
import org.magmaoffenburg.roboviz.Main
import org.magmaoffenburg.roboviz.configuration.Config.*
import org.magmaoffenburg.roboviz.gui.MainWindow
import org.magmaoffenburg.roboviz.util.DataTypes
import org.magmaoffenburg.roboviz.util.Mode
import rv.comm.NetworkManager
import rv.comm.drawing.Drawings
import rv.comm.rcssserver.LogPlayer
Expand Down Expand Up @@ -115,7 +115,7 @@ class Renderer : GLProgram(MainWindow.instance.width, MainWindow.instance.height
// initialize all camera stuff
cameraController = CameraController(drawable)

if (Main.mode == DataTypes.Mode.LIVE) {
if (Main.mode == Mode.LIVE) {
netManager = NetworkManager()
netManager.init()
netManager.server.addChangeListener(world.gameState)
Expand All @@ -132,7 +132,7 @@ class Renderer : GLProgram(MainWindow.instance.width, MainWindow.instance.height
if (activeScreenIsInitialized()) {
activeScreen.setEnabled(MainWindow.glCanvas, false)
}
activeScreen = if (Main.mode == DataTypes.Mode.LIVE) LiveGameScreen() else LogfileModeScreen()
activeScreen = if (Main.mode == Mode.LIVE) LiveGameScreen() else LogfileModeScreen()
activeScreen.setEnabled(MainWindow.glCanvas, true)

gl?.let { initEffects(gl) }
Expand Down Expand Up @@ -415,18 +415,18 @@ class Renderer : GLProgram(MainWindow.instance.width, MainWindow.instance.height
cameraController.initPicker()

when (Main.mode) {
DataTypes.Mode.LIVE -> {
Mode.LIVE -> {
netManager = NetworkManager()
netManager.init()
netManager.server.addChangeListener(world.gameState)
netManager.server.addChangeListener(MainWindow.instance)
}
DataTypes.Mode.LOG -> {
Mode.LOG -> {
initLogPlayer()
}
}

activeScreen = if (Main.mode == DataTypes.Mode.LIVE) LiveGameScreen() else LogfileModeScreen()
activeScreen = if (Main.mode == Mode.LIVE) LiveGameScreen() else LogfileModeScreen()
activeScreen.setEnabled(MainWindow.glCanvas, true)
}

Expand Down
10 changes: 3 additions & 7 deletions src/main/kotlin/org/magmaoffenburg/roboviz/util/DataTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package org.magmaoffenburg.roboviz.util

import java.lang.IllegalStateException

class DataTypes {

enum class Mode {
LOG,
LIVE
}

enum class Mode {
LOG,
LIVE
}

enum class ConfirmResult {
Expand Down

0 comments on commit d1d7453

Please sign in to comment.