Cached length

This commit is contained in:
Willem Cazander 2022-10-13 14:38:07 +02:00
parent 9c1161e84c
commit 3acc28dbbf
9 changed files with 97 additions and 29 deletions

View file

@ -31,7 +31,7 @@ public class CalculatorComponent {
private final DeskAppLauncher launcher; private final DeskAppLauncher launcher;
public CalculatorComponent() { public CalculatorComponent() {
launcher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Calculator", () -> new CalculatorDeskApp(createBundle())); launcher = new DeskAppLauncher(DeskAppMenuSection.SCIENCE, "Calculator", () -> new CalculatorDeskApp(createBundle()));
} }
private ResourceBundle createBundle() { private ResourceBundle createBundle() {

View file

@ -49,7 +49,7 @@ public class GlyphDemoComponent {
unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle(), unicode4DService)); unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle(), unicode4DService));
baseGlyphLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Glyph Set", () -> new DemoGlyphSetDeskApp(createBundle())); baseGlyphLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Glyph Set", () -> new DemoGlyphSetDeskApp(createBundle()));
basePartLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Number Parts", () -> new DemoNumberPartDeskApp(createBundle())); basePartLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Number Parts", () -> new DemoNumberPartDeskApp(createBundle()));
unitConverterLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Unitˣᶜ Converter", () -> new DemoUnitConverterDeskApp(unitManager)); unitConverterLauncher = new DeskAppLauncher(DeskAppMenuSection.SCIENCE, "Unitˣᶜ Converter", () -> new DemoUnitConverterDeskApp(unitManager));
} }
private ResourceBundle createBundle() { private ResourceBundle createBundle() {

View file

@ -1,5 +1,6 @@
package love.distributedrebirth.gdxapp4d.app.glyphdemo.apps; package love.distributedrebirth.gdxapp4d.app.glyphdemo.apps;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -16,6 +17,8 @@ import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection;
import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer;
import love.distributedrebirth.numberxd.base2t.part.T10PartDecimal;
import love.distributedrebirth.numberxd.base2t.part.T16PartHex;
import net.forwardfire.unitxc.UnitXCManager; import net.forwardfire.unitxc.UnitXCManager;
import net.forwardfire.unitxc.model.UnitXCGroup; import net.forwardfire.unitxc.model.UnitXCGroup;
import net.forwardfire.unitxc.model.UnitXCType; import net.forwardfire.unitxc.model.UnitXCType;
@ -34,7 +37,7 @@ public class DemoUnitConverterDeskApp extends AbstractDeskApp implements DeskApp
private final ImInt convertFromType = new ImInt(); private final ImInt convertFromType = new ImInt();
private final ImInt unitTypeLimit = new ImInt(5432); private final ImInt unitTypeLimit = new ImInt(5432);
private final List<UnitXCType> convertFromTypes; private final List<UnitXCType> convertFromTypes;
private final long totalUnits; private final BigInteger totalUnits;
private String[] convertFromTypeNames; private String[] convertFromTypeNames;
public DemoUnitConverterDeskApp(UnitXCManager unitManager) { public DemoUnitConverterDeskApp(UnitXCManager unitManager) {
@ -60,7 +63,7 @@ public class DemoUnitConverterDeskApp extends AbstractDeskApp implements DeskApp
long tc = typeGroup.getUnitTypeSize(); long tc = typeGroup.getUnitTypeSize();
ts += tc; ts += tc;
} }
this.totalUnits = ts; this.totalUnits = BigInteger.valueOf(ts); // TODO: goto DEC144 for counting unit types
updateConvertFromType(); updateConvertFromType();
updateUnitType(); updateUnitType();
@ -73,7 +76,9 @@ public class DemoUnitConverterDeskApp extends AbstractDeskApp implements DeskApp
@Override @Override
public void render() { public void render() {
ImGui.text("Total units loaded: "+totalUnits); String amount10 = totalUnits.toString(T10PartDecimal.DEFAULT.BãßĦǿɇṽḝę̃ɬḪễïđ());
String amount16 = totalUnits.toString(T16PartHex.DEFAULT.BãßĦǿɇṽḝę̃ɬḪễïđ());
ImGui.text("Total units loaded: "+amount10+" ("+amount16+")");
// TODO: don't do update on render thread // TODO: don't do update on render thread
if (ImGui.inputDouble("ConvertValue", convertValue)) { if (ImGui.inputDouble("ConvertValue", convertValue)) {

View file

@ -0,0 +1,5 @@
package love.distributedrebirth.bassboonyd;
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public interface BãßBȍőnInitMarkerʸᴰ {
}

View file

@ -18,14 +18,6 @@ public interface DefaultEnumSetʸᴰ<T> extends DefaultEnumBaseʸᴰ<T> {
return ordinal() + 1; return ordinal() + 1;
} }
default int LENGTH() {
return BãßĦǿɇṽḝę̃ɬḪễïđ();
}
default int BãßĦǿɇṽḝę̃ɬḪễïđ() {
return BãßInstances().length;
}
default List<T> BãßInstancesList() { default List<T> BãßInstancesList() {
return Arrays.asList(BãßInstances()); return Arrays.asList(BãßInstances());
} }

View file

@ -1,20 +1,63 @@
package love.distributedrebirth.bassboonyd; package love.distributedrebirth.bassboonyd;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.LinkedHashSet;
import java.util.Set;
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
@BãßBȍőnAnnotationInfoʸᴰ(required = {}) @BãßBȍőnAnnotationInfoʸᴰ(required = {})
public interface DefaultInitMethodʸᴰ { public interface DefaultInitMethodʸᴰ {
default void BOON_INIT(Object boon) { default void BOON_INIT(Object boon) {
try {
for (Method m:boon.getClass().getMethods()) { final class InitScanner {
if (m.isAnnotationPresent(BãßBȍőnInitMethodʸᴰ.class)) {
m.invoke(boon, this); public void scanInterfaces(Object boon, Object bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
for (Class<?> interfaceClass:walkInterfaces(boon.getClass(), new LinkedHashSet<>())) {
for (Class<?> declaredClass:((Class<?>) interfaceClass).getDeclaredClasses()) {
initStaticMarker(declaredClass, bbc);
}
} }
} }
public void scanClass(Object boon, Object bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
for (Class<?> declaredClass:boon.getClass().getDeclaredClasses()) {
initStaticMarker(declaredClass, bbc);
}
}
private void initStaticMarker(Class<?> declaredClass, Object bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (!BãßBȍőnInitMarkerʸᴰ.class.isAssignableFrom(declaredClass)) {
return;
}
for (Method m:declaredClass.getDeclaredMethods()) {
if (m.isAnnotationPresent(BãßBȍőnInitMethodʸᴰ.class)) {
m.setAccessible(true);
m.invoke(null, bbc);
}
}
}
private Set<Class<?>> walkInterfaces(Class<?> clazz, Set<Class<?>> result) {
while (clazz != null) {
for (Class<?> next : clazz.getInterfaces()) {
if (result.add(next)) {
return walkInterfaces(next, result);
}
}
clazz = clazz.getSuperclass();
}
return result;
}
}
InitScanner init = new InitScanner();
try {
init.scanInterfaces(boon, this);
init.scanClass(boon, this);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
} }

View file

@ -13,6 +13,7 @@ public enum BãßBȍőnPartKeyʸᴰ implements BãßBȍőnCoffinStoreKeyʸᴰ {
MAP_TONE, MAP_TONE,
MAP_CHINA, MAP_CHINA,
MAP_CACHE,
ALT_1_VALUE, ALT_1_VALUE,
ALT_2_VALUE, ALT_2_VALUE,

View file

@ -5,22 +5,13 @@ import java.util.Map;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinOpenʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinOpenʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinStoreʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinStoreʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnInitMarkerʸᴰ;
import love.distributedrebirth.bassboonyd.DefaultEnumSetʸᴰ; import love.distributedrebirth.bassboonyd.DefaultEnumSetʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnInitMethodʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnInitMethodʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
public interface BãßBȍőnPartʸᴰ<T extends BãßBȍőnPartʸᴰ<T>> extends DefaultEnumSetʸᴰ<T>, BãßBȍőnCoffinStoreʸᴰ<BãßBȍőnPartKeyʸᴰ> { public interface BãßBȍőnPartʸᴰ<T extends BãßBȍőnPartʸᴰ<T>> extends DefaultEnumSetʸᴰ<T>, BãßBȍőnCoffinStoreʸᴰ<BãßBȍőnPartKeyʸᴰ> {
@BãßBȍőnInitMethodʸᴰ
default void initMapTone(BãßBȍőnCoffinOpenʸᴰ<BãßBȍőnPartKeyʸᴰ> BBC) {
BBC.PUT_MAP(BãßBȍőnPartKeyʸᴰ.MAP_TONE);
}
@BãßBȍőnInitMethodʸᴰ
default void initMapChina(BãßBȍőnCoffinOpenʸᴰ<BãßBȍőnPartKeyʸᴰ> BBC) {
BBC.PUT_MAP(BãßBȍőnPartKeyʸᴰ.MAP_CHINA);
}
default String BȍőnDialTone() { default String BȍőnDialTone() {
return GET_BBC().GET_STR(BãßBȍőnPartKeyʸᴰ.DIAL_TONE); return GET_BBC().GET_STR(BãßBȍőnPartKeyʸᴰ.DIAL_TONE);
} }
@ -50,4 +41,36 @@ public interface BãßBȍőnPartʸᴰ<T extends BãßBȍőnPartʸᴰ<T>> extends
} }
return (T) mapChina.get(chinaKey); return (T) mapChina.get(chinaKey);
} }
public static class Init implements BãßBȍőnInitMarkerʸᴰ {
@BãßBȍőnInitMethodʸᴰ
private static void initMapTone(BãßBȍőnCoffinOpenʸᴰ<BãßBȍőnPartKeyʸᴰ> BBC) {
BBC.PUT_MAP(BãßBȍőnPartKeyʸᴰ.MAP_TONE);
}
@BãßBȍőnInitMethodʸᴰ
private static void initMapChina(BãßBȍőnCoffinOpenʸᴰ<BãßBȍőnPartKeyʸᴰ> BBC) {
BBC.PUT_MAP(BãßBȍőnPartKeyʸᴰ.MAP_CHINA);
}
@BãßBȍőnInitMethodʸᴰ
private static void initMapCache(BãßBȍőnCoffinOpenʸᴰ<BãßBȍőnPartKeyʸᴰ> BBC) {
BBC.PUT_MAP(BãßBȍőnPartKeyʸᴰ.MAP_CACHE);
}
}
public static class MapCacheKey {
private static final String LENGTH = "length";
}
default int BãßĦǿɇṽḝę̃ɬḪễïđ() {
Map<String,Object> mapCache = GET_BBC().GET_MAP_OBJ(BãßBȍőnPartKeyʸᴰ.MAP_CACHE);
Integer length = Integer.class.cast(mapCache.get(MapCacheKey.LENGTH));
if (length == null) {
length = BãßInstances().length;
mapCache.put(MapCacheKey.LENGTH, length);
}
return length;
}
} }

View file

@ -208,7 +208,6 @@ public class GDXAppTos4Activator implements BundleActivator {
} }
bootScreen.bootLine("gdx-font: "+parameter.characters.length()+" glyphs loaded."); bootScreen.bootLine("gdx-font: "+parameter.characters.length()+" glyphs loaded.");
context.registerService(SystemGdxFont.class.getName(), new SystemGdxFontImpl(gdxFont), new Hashtable<String, String>()); context.registerService(SystemGdxFont.class.getName(), new SystemGdxFontImpl(gdxFont), new Hashtable<String, String>());
context.registerService(SystemGdxLog.class.getName(), systemGdxLog, new Hashtable<String, String>()); context.registerService(SystemGdxLog.class.getName(), systemGdxLog, new Hashtable<String, String>());
context.registerService(SystemGdxBootArgs.class.getName(), new SystemGdxBootArgsImpl(), new Hashtable<String, String>()); context.registerService(SystemGdxBootArgs.class.getName(), new SystemGdxBootArgsImpl(), new Hashtable<String, String>());