From df0183d2f56c8529b74f0dd90aeca621949e8db3 Mon Sep 17 00:00:00 2001 From: sillysagiri Date: Mon, 14 Oct 2024 23:10:32 +0700 Subject: [PATCH] remove general --- src/sillysagiri/Input.java | 43 +++++++++++++++++++++++-------------- src/sillysagiri/Sagiri.java | 13 +++++------ 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/sillysagiri/Input.java b/src/sillysagiri/Input.java index 7cba864..aea04dd 100644 --- a/src/sillysagiri/Input.java +++ b/src/sillysagiri/Input.java @@ -1,9 +1,10 @@ package sillysagiri; +import java.util.Enumeration; import java.util.Hashtable; public final class Input { - public Hashtable hash_keyState = new Hashtable<>(); + public Hashtable hash_keyState = new Hashtable(20); public int state_anyKey = 0; public int state_touchState = Sagiri.TOUCH_NONE; @@ -18,11 +19,15 @@ public final class Input { public final void Update() { - for (Integer key : hash_keyState.keySet()) + Enumeration i = hash_keyState.keys(); + while(i.hasMoreElements()) { - int value = hash_keyState.get(key); - if (value == -1) hash_keyState.remove(key); - else hash_keyState.put(key, value+1); + 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++; @@ -31,12 +36,13 @@ public final class Input { public final void HandleKeyDown(int keycode) { - Integer value = hash_keyState.get(keycode); + Integer key = new Integer(keycode); + Integer value = (Integer)hash_keyState.get(key); if (value != null) - hash_keyState.put(keycode, new Integer(Math.max(value, 1))); + hash_keyState.put(key, new Integer(Math.max(value.intValue(), 1))); else - hash_keyState.put(keycode, 1); + hash_keyState.put(key, new Integer(1)); state_anyKey = Math.max(state_anyKey, 1); state_lastKey = keycode; @@ -44,7 +50,9 @@ public final class Input { public final void HandleKeyUp(int keycode) { - hash_keyState.put(keycode, -1); + Integer key = new Integer(keycode); + + hash_keyState.put(key, new Integer(-1)); state_anyKey = -1; state_lastKey = keycode; } @@ -58,7 +66,8 @@ public final class Input { public final boolean IsKeyHeld(int keycode) { - Integer value = hash_keyState.get(keycode); + Integer key = new Integer(keycode); + Integer value = (Integer)hash_keyState.get(key); if (value != null) return value.intValue() > 0; @@ -68,14 +77,15 @@ public final class Input { public final boolean IsKeyHeld(int[] keycode) { - for (int i : keycode) + for (int i=0; i