Skip to content

Commit

Permalink
Fix crashes loading files and clearing edits, apparently caused by ch…
Browse files Browse the repository at this point in the history
…anges to how 1.8 uses threads.
  • Loading branch information
totemo committed Oct 8, 2015
1 parent 2cd1d92 commit c78a6aa
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 78 deletions.
4 changes: 4 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Change History
==============
0.12.1.132-mc1.8.0
------------------
* Fix crashes loading files and clearing edits, apparently caused by changes to how 1.8 uses threads.

0.12.0.130-mc1.8.0
------------------
* Added key bindings to show a Watson in-game GUI, teleport to next or previous ore (/w tp next|prev) and queries of edits before and after the selection (/w pre|post).
Expand Down
2 changes: 1 addition & 1 deletion build/build_watson.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<!-- The version of your mod, can be any string as long as it's valid as part of a file name -->
<!-- and should match the version string returned by your mod. -->
<property name="version" value="0.12.0" />
<property name="version" value="0.12.1" />

<!-- The Minecraft version the mod is for, appended to the output file name for reference -->
<property name="mcversion" value="1.8.0" />
Expand Down
4 changes: 2 additions & 2 deletions build/buildnumber.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Tue Sep 22 18:53:31 ACST 2015
build.number=131
#Fri Oct 09 08:04:08 ACDT 2015
build.number=133
4 changes: 2 additions & 2 deletions res/litemod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

"name": "watson",
"mcversion": "1.8.0",
"version": "0.12.0.130-mc1.8.0",
"revision": "130",
"version": "0.12.1.132-mc1.8.0",
"revision": "132",
"author": "totemo",
"description": "A 3-D log visualisation tool.",
"classTransformerClasses": [ "watson.transformer.WatsonTransformer" ]
Expand Down
112 changes: 39 additions & 73 deletions src/watson/db/BlockEditSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
import java.util.regex.Pattern;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;

import net.minecraft.client.renderer.GlStateManager;
import org.lwjgl.opengl.GL11;

import watson.Configuration;
import watson.Controller;
import watson.DisplaySettings;
Expand All @@ -45,11 +40,11 @@ public BlockEditSet()
// --------------------------------------------------------------------------
/**
* Load additional entries from the specified file.
*
*
* @param file the file to load.
* @return the number of edits loaded.
*/
public int load(File file)
public synchronized int load(File file)
throws Exception
{
BufferedReader reader = new BufferedReader(new FileReader(file));
Expand Down Expand Up @@ -84,7 +79,7 @@ public int load(File file)
int z = Integer.parseInt(edit.group(13));

BlockType type = BlockTypeRegistry.instance.getBlockTypeByIdData(id,
data);
data);
blockEdit = new BlockEdit(time.getTimeInMillis(), player, created, x,
y, z, type);
addBlockEdit(blockEdit);
Expand Down Expand Up @@ -121,20 +116,20 @@ public int load(File file)
// --------------------------------------------------------------------------
/**
* Save all {@link BlockEdit}s to the specified file.
*
*
* Each line is of the form:
*
*
* <pre>
* YYYY-MM-DD|hh:mm:ss|action|id|data|x|y|z
* </pre>
*
*
* Where action is c (created) or d (destroyed) and id is the numeric block
* type.
*
*
* @param file the file to save.
* @return the number of edits saved.
*/
public int save(File file)
public synchronized int save(File file)
throws IOException
{
PrintWriter writer = new PrintWriter(new BufferedWriter(
Expand All @@ -152,7 +147,7 @@ public int save(File file)
for (Annotation annotation : _annotations)
{
writer.format("#%d|%d|%d|%s\n", annotation.getX(), annotation.getY(),
annotation.getZ(), annotation.getText());
annotation.getZ(), annotation.getText());
}
return editCount;
}
Expand All @@ -166,7 +161,7 @@ public int save(File file)
/**
* Remove all entries from the list.
*/
public void clear()
public synchronized void clear()
{
_playerEdits.clear();
_annotations.clear();
Expand All @@ -176,14 +171,14 @@ public void clear()
// --------------------------------------------------------------------------
/**
* Find an edit with the specified coordinates and, optionally, player.
*
*
* @param x the x coordinate of the block
* @param y the y coordinate of the block
* @param z the z coordinate of the block
* @param player the player name (can be null for a wildcard).
* @return the matching edit, or null if not found.
*/
public BlockEdit findEdit(int x, int y, int z, String player)
public synchronized BlockEdit findEdit(int x, int y, int z, String player)
{
if (player != null)
{
Expand All @@ -208,27 +203,27 @@ public BlockEdit findEdit(int x, int y, int z, String player)
// --------------------------------------------------------------------------
/**
* Add the specified edit to the list.
*
*
* State variables describing the most recent edit (player, time, etc.) are
* updated.
*
*
* @param edit the BlockEdit describing an edit to add.
* @return true if the edit passes the currently set filters.
*/
public boolean addBlockEdit(BlockEdit edit)
public synchronized boolean addBlockEdit(BlockEdit edit)
{
return addBlockEdit(edit, true);
}

// --------------------------------------------------------------------------
/**
* Add the specified edit to the list.
*
*
* @param edit the BlockEdit describing an edit to add.
* @param updateVariables update the state variables for the most recent edit.
* @return true if the edit passes the currently set filters.
*/
public boolean addBlockEdit(BlockEdit edit, boolean updateVariables)
public synchronized boolean addBlockEdit(BlockEdit edit, boolean updateVariables)
{
if (Controller.instance.getFilters().isAcceptedPlayer(edit.player))
{
Expand Down Expand Up @@ -269,7 +264,7 @@ public boolean addBlockEdit(BlockEdit edit, boolean updateVariables)
* List the number and visibility of stored edits on a per player basis in the
* dimension to which this BlockEditSet applies.
*/
public void listEdits()
public synchronized void listEdits()
{
if (_playerEdits.size() == 0)
{
Expand All @@ -281,44 +276,44 @@ public void listEdits()
for (PlayerEditSet editsByPlayer : _playerEdits.values())
{
Chat.localOutput(String.format(Locale.US,
" %s - %d edits %s", editsByPlayer.getPlayer(),
editsByPlayer.getBlockEditCount(),
(editsByPlayer.isVisible() ? "shown" : "hidden")));
" %s - %d edits %s", editsByPlayer.getPlayer(),
editsByPlayer.getBlockEditCount(),
(editsByPlayer.isVisible() ? "shown" : "hidden")));
}
}
} // listEdits

// --------------------------------------------------------------------------
/**
* Set the visibility of the edits for the specified player.
*
*
* @param player the name of the player.
* @param visible if true, edits are shown.
*/
public void setEditVisibility(String player, boolean visible)
public synchronized void setEditVisibility(String player, boolean visible)
{
player = player.toLowerCase();
PlayerEditSet editsByPlayer = _playerEdits.get(player);
if (editsByPlayer != null)
{
editsByPlayer.setVisible(visible);
Chat.localOutput(String.format(Locale.US,
"%d edits by %s are now %s.", editsByPlayer.getBlockEditCount(),
editsByPlayer.getPlayer(), (editsByPlayer.isVisible() ? "shown"
: "hidden")));
"%d edits by %s are now %s.", editsByPlayer.getBlockEditCount(),
editsByPlayer.getPlayer(), (editsByPlayer.isVisible() ? "shown"
: "hidden")));
}
else
{
Chat.localError(String.format(Locale.US,
"There are no stored edits for %s.", player));
"There are no stored edits for %s.", player));
}
} // setEditVisibility

// --------------------------------------------------------------------------
/**
* @param player the name of the player.
*/
public void removeEdits(String player)
public synchronized void removeEdits(String player)
{
player = player.toLowerCase();
PlayerEditSet editsByPlayer = _playerEdits.get(player);
Expand All @@ -327,21 +322,21 @@ public void removeEdits(String player)
_playerEdits.remove(player.toLowerCase());
getOreDB().removeDeposits(player);
Chat.localOutput(String.format(Locale.US,
"%d edits by %s were removed.", editsByPlayer.getBlockEditCount(),
editsByPlayer.getPlayer()));
"%d edits by %s were removed.", editsByPlayer.getBlockEditCount(),
editsByPlayer.getPlayer()));
}
else
{
Chat.localError(String.format(Locale.US,
"There are no stored edits for %s.", player));
"There are no stored edits for %s.", player));
}
} // removeEdits

// --------------------------------------------------------------------------
/**
* Draw wireframe outlines of all blocks.
*/
public void drawOutlines()
public synchronized void drawOutlines()
{
if (Controller.instance.getDisplaySettings().isOutlineShown())
{
Expand All @@ -356,7 +351,7 @@ public void drawOutlines()
/**
* Draw direction vectors indicating motion of the miner.
*/
public void drawVectors()
public synchronized void drawVectors()
{
DisplaySettings settings = Controller.instance.getDisplaySettings();
if (settings.areVectorsShown())
Expand All @@ -374,7 +369,7 @@ public void drawVectors()
/**
* Draw all of the annotations associated with this BlockEditSet.
*/
public void drawAnnotations()
public synchronized void drawAnnotations()
{
DisplaySettings settings = Controller.instance.getDisplaySettings();
if (settings.areAnnotationsShown() && !_annotations.isEmpty())
Expand All @@ -386,30 +381,10 @@ public void drawAnnotations()
} // if drawing annotations
} // drawAnnotations

// --------------------------------------------------------------------------
/**
* Experimental: draw a HUD overlay listing ores.
*/
public void drawHUD()
{
try
{
GlStateManager.pushMatrix();

Minecraft mc = Minecraft.getMinecraft();
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);

}
finally
{
GlStateManager.popMatrix();
}
} // drawHUD

// --------------------------------------------------------------------------
/**
* Return the list of {@link Annotation}s.
*
*
* @return the list of {@link Annotation}s.
*/
public ArrayList<Annotation> getAnnotations()
Expand All @@ -420,24 +395,14 @@ public ArrayList<Annotation> getAnnotations()
// --------------------------------------------------------------------------
/**
* Return the spatial database of ore deposits.
*
*
* @return the spatial database of ore deposits.
*/
public OreDB getOreDB()
{
return _oreDB;
}

// --------------------------------------------------------------------------
/**
* Start animating all of the edits in the list.
*/
public void startAnimating()
{
// Record current time as start time.
// Set cursor in _edits to oldest edit position.
}

// --------------------------------------------------------------------------
/**
* A map from lowercase player name to {@link PlayerEditSet} containing that
Expand All @@ -460,8 +425,9 @@ public void startAnimating()
* The cycle of colours used to draw vectors for different players.
*/
protected static final ARGB[] _vectorColours = {
// Formatters...
new ARGB(204, 255, 255, 140), // Pale yellow.

new ARGB(204, 255, 255, 140), // Pale
// yellow.
new ARGB(204, 140, 158, 255), // Light blue.
new ARGB(204, 255, 140, 140), // Salmon.
new ARGB(204, 121, 255, 140), // Mint.
Expand Down

0 comments on commit c78a6aa

Please sign in to comment.