Skip to content

Commit

Permalink
Beta rendering system
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry282 committed Aug 13, 2024
1 parent 14be639 commit 4126a8a
Show file tree
Hide file tree
Showing 10 changed files with 545 additions and 13 deletions.
14 changes: 10 additions & 4 deletions src/main/kotlin/funnymap/FunnyMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ package funnymap

import funnymap.commands.FunnyMapCommands
import funnymap.config.Config
import funnymap.features.dungeon.Dungeon
import funnymap.features.dungeon.MapRender
import funnymap.features.dungeon.RunInformation
import funnymap.features.dungeon.WitherDoorESP
import funnymap.features.dungeon.*
import funnymap.ui.GuiRenderer
import funnymap.utils.Location
import funnymap.utils.UpdateChecker
import gg.essential.api.EssentialAPI
import gg.essential.vigilance.gui.SettingsGui
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.settings.KeyBinding
import net.minecraftforge.client.ClientCommandHandler
import net.minecraftforge.client.event.GuiOpenEvent
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.client.registry.ClientRegistry
import net.minecraftforge.fml.common.Mod
Expand Down Expand Up @@ -105,4 +104,11 @@ object FunnyMap {
MapRender.legitPeek = !MapRender.legitPeek
}
}

@SubscribeEvent
fun onGuiClose(event: GuiOpenEvent) {
if (event.gui == null && mc.currentScreen is SettingsGui) {
MapRenderList.renderUpdated = true
}
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/funnymap/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,13 @@ object Config : Vigilant(File("./config/funnymap/config.toml"), "Funny Map", sor
)
var paulBonus = false

@Property(
name = "Beta Rendering",
type = PropertyType.SWITCH,
category = "Debug"
)
var renderBeta = true

@Property(
name = "Custom Prefix",
type = PropertyType.TEXT,
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/funnymap/features/dungeon/DungeonScan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ object DungeonScan {
MapUpdate.roomAdded = true
}
Dungeon.Info.dungeonList[z * 11 + x] = it
MapRenderList.renderUpdated = true
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/kotlin/funnymap/features/dungeon/MapRender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import java.awt.Color
object MapRender {
var dynamicRotation = 0f
var legitPeek = false
set(value) {
if (field != value && Config.legitMode) {
MapRenderList.renderUpdated = true
}
field = value
}

val legitRender: Boolean
get() = Config.legitMode && !legitPeek
Expand Down Expand Up @@ -79,7 +85,7 @@ object MapRender {
}
}

private fun setupRotate() {
fun setupRotate() {
val scale = ScaledResolution(mc).scaleFactor
GL11.glEnable(GL11.GL_SCISSOR_TEST)
GL11.glScissor(
Expand Down Expand Up @@ -226,7 +232,7 @@ object MapRender {
GlStateManager.popMatrix()
}

private fun renderPlayerHeads() {
fun renderPlayerHeads() {
try {
if (Dungeon.dungeonTeammates.isEmpty()) {
RenderUtils.drawPlayerHead(mc.thePlayer.name, DungeonPlayer(mc.thePlayer.locationSkin).apply {
Expand Down Expand Up @@ -267,7 +273,7 @@ object MapRender {
)
}

private fun renderRunInformation() {
fun renderRunInformation() {
GlStateManager.pushMatrix()
GlStateManager.translate(64f, 128f, 0f)
GlStateManager.scale(2.0 / 3.0, 2.0 / 3.0, 1.0)
Expand Down
220 changes: 220 additions & 0 deletions src/main/kotlin/funnymap/features/dungeon/MapRenderList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
package funnymap.features.dungeon

import funnymap.FunnyMap.mc
import funnymap.config.Config
import funnymap.core.map.*
import funnymap.features.dungeon.MapRender.dynamicRotation
import funnymap.features.dungeon.MapRender.legitRender
import funnymap.utils.Location.inBoss
import funnymap.utils.MapUtils
import funnymap.utils.MapUtils.connectorSize
import funnymap.utils.MapUtils.halfRoomSize
import funnymap.utils.MapUtils.roomSize
import funnymap.utils.RenderUtils.darken
import funnymap.utils.RenderUtils.grayScale
import funnymap.utils.RenderUtilsGL
import funnymap.utils.Utils.equalsOneOf
import net.minecraft.client.renderer.GlStateManager
import org.lwjgl.opengl.GL11
import java.awt.Color

object MapRenderList {
var renderUpdated = false
private var borderGlList = -1
private var roomGlList = -1

fun updateRenderMap() {
if (borderGlList == -1) {
borderGlList = GL11.glGenLists(1)
GL11.glNewList(borderGlList, GL11.GL_COMPILE)
RenderUtilsGL.renderRect(
0.0, 0.0, 128.0, if (Config.mapShowRunInformation) 142.0 else 128.0, Config.mapBackground
)
RenderUtilsGL.renderRectBorder(
0.0,
0.0,
128.0,
if (Config.mapShowRunInformation) 142.0 else 128.0,
Config.mapBorderWidth.toDouble(),
Config.mapBorder
)
GL11.glEndList()
}

if (renderUpdated && Config.renderBeta) {
if (roomGlList >= 0) {
GL11.glDeleteLists(roomGlList, 1)
roomGlList = -1
}
roomGlList = GL11.glGenLists(1)
renderUpdated = false

GL11.glNewList(roomGlList, GL11.GL_COMPILE)
renderRooms()
renderText()
GL11.glEndList()

}
}

fun renderMap() {
if (roomGlList == -1 || borderGlList == -1 || renderUpdated) {
updateRenderMap()
}

mc.mcProfiler.startSection("border")

if (borderGlList != -1) GL11.glCallList(borderGlList)

mc.mcProfiler.endSection()

if (Config.mapRotate) {
GlStateManager.pushMatrix()
MapRender.setupRotate()
} else if (Config.mapDynamicRotate) {
GlStateManager.translate(64.0, 64.0, 0.0)
GlStateManager.rotate(dynamicRotation, 0f, 0f, 1f)
GlStateManager.translate(-64.0, -64.0, 0.0)
}

mc.mcProfiler.startSection("rooms")

if (roomGlList != -1) GL11.glCallList(roomGlList)

if (!inBoss) {
mc.mcProfiler.endStartSection("heads")
MapRender.renderPlayerHeads()
}

mc.mcProfiler.endSection()

if (Config.mapRotate) {
GL11.glDisable(GL11.GL_SCISSOR_TEST)
GlStateManager.popMatrix()
} else if (Config.mapDynamicRotate) {
GlStateManager.translate(64.0, 64.0, 0.0)
GlStateManager.rotate(-dynamicRotation, 0f, 0f, 1f)
GlStateManager.translate(-64.0, -64.0, 0.0)
}

if (Config.mapShowRunInformation) {
mc.mcProfiler.startSection("footer")
MapRender.renderRunInformation()
mc.mcProfiler.endSection()
}
}

private fun renderRooms() {
GlStateManager.translate(MapUtils.startCorner.first.toFloat(), MapUtils.startCorner.second.toFloat(), 0f)

var yPos = 0
var yStep = 0

for (y in 0..10) {
val yEven = y % 2 == 0
yPos += yStep
yStep = if (yEven) roomSize else connectorSize
var xPos = 0
var xStep = 0
for (x in 0..10) {
val xEven = x % 2 == 0
xPos += xStep
xStep = if (xEven) roomSize else connectorSize

val tile = Dungeon.Info.dungeonList[y * 11 + x]
if (tile is Unknown) continue
if (legitRender && tile.state == RoomState.UNDISCOVERED) continue

var color = tile.color

if (tile.state.equalsOneOf(RoomState.UNDISCOVERED, RoomState.UNOPENED) &&
!legitRender && Dungeon.Info.startTime != 0L
) {
if (Config.mapDarkenUndiscovered) {
color = color.darken(1 - Config.mapDarkenPercent)
}
if (Config.mapGrayUndiscovered) {
color = color.grayScale()
}
}

when (tile) {
is Room -> {
RenderUtilsGL.renderRect(xPos, yPos, xStep, yStep, color)
if (legitRender && tile.state == RoomState.UNOPENED) {
RenderUtilsGL.drawCheckmark(xPos.toFloat(), yPos.toFloat(), tile.state)
}
}

is Door -> {
val doorOffset = if (roomSize == 16) 5 else 6
if (xEven) {
RenderUtilsGL.renderRect(xPos + doorOffset, yPos, xStep - doorOffset * 2, yStep, color)
} else {
RenderUtilsGL.renderRect(xPos, yPos + doorOffset, xStep, yStep - doorOffset * 2, color)
}
}
}
}
}
GlStateManager.translate(-MapUtils.startCorner.first.toFloat(), -MapUtils.startCorner.second.toFloat(), 0f)
}

private fun renderText() {
GlStateManager.translate(MapUtils.startCorner.first.toFloat(), MapUtils.startCorner.second.toFloat(), 0f)

Dungeon.Info.uniqueRooms.forEach { unique ->
val room = unique.mainRoom
if (legitRender && room.state.equalsOneOf(RoomState.UNDISCOVERED, RoomState.UNOPENED)) return@forEach
val checkPos = unique.getCheckmarkPosition()
val namePos = unique.getNamePosition()
val xPosCheck = (checkPos.first / 2f) * (roomSize + connectorSize)
val yPosCheck = (checkPos.second / 2f) * (roomSize + connectorSize)
val xPosName = (namePos.first / 2f) * (roomSize + connectorSize)
val yPosName = (namePos.second / 2f) * (roomSize + connectorSize)

if (Config.mapCheckmark != 0 && Config.mapRoomSecrets != 2) {
RenderUtilsGL.drawCheckmark(xPosCheck, yPosCheck, room.state)
}

val color = if (Config.mapColorText) when (room.state) {
RoomState.GREEN -> Color(0x55ff55)
RoomState.CLEARED, RoomState.FAILED -> Color(0xffffff)
else -> Color(0xaaaaaa)
} else Color(0xffffff)

if (Config.mapRoomSecrets == 2) {
GlStateManager.pushMatrix()
GlStateManager.translate(
xPosCheck + halfRoomSize, yPosCheck + 2 + halfRoomSize, 0f
)
GlStateManager.scale(2f, 2f, 1f)
RenderUtilsGL.renderCenteredText(listOf(room.data.secrets.toString()), 0, 0, color)
GlStateManager.popMatrix()
}

val name = mutableListOf<String>()

if (Config.mapRoomNames != 0 && room.data.type.equalsOneOf(
RoomType.PUZZLE,
RoomType.TRAP
) || Config.mapRoomNames == 2 && room.data.type.equalsOneOf(
RoomType.NORMAL, RoomType.RARE, RoomType.CHAMPION
)
) {
name.addAll(room.data.name.split(" "))
}
if (room.data.type == RoomType.NORMAL && Config.mapRoomSecrets == 1) {
name.add(room.data.secrets.toString())
}
// Offset + half of roomsize
RenderUtilsGL.renderCenteredText(
name,
xPosName.toInt() + halfRoomSize,
yPosName.toInt() + halfRoomSize,
color
)
}
GlStateManager.translate(-MapUtils.startCorner.first.toFloat(), -MapUtils.startCorner.second.toFloat(), 0f)
}
}
6 changes: 6 additions & 0 deletions src/main/kotlin/funnymap/features/dungeon/MapUpdate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ object MapUpdate {
if (mapTile is Unknown) continue

if (room is Unknown) {
MapRenderList.renderUpdated = true
roomAdded = true
Dungeon.Info.dungeonList[z * 11 + x] = mapTile
continue
}

if (mapTile.state.ordinal < room.state.ordinal) {
MapRenderList.renderUpdated = true
PlayerTracker.roomStateChange(room, room.state, mapTile.state)
if (room is Room && room.data.type == RoomType.BLOOD && mapTile.state == RoomState.GREEN) {
RunInformation.bloodDone = true
Expand All @@ -125,19 +127,22 @@ object MapUpdate {

if (mapTile is Room && room is Room) {
if (room.data.type != mapTile.data.type && mapTile.data.type != RoomType.NORMAL) {
MapRenderList.renderUpdated = true
room.data.type = mapTile.data.type
}
}

if (mapTile is Door && room is Door) {
if (mapTile.type == DoorType.WITHER && room.type != DoorType.WITHER) {
MapRenderList.renderUpdated = true
room.type = mapTile.type
}
}

if (room is Door && room.type.equalsOneOf(DoorType.ENTRANCE, DoorType.WITHER, DoorType.BLOOD)) {
if (mapTile is Door && mapTile.type == DoorType.WITHER) {
if (room.opened) {
MapRenderList.renderUpdated = true
room.opened = false
}
} else if (!room.opened && mc.theWorld.getChunkFromChunkCoords(
Expand All @@ -146,6 +151,7 @@ object MapUpdate {
).isLoaded &&
mc.theWorld.getBlockState(BlockPos(room.x, 69, room.z)).block == Blocks.air
) {
MapRenderList.renderUpdated = true
room.opened = true
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/funnymap/ui/MapElement.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package funnymap.ui

import funnymap.config.Config
import funnymap.features.dungeon.MapRender
import funnymap.features.dungeon.MapRenderList
import funnymap.utils.Location

class MapElement : MovableGuiElement() {
Expand All @@ -16,7 +17,11 @@ class MapElement : MovableGuiElement() {
override var y2: Int = (y + h * scale).toInt()

override fun render() {
MapRender.renderMap()
if (Config.renderBeta) {
MapRenderList.renderMap()
} else {
MapRender.renderMap()
}
}

override fun shouldRender(): Boolean {
Expand Down
Loading

0 comments on commit 4126a8a

Please sign in to comment.