Files
LNXSDK/leenkx/Sources/iron/culling/TemporalState.hx
2026-10-15 02:41:03 -07:00

80 lines
2.3 KiB
Haxe

package iron.culling;
class TemporalState {
public var visibleLastFrame: haxe.ds.IntMap<Bool>;
public var visibleLastShadow: haxe.ds.IntMap<Bool>;
public var frameLastTested: haxe.ds.IntMap<Int>;
public var occlusionConfidence: haxe.ds.IntMap<Int>;
public var capacity: Int = 0;
public var frameCount: Int = 0;
public function new() {
visibleLastFrame = new haxe.ds.IntMap<Bool>();
visibleLastShadow = new haxe.ds.IntMap<Bool>();
frameLastTested = new haxe.ds.IntMap<Int>();
occlusionConfidence = new haxe.ds.IntMap<Int>();
}
public function ensureCapacity(cap: Int) {
if (capacity < cap) capacity = cap;
}
public inline function wasVisibleLastFrame(i: Int): Bool {
return visibleLastFrame.exists(i);
}
public inline function wasVisibleShadowLastFrame(i: Int): Bool {
return visibleLastShadow.exists(i);
}
public inline function needsTest(i: Int, maxSkipFrames: Int): Bool {
if (visibleLastFrame.exists(i)) return false; // assumed visible
var lastTested = frameLastTested.get(i);
if (lastTested == null) return true;
return frameCount - lastTested >= maxSkipFrames;
}
public inline function needsVisibleReTest(i: Int, retestInterval: Int): Bool {
var lastTested = frameLastTested.get(i);
if (lastTested == null) return true;
return frameCount - lastTested >= retestInterval;
}
public inline function setVisible(i: Int, visible: Bool) {
if (visible) {
visibleLastFrame.set(i, true);
occlusionConfidence.remove(i);
} else {
visibleLastFrame.remove(i);
var conf = occlusionConfidence.get(i);
occlusionConfidence.set(i, conf == null ? 1 : Std.int(Math.min(255, conf + 1)));
}
}
public inline function markTested(i: Int) {
frameLastTested.set(i, frameCount);
}
public inline function setVisibleShadow(i: Int, visible: Bool) {
if (visible) visibleLastShadow.set(i, true);
else visibleLastShadow.remove(i);
}
public inline function advanceFrame() {
frameCount++;
}
public function clear() {
visibleLastFrame = new haxe.ds.IntMap<Bool>();
visibleLastShadow = new haxe.ds.IntMap<Bool>();
frameLastTested = new haxe.ds.IntMap<Int>();
occlusionConfidence = new haxe.ds.IntMap<Int>();
}
public inline function getConfidence(i: Int): Int {
var c = occlusionConfidence.get(i);
return c == null ? 0 : c;
}
}