Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 1.7.10-shortening
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/java/com/kamesuta/mc/signpic/entry/content/ContentManager.java
  • Loading branch information
Kamesuta committed Dec 2, 2016
2 parents 307f064 + e4905ed commit 7ceca6d
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.kamesuta.mc.bnnwidget;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

public class ShortestFloatFormatter {
private static final DecimalFormat signformat;

static {
final DecimalFormat format = new DecimalFormat(".##");
final DecimalFormatSymbols custom = new DecimalFormatSymbols();
custom.setDecimalSeparator('.');
format.setDecimalFormatSymbols(custom);
signformat = format;
}

public static String format(final float f) {
if (f==0)
return "0";

final String str = signformat.format(f);

final String cut = ".0";

int end = str.length();
int last = cut.length();

while (end!=0&&last!=0)
if (cut.charAt(last-1)==str.charAt(end-1))
end--;
else
last--;
return str.substring(0, end);
}
}
31 changes: 4 additions & 27 deletions src/main/java/com/kamesuta/mc/bnnwidget/component/MNumber.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.kamesuta.mc.bnnwidget.component;

import java.text.DecimalFormat;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import com.kamesuta.mc.bnnwidget.ShortestFloatFormatter;
import com.kamesuta.mc.bnnwidget.WEvent;
import com.kamesuta.mc.bnnwidget.WPanel;
import com.kamesuta.mc.bnnwidget.position.Area;
import com.kamesuta.mc.bnnwidget.position.Coord;
import com.kamesuta.mc.bnnwidget.position.Point;
import com.kamesuta.mc.bnnwidget.position.R;
import com.kamesuta.mc.signpic.image.meta.ImageMeta.MetaParser;

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
Expand Down Expand Up @@ -54,7 +52,7 @@ else if (GuiScreen.isCtrlKeyDown())
f = .01f;
else
f = 1f;
MNumber.this.field.setText(format(NumberUtils.toFloat(MNumber.this.field.getText())-f));
MNumber.this.field.setText(ShortestFloatFormatter.format(NumberUtils.toFloat(MNumber.this.field.getText())-f));
return true;
}

Expand All @@ -66,12 +64,12 @@ else if (GuiScreen.isCtrlKeyDown())
f = .01f;
else
f = 1f;
MNumber.this.field.setText(format(NumberUtils.toFloat(MNumber.this.field.getText())+f));
MNumber.this.field.setText(ShortestFloatFormatter.format(NumberUtils.toFloat(MNumber.this.field.getText())+f));
return true;
}

public MNumber setNumber(final float f) {
this.field.setText(Float.isNaN(f) ? "" : MetaParser.format(f));
this.field.setText(Float.isNaN(f) ? "" : ShortestFloatFormatter.format(f));
return this;
}

Expand All @@ -95,25 +93,4 @@ public MNumber setUnknownLabel(final String s) {

protected void onNumberChanged(final String oldText, final String newText) {
}

private static final DecimalFormat signformat = new DecimalFormat(".##");

public static String format(final float f) {
if (f==0)
return "0";

final String str = signformat.format(f);

final String cut = ".0";

int end = str.length();
int last = cut.length();

while (end!=0&&last!=0)
if (cut.charAt(last-1)==str.charAt(end-1))
end--;
else
last--;
return str.substring(0, end);
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/kamesuta/mc/signpic/entry/EntryId.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ public static EntryId fromStrings(final String[] strings) {
}

public static EntryId fromTile(final TileEntitySign tile) {
if (tile==null)
return blank;
return fromStrings(tile.signText);
}

public static EntryId fromChats(final IChatComponent[] chats) {
if (chats==null)
return blank;
final StringBuilder stb = new StringBuilder();
for (final IChatComponent chat : chats)
if (chat!=null)
Expand All @@ -75,6 +79,8 @@ public static EntryId fromChats(final IChatComponent[] chats) {
}

public static EntryId fromItemStack(final ItemStack itemStack) {
if (itemStack==null)
return blank;
final String name = itemStack.getDisplayName();
final int index = StringUtils.lastIndexOf(name, "}");
return from(StringUtils.substring(itemStack.getDisplayName(), 0, index!=StringUtils.INDEX_NOT_FOUND ? index+1 : 0));
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/kamesuta/mc/signpic/entry/EntryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class EntryManager implements ITickEntry {
public static final EntryManager instance = new EntryManager();

private final Map<EntryId, EntrySlot<Entry>> registry = Maps.newHashMap();
private final Map<EntryId, EntrySlot<Entry>> registry = Maps.newConcurrentMap();

protected Entry get(final EntryId id) {
final EntrySlot<Entry> entries = this.registry.get(id);
Expand All @@ -29,9 +29,8 @@ public void onTick() {
final Map.Entry<EntryId, EntrySlot<Entry>> entry = itr.next();
final EntrySlot<Entry> collectableSignEntry = entry.getValue();

if (collectableSignEntry.shouldCollect()) {
if (collectableSignEntry.shouldCollect())
itr.remove();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.kamesuta.mc.signpic.entry.content;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.google.common.collect.Maps;
import com.google.common.collect.Queues;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.kamesuta.mc.signpic.Config;
import com.kamesuta.mc.signpic.CoreEvent;
Expand All @@ -23,9 +24,9 @@ public class ContentManager implements ITickEntry {

public final ExecutorService threadpool = Executors.newFixedThreadPool(Config.instance.contentLoadThreads,
new ThreadFactoryBuilder().setNameFormat("signpic-content-%d").build());
private final HashMap<ContentId, ContentSlot> registry = new HashMap<ContentId, ContentSlot>();
private final Deque<ContentSlot> loadqueue = new ArrayDeque<ContentSlot>();
private final Deque<IDivisionProcessable> divisionqueue = new ArrayDeque<IDivisionProcessable>();
private final Map<ContentId, ContentSlot> registry = Maps.newConcurrentMap();
private final Queue<ContentSlot> loadqueue = Queues.newConcurrentLinkedQueue();
private final Queue<IDivisionProcessable> divisionqueue = Queues.newConcurrentLinkedQueue();
private int loadtick = 0;
private int divisiontick = 0;

Expand All @@ -46,9 +47,7 @@ public void run() {
}

public void enqueueDivision(final IDivisionProcessable divisionProcessable) {
synchronized (this.divisionqueue) {
this.divisionqueue.offer(divisionProcessable);
}
this.divisionqueue.offer(divisionProcessable);
}

protected Content get(final ContentId id) {
Expand Down Expand Up @@ -82,9 +81,7 @@ public void onTick() {
if ((divisionprocess = this.divisionqueue.peek())!=null)
try {
if (divisionprocess.onDivisionProcess())
synchronized (this.divisionqueue) {
this.divisionqueue.poll();
}
this.divisionqueue.poll();
} catch (final Exception e) {
e.printStackTrace();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kamesuta/mc/signpic/gui/GuiImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void draw(final WEvent ev, final Area pgp, final Point p, final float fra
add(new WPanel(new R()) {
@Override
protected void initWidget() {
final VCommon var = V.range(V.a(.5f), V.a(.8f), V.p(.5f));
final VCommon var = V.a(.8f);
add(new UpdateLogo(new R(Coord.width(var), Coord.height(var), Coord.pleft(.5f), Coord.ptop(.5f)).child(Coord.pleft(-.5f), Coord.ptop(-.5f))));
add(new MScaledLabel(new R(Coord.pleft(.5f), Coord.top(0), Coord.pheight(.4f), Coord.width(2)).child(Coord.pleft(-.5f))).setText(I18n.format("signpic.advmsg.format.unsupported")).setColor(0xff9900).setShadow(true));
if (Informations.instance.isUpdateRequired())
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/com/kamesuta/mc/signpic/image/meta/ImageMeta.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kamesuta.mc.signpic.image.meta;

import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -77,27 +76,6 @@ public String toString() {
}

public static abstract class MetaParser {
private static final DecimalFormat signformat = new DecimalFormat(".##");

public static String format(final float f) {
if (f==0)
return "0";

final String str = signformat.format(f);

final String cut = ".0";

int end = str.length();
int last = cut.length();

while (end!=0&&last!=0)
if (cut.charAt(last-1)==str.charAt(end-1))
end--;
else
last--;
return str.substring(0, end);
}

public abstract boolean parse(String src, String key, String value);

public abstract MetaParser reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import com.kamesuta.mc.bnnwidget.ShortestFloatFormatter;

public class ImageOffset extends ImageMeta.MetaParser {
public static final float defaultOffset = 0.5f;

Expand Down Expand Up @@ -56,24 +58,24 @@ public String compose() {
if (this.x!=0)
if (this.x<0)
if (this.x==-defaultOffset) stb.append("L");
else stb.append("L").append(format(-this.x));
else stb.append("L").append(ShortestFloatFormatter.format(-this.x));
else
if (this.x==defaultOffset) stb.append("R");
else stb.append("R").append(format(this.x));
else stb.append("R").append(ShortestFloatFormatter.format(this.x));
if (this.y!=0)
if (this.y<0)
if (this.y==-defaultOffset) stb.append("D");
else stb.append("D").append(format(-this.y));
else stb.append("D").append(ShortestFloatFormatter.format(-this.y));
else
if (this.y==defaultOffset) stb.append("U");
else stb.append("U").append(format(this.y));
else stb.append("U").append(ShortestFloatFormatter.format(this.y));
if (this.z!=0)
if (this.z<0)
if (this.z==-defaultOffset) stb.append("B");
else stb.append("B").append(format(-this.z));
else stb.append("B").append(ShortestFloatFormatter.format(-this.z));
else
if (this.z==defaultOffset) stb.append("F");
else stb.append("F").append(format(this.z));
else stb.append("F").append(ShortestFloatFormatter.format(this.z));
return stb.toString();
/* @formatter:on */
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import com.kamesuta.mc.bnnwidget.ShortestFloatFormatter;
import com.kamesuta.mc.signpic.render.OpenGL;

public class ImageRotation extends ImageMeta.MetaParser {
Expand Down Expand Up @@ -71,7 +72,7 @@ public String compose() {
else if (rotate==defaultOffset)
return this.type.name();
else
return this.type.name()+format(rotate);
return this.type.name()+ShortestFloatFormatter.format(rotate);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import com.kamesuta.mc.bnnwidget.ShortestFloatFormatter;
import com.kamesuta.mc.bnnwidget.position.Area;

public class ImageSize extends ImageMeta.MetaParser implements Cloneable {
Expand Down Expand Up @@ -140,7 +141,7 @@ else if (StringUtils.equals(key, "x"))

@Override
public String compose() {
return (vaildWidth() ? format(this.width) : "")+(vaildHeight() ? "x"+format(this.height) : "");
return (vaildWidth() ? ShortestFloatFormatter.format(this.width) : "")+(vaildHeight() ? "x"+ShortestFloatFormatter.format(this.height) : "");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import com.kamesuta.mc.bnnwidget.ShortestFloatFormatter;

public class ImageTextureMap extends ImageMeta.MetaParser {
public static final float defaultUV = 0f;
// Width Height
Expand Down Expand Up @@ -58,19 +60,19 @@ public boolean parse(final String src, final String key, final String value) {
public String compose() {
final StringBuilder stb = new StringBuilder();
if (this.u!=defaultUV)
stb.append("u").append(format(this.u));
stb.append("u").append(ShortestFloatFormatter.format(this.u));
if (this.v!=defaultUV)
stb.append("v").append(format(this.v));
stb.append("v").append(ShortestFloatFormatter.format(this.v));
if (this.w!=defaultWH)
stb.append("w").append(format(this.w));
stb.append("w").append(ShortestFloatFormatter.format(this.w));
if (this.h!=defaultWH)
stb.append("h").append(format(this.h));
stb.append("h").append(ShortestFloatFormatter.format(this.h));
if (this.c!=defaultCS)
stb.append("c").append(format(this.c));
stb.append("c").append(ShortestFloatFormatter.format(this.c));
if (this.s!=defaultCS)
stb.append("s").append(format(this.s));
stb.append("s").append(ShortestFloatFormatter.format(this.s));
if (this.o!=defaultOpacity)
stb.append("o").append(format(this.o));
stb.append("o").append(ShortestFloatFormatter.format(this.o));
if (this.r!=defaultRepeat)
stb.append("r");
if (this.m!=defaultMipMap)
Expand Down

0 comments on commit 7ceca6d

Please sign in to comment.