2015-01-18 20:29:48 +01:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
|
|
|
* Copyright (C) 2014, 2015 Jeffrey Han
|
|
|
|
*
|
|
|
|
* opsu! is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu! is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package itdelatrisu.opsu;
|
|
|
|
|
|
|
|
import itdelatrisu.opsu.audio.MusicController;
|
|
|
|
|
|
|
|
import org.newdawn.slick.AppGameContainer;
|
|
|
|
import org.newdawn.slick.Game;
|
|
|
|
import org.newdawn.slick.SlickException;
|
2015-01-21 01:01:18 +01:00
|
|
|
import org.newdawn.slick.opengl.InternalTextureLoader;
|
2015-01-18 20:29:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* AppGameContainer extension that sends critical errors to ErrorHandler.
|
|
|
|
*/
|
|
|
|
public class Container extends AppGameContainer {
|
2015-01-22 06:44:45 +01:00
|
|
|
/** SlickException causing game failure. */
|
2015-01-18 20:29:48 +01:00
|
|
|
protected SlickException e = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new container wrapping a game
|
2015-01-22 06:44:45 +01:00
|
|
|
*
|
2015-01-18 20:29:48 +01:00
|
|
|
* @param game The game to be wrapped
|
|
|
|
* @throws SlickException Indicates a failure to initialise the display
|
|
|
|
*/
|
|
|
|
public Container(Game game) throws SlickException {
|
|
|
|
super(game);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new container wrapping a game
|
2015-01-22 06:44:45 +01:00
|
|
|
*
|
2015-01-18 20:29:48 +01:00
|
|
|
* @param game The game to be wrapped
|
|
|
|
* @param width The width of the display required
|
|
|
|
* @param height The height of the display required
|
|
|
|
* @param fullscreen True if we want fullscreen mode
|
|
|
|
* @throws SlickException Indicates a failure to initialise the display
|
|
|
|
*/
|
|
|
|
public Container(Game game, int width, int height, boolean fullscreen) throws SlickException {
|
2015-01-23 22:06:57 +01:00
|
|
|
super(game, width, height, fullscreen);
|
2015-01-18 20:29:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void start() throws SlickException {
|
|
|
|
try {
|
|
|
|
setup();
|
|
|
|
getDelta();
|
|
|
|
while (running())
|
|
|
|
gameLoop();
|
|
|
|
} finally {
|
2015-01-21 01:01:18 +01:00
|
|
|
// destroy the game container
|
|
|
|
close_sub();
|
2015-01-18 20:29:48 +01:00
|
|
|
destroy();
|
2015-01-21 01:01:18 +01:00
|
|
|
|
|
|
|
// report any critical errors
|
2015-01-18 20:29:48 +01:00
|
|
|
if (e != null) {
|
|
|
|
ErrorHandler.error(null, e, true);
|
|
|
|
e = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forceExit)
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
|
2015-01-21 01:01:18 +01:00
|
|
|
/**
|
|
|
|
* Actions to perform before destroying the game container.
|
|
|
|
*/
|
|
|
|
private void close_sub() {
|
|
|
|
// save user options
|
|
|
|
Options.saveOptions();
|
|
|
|
|
|
|
|
// close server socket
|
|
|
|
Opsu.closeSocket();
|
|
|
|
|
|
|
|
// destroy images
|
|
|
|
InternalTextureLoader.get().clear();
|
2015-01-21 01:24:59 +01:00
|
|
|
|
2015-01-21 01:01:18 +01:00
|
|
|
// reset image references
|
|
|
|
GameImage.clearReferences();
|
|
|
|
OsuFile.resetImageCache();
|
2015-01-21 01:24:59 +01:00
|
|
|
|
|
|
|
// prevent loading tracks from re-initializing OpenAL
|
|
|
|
MusicController.reset();
|
2015-01-21 01:01:18 +01:00
|
|
|
}
|
|
|
|
|
2015-01-18 20:29:48 +01:00
|
|
|
@Override
|
|
|
|
protected void updateAndRender(int delta) throws SlickException {
|
|
|
|
try {
|
|
|
|
super.updateAndRender(delta);
|
|
|
|
} catch (SlickException e) {
|
2015-01-21 01:01:18 +01:00
|
|
|
this.e = e; // store exception to display later
|
|
|
|
throw e; // re-throw exception
|
2015-01-18 20:29:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|