remove iterators for slight performance gains

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 3 years ago committed by GitHub
parent 8717d2270b
commit 2c0ef99871
  1. BIN
      bin/RabiClone.jar
  2. 28
      src/sig/RabiClone.java
  3. 6
      src/sig/engine/KeyBind.java
  4. 3
      src/sig/engine/String.java
  5. 9
      src/sig/objects/ConfigureControls.java

Binary file not shown.

@ -51,6 +51,10 @@ public class RabiClone{
public static long lastControllerScan = System.currentTimeMillis();
static long lastUpdate=System.nanoTime();
final static long TARGET_FRAMETIME = 8333333l;
static long lastReportedTime=System.currentTimeMillis();
public static void main(String[] args) {
Key.InitializeKeyConversionMap();
@ -124,8 +128,11 @@ public class RabiClone{
OBJ.remove(i--);
}
}
waitForNextFrame();
}
}
private static void handleGameControllers() {
for (int i=0;i<CONTROLLERS.length;i++) {
@ -161,4 +168,25 @@ public class RabiClone{
}
f.setSize(f.getWidth()*SIZE_MULTIPLIER,(int)((f.getWidth()*SIZE_MULTIPLIER)/1.77777777778d));
}
private static void waitForNextFrame() {
long newTime = System.nanoTime();
if (newTime-lastUpdate<TARGET_FRAMETIME) {
long timeRemaining=TARGET_FRAMETIME-(newTime-lastUpdate);
long millis = timeRemaining/1000000l;
int nanos = (int)(timeRemaining-millis*1000000l);
//System.out.println(timeRemaining+"/"+millis+" Nanos:"+nanos);
try {
Thread.sleep(millis,nanos);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
if (System.currentTimeMillis()-lastReportedTime>1000) {
System.err.println("WARNING! Update loop is underperforming!");
lastReportedTime=System.currentTimeMillis();
}
}
lastUpdate=newTime;
}
}

@ -76,9 +76,11 @@ public class KeyBind {
public static void poll() {
//Polls all KeyBinds based on device.
for (Action a : Action.values()) {
for (int i=0;i<Action.values().length;i++) {
Action a = Action.values()[i];
boolean held = false;
for (KeyBind c : KEYBINDS.get(a)) {
for (int j=0;j<KEYBINDS.get(a).size();j++) {
KeyBind c = KEYBINDS.get(a).get(j);
held = c.isKeyHeld();
if (held) {
break;

@ -27,7 +27,8 @@ public class String{
return this;
}
public String append(java.lang.Object...obj) {
for (java.lang.Object o : obj) {
for (int i=0;i<obj.length;i++) {
java.lang.Object o = obj[i];
this.sb.append(o.toString());
updateBounds(o.toString());
}

@ -35,17 +35,18 @@ public class ConfigureControls extends Object{
}
private void updateHighlightSections() {
for (Action a : Action.values()) {
for (int i=0;i<Action.values().length;i++) {
Action a = Action.values()[i];
actionHighlightSections.add(new ArrayList<Integer>());
StringBuilder renderedText=new StringBuilder(a.toString()).append(": ");
List<Integer> sectionList = actionHighlightSections.get(a.ordinal());
sectionList.clear();
for (int i=0;i<KeyBind.KEYBINDS.get(a).size();i++) {
KeyBind c = KeyBind.KEYBINDS.get(a).get(i);
for (int j=0;j<KeyBind.KEYBINDS.get(a).size();j++) {
KeyBind c = KeyBind.KEYBINDS.get(a).get(j);
sectionList.add(renderedText.length()+1);
renderedText.append(c.getName());
sectionList.add(renderedText.length());
renderedText.append(i!=KeyBind.KEYBINDS.get(a).size()-1?",":"");
renderedText.append(j!=KeyBind.KEYBINDS.get(a).size()-1?",":"");
}
}
}

Loading…
Cancel
Save