Skip to content

Commit 19bc497

Browse files
committed
🐔 Fix instanced blocked rendering
⚡️ Add spark profiling
1 parent af78200 commit 19bc497

File tree

16 files changed

+287
-103
lines changed

16 files changed

+287
-103
lines changed

.idea/runConfigurations/Start_Game.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
id("com.osmerion.lwjgl3") version "0.5.0"
55
}
66

7-
group = 'com.james090500'
7+
group = 'com.james090500.client'
88
version = project.version
99

1010
java {
@@ -54,8 +54,8 @@ tasks.withType(Jar).configureEach {
5454
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
5555
manifest {
5656
attributes(
57-
'Implementation-Title': project.name,
58-
'Implementation-Version': project.version
57+
'Implementation-Title': project.name,
58+
'Implementation-Version': project.version
5959
)
6060
}
6161
}

profiler/build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group = 'com.james090500.profiler'
6+
version = '0.0.1'
7+
8+
repositories {
9+
mavenCentral()
10+
maven {
11+
name 'luck-repo'
12+
url 'https://repo.lucko.me/'
13+
}
14+
}
15+
16+
dependencies {
17+
implementation "net.kyori:adventure-text-serializer-plain:4.24.0"
18+
implementation "me.lucko:spark-common:1.10.142-SNAPSHOT"
19+
implementation 'org.slf4j:slf4j-simple:2.0.16'
20+
implementation 'com.google.code.gson:gson:2.9.0'
21+
implementation('com.google.guava:guava:31.1-jre') {
22+
exclude(module: 'jsr305')
23+
exclude(module: 'error_prone_annotations')
24+
exclude(module: 'failureaccess')
25+
exclude(module: 'listenablefuture')
26+
exclude(module: 'j2objc-annotations')
27+
exclude(module: 'checker-qual')
28+
}
29+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package com.james090500.profiler;
2+
3+
import me.lucko.spark.common.SparkPlatform;
4+
import me.lucko.spark.common.SparkPlugin;
5+
import me.lucko.spark.common.command.CommandResponseHandler;
6+
import me.lucko.spark.common.platform.PlatformInfo;
7+
import me.lucko.spark.common.util.SparkThreadFactory;
8+
import me.lucko.spark.common.util.classfinder.ClassFinder;
9+
import me.lucko.spark.common.util.classfinder.FallbackClassFinder;
10+
import net.kyori.adventure.text.Component;
11+
import net.kyori.adventure.text.format.NamedTextColor;
12+
13+
import java.io.PrintWriter;
14+
import java.io.StringWriter;
15+
import java.nio.file.Path;
16+
import java.nio.file.Paths;
17+
import java.util.Set;
18+
import java.util.concurrent.CompletableFuture;
19+
import java.util.concurrent.ConcurrentHashMap;
20+
import java.util.concurrent.Executors;
21+
import java.util.concurrent.ScheduledExecutorService;
22+
import java.util.logging.Level;
23+
import java.util.stream.Stream;
24+
25+
public class Spark implements SparkPlugin {
26+
private final Set<StandaloneCommandSender> senders;
27+
private final ScheduledExecutorService scheduler;
28+
private final SparkPlatform platform;
29+
30+
public Spark(String argument) {
31+
this.senders = ConcurrentHashMap.newKeySet();
32+
this.senders.add(StandaloneCommandSender.SYSTEM_OUT);
33+
this.scheduler = Executors.newScheduledThreadPool(4, new SparkThreadFactory());
34+
this.platform = new SparkPlatform(this);
35+
this.platform.enable();
36+
37+
if (argument.contains("start")) {
38+
execute(new String[]{"profiler", "start"}, StandaloneCommandSender.SYSTEM_OUT).join();
39+
40+
if (argument.contains("open")) {
41+
execute(new String[]{"profiler", "open"}, StandaloneCommandSender.SYSTEM_OUT).join();
42+
}
43+
}
44+
}
45+
46+
public void disable() {
47+
this.platform.disable();
48+
this.scheduler.shutdown();
49+
}
50+
51+
public CompletableFuture<Void> execute(String[] args, StandaloneCommandSender sender) {
52+
return this.platform.executeCommand(sender, args);
53+
}
54+
55+
public CommandResponseHandler createResponseHandler(StandaloneCommandSender sender) {
56+
return new CommandResponseHandler(this.platform, sender);
57+
}
58+
59+
@Override
60+
public String getVersion() {
61+
return "@version@";
62+
}
63+
64+
@Override
65+
public Path getPluginDirectory() {
66+
return Paths.get("spark");
67+
}
68+
69+
@Override
70+
public String getCommandName() {
71+
return "spark";
72+
}
73+
74+
@Override
75+
public Stream<StandaloneCommandSender> getCommandSenders() {
76+
return this.senders.stream();
77+
}
78+
79+
@Override
80+
public void executeAsync(Runnable task) {
81+
this.scheduler.execute(task);
82+
}
83+
84+
@Override
85+
public void log(Level level, String msg) {
86+
log(level, msg, null);
87+
}
88+
89+
@Override
90+
public void log(Level level, String msg, Throwable throwable) {
91+
CommandResponseHandler resp = createResponseHandler(StandaloneCommandSender.SYSTEM_OUT);
92+
if (level.intValue() >= 900 || throwable != null) { // severe/warning
93+
resp.replyPrefixed(Component.text(msg, NamedTextColor.RED));
94+
if (throwable != null) {
95+
StringWriter stringWriter = new StringWriter();
96+
throwable.printStackTrace(new PrintWriter(stringWriter));
97+
resp.replyPrefixed(Component.text(stringWriter.toString(), NamedTextColor.YELLOW));
98+
}
99+
} else {
100+
resp.replyPrefixed(Component.text(msg));
101+
}
102+
}
103+
104+
@Override
105+
public ClassFinder createClassFinder() {
106+
return FallbackClassFinder.INSTANCE;
107+
}
108+
109+
@Override
110+
public PlatformInfo getPlatformInfo() {
111+
return new PlatformInfo() {
112+
@Override
113+
public Type getType() {
114+
return Type.APPLICATION;
115+
}
116+
117+
@Override
118+
public String getName() {
119+
return "BlockGame";
120+
}
121+
122+
@Override
123+
public String getBrand() {
124+
return "";
125+
}
126+
127+
@Override
128+
public String getVersion() {
129+
return "";
130+
}
131+
132+
@Override
133+
public String getMinecraftVersion() {
134+
return "";
135+
}
136+
};
137+
}
138+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.james090500.profiler;
2+
3+
import me.lucko.spark.common.command.sender.AbstractCommandSender;
4+
import net.kyori.adventure.text.Component;
5+
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
6+
7+
import java.util.UUID;
8+
9+
public class StandaloneCommandSender extends AbstractCommandSender<StandaloneCommandSender.Output> {
10+
public static final StandaloneCommandSender SYSTEM_OUT = new StandaloneCommandSender(System.out::println);
11+
12+
public StandaloneCommandSender(Output output) {
13+
super(output);
14+
}
15+
16+
@Override
17+
public String getName() {
18+
return "BlockGame";
19+
}
20+
21+
@Override
22+
public UUID getUniqueId() {
23+
return null;
24+
}
25+
26+
@Override
27+
public void sendMessage(Component message) {
28+
System.out.println(PlainTextComponentSerializer.plainText().serialize(message));
29+
}
30+
31+
@Override
32+
public boolean hasPermission(String permission) {
33+
return true;
34+
}
35+
36+
public interface Output {
37+
void sendMessage(String message);
38+
}
39+
40+
}

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
rootProject.name = 'blockgame-client'
2+
3+
include 'profiler'

src/main/java/com/james090500/BlockGame.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class BlockGame {
4141
public BlockGame() {
4242
instance = this;
4343

44+
//spark = new Spark("start open");
45+
4446
clientWindow = new ClientWindow();
4547
clientWindow.create();
4648

@@ -144,6 +146,8 @@ public void exit() {
144146
this.world = null;
145147
this.camera = null;
146148

149+
//spark.disable();
150+
147151
glfwSetInputMode(clientWindow.getWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
148152
}
149153

src/main/java/com/james090500/blocks/Blocks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static int getTotalBlocks() {
6666

6767
static {
6868
Blocks.REGISTRY.forEach((id, block) -> {
69-
if(block instanceof IBlockRender) block.getModel().create();
69+
if(block.getModel() != null) block.getModel().create();
7070
});
7171
}
7272
}

src/main/java/com/james090500/blocks/CactusBlock.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import it.unimi.dsi.fastutil.objects.ObjectList;
66
import org.joml.Vector3i;
77

8-
public class CactusBlock extends Block implements IBlockRender {
8+
public class CactusBlock extends Block {
99

1010
public CactusBlock(byte id) {
1111
super(id);
@@ -18,16 +18,11 @@ public CactusBlock(byte id) {
1818
@Override
1919
public TextureLocation getTexture(String face) {
2020
if (face.equalsIgnoreCase("top")) {
21-
return TextureLocation.get("assets/blocks/cactus_side_top");
21+
return TextureLocation.get("assets/blocks/cactus_top");
2222
} else if (face.equalsIgnoreCase("bottom")) {
23-
return TextureLocation.get("assets/blocks/cactus_side_bottom");
23+
return TextureLocation.get("assets/blocks/cactus_bottom");
2424
} else {
2525
return this.texture;
2626
}
2727
}
28-
29-
@Override
30-
public void render(ObjectList<Vector3i> positions) {
31-
this.model.render(positions);
32-
}
3328
}

src/main/java/com/james090500/blocks/RedFlowerBlock.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import it.unimi.dsi.fastutil.objects.ObjectList;
66
import org.joml.Vector3i;
77

8-
public class RedFlowerBlock extends VegetationBlock implements IBlockRender {
8+
public class RedFlowerBlock extends VegetationBlock {
99

1010
public RedFlowerBlock(byte id) {
1111
super(id);
@@ -16,9 +16,4 @@ public RedFlowerBlock(byte id) {
1616
this.solid = false;
1717
this.model = new VegetationModel(this.uv, this.texture);
1818
}
19-
20-
@Override
21-
public void render(ObjectList<Vector3i> positions) {
22-
this.model.render(positions);
23-
}
2419
}

0 commit comments

Comments
 (0)