remove general

This commit is contained in:
sillysagiri 2024-10-14 23:10:32 +07:00
parent f9f1a85eff
commit df0183d2f5
2 changed files with 32 additions and 24 deletions

View File

@ -1,9 +1,10 @@
package sillysagiri; package sillysagiri;
import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
public final class Input { public final class Input {
public Hashtable<Integer, Integer> hash_keyState = new Hashtable<>(); public Hashtable hash_keyState = new Hashtable(20);
public int state_anyKey = 0; public int state_anyKey = 0;
public int state_touchState = Sagiri.TOUCH_NONE; public int state_touchState = Sagiri.TOUCH_NONE;
@ -18,11 +19,15 @@ public final class Input {
public final void Update() public final void Update()
{ {
for (Integer key : hash_keyState.keySet()) Enumeration i = hash_keyState.keys();
while(i.hasMoreElements())
{ {
int value = hash_keyState.get(key); Integer key = (Integer)i.nextElement();
if (value == -1) hash_keyState.remove(key); Integer value = (Integer)hash_keyState.get(key);
else hash_keyState.put(key, value+1);
if (value.intValue() == -1) hash_keyState.remove(key);
else hash_keyState.put(key, new Integer(value.intValue()+1));
} }
if (state_anyKey != 0) state_anyKey++; if (state_anyKey != 0) state_anyKey++;
@ -31,12 +36,13 @@ public final class Input {
public final void HandleKeyDown(int keycode) 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) 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 else
hash_keyState.put(keycode, 1); hash_keyState.put(key, new Integer(1));
state_anyKey = Math.max(state_anyKey, 1); state_anyKey = Math.max(state_anyKey, 1);
state_lastKey = keycode; state_lastKey = keycode;
@ -44,7 +50,9 @@ public final class Input {
public final void HandleKeyUp(int keycode) 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_anyKey = -1;
state_lastKey = keycode; state_lastKey = keycode;
} }
@ -58,7 +66,8 @@ public final class Input {
public final boolean IsKeyHeld(int keycode) 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) if (value != null)
return value.intValue() > 0; return value.intValue() > 0;
@ -68,14 +77,15 @@ public final class Input {
public final boolean IsKeyHeld(int[] keycode) public final boolean IsKeyHeld(int[] keycode)
{ {
for (int i : keycode) for (int i=0; i<keycode.length; i++)
if (IsKeyHeld(keycode[i])) return true; if (IsKeyHeld(keycode[i])) return true;
return false; return false;
} }
public final boolean IsKeyDown(int keycode) public final boolean IsKeyDown(int keycode)
{ {
Integer value = hash_keyState.get(keycode); Integer key = new Integer(keycode);
Integer value = (Integer)hash_keyState.get(key);
if (value != null) if (value != null)
return value.intValue() == 0; return value.intValue() == 0;
@ -85,14 +95,15 @@ public final class Input {
public final boolean IsKeyDown(int[] keycode) public final boolean IsKeyDown(int[] keycode)
{ {
for (int i : keycode) for (int i=0; i<keycode.length; i++)
if (IsKeyDown(keycode[i])) return true; if (IsKeyDown(keycode[i])) return true;
return false; return false;
} }
public final boolean IsKeyReleased(int keycode) public final boolean IsKeyReleased(int keycode)
{ {
Integer value = hash_keyState.get(keycode); Integer key = new Integer(keycode);
Integer value = (Integer)hash_keyState.get(key);
if (value != null) if (value != null)
return value.intValue() == -1; return value.intValue() == -1;
@ -102,7 +113,7 @@ public final class Input {
public final boolean IsKeyReleased(int[] keycode) public final boolean IsKeyReleased(int[] keycode)
{ {
for (int i : keycode) for (int i=0; i<keycode.length; i++)
if (IsKeyReleased(keycode[i])) return true; if (IsKeyReleased(keycode[i])) return true;
return false; return false;
} }
@ -111,5 +122,5 @@ public final class Input {
public final boolean IsKeyDownAny() { return state_anyKey == 1; } public final boolean IsKeyDownAny() { return state_anyKey == 1; }
public final boolean IsKeyReleasedAny() { return state_anyKey == -1; } public final boolean IsKeyReleasedAny() { return state_anyKey == -1; }
public final int getKeyStatus(int keycode) { return hash_keyState.get(keycode); } public final Integer getKeyStatus(int keycode) { return (Integer)hash_keyState.get(new Integer(keycode)); }
} }

View File

@ -15,24 +15,21 @@ public class Sagiri
public int fps = 20; public int fps = 20;
private Scene _scene_current; private Scene _scene_current = null;
private long _time_begin; public long time_begin = 0;
private long _time_delta; public long time_delta = 0;
public Sagiri() public Sagiri()
{ {
_instance = this; _instance = this;
input = new Input(); input = new Input();
_scene_current = null;
} }
public void Update(Graphics g) public void Update(Graphics g)
{ {
_time_begin = System.currentTimeMillis();
input.Update(); input.Update();
if (_scene_current != null) if (_scene_current != null)
_scene_current.Update(_time_delta = System.currentTimeMillis() - _time_begin, g); _scene_current.Update(time_delta, g);
} }
public Scene Get_Scene() { return _scene_current; } public Scene Get_Scene() { return _scene_current; }
@ -47,5 +44,5 @@ public class Sagiri
_scene_current = scene; _scene_current = scene;
} }
public final long GetFrameTime() { return _time_delta; } public final long GetFrameTime() { return time_delta; }
} }