-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
External Storage gametests
- Loading branch information
Showing
10 changed files
with
1,429 additions
and
76 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
42 changes: 22 additions & 20 deletions
42
...om/refinedmods/refinedstorage/common/storage/externalstorage/ExternalStorageWorkRate.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 |
---|---|---|
@@ -1,40 +1,42 @@ | ||
package com.refinedmods.refinedstorage.common.storage.externalstorage; | ||
|
||
import com.google.common.util.concurrent.RateLimiter; | ||
|
||
class ExternalStorageWorkRate { | ||
private static final double[] RATE_LIMITERS = new double[] { | ||
0.5D, // slowest, every 2 sec | ||
0.75D, // faster | ||
1D, // medium, every 1 sec | ||
2D, // faster, every 0.5 sec | ||
3D // fastest | ||
private static final int[] OPERATION_COUNTS = new int[] { | ||
40, // slowest, every 2 sec | ||
30, // faster, every 1.5 sec | ||
20, // medium, every 1 sec | ||
10, // faster, every 0.5 sec | ||
5 // fastest, every 0.25 sec | ||
}; | ||
|
||
private int idx = 2; // medium | ||
private final RateLimiter rateLimiter = RateLimiter.create(RATE_LIMITERS[idx]); | ||
private int counter = 0; | ||
private int threshold = OPERATION_COUNTS[idx]; | ||
|
||
boolean canDoWork() { | ||
return rateLimiter.tryAcquire(); | ||
counter++; | ||
if (counter >= threshold) { | ||
counter = 0; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void faster() { | ||
if (idx + 1 >= RATE_LIMITERS.length) { | ||
return; | ||
if (idx + 1 < OPERATION_COUNTS.length) { | ||
idx++; | ||
updateThreshold(); | ||
} | ||
idx++; | ||
updateRate(); | ||
} | ||
|
||
void slower() { | ||
if (idx - 1 < 0) { | ||
return; | ||
if (idx - 1 >= 0) { | ||
idx--; | ||
updateThreshold(); | ||
} | ||
idx--; | ||
updateRate(); | ||
} | ||
|
||
private void updateRate() { | ||
rateLimiter.setRate(RATE_LIMITERS[idx]); | ||
private void updateThreshold() { | ||
threshold = OPERATION_COUNTS[idx]; | ||
} | ||
} |
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
Oops, something went wrong.