org.newdawn.slick.util.Log Java Examples
The following examples show how to use
org.newdawn.slick.util.Log.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GUITest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.BasicGame#keyPressed(int, char) */ public void keyPressed(int key, char c) { if (key == Input.KEY_ESCAPE) { System.exit(0); } if (key == Input.KEY_F2) { app.setDefaultMouseCursor(); } if (key == Input.KEY_F1) { if (app != null) { try { app.setDisplayMode(640,480,false); } catch (SlickException e) { Log.error(e); } } } }
Example #2
Source File: ParticleIO.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Save a single emitter to the XML file * * @param out * The location to which we should save * @param emitter * The emitter to store to the XML file * @throws IOException * Indicates a failure to write or encode the XML */ public static void saveEmitter(OutputStream out, ConfigurableEmitter emitter) throws IOException { try { DocumentBuilder builder = DocumentBuilderFactory.newInstance() .newDocumentBuilder(); Document document = builder.newDocument(); document.appendChild(emitterToElement(document, emitter)); Result result = new StreamResult(new OutputStreamWriter(out, "utf-8")); DOMSource source = new DOMSource(document); TransformerFactory factory = TransformerFactory.newInstance(); Transformer xformer = factory.newTransformer(); xformer.setOutputProperty(OutputKeys.INDENT, "yes"); xformer.transform(source, result); } catch (Exception e) { Log.error(e); throw new IOException("Failed to save emitter"); } }
Example #3
Source File: Mp3InputStream.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
@Override public int read(byte[] b, int off, int len) throws IOException { for (int i = 0; i < len; i++) { try { int value = read(); if (value >= 0) b[i] = (byte) value; else return (i == 0) ? -1 : i; } catch (IOException e) { Log.error(e); return i; } } return len; }
Example #4
Source File: PBufferGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.Graphics#enable() */ protected void enable() { SlickCallable.enterSafeBlock(); try { if (pbuffer.isBufferLost()) { pbuffer.destroy(); init(); } pbuffer.makeCurrent(); } catch (Exception e) { Log.error("Failed to recreate the PBuffer"); throw new RuntimeException(e); } // Put the renderer contents to the texture GL.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID()); pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER); TextureImpl.unbind(); initGL(); }
Example #5
Source File: BeatmapDifficultyCalculator.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Computes the strain values for the beatmap. * @return true if successful, false otherwise */ private boolean calculateStrainValues() { // Traverse hitObjects in pairs to calculate the strain value of NextHitObject from // the strain value of CurrentHitObject and environment. if (tpHitObjects.length == 0) { Log.warn("Can not compute difficulty of empty beatmap."); return false; } tpHitObject currentHitObject = tpHitObjects[0]; tpHitObject nextHitObject; int index = 0; // First hitObject starts at strain 1. 1 is the default for strain values, // so we don't need to set it here. See tpHitObject. while (++index < tpHitObjects.length) { nextHitObject = tpHitObjects[index]; nextHitObject.calculateStrains(currentHitObject); currentHitObject = nextHitObject; } return true; }
Example #6
Source File: Image.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Create an image based on a file at the specified location * * @param ref The location of the image file to load * @param flipped True if the image should be flipped on the y-axis on load * @param f The filtering method to use when scaling this image * @param transparent The color to treat as transparent * @throws SlickException Indicates a failure to load the image */ public Image(String ref, boolean flipped, int f, Color transparent) throws SlickException { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; this.transparent = transparent; this.flipped = flipped; try { this.ref = ref; int[] trans = null; if (transparent != null) { trans = new int[3]; trans[0] = (int) (transparent.r * 255); trans[1] = (int) (transparent.g * 255); trans[2] = (int) (transparent.b * 255); } texture = InternalTextureLoader.get().getTexture(ref, flipped, filter, trans); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to load image from: "+ref, e); } }
Example #7
Source File: Music.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Create and load a piece of music (either OGG or MOD/XM) * @param in The stream to read the music from * @param ref The symbolic name of this music * @throws SlickException Indicates a failure to read the music from the stream */ public Music(InputStream in, String ref) throws SlickException { SoundStore.get().init(); try { if (ref.toLowerCase().endsWith(".ogg")) { sound = SoundStore.get().getOgg(in); } else if (ref.toLowerCase().endsWith(".wav")) { sound = SoundStore.get().getWAV(in); } else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) { sound = SoundStore.get().getMOD(in); } else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) { sound = SoundStore.get().getAIF(in); } else { throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported."); } } catch (Exception e) { Log.error(e); throw new SlickException("Failed to load music: "+ref); } }
Example #8
Source File: PBufferUniqueGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.Graphics#enable() */ protected void enable() { SlickCallable.enterSafeBlock(); try { if (pbuffer.isBufferLost()) { pbuffer.destroy(); init(); } pbuffer.makeCurrent(); } catch (Exception e) { Log.error("Failed to recreate the PBuffer"); Log.error(e); throw new RuntimeException(e); } // Put the renderer contents to the texture TextureImpl.unbind(); initGL(); }
Example #9
Source File: PBufferGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Initialise the PBuffer that will be used to render to * * @throws SlickException */ private void init() throws SlickException { try { Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter()); final RenderTexture rt = new RenderTexture(false, true, false, false, RenderTexture.RENDER_TEXTURE_2D, 0); pbuffer = new Pbuffer(screenWidth, screenHeight, new PixelFormat(8, 0, 0), rt, null); // Initialise state of the pbuffer context. pbuffer.makeCurrent(); initGL(); GL.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID()); pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER); image.draw(0,0); image.setTexture(tex); Display.makeCurrent(); } catch (Exception e) { Log.error(e); throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?"); } }
Example #10
Source File: Mp3InputStream.java From opsu with GNU General Public License v3.0 | 6 votes |
@Override public int read(byte[] b, int off, int len) throws IOException { for (int i = 0; i < len; i++) { try { int value = read(); if (value >= 0) b[i] = (byte) value; else return (i == 0) ? -1 : i; } catch (IOException e) { Log.error(e); return i; } } return len; }
Example #11
Source File: DisplayContainer.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
public void updateDisplayMode(int width, int height) { int screenWidth = nativeDisplayMode.getWidth(); int screenHeight = nativeDisplayMode.getHeight(); // check for larger-than-screen dimensions if (!OPTION_ALLOW_LARGER_RESOLUTIONS.state && (screenWidth < width || screenHeight < height)) { width = 800; height = 600; } if (!OPTION_FULLSCREEN.state) { boolean borderless = (screenWidth == width && screenHeight == height); System.setProperty("org.lwjgl.opengl.Window.undecorated", Boolean.toString(borderless)); } try { setDisplayMode(width, height, OPTION_FULLSCREEN.state); } catch (Exception e) { bubNotifs.send(BUB_RED, "Failed to change display mode"); Log.error("Failed to set display mode.", e); } }
Example #12
Source File: Image.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Load the image * * @param in The input stream to read the image from * @param ref The name that should be assigned to the image * @param flipped True if the image should be flipped on the y-axis on load * @param f The filter to use when scaling this image * @param transparent The color to treat as transparent * @throws SlickException Indicates a failure to load the image */ private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; try { this.ref = ref; int[] trans = null; if (transparent != null) { trans = new int[3]; trans[0] = (int) (transparent.r * 255); trans[1] = (int) (transparent.g * 255); trans[2] = (int) (transparent.b * 255); } texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to load image from: "+ref, e); } }
Example #13
Source File: AppletGameContainer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * {@inheritDoc} */ public void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException { try { Image temp = new Image(get2Fold(image.getWidth()), get2Fold(image.getHeight())); Graphics g = temp.getGraphics(); ByteBuffer buffer = BufferUtils.createByteBuffer(temp.getWidth() * temp.getHeight() * 4); g.drawImage(image.getFlippedCopy(false, true), 0, 0); g.flush(); g.getArea(0,0,temp.getWidth(),temp.getHeight(),buffer); Cursor cursor = CursorLoader.get().getCursor(buffer, hotSpotX, hotSpotY,temp.getWidth(),temp.getHeight()); Mouse.setNativeCursor(cursor); } catch (Throwable e) { Log.error("Failed to load and apply cursor.", e); throw new SlickException("Failed to set mouse cursor", e); } }
Example #14
Source File: AppGameContainer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.GameContainer#setMouseCursor(org.newdawn.slick.Image, int, int) */ public void setMouseCursor(Image image, int hotSpotX, int hotSpotY) throws SlickException { try { Image temp = new Image(get2Fold(image.getWidth()), get2Fold(image.getHeight())); Graphics g = temp.getGraphics(); ByteBuffer buffer = BufferUtils.createByteBuffer(temp.getWidth() * temp.getHeight() * 4); g.drawImage(image.getFlippedCopy(false, true), 0, 0); g.flush(); g.getArea(0,0,temp.getWidth(),temp.getHeight(),buffer); Cursor cursor = CursorLoader.get().getCursor(buffer, hotSpotX, hotSpotY,temp.getWidth(),temp.getHeight()); Mouse.setNativeCursor(cursor); } catch (Throwable e) { Log.error("Failed to load and apply cursor.", e); throw new SlickException("Failed to set mouse cursor", e); } }
Example #15
Source File: BeatmapDifficultyCalculator.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Computes the strain values for the beatmap. * @return true if successful, false otherwise */ private boolean calculateStrainValues() { // Traverse hitObjects in pairs to calculate the strain value of NextHitObject from // the strain value of CurrentHitObject and environment. if (tpHitObjects.length == 0) { Log.warn("Can not compute difficulty of empty beatmap."); return false; } tpHitObject currentHitObject = tpHitObjects[0]; tpHitObject nextHitObject; int index = 0; // First hitObject starts at strain 1. 1 is the default for strain values, // so we don't need to set it here. See tpHitObject. while (++index < tpHitObjects.length) { nextHitObject = tpHitObjects[index]; nextHitObject.calculateStrains(currentHitObject); currentHitObject = nextHitObject; } return true; }
Example #16
Source File: Music.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Create and load a piece of music (either OGG or MOD/XM) * @param in The stream to read the music from * @param ref The symbolic name of this music * @throws SlickException Indicates a failure to read the music from the stream */ public Music(InputStream in, String ref) throws SlickException { SoundStore.get().init(); try { if (ref.toLowerCase().endsWith(".ogg")) { sound = SoundStore.get().getOgg(in); } else if (ref.toLowerCase().endsWith(".wav")) { sound = SoundStore.get().getWAV(in); } else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) { sound = SoundStore.get().getMOD(in); } else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) { sound = SoundStore.get().getAIF(in); } else { throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported."); } } catch (Exception e) { Log.error(e); throw new SlickException("Failed to load music: "+ref); } }
Example #17
Source File: BeatmapWatchService.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Destroys the watch service instance, if any. * Subsequent calls to {@link #get()} will return {@code null}. */ public static void destroy() { if (ws == null) return; try { ws.watcher.close(); ws.service.shutdownNow(); ws = null; } catch (IOException e) { String msg = "An I/O exception occurred while closing the previous watch service."; Log.error(msg, e); barNotifs.send(msg); ws = null; } }
Example #18
Source File: BeatmapWatchService.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Creates a new watch service instance (overwriting any previous instance), * registers the beatmap directory, and starts processing events. */ public static void create() { // close the existing watch service destroy(); // create a new watch service try { ws = new BeatmapWatchService(); ws.register(config.beatmapDir.toPath()); } catch (IOException e) { Log.error("Could not create watch service", e); bubNotifs.send(BUB_RED, "Could not create watch service"); return; } // start processing events ws.start(); }
Example #19
Source File: TransitionTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get the next transition pair that we'lluse * * @return The pair of transitions used to enter and leave the next state */ public Transition[] getNextTransitionPair() { Transition[] pair = new Transition[2]; try { if (transitions[index][0] != null) { pair[0] = (Transition) transitions[index][0].newInstance(); } if (transitions[index][1] != null) { pair[1] = (Transition) transitions[index][1].newInstance(); } } catch (Throwable e) { Log.error(e); } index++; if (index >= transitions.length) { index = 0; } return pair; }
Example #20
Source File: Fonts.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Adds and loads glyphs for a font. * @param font the font to add the glyphs to * @param s the string containing the glyphs to load */ public static void loadGlyphs(UnicodeFont font, String s) { if (s == null || s.isEmpty()) return; // get set of added strings HashSet<String> set = loadedGlyphs.get(font); if (set == null) { set = new HashSet<String>(); loadedGlyphs.put(font, set); } else if (set.contains(s)) return; // string already in set // load glyphs font.addGlyphs(s); set.add(s); try { font.loadGlyphs(); } catch (SlickException e) { Log.warn(String.format("Failed to load glyphs for string '%s'.", s), e); } }
Example #21
Source File: Image.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Load the image * * @param in The input stream to read the image from * @param ref The name that should be assigned to the image * @param flipped True if the image should be flipped on the y-axis on load * @param f The filter to use when scaling this image * @param transparent The color to treat as transparent * @throws SlickException Indicates a failure to load the image */ private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; try { this.ref = ref; int[] trans = null; if (transparent != null) { trans = new int[3]; trans[0] = (int) (transparent.r * 255); trans[1] = (int) (transparent.g * 255); trans[2] = (int) (transparent.b * 255); } texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to load image from: "+ref, e); } }
Example #22
Source File: Music.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Create and load a piece of music (either OGG or MOD/XM) * * @param ref The location of the music * @param streamingHint A hint to indicate whether streaming should be used if possible * @throws SlickException */ public Music(String ref, boolean streamingHint) throws SlickException { SoundStore.get().init(); try { if (ref.toLowerCase().endsWith(".ogg")) { if (streamingHint) { sound = SoundStore.get().getOggStream(ref); } else { sound = SoundStore.get().getOgg(ref); } } else if (ref.toLowerCase().endsWith(".wav")) { sound = SoundStore.get().getWAV(ref); } else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) { sound = SoundStore.get().getMOD(ref); } else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) { sound = SoundStore.get().getAIF(ref); } else { throw new SlickException("Only .xm, .mod, .ogg, and .aif/f are currently supported."); } } catch (Exception e) { Log.error(e); throw new SlickException("Failed to load sound: "+ref); } }
Example #23
Source File: ImageDataFactory.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Check PNG loader property. If set the native PNG loader will * not be used. */ private static void checkProperty() { if (!pngLoaderPropertyChecked) { pngLoaderPropertyChecked = true; try { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { String val = System.getProperty(PNG_LOADER); if ("false".equalsIgnoreCase(val)) { usePngLoader = false; } Log.info("Use Java PNG Loader = " + usePngLoader); return null; } }); } catch (Throwable e) { // ignore, security failure - probably an applet } } }
Example #24
Source File: PBufferGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.Graphics#disable() */ protected void disable() { GL.flush(); // Bind the texture after rendering. GL.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID()); pbuffer.bindTexImage(Pbuffer.FRONT_LEFT_BUFFER); try { Display.makeCurrent(); } catch (LWJGLException e) { Log.error(e); } SlickCallable.leaveSafeBlock(); }
Example #25
Source File: Fonts.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Adds and loads glyphs for a font. * @param font the font to add the glyphs to * @param c the character to load */ public static void loadGlyphs(UnicodeFont font, char c) { font.addGlyphs(c, c); try { font.loadGlyphs(); } catch (SlickException e) { Log.warn(String.format("Failed to load glyphs for codepoint '%d'.", (int) c), e); } }
Example #26
Source File: TimingPoint.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Constructor. * @param line the line to be parsed */ public TimingPoint(String line) { /** * [TIMING POINT FORMATS] * Non-inherited: * offset,msPerBeat,meter,sampleType,sampleSet,volume,inherited,kiai * * Inherited: * offset,velocity,meter,sampleType,sampleSet,volume,inherited,kiai */ // TODO: better support for old formats String[] tokens = line.split(","); try { this.time = (int) Float.parseFloat(tokens[0]); // rare float this.meter = Integer.parseInt(tokens[2]); this.sampleType = Byte.parseByte(tokens[3]); this.sampleTypeCustom = Byte.parseByte(tokens[4]); this.sampleVolume = Integer.parseInt(tokens[5]); // this.inherited = Utils.parseBoolean(tokens[6]); if (tokens.length > 7) this.kiai = Utils.parseBoolean(tokens[7]); } catch (ArrayIndexOutOfBoundsException e) { Log.debug(String.format("Error parsing timing point: '%s'", line)); } // tokens[1] is either beatLength (positive) or velocity (negative) float beatLength = Float.parseFloat(tokens[1]); if (beatLength > 0) this.beatLength = beatLength; else { this.velocity = (int) beatLength; this.inherited = true; } }
Example #27
Source File: GameContainer.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Create a new game container wrapping a given game * * @param game The game to be wrapped */ protected GameContainer(Game game) { this.game = game; lastFrame = getTime(); getBuildVersion(); Log.checkVerboseLogSetting(); }
Example #28
Source File: Image.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create an image from a image data source. Note that this method uses * * @param data The pixelData to use to create the image * @param f The filter to use when scaling this image */ public Image(ImageData data, int f) { try { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; texture = InternalTextureLoader.get().getTexture(data, this.filter); ref = texture.toString(); } catch (IOException e) { Log.error(e); } }
Example #29
Source File: PBufferGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a new graphics context around a pbuffer * * @param image The image we're rendering to * @throws SlickException Indicates a failure to use pbuffers */ public PBufferGraphics(Image image) throws SlickException { super(image.getTexture().getTextureWidth(), image.getTexture().getTextureHeight()); this.image = image; Log.debug("Creating pbuffer(rtt) "+image.getWidth()+"x"+image.getHeight()); if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) { throw new SlickException("Your OpenGL card does not support PBuffers and hence can't handle the dynamic images required for this application."); } if ((Pbuffer.getCapabilities() & Pbuffer.RENDER_TEXTURE_SUPPORTED) == 0) { throw new SlickException("Your OpenGL card does not support Render-To-Texture and hence can't handle the dynamic images required for this application."); } init(); }
Example #30
Source File: ImageLoader.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
/** * Releases all resources. */ public void destroy() { interrupt(); loaderThread = null; if (image != null && !image.isDestroyed()) { try { image.destroy(); } catch (SlickException e) { Log.warn(String.format("Failed to destroy image '%s'.", image.getResourceReference()), e); } image = null; } data = null; }