Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix advanced chunk monitoring system #3499

Merged
merged 7 commits into from
Oct 24, 2018

Conversation

llvieira
Copy link
Member

@llvieira llvieira commented Oct 6, 2018

Contains

Fixes #3010. The goal here is to fix the problem of preventing the game from close cleanly. After dive into the code I realize that the Thread created by ExecutorService in ThreadMonitorPanel, PerformanceMonitorPanel and ChunkMonitorDisplay keeps running after the game closes. Therefore, I changed a little the way thread monitors work. Also the whole monitor code were cleaned up.

To fix the problem I created a variable called stopThread for each of the three monitors. If stopThread is true then the monitor thread leaves the loop and the executor service is shutdown, which will allow the game to close gracefully.

How to test

  • Toggle "monitoringEnabled": false, to true in config.cfg (run the game once to get one).
  • Run the game.
  • Close the game.

@GooeyHub
Copy link
Member

GooeyHub commented Oct 6, 2018

Hooray Jenkins reported success with all tests good!

@llvieira llvieira changed the title New implementation of advanced chunk monitoring system - WIP New implementation of advanced chunk monitoring system Oct 6, 2018
@GooeyHub
Copy link
Member

GooeyHub commented Oct 8, 2018

Hooray Jenkins reported success with all tests good!

@GooeyHub
Copy link
Member

GooeyHub commented Oct 9, 2018

Hooray Jenkins reported success with all tests good!

@llvieira llvieira changed the title New implementation of advanced chunk monitoring system Fix advanced chunk monitoring system Oct 9, 2018
@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

Copy link
Member

@Cervator Cervator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor tweaks suggested, but the cleanup appears solid and I can confirm the game exits cleanly 👍


add(tabs, BorderLayout.CENTER);
}

/**
* This method goes through three steps:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to start any Javadoc with a brief single sentence describing the overall goal of the method, then optionally dig into the details later. First sentence gets used in the summary box in the Javadoc site, which in this case would thus end up solely containing "This method goes through three steps:" :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Fixed! :-)

private final transient Runnable renderTask;

/**
* If true, the active monitoring thread in executor service should stop.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the one-line format here since it is a field and tiny

Suggested change
* If true, the active monitoring thread in executor service should stop.
/** If true, the active monitoring thread in executor service should stop. */

(Trying out the new GitHub "Suggestion" feature, but it originates in one line yet my suggestion replaces three lines - hmm)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -105,13 +104,18 @@ public ChunkMonitorDisplay(int refreshInterval, int chunkSize) {
addMouseListener(ml);
addMouseMotionListener(ml);
addMouseWheelListener(ml);
this.followPlayer = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the removal of setFollowPlayer this var itself might be obsolete since there's no way to change it. Probably either keep the setter in expectation that it'll be added as a toggle in the UI sometime or just remove it entirely :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to keep the setter, so we can open an issue to add that new UI functionality.

public static final Color COLOR_INVALID = Color.red;

private static final Logger logger = LoggerFactory.getLogger(ChunkMonitorDisplay.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ChunkMonitorDisplay.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All caps logger or not is a tricky subject. See https://stackoverflow.com/questions/1417190/should-a-static-final-logger-be-declared-in-upper-case - generally we've kept it lower case so probably best to stay consistent that way, at least for now :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, according to Java Code Style is should be lower-case. I changed it after CheckStyle scan, however CheckStyle cannot check if this object reference is never followed by a ".".

@@ -694,12 +631,12 @@ private void renderSelectedChunk(Graphics2D g, int offsetx, int offsety, Vector3
}

private void renderBox(Graphics2D g, int offsetx, int offsety, Rectangle box) {
g.setColor(Color.white);
g.setColor(Color.WHITE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case change on the other hand is definitely good 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 😃


/**
* If true, the active monitoring thread in executor service should stop.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another could-be one-liner

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

5 similar comments
@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

@Cervator Cervator merged commit d1c5439 into MovingBlocks:develop Oct 24, 2018
@Cervator
Copy link
Member

All good, thanks! :-)

@Cervator Cervator added the Type: Bug Issues reporting and PRs fixing problems label Oct 24, 2018
@Cervator Cervator added this to the v2.1.0 milestone Oct 24, 2018
@llvieira llvieira deleted the refator-advanced-monitoring branch October 24, 2018 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issues reporting and PRs fixing problems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Advanced chunk monitor prevents game from closing cleanly
3 participants