|
| 1 | +/* |
| 2 | + * Copyright 2026 Lambda |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.lambda.graphics.mc |
| 19 | + |
| 20 | +import com.lambda.graphics.esp.RegionESP |
| 21 | +import com.lambda.graphics.esp.ShapeScope |
| 22 | +import java.util.concurrent.ConcurrentHashMap |
| 23 | +import kotlin.math.floor |
| 24 | + |
| 25 | +/** |
| 26 | + * Interpolated region-based ESP system for smooth entity rendering. |
| 27 | + * |
| 28 | + * This system rebuilds and uploads vertices every frame. Callers are responsible for providing |
| 29 | + * interpolated positions (e.g., using entity.prevX/x with tickDelta). The tick() method swaps |
| 30 | + * builders to allow smooth transitions between frames. |
| 31 | + */ |
| 32 | +class ImmediateRegionESP(name: String, depthTest: Boolean = false) : RegionESP(name, depthTest) { |
| 33 | + // Current frame builders (being populated this tick) |
| 34 | + private val currBuilders = ConcurrentHashMap<Long, ShapeScope>() |
| 35 | + |
| 36 | + override fun shapes(x: Double, y: Double, z: Double, block: ShapeScope.() -> Unit) { |
| 37 | + val key = getRegionKey(x, y, z) |
| 38 | + val scope = |
| 39 | + currBuilders.getOrPut(key) { |
| 40 | + val size = RenderRegion.REGION_SIZE |
| 41 | + val rx = (size * floor(x / size)).toInt() |
| 42 | + val ry = (size * floor(y / size)).toInt() |
| 43 | + val rz = (size * floor(z / size)).toInt() |
| 44 | + ShapeScope(RenderRegion(rx, ry, rz)) |
| 45 | + } |
| 46 | + scope.apply(block) |
| 47 | + } |
| 48 | + |
| 49 | + override fun clear() { |
| 50 | + currBuilders.clear() |
| 51 | + } |
| 52 | + |
| 53 | + fun tick() { |
| 54 | + currBuilders.clear() |
| 55 | + } |
| 56 | + |
| 57 | + override fun upload() { |
| 58 | + val activeKeys = currBuilders.keys.toSet() |
| 59 | + |
| 60 | + currBuilders.forEach { (key, scope) -> |
| 61 | + val renderer = renderers.getOrPut(key) { RegionRenderer(scope.region) } |
| 62 | + renderer.upload(scope.builder.collector) |
| 63 | + } |
| 64 | + |
| 65 | + renderers.forEach { (key, renderer) -> |
| 66 | + if (key !in activeKeys) { |
| 67 | + renderer.clearData() |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments