Refactoring & cleaning

This commit is contained in:
ondra
2014-04-08 19:21:40 +02:00
parent cc85d8a9d3
commit f3c6f4f0f5
33 changed files with 156 additions and 186 deletions
+24 -24
View File
@@ -44,7 +44,7 @@ public class App implements AppAccess {
// modules
private InputSystem inputSystem;
private DisplaySystem displaySystem;
private static SoundSystem soundSystem;
private SoundSystem soundSystem;
private EventBus eventBus;
private GameLoop mainLoop;
private ScreenRegistry screens;
@@ -108,9 +108,9 @@ public class App implements AppAccess {
{
Log.i("Shutting down subsystems...");
if (bus() != null) {
bus().send(new DestroyEvent());
bus().destroy();
if (getEventBus() != null) {
getEventBus().send(new DestroyEvent());
getEventBus().destroy();
}
Log.i("Terminating...");
@@ -209,20 +209,20 @@ public class App implements AppAccess {
Log.f3("Registering channels...");
// framework events
bus().addChannel(DestroyEvent.class, Destroyable.class);
bus().addChannel(UpdateEvent.class, Updateable.class);
getEventBus().addChannel(DestroyEvent.class, Destroyable.class);
getEventBus().addChannel(UpdateEvent.class, Updateable.class);
// input events
bus().addChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
bus().addChannel(KeyboardEvent.class, KeyboardEvent.Listener.class);
bus().addChannel(MouseMotionEvent.class, MouseMotionEvent.Listener.class);
bus().addChannel(MouseButtonEvent.class, MouseButtonEvent.Listener.class);
getEventBus().addChannel(ScreenChangeEvent.class, ScreenChangeEvent.Listener.class);
getEventBus().addChannel(KeyEvent.class, KeyEvent.Listener.class);
getEventBus().addChannel(MouseMotionEvent.class, MouseMotionEvent.Listener.class);
getEventBus().addChannel(MouseButtonEvent.class, MouseButtonEvent.Listener.class);
// control events
bus().addChannel(ScreenRequestEvent.class, ScreenRequestEvent.Listener.class);
bus().addChannel(ResourceLoadRequest.class, ResourceLoadRequest.Listener.class);
bus().addChannel(ActionRequest.class, ActionRequest.Listener.class);
bus().addChannel(MainLoopTaskRequest.class, MainLoopTaskRequest.Listener.class);
getEventBus().addChannel(ScreenRequestEvent.class, ScreenRequestEvent.Listener.class);
getEventBus().addChannel(ResourceLoadRequest.class, ResourceLoadRequest.Listener.class);
getEventBus().addChannel(ActionRequest.class, ActionRequest.Listener.class);
getEventBus().addChannel(MainLoopTaskRequest.class, MainLoopTaskRequest.Listener.class);
}
@@ -231,32 +231,32 @@ public class App implements AppAccess {
Log.f3("Setting up hot keys...");
// Go fullscreen
input().bindKeyStroke(new KeyStroke(Keys.KEY_F11), new Runnable() {
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F11), new Runnable() {
@Override
public void run()
{
bus().send(new ActionRequest(RequestType.FULLSCREEN));
getEventBus().send(new ActionRequest(RequestType.FULLSCREEN));
}
});
// Take screenshot
input().bindKeyStroke(new KeyStroke(Keys.KEY_F2), new Runnable() {
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_F2), new Runnable() {
@Override
public void run()
{
bus().send(new ActionRequest(RequestType.SCREENSHOT));
getEventBus().send(new ActionRequest(RequestType.SCREENSHOT));
}
});
// Exit
input().bindKeyStroke(new KeyStroke(Keys.KEY_LCONTROL, Keys.KEY_Q), new Runnable() {
getInput().bindKeyStroke(new KeyStroke(Keys.KEY_LCONTROL, Keys.KEY_Q), new Runnable() {
@Override
public void run()
{
bus().send(new ActionRequest(RequestType.SHUTDOWN));
getEventBus().send(new ActionRequest(RequestType.SHUTDOWN));
}
});
}
@@ -323,7 +323,7 @@ public class App implements AppAccess {
* @return sound system of the running instance
*/
@Override
public SoundSystem snd()
public SoundSystem getSoundSystem()
{
return soundSystem;
}
@@ -333,7 +333,7 @@ public class App implements AppAccess {
* @return input system of the running instance
*/
@Override
public InputSystem input()
public InputSystem getInput()
{
return inputSystem;
}
@@ -343,7 +343,7 @@ public class App implements AppAccess {
* @return display system of the running instance
*/
@Override
public DisplaySystem disp()
public DisplaySystem getDisplay()
{
return displaySystem;
}
@@ -353,7 +353,7 @@ public class App implements AppAccess {
* @return event bus
*/
@Override
public EventBus bus()
public EventBus getEventBus()
{
return eventBus;
}
+1 -1
View File
@@ -60,7 +60,7 @@ public class MainLoop extends GameLoop implements ActionRequest.Listener {
@Override
public void execute()
{
disp().switchFullscreen();
getDisplay().switchFullscreen();
}
};
}
@@ -60,7 +60,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
@Override
public String getText()
{
return "Running at " + disp().getFps() + " fps!";
return "Running at " + getDisplay().getFps() + " fps!";
}
});
@@ -25,33 +25,11 @@ public class ScreenTestBouncy extends LayeredScreen {
@Override
public void run()
{
bus().send(new ScreenRequestEvent("test.cat"));
getEventBus().send(new ScreenRequestEvent("test.cat"));
}
});
}
@Override
protected void deinitScreen()
{
// no impl
}
@Override
protected void onScreenEnter()
{
// no impl
}
@Override
protected void onScreenLeave()
{
// no impl
}
@Override
public String getId()
{
@@ -97,7 +97,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
public void render()
{
cat.render();
text.render(disp().getFps()+" fps");
text.render(getDisplay().getFps()+" fps");
}
}
@@ -26,8 +26,8 @@ public class ScreenTestCat extends LayeredScreen {
@Override
public void run()
{
snd().fadeOutAllLoops();
bus().sendDelayed(new ActionRequest(RequestType.SHUTDOWN), 3);
getSoundSystem().fadeOutAllLoops();
getEventBus().sendDelayed(new ActionRequest(RequestType.SHUTDOWN), 3);
}
});
@@ -36,22 +36,16 @@ public class ScreenTestCat extends LayeredScreen {
@Override
public void run()
{
bus().send(new ScreenRequestEvent("test.bouncy"));
getEventBus().send(new ScreenRequestEvent("test.bouncy"));
}
});
}
@Override
protected void deinitScreen()
{
}
@Override
protected void onScreenEnter()
{
snd().fadeOutAllLoops();
getSoundSystem().fadeOutAllLoops();
Res.getLoop("test.wilderness").fadeIn();
}
@@ -21,27 +21,6 @@ public class ScreenTestFont extends Screen {
}
@Override
protected void deinitScreen()
{
//
}
@Override
protected void onScreenEnter()
{
//
}
@Override
protected void onScreenLeave()
{
//
}
@Override
protected void renderScreen()
{
@@ -53,16 +32,6 @@ public class ScreenTestFont extends Screen {
final Coord origin = getRect().getCenter().sub(space.half());
fr.draw(str, origin, height, RGB.GREEN);
// final GLFont font = Res.getFont("");
//
// final String s = "It works!";
// final double scale = getRect().height() / 50D;
// Render.pushState();
// Render.translate(getRect().getCenter().sub(font.getNeededSpace(s).mul(scale).half()));
// Render.scale(new Coord(scale));
// font.draw("It works!");
// Render.popState();
}