Skip to content

Commit

Permalink
use this. for instance method access
Browse files Browse the repository at this point in the history
  • Loading branch information
douira committed Nov 5, 2023
1 parent cc50496 commit a5475c7
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ default int calculateNormals(boolean calculateUnitNormal) {
// quantize the coordinates on the surface of the cube.
// in each axis the number of values is 2 * QUANTIZATION_FACTOR + 1.
// the total number of normals is the number of points on that cube's surface.
setGFNINormal(
this.setGFNINormal(
(int) (normX * GFNI.QUANTIZATION_FACTOR),
(int) (normY * GFNI.QUANTIZATION_FACTOR),
(int) (normZ * GFNI.QUANTIZATION_FACTOR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public BuilderTaskOutput(RenderSection render, int buildTime) {

public void deleteFully() {
this.fullyDeleted = true;
deleteAfterUpload();
this.deleteAfterUpload();
}

public void deleteAfterUploadSafe() {
if (!this.fullyDeleted) {
deleteAfterUpload();
this.deleteAfterUpload();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void setIndexData(int localSectionIndex, GlBufferSegment allocation) {
public void removeData(int localSectionIndex) {
this.removeVertexData(localSectionIndex, false);
if (this.storesIndices) {
removeIndexData(localSectionIndex);
this.removeIndexData(localSectionIndex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ private void sort(Vector3fc cameraPos, boolean isAngleTrigger) {
IntBuffer indexBuffer = this.getBuffer().getDirectBuffer().asIntBuffer();

if (this.quads.length > MAX_TOPO_SORT_QUADS) {
turnGFNITriggerOff();
turnDirectTriggerOn();
this.turnGFNITriggerOff();
this.turnDirectTriggerOn();
}

if (this.GFNITrigger && !isAngleTrigger) {
Expand All @@ -106,13 +106,13 @@ private void sort(Vector3fc cameraPos, boolean isAngleTrigger) {
if (sortTime > (this.consecutiveTopoSortFailures > 0
? MAX_FAILING_TOPO_SORT_TIME_NS
: MAX_TOPO_SORT_TIME_NS)) {
turnGFNITriggerOff();
turnDirectTriggerOn();
this.turnGFNITriggerOff();
this.turnDirectTriggerOn();
}

if (result) {
// disable distance sorting because topo sort seems to be possible.
turnDirectTriggerOff();
this.turnDirectTriggerOff();
this.consecutiveTopoSortFailures = 0;
return;
} else {
Expand All @@ -123,9 +123,9 @@ private void sort(Vector3fc cameraPos, boolean isAngleTrigger) {
// sort success from a different angle.
this.consecutiveTopoSortFailures++;
if (this.consecutiveTopoSortFailures >= getAttemptsForTime(sortTime)) {
turnGFNITriggerOff();
this.turnGFNITriggerOff();
}
turnDirectTriggerOn();
this.turnDirectTriggerOn();
}
}
if (this.directTrigger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public void triggerSections(BiConsumer<Long, Boolean> triggerSectionCallback, Ca
triggeredNormals.clear();
this.triggerSectionCallback = triggerSectionCallback;

processGFNITriggers(movement);
processDirectTriggers(movement);
this.processGFNITriggers(movement);
this.processDirectTriggers(movement);

var newTriggeredSectionsCount = this.triggeredSections.size();
var newTriggeredNormalCount = this.triggeredNormals.size();
Expand Down Expand Up @@ -279,7 +279,7 @@ private void processDirectTriggers(CameraMovement movement) {
remainingAngle -= Math.acos(angleCos);
}

insertDirectAngleTrigger(data, camera, remainingAngle);
this.insertDirectAngleTrigger(data, camera, remainingAngle);
} else {
double remainingDistance = DIRECT_TRIGGER_DISTANCE;
double lastTriggerCurrentCameraDistSquared = data.triggerCameraPos.distanceSquared(camera);
Expand All @@ -291,21 +291,22 @@ private void processDirectTriggers(CameraMovement movement) {
remainingDistance -= Math.sqrt(lastTriggerCurrentCameraDistSquared);
}

insertDirectDistanceTrigger(data, camera, remainingDistance);
this.insertDirectDistanceTrigger(data, camera, remainingDistance);
}
}
}

private void insertDirectAngleTrigger(DirectTriggerData data, Vector3dc cameraPos, double remainingAngle) {
double triggerCameraSectionCenterDist = data.getSectionCenterTriggerCameraDist();
double centerMinDistance = Math.tan(remainingAngle) * (triggerCameraSectionCenterDist - SECTION_CENTER_DIST);
insertJitteredTrigger(this.accumulatedDistance + centerMinDistance, data);
this.insertJitteredTrigger(this.accumulatedDistance + centerMinDistance, data);
}

private void insertDirectDistanceTrigger(DirectTriggerData data, Vector3dc cameraPos, double remainingDistance) {
insertJitteredTrigger(this.accumulatedDistance + remainingDistance, data);
this.insertJitteredTrigger(this.accumulatedDistance + remainingDistance, data);
}

// TODO: instead of jittering use Tree<Object> where object is either a list or an individual record?
// jitters the double values to never overwrite the same key. abuses that
// doubles have more precision than we need to make them a kind of hash table
private double lastJittered = -1;
Expand Down Expand Up @@ -352,23 +353,23 @@ private void triggerSectionDirect(ChunkSectionPos sectionPos) {

public void applyTriggerChanges(DynamicData data, ChunkSectionPos pos, Vector3dc cameraPos) {
if (data.turnGFNITriggerOff) {
disableGFNITriggering(pos.asLong());
this.disableGFNITriggering(pos.asLong());
}
if (data.turnDirectTriggerOn) {
enableDirectTriggering(data, pos, cameraPos);
this.enableDirectTriggering(data, pos, cameraPos);
}
if (data.turnDirectTriggerOff) {
disableDirectTriggering(data);
this.disableDirectTriggering(data);
}
data.clearTriggerChanges();
}

private void enableDirectTriggering(DynamicData data, ChunkSectionPos section, Vector3dc cameraPos) {
var newData = new DirectTriggerData(data, section, cameraPos);
if (newData.isAngleTriggering(cameraPos)) {
insertDirectAngleTrigger(newData, cameraPos, TRIGGER_ANGLE);
this.insertDirectAngleTrigger(newData, cameraPos, TRIGGER_ANGLE);
} else {
insertDirectDistanceTrigger(newData, cameraPos, DIRECT_TRIGGER_DISTANCE);
this.insertDirectDistanceTrigger(newData, cameraPos, DIRECT_TRIGGER_DISTANCE);
}
}

Expand All @@ -393,9 +394,9 @@ public void removeSection(TranslucentData oldData, long sectionPos) {
if (oldData == null) {
return;
}
disableGFNITriggering(sectionPos);
disableDirectTriggering(oldData);
decrementSortTypeCounter(oldData);
this.disableGFNITriggering(sectionPos);
this.disableDirectTriggering(oldData);
this.decrementSortTypeCounter(oldData);
}

private void addSectionInNewNormalLists(DynamicData dynamicData, AccumulationGroup accGroup) {
Expand All @@ -417,7 +418,7 @@ private void removeSectionFromList(NormalList normalList, long sectionPos) {

private void disableGFNITriggering(long sectionPos) {
for (var normalList : this.normalLists.values()) {
removeSectionFromList(normalList, sectionPos);
this.removeSectionFromList(normalList, sectionPos);
}
}

Expand All @@ -432,7 +433,7 @@ private void initiallyEnableGFNITriggering(DynamicData data, long sectionPos) {
var accGroup = collector.getGroupForNormal(normalList);
if (normalList.hasSection(sectionPos)) {
if (accGroup == null) {
removeSectionFromList(normalList, sectionPos);
this.removeSectionFromList(normalList, sectionPos);
} else {
normalList.updateSection(accGroup, sectionPos);
}
Expand All @@ -448,13 +449,13 @@ private void initiallyEnableGFNITriggering(DynamicData data, long sectionPos) {
if (collector.axisAlignedDistances != null) {
for (var accGroup : collector.axisAlignedDistances) {
if (accGroup != null) {
addSectionInNewNormalLists(data, accGroup);
this.addSectionInNewNormalLists(data, accGroup);
}
}
}
if (collector.unalignedDistances != null) {
for (var accGroup : collector.unalignedDistances.values()) {
addSectionInNewNormalLists(data, accGroup);
this.addSectionInNewNormalLists(data, accGroup);
}
}

Expand All @@ -477,28 +478,28 @@ public void integrateTranslucentData(TranslucentData oldData, TranslucentData ne

long sectionPos = newData.sectionPos.asLong();

incrementSortTypeCounter(newData);
this.incrementSortTypeCounter(newData);

// remove the section if the data doesn't need to trigger on face planes
if (newData instanceof DynamicData dynamicData) {
disableDirectTriggering(oldData);
decrementSortTypeCounter(oldData);
this.disableDirectTriggering(oldData);
this.decrementSortTypeCounter(oldData);
if (dynamicData.GFNITrigger) {
initiallyEnableGFNITriggering(dynamicData, sectionPos);
this.initiallyEnableGFNITriggering(dynamicData, sectionPos);
} else {
// remove the collector since this section is never going to get gfni triggering
// (there's no option to add sections to GFNI later currently)
dynamicData.deleteCollector();
}
if (dynamicData.directTrigger) {
enableDirectTriggering(dynamicData, newData.sectionPos, cameraPos);
this.enableDirectTriggering(dynamicData, newData.sectionPos, cameraPos);
}

// clear trigger changes on data change because the current state of trigger
// types was just set
dynamicData.clearTriggerChanges();
} else {
removeSection(oldData, sectionPos);
this.removeSection(oldData, sectionPos);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Group {
double baseDistance;

Group(AccumulationGroup accGroup) {
replaceWith(accGroup);
this.replaceWith(accGroup);
}

void replaceWith(AccumulationGroup accGroup) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ void addSection(AccumulationGroup accGroup, long sectionPos) {
var group = new Group(accGroup);

this.groupsBySection.put(sectionPos, group);
addGroupInterval(group);
this.addGroupInterval(group);
}

void removeSection(long sectionPos) {
Group group = this.groupsBySection.remove(sectionPos);
if (group != null) {
removeGroupInterval(group);
this.removeGroupInterval(group);
}
}

Expand All @@ -167,8 +167,8 @@ void updateSection(AccumulationGroup accGroup, long sectionPos) {
return;
}

removeGroupInterval(group);
this.removeGroupInterval(group);
group.replaceWith(accGroup);
addGroupInterval(group);
this.addGroupInterval(group);
}
}

0 comments on commit a5475c7

Please sign in to comment.