Skip to content

Commit d8126c0

Browse files
committed
Add memory accessing functions.
1 parent db4bfdd commit d8126c0

File tree

4 files changed

+101
-7
lines changed

4 files changed

+101
-7
lines changed

src/main/java/alexiil/mc/mod/load/ClsManager.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ public class ClsManager {
7777
FUNC_CTX.put_s("tip", Tips::getFirstTip);
7878
FUNC_CTX.put_l("tip_count", Tips::getTipCount);
7979
FUNC_CTX.put_l_o("tip", String.class, Tips::getTip);
80+
81+
FUNC_CTX.put_l("memory_bytes_total", Runtime.getRuntime()::totalMemory);
82+
FUNC_CTX.put_l("memory_bytes_max", Runtime.getRuntime()::maxMemory);
83+
FUNC_CTX.put_l("memory_bytes_free", Runtime.getRuntime()::freeMemory);
84+
FUNC_CTX.put_l("memory_bytes_used", () -> {
85+
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
86+
});
87+
88+
FUNC_CTX.put_l("memory_total", () -> Runtime.getRuntime().totalMemory() / 1024 / 1024);
89+
FUNC_CTX.put_l("memory_max", () -> Runtime.getRuntime().maxMemory() / 1024 / 1024);
90+
FUNC_CTX.put_l("memory_free", () -> Runtime.getRuntime().freeMemory() / 1024 / 1024);
91+
FUNC_CTX.put_l("memory_used", () -> {
92+
return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024;
93+
});
8094
}
8195

8296
public static boolean load() throws InvalidExpressionException {

src/main/java/alexiil/mc/mod/load/render/FontRendererSeparate.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public FontRendererSeparate(GameSettings settings, ResourceLocation location, Te
2626
super(settings, location, textureManagerIn, unicode);
2727

2828
loadTex(location);
29+
// TODO: Load unicode pages?
2930
// for (int i = 0; i < 256; i++) {
3031

3132
// }

src/main/java/alexiil/mc/mod/load/render/MainSplashRenderer.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,19 @@ public class MainSplashRenderer {
7474
private static volatile boolean finishedLoading = false;
7575

7676
static {
77-
lock = get(SplashProgress.class, "lock");
78-
mutex = get(SplashProgress.class, "mutex");
77+
lock = get(SplashProgress.class, "lock", Lock.class);
78+
mutex = get(SplashProgress.class, "mutex", Semaphore.class);
7979
}
8080

8181
public static long getTotalTime() {
8282
return diff;
8383
}
8484

85-
@SuppressWarnings("unchecked")
86-
private static <T> T get(Class<?> cls, String name) {
85+
private static <T> T get(Class<?> cls, String name, Class<T> type) {
8786
try {
8887
Field fld = cls.getDeclaredField(name);
8988
fld.setAccessible(true);
90-
return (T) fld.get(null);
89+
return type.cast(fld.get(null));
9190
} catch (Throwable t) {
9291
throw new Error(t);
9392
}
@@ -113,7 +112,7 @@ public static void finish() {
113112

114113
// This is called instead of SplashProgress$3.run
115114
public static void run() {
116-
fontRenderer = get(SplashProgress.class, "fontRenderer");
115+
fontRenderer = get(SplashProgress.class, "fontRenderer", FontRenderer.class);
117116

118117
boolean transitionOutDone = false;
119118
start = System.currentTimeMillis();
@@ -133,7 +132,7 @@ public static void run() {
133132
glLoadIdentity();
134133

135134
diff = System.currentTimeMillis() - start;
136-
if (diff < 3000 || !reachedConstruct) {
135+
if (diff < 2500 || !reachedConstruct) {
137136
renderMojangFrame();
138137
} else if (!finishedLoading) {
139138
renderFrame();
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"renders": [
3+
"sample/dirt_background",
4+
"sample/text_percentage_scrolling",
5+
{
6+
"image": {
7+
"parent": "sample/bottom_bar",
8+
"colour": "0xFF_00_00_00",
9+
"position": { "width": "screen_width" }
10+
}
11+
},
12+
{
13+
"image": {
14+
"parent": "sample/bottom_bar",
15+
"colour": "0xFF_11_44_CC"
16+
}
17+
},
18+
{
19+
"image": {
20+
"parent": "builtin/text",
21+
"image": "textures/font/ascii.png",
22+
"position_type": "TOP_LEFT",
23+
"offset_pos": "TOP_LEFT",
24+
"text": "memory_used() + ' MiB / ' + memory_total() + ' MiB'",
25+
"position": {
26+
"x": 10, "y": 10
27+
}
28+
}
29+
},
30+
{
31+
"image": {
32+
"parent": "builtin/text",
33+
"image": "textures/font/ascii.png",
34+
"position_type": "TOP_LEFT",
35+
"offset_pos": "TOP_LEFT",
36+
"text": "floor(time * 10) / 10.0 + 's'",
37+
"position": {
38+
"x": 10, "y": 24
39+
}
40+
}
41+
}
42+
],
43+
"functions": [
44+
45+
],
46+
"variables": {
47+
"max_scroll_count": "screen_height / (2 * 16)",
48+
"scroll_text": "status + (is_reloading ? '' : (' - ' + sub_status))"
49+
},
50+
"factories": [
51+
{
52+
"parent": "builtin/change",
53+
"change": "scroll_text",
54+
"variables": {
55+
"factory_age" : "factory_count - factory_index"
56+
},
57+
"kept_variables": {
58+
"factory_status": "scroll_text"
59+
},
60+
"to_create": {
61+
"should_render": "factory_age < max_scroll_count",
62+
"image": {
63+
"parent": "builtin/text",
64+
"image": "textures/font/ascii.png",
65+
"position_type": "BOTTOM_LEFT",
66+
"offset_pos": "BOTTOM_LEFT",
67+
"text": "factory_status + (factory_age == 1 ? ( is_reloading ? ' - ' + sub_status : '') : '')",
68+
"position": {
69+
"x": "30",
70+
"y": "(factory_index - factory_count) * 16 - 4"
71+
},
72+
"colour": "0xFF_00_00_00 | (0x01_01_01 * (0xFF - 0xFF * factory_age / max_scroll_count).max(0x20))"
73+
}
74+
}
75+
}
76+
],
77+
"actions": [
78+
79+
]
80+
}

0 commit comments

Comments
 (0)