remove general
This commit is contained in:
parent
f9f1a85eff
commit
df0183d2f5
@ -1,9 +1,10 @@
|
||||
package sillysagiri;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
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_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<keycode.length; i++)
|
||||
if (IsKeyHeld(keycode[i])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
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)
|
||||
return value.intValue() == 0;
|
||||
@ -85,14 +95,15 @@ public final class Input {
|
||||
|
||||
public final boolean IsKeyDown(int[] keycode)
|
||||
{
|
||||
for (int i : keycode)
|
||||
for (int i=0; i<keycode.length; i++)
|
||||
if (IsKeyDown(keycode[i])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
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)
|
||||
return value.intValue() == -1;
|
||||
@ -102,7 +113,7 @@ public final class Input {
|
||||
|
||||
public final boolean IsKeyReleased(int[] keycode)
|
||||
{
|
||||
for (int i : keycode)
|
||||
for (int i=0; i<keycode.length; i++)
|
||||
if (IsKeyReleased(keycode[i])) return true;
|
||||
return false;
|
||||
}
|
||||
@ -111,5 +122,5 @@ public final class Input {
|
||||
public final boolean IsKeyDownAny() { 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)); }
|
||||
}
|
||||
|
@ -15,24 +15,21 @@ public class Sagiri
|
||||
|
||||
public int fps = 20;
|
||||
|
||||
private Scene _scene_current;
|
||||
private long _time_begin;
|
||||
private long _time_delta;
|
||||
private Scene _scene_current = null;
|
||||
public long time_begin = 0;
|
||||
public long time_delta = 0;
|
||||
|
||||
public Sagiri()
|
||||
{
|
||||
_instance = this;
|
||||
input = new Input();
|
||||
_scene_current = null;
|
||||
}
|
||||
|
||||
public void Update(Graphics g)
|
||||
{
|
||||
_time_begin = System.currentTimeMillis();
|
||||
|
||||
input.Update();
|
||||
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; }
|
||||
@ -47,5 +44,5 @@ public class Sagiri
|
||||
_scene_current = scene;
|
||||
}
|
||||
|
||||
public final long GetFrameTime() { return _time_delta; }
|
||||
public final long GetFrameTime() { return time_delta; }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user