Skip to content

Commit

Permalink
Add HUDCaching FPS (from PolyPatcher)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest authored and mitchej123 committed Jul 12, 2024
1 parent f79e112 commit 7e4292b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ public class AngelicaConfig {
@Config.DefaultBoolean(true)
public static boolean showSplashMemoryBar;

@Config.Comment("Renders the HUD elements once per tick and reuses the pixels to improve performance. [Experimental]")
@Config.Comment("Renders the HUD elements once per 20 frames (by default) and reuses the pixels to improve performance. [Experimental]")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean enableHudCaching;

@Config.Comment("The amount of frames to wait before updating the HUD elements. [Experimental]")
@Config.DefaultInt(20)
@Config.RangeInt(min = 1, max = 60)
public static int hudCachingFPS = 20;

@Config.Comment("Batch drawScreen fonts [Experimental]")
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import com.gtnewhorizons.angelica.compat.ModStatus;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.mixins.early.angelica.hudcaching.RenderGameOverlayEventAccessor;
import cpw.mods.fml.common.eventhandler.EventPriority;
import net.dries007.holoInventory.client.Renderer;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class HUDCaching {
private static final Minecraft mc = Minecraft.getMinecraft();
public static Framebuffer framebuffer;
private static boolean dirty = true;
private static long nextHudRefresh;

public static boolean renderingCacheOverride;

Expand Down Expand Up @@ -106,13 +108,6 @@ public void onKeypress(InputEvent.KeyInputEvent event) {

/* TODO END REMOVE DEBUG STUFF */

@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
dirty = true;
}
}

// highest so it runs before the GLSM load event
@SubscribeEvent(priority = EventPriority.HIGH)
public void onJoinWorld(WorldEvent.Load event) {
Expand All @@ -136,8 +131,13 @@ public static void renderCachedHud(EntityRenderer renderer, GuiIngame ingame, fl
return;
}

if (System.currentTimeMillis() > nextHudRefresh) {
dirty = true;
}

if (dirty) {
dirty = false;
nextHudRefresh = System.currentTimeMillis() + (1000 / AngelicaConfig.hudCachingFPS);
resetFramebuffer(mc.displayWidth, mc.displayHeight);
framebuffer.bindFramebuffer(false);
renderingCacheOverride = true;
Expand Down

0 comments on commit 7e4292b

Please sign in to comment.