remove hashmap

This commit is contained in:
sillysagiri 2024-10-16 13:42:49 +07:00
parent cc06f3c961
commit 03b4553a5b

View File

@ -1,14 +1,9 @@
package sillysagiri; package sillysagiri;
import java.util.Enumeration;
import java.util.Hashtable;
public final class Input { public final class Input {
public Hashtable hash_keyState = new Hashtable(20); public int state_keycode = KeyCode.NONE;
public int state_keyphase = 0;
public int state_anyKey = 0;
public int state_touchState = Sagiri.TOUCH_NONE; public int state_touchState = Sagiri.TOUCH_NONE;
public int state_lastKey = 0;
public int touchX = 0; public int touchX = 0;
public int touchY = 0; public int touchY = 0;
@ -19,42 +14,21 @@ public final class Input {
public final void Update() public final void Update()
{ {
Enumeration i = hash_keyState.keys(); if (state_keyphase == 0) state_keyphase = KeyCode.NONE;
while(i.hasMoreElements()) if (state_keyphase != 0 && state_keyphase != KeyCode.NONE) state_keyphase++;
{
Integer key = (Integer)i.nextElement();
Integer value = (Integer)hash_keyState.get(key);
if (value.intValue() == -1) hash_keyState.remove(key);
else hash_keyState.put(key, new Integer(value.intValue()+1));
}
if (state_anyKey != 0) state_anyKey++;
state_touchState = Sagiri.TOUCH_NONE; state_touchState = Sagiri.TOUCH_NONE;
} }
public final void HandleKeyDown(int keycode) public final void HandleKeyDown(int keycode)
{ {
Integer key = new Integer(keycode); state_keyphase = Math.max(state_keyphase, 1);
Integer value = (Integer)hash_keyState.get(key); state_keycode = keycode;
if (value != null)
hash_keyState.put(key, new Integer(Math.max(value.intValue(), 1)));
else
hash_keyState.put(key, new Integer(1));
state_anyKey = Math.max(state_anyKey, 1);
state_lastKey = keycode;
} }
public final void HandleKeyUp(int keycode) public final void HandleKeyUp(int keycode)
{ {
Integer key = new Integer(keycode); state_keyphase = -1;
state_keycode = keycode;
hash_keyState.put(key, new Integer(-1));
state_anyKey = -1;
state_lastKey = keycode;
} }
public final void HandleTouch(int phase, int x, int y) public final void HandleTouch(int phase, int x, int y)
@ -66,13 +40,7 @@ public final class Input {
public final boolean IsKeyHeld(int keycode) public final boolean IsKeyHeld(int keycode)
{ {
Integer key = new Integer(keycode); return (state_keycode == keycode) && (state_keyphase > 0);
Integer value = (Integer)hash_keyState.get(key);
if (value != null)
return value.intValue() > 0;
else
return false;
} }
public final boolean IsKeyHeld(int[] keycode) public final boolean IsKeyHeld(int[] keycode)
@ -84,13 +52,7 @@ public final class Input {
public final boolean IsKeyDown(int keycode) public final boolean IsKeyDown(int keycode)
{ {
Integer key = new Integer(keycode); return (state_keycode == keycode) && (state_keyphase == 0);
Integer value = (Integer)hash_keyState.get(key);
if (value != null)
return value.intValue() == 0;
else
return false;
} }
public final boolean IsKeyDown(int[] keycode) public final boolean IsKeyDown(int[] keycode)
@ -102,13 +64,7 @@ public final class Input {
public final boolean IsKeyReleased(int keycode) public final boolean IsKeyReleased(int keycode)
{ {
Integer key = new Integer(keycode); return (state_keycode == keycode) && (state_keyphase == -1);
Integer value = (Integer)hash_keyState.get(key);
if (value != null)
return value.intValue() == -1;
else
return false;
} }
public final boolean IsKeyReleased(int[] keycode) public final boolean IsKeyReleased(int[] keycode)
@ -118,9 +74,7 @@ public final class Input {
return false; return false;
} }
public final boolean IsKeyHeldAny() { return state_anyKey > 1; } public final boolean IsKeyHeldAny() { return state_keyphase > 1; }
public final boolean IsKeyDownAny() { return state_anyKey == 1; } public final boolean IsKeyDownAny() { return state_keyphase == 1; }
public final boolean IsKeyReleasedAny() { return state_anyKey == -1; } public final boolean IsKeyReleasedAny() { return state_keyphase == -1; }
public final Integer getKeyStatus(int keycode) { return (Integer)hash_keyState.get(new Integer(keycode)); }
} }