Skip to content

Commit

Permalink
add RenderDoc helper
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Sep 10, 2024
1 parent 9e474bd commit 31e0692
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public static class Client {
RuntimeEnvironmentType.CLIENT.orElseThrow();
}

public static final boolean RENDER_SLOT_NUMBERS = DEBUG_MODE || Env.getBool("debug.render.slotnumber");
public static final boolean LOAD_RENDERDOC = Env.getBool("debug.render.load_renderdoc");

public static final boolean LOG_MISSING_TRANSLATIONS = DEVELOPMENT_ENVIRONMENT || Env.getBool("debug.log.missing_translations");

public static final boolean RENDER_SLOT_NUMBERS = DEBUG_MODE || Env.getBool("debug.render.slotnumber");
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package dev.upcraft.sparkweave.api.logging;

import dev.upcraft.sparkweave.SparkweaveMod;
import dev.upcraft.sparkweave.api.annotation.CallerSensitive;
import dev.upcraft.sparkweave.api.reflect.ContextHelper;
import dev.upcraft.sparkweave.api.platform.ModContainer;
import dev.upcraft.sparkweave.api.reflect.ContextHelper;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Configurator;

public class SparkweaveLoggerFactory {

private static final LoggerContext ctx = Configurator.initialize(SparkweaveLoggerFactory.class.getClassLoader(), ConfigurationSource.fromResource("/assets/sparkweave/log4j2.xml", SparkweaveLoggerFactory.class.getClassLoader()));
private static final LoggerContext ctx = Configurator.initialize(SparkweaveLoggerFactory.class.getClassLoader(), ConfigurationSource.fromResource("/assets/%s/log4j2.xml".formatted(SparkweaveMod.MODID), SparkweaveLoggerFactory.class.getClassLoader()));

private SparkweaveLoggerFactory() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static String get(String name, String prefix) {
return System.getProperty(name);
}

return System.getProperty(prefix + "." + name);
return System.getProperty(prefix + '.' + name);
}

@CallerSensitive
Expand All @@ -36,7 +36,7 @@ public static boolean getBool(String name, String prefix) {
return Boolean.getBoolean(name);
}

return Boolean.getBoolean(prefix + "." + name);
return Boolean.getBoolean(prefix + '.' + name);
}

@CallerSensitive
Expand All @@ -51,7 +51,7 @@ public static int getInt(String name, String prefix) {
return Integer.getInteger(name, 0);
}

return Integer.getInteger(prefix + "." + name, 0);
return Integer.getInteger(prefix + '.' + name, 0);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package dev.upcraft.sparkweave.client.render;

import dev.upcraft.sparkweave.api.SparkweaveApi;
import dev.upcraft.sparkweave.logging.SparkweaveLogging;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;

public class RenderDocHelper {

private static final Logger LOGGER = SparkweaveLogging.getLogger();

public static void init() {
if(SparkweaveApi.Client.LOAD_RENDERDOC) {
var libraryPath = System.getProperty("java.library.path");

var rdHome = System.getenv("RENDERDOC_HOME");
if(rdHome != null) {
LOGGER.debug("appending RENDERDOC_HOME to native library path");
libraryPath += File.pathSeparatorChar + rdHome;
System.setProperty("java.library.path", libraryPath);
}

var libraryName = System.mapLibraryName("renderdoc");

var loaded = false;
for(var dir : libraryPath.split(File.pathSeparator)) {
try {
var searchPath = Path.of(dir, libraryName).toAbsolutePath();
if(Files.exists(searchPath)) {
LOGGER.debug("Attempting to load RenderDoc from {}", searchPath);
System.load(searchPath.toString());
loaded = true;
break;
}
} catch (SecurityException | UnsatisfiedLinkError e) {
LOGGER.error("unable to load RenderDoc library", e);
break;
}
}

if(!loaded) {
LOGGER.warn("RenderDoc not found or unable to load");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.upcraft.sparkweave.mixin.client;

import dev.upcraft.sparkweave.client.render.RenderDocHelper;
import net.minecraft.client.main.Main;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Main.class)
public class MainMixin {

@Inject(method = "main", at = @At("HEAD"), remap = false)
private static void loadRenderdoc(String[] args, CallbackInfo ci) {
RenderDocHelper.init();
}
}
2 changes: 1 addition & 1 deletion Common/src/main/resources/assets/sparkweave/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t/%logger{36}][%level] %msg%n"/>
</File>
<Async name="SparkweaveDebugAsync">
<AppenderRef ref="MeshDebug" />
<AppenderRef ref="SparkweaveDebug" />
</Async>
</Appenders>
<Loggers>
Expand Down
1 change: 1 addition & 0 deletions Common/src/main/resources/sparkweave.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"mixins": [
],
"client": [
"client.MainMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 31e0692

Please sign in to comment.