-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change: Use integer handles for graphics state to avoid passing types
- Loading branch information
1 parent
2fb1d28
commit de545a5
Showing
42 changed files
with
803 additions
and
592 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
98 changes: 98 additions & 0 deletions
98
src/main/java/me/jellysquid/mods/sodium/client/render/chunk/ChunkGraphicsStateArray.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,98 @@ | ||
package me.jellysquid.mods.sodium.client.render.chunk; | ||
|
||
import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass; | ||
|
||
public class ChunkGraphicsStateArray { | ||
private final int[] key; | ||
private final int[] value; | ||
|
||
private int size; | ||
|
||
public ChunkGraphicsStateArray(int size) { | ||
this.key = new int[size]; | ||
this.value = new int[size]; | ||
} | ||
|
||
public int get(BlockRenderPass pass) { | ||
return this.get(pass.ordinal()); | ||
} | ||
|
||
public int get(int pass) { | ||
for (int i = 0; i < this.size; i++) { | ||
if (this.key[i] == pass) { | ||
return this.value[i]; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
public void set(BlockRenderPass pass, int value) { | ||
this.set(pass.ordinal(), value); | ||
} | ||
|
||
public void set(int pass, int value) { | ||
if (value == -1) { | ||
this.remove(pass); | ||
|
||
return; | ||
} | ||
|
||
for (int i = 0; i < this.size; i++) { | ||
if (this.key[i] == pass) { | ||
this.value[i] = value; | ||
return; | ||
} | ||
} | ||
|
||
int i = this.size++; | ||
|
||
this.key[i] = pass; | ||
this.value[i] = value; | ||
} | ||
|
||
public int remove(BlockRenderPass pass) { | ||
return this.remove(pass.ordinal()); | ||
} | ||
|
||
public int remove(int pass) { | ||
int value = -1; | ||
int split = -1; | ||
|
||
for (int i = 0; i < this.size; i++) { | ||
if (this.key[i] == pass) { | ||
split = i; | ||
value = this.value[i]; | ||
|
||
break; | ||
} | ||
} | ||
|
||
if (split < 0) { | ||
return - 1; | ||
} | ||
|
||
this.size--; | ||
|
||
System.arraycopy(this.key, split + 1, this.key, split, this.size - split); | ||
System.arraycopy(this.value, split + 1, this.value, split, this.size - split); | ||
|
||
return value; | ||
} | ||
|
||
public int getKey(int i) { | ||
return this.key[i]; | ||
} | ||
|
||
public int getValue(int i) { | ||
return this.value[i]; | ||
} | ||
|
||
public int getSize() { | ||
return this.size; | ||
} | ||
|
||
public void clear() { | ||
this.size = 0; | ||
} | ||
} |
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
Oops, something went wrong.