-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Began work on download system and visibility tracker
- Loading branch information
Showing
7 changed files
with
114 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/me/cortex/nvidium/managers/VisibilityTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package me.cortex.nvidium.managers; | ||
|
||
import me.cortex.nvidium.gl.buffers.Buffer; | ||
import me.cortex.nvidium.util.DownloadTaskStream; | ||
import org.lwjgl.system.MemoryUtil; | ||
|
||
//NOTE: the visibility tracker and RenderPipeline must be kept in frame perfect sync else all hell breaks loose | ||
public class VisibilityTracker { | ||
private final DownloadTaskStream downloadStream; | ||
private int frameId; | ||
private final short[][] regions; | ||
private final byte[] frameIds; | ||
private final RegionManager regionManager; | ||
public VisibilityTracker(DownloadTaskStream downloadStream, int frames, RegionManager regionManager) { | ||
this.downloadStream = downloadStream; | ||
this.regionManager = regionManager; | ||
regions = new short[frames][]; | ||
frameIds = new byte[frames]; | ||
} | ||
|
||
public void onFrame(short[] visibleRegions, Buffer regionVisibility) { | ||
frameIds[(frameId)% regions.length] = (byte) (frameId-1); | ||
regions[(frameId++)% regions.length] = visibleRegions; | ||
downloadStream.download(regionVisibility, 0, visibleRegions.length, this::onDownload); | ||
} | ||
|
||
private void onDownload(long ptr) { | ||
int pframe = frameId - (this.regions.length - 1); | ||
var regions = this.regions[pframe%this.regions.length]; | ||
byte frame = frameIds[pframe%this.regions.length]; | ||
for (int i = 0; i < regions.length; i++) { | ||
if (MemoryUtil.memGetByte(ptr + i) == frame) { | ||
regionManager.markVisible(regions[i], pframe); | ||
} else { | ||
regionManager.markFrustum(regions[i], pframe); | ||
} | ||
} | ||
} | ||
|
||
public void delete() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters