Java Code Examples for org.newdawn.slick.util.Log#error()

The following examples show how to use org.newdawn.slick.util.Log#error() . 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: Music.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create and load a piece of music (either OGG or MOD/XM)
 * 
 * @param url The location of the music
 * @param streamingHint A hint to indicate whether streaming should be used if possible
 * @throws SlickException
 */
public Music(URL url, boolean streamingHint) throws SlickException {
	SoundStore.get().init();
	String ref = url.getFile();
	
	try {
		if (ref.toLowerCase().endsWith(".ogg")) {
			if (streamingHint) {
				sound = SoundStore.get().getOggStream(url);
			} else {
				sound = SoundStore.get().getOgg(url.openStream());
			}
		} else if (ref.toLowerCase().endsWith(".wav")) {
			sound = SoundStore.get().getWAV(url.openStream());
		} else if (ref.toLowerCase().endsWith(".xm") || ref.toLowerCase().endsWith(".mod")) {
			sound = SoundStore.get().getMOD(url.openStream());
		} else if (ref.toLowerCase().endsWith(".aif") || ref.toLowerCase().endsWith(".aiff")) {
			sound = SoundStore.get().getAIF(url.openStream());
		} 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: "+url);
	}
}
 
Example 2
Source File: VolumeControl.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
private static void linkShader(int program, int vert, int frag)
{
	if (program == -1) {
		return;
	}

	glAttachShader(program, vert);
	glAttachShader(program, frag);
	glLinkProgram(program);

	if (glGetProgrami(program, GL_LINK_STATUS) != GL_TRUE) {
		String error = glGetProgramInfoLog(program, 1024);
		Log.error("Program linking failed.", new Exception(error));
		destroyProgram();
	}
}
 
Example 3
Source File: PBufferGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @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 4
Source File: OggInputStream.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see java.io.InputStream#read(byte[], int, int)
 */
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 {
				if (i == 0) {						
					return -1;
				} else {
					return i;
				}
			}
		} catch (IOException e) {
			Log.error(e);
			return i;
		}
	}
	
	return len;
}
 
Example 5
Source File: AppGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @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 6
Source File: ParticleSystem.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a duplicate of this system. This would have been nicer as a different interface
 * but may cause to much API change headache. Maybe next full version release it should be
 * rethought.
 * 
 * TODO: Consider refactor at next point release
 * 
 * @return A copy of this particle system
 * @throws SlickException Indicates a failure during copy or a invalid particle system to be duplicated
 */
public ParticleSystem duplicate() throws SlickException {
	for (int i=0;i<emitters.size();i++) {
		if (!(emitters.get(i) instanceof ConfigurableEmitter)) {
			throw new SlickException("Only systems contianing configurable emitters can be duplicated");
		}
	}

	ParticleSystem theCopy = null;
	try {
		ByteArrayOutputStream bout = new ByteArrayOutputStream();
		ParticleIO.saveConfiguredSystem(bout, this);
		ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
		theCopy = ParticleIO.loadConfiguredSystem(bin);
	} catch (IOException e) {
		Log.error("Failed to duplicate particle system");
		throw new SlickException("Unable to duplicated particle system", e);
	}
	
	return theCopy;
}
 
Example 7
Source File: FontTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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_SPACE) {
		try {
			container.setDisplayMode(640, 480, false);
		} catch (SlickException e) {
			Log.error(e);
		}
	}
}
 
Example 8
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see java.applet.Applet#init()
 */
public void init() {
   removeAll();
   setLayout(new BorderLayout());
   setIgnoreRepaint(true);

   try {
      Game game = (Game) Class.forName(getParameter("game")).newInstance();
      
      container = new Container(game);
      canvas = new ContainerPanel(container);
      displayParent = new Canvas() {
         public final void addNotify() {
            super.addNotify();
            startLWJGL();
         }
         public final void removeNotify() {
            destroyLWJGL();
            super.removeNotify();
         }

      };

      displayParent.setSize(getWidth(), getHeight());
      add(displayParent);
      displayParent.setFocusable(true);
      displayParent.requestFocus();
      displayParent.setIgnoreRepaint(true);
      setVisible(true);
   } catch (Exception e) {
      Log.error(e);
      throw new RuntimeException("Unable to create game container");
   }
}
 
Example 9
Source File: Animation.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Add animation frame to the animation.
 * @param duration The duration to display the frame for
 * @param x The x location of the frame on the <tt>SpriteSheet</tt>
 * @param y The y location of the frame on the <tt>spriteSheet</tt>
 */
public void addFrame(int duration, int x, int y){
   if (duration == 0) {
      Log.error("Invalid duration: "+duration);
      throw new RuntimeException("Invalid duration: "+duration);
   }
 
    if (frames.isEmpty()) {
      nextChange = (int) (duration / speed);
   }
   
   frames.add(new Frame(duration, x, y));
   currentFrame = 0;      
}
 
Example 10
Source File: Utils.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the directory where the application is being run.
 * @return the directory, or null if it could not be determined
 */
public static File getRunningDirectory() {
	try {
		return new File(Opsu.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
	} catch (URISyntaxException e) {
		Log.error("Could not get the running directory.", e);
		return null;
	}
}
 
Example 11
Source File: GameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the build number of slick 
 * 
 * @return The build number of slick
 */
public static int getBuildVersion() {
	try {
		Properties props = new Properties();
		props.load(ResourceLoader.getResourceAsStream("version"));
		
		int build = Integer.parseInt(props.getProperty("build"));
		Log.info("Slick Build #"+build);
		
		return build;
	} catch (Exception e) {
		Log.error("Unable to determine Slick build number");
		return -1;
	}
}
 
Example 12
Source File: ConfigurableEmitter.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a duplicate of this emitter.
 * The duplicate should be added to a ParticleSystem to be used.
 * @return a copy if no IOException occurred, null otherwise
 */
public ConfigurableEmitter duplicate() {
	ConfigurableEmitter theCopy = null;
	try {
		ByteArrayOutputStream bout = new ByteArrayOutputStream();
		ParticleIO.saveEmitter(bout, this);
		ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
		theCopy = ParticleIO.loadEmitter(bin);
	} catch (IOException e) {
		Log.error("Slick: ConfigurableEmitter.duplicate(): caught exception " + e.toString());
		return null;
	}
	return theCopy;
}
 
Example 13
Source File: CanvasGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Check the dimensions of the canvas match the display
 */
public void checkDimensions() {
	if ((width != CanvasGameContainer.this.getWidth()) ||
	    (height != CanvasGameContainer.this.getHeight())) {
		
		try {
			setDisplayMode(CanvasGameContainer.this.getWidth(), 
						   CanvasGameContainer.this.getHeight(), false);
		} catch (SlickException e) {
			Log.error(e);
		}
	}
}
 
Example 14
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
    * @see org.newdawn.slick.GameContainer#setMouseCursor(org.lwjgl.input.Cursor, int, int)
    */
   public void setMouseCursor(Cursor cursor, int hotSpotX, int hotSpotY) throws SlickException {
      try {
         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: StreamSound.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.openal.AudioImpl#playAsMusic(float, float, boolean)
 */
public int playAsMusic(float pitch, float gain, boolean loop) {
	try {
		cleanUpSource();
		
		player.setup(pitch);
		player.play(loop);
		SoundStore.get().setStream(player);
	} catch (IOException e) {
		Log.error("Failed to read OGG source: "+player.getSource());
	}
	
	return SoundStore.get().getSource(0);
}
 
Example 16
Source File: AppletGameContainer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialise GL state
 */
protected void initGL() {
   try {
      InternalTextureLoader.get().clear();
      SoundStore.get().clear();

      container.initApplet();
   } catch (Exception e) {
      Log.error(e);
      container.stopApplet();
   }
}
 
Example 17
Source File: ParticleEditor.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Import an emitter XML file
 */
public void importEmitter() {
	chooser.setDialogTitle("Open");
	int resp = chooser.showOpenDialog(this);
	if (resp == JFileChooser.APPROVE_OPTION) {
		File file = chooser.getSelectedFile();
		File path = file.getParentFile();
		
		try {
			final ConfigurableEmitter emitter = ParticleIO.loadEmitter(file);
			
			
			if (emitter.getImageName() != null) {
				File possible = new File(path, emitter.getImageName());
				
				if (possible.exists()) {
					emitter.setImageName(possible.getAbsolutePath());
				} else {
					chooser.setDialogTitle("Locate the image: "+emitter.getImageName());
					resp = chooser.showOpenDialog(this);
					FileFilter filter = new FileFilter() {
						public boolean accept(File f) {
							if (f.isDirectory()) {
								return true;
							}
							
							return (f.getName().equals(emitter.getImageName()));
						}

						public String getDescription() {
							return emitter.getImageName();
						}
					};
					chooser.addChoosableFileFilter(filter);
					if (resp == JFileChooser.APPROVE_OPTION) {
						File image = chooser.getSelectedFile();
						emitter.setImageName(image.getAbsolutePath());
						path = image.getParentFile();
					}
					chooser.resetChoosableFileFilters();
					chooser.addChoosableFileFilter(xmlFileFilter);
				}
			}
			
			addEmitter(emitter);
			emitters.setSelected(emitter);
		} catch (IOException e) {
			Log.error(e);
			JOptionPane.showMessageDialog(this, e.getMessage());
		}
	}
}
 
Example 18
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get the Sound based on a specified OGG file
 * 
 * @param ref The reference to the OGG file in the classpath
 * @param in The stream to the OGG to load
 * @return The Sound read from the OGG file
 * @throws IOException Indicates a failure to load the OGG
 */
public Audio getOgg(String ref, InputStream in) throws IOException {
	if (!soundWorks) {
		return new NullAudio();
	}
	if (!inited) {
		throw new RuntimeException("Can't load sounds until SoundStore is init(). Use the container init() method.");
	}
	if (deferred) {
		return new DeferredSound(ref, in, DeferredSound.OGG);
	}
	
	int buffer = -1;
	
	if (loaded.get(ref) != null) {
		buffer = ((Integer) loaded.get(ref)).intValue();
	} else {
		try {
			IntBuffer buf = BufferUtils.createIntBuffer(1);
			
			OggDecoder decoder = new OggDecoder();
			OggData ogg = decoder.getData(in);
			
			AL10.alGenBuffers(buf);
			AL10.alBufferData(buf.get(0), ogg.channels > 1 ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_MONO16, ogg.data, ogg.rate);
			
			loaded.put(ref,new Integer(buf.get(0)));
			                     
			buffer = buf.get(0);
		} catch (Exception e) {
			Log.error(e);
			Sys.alert("Error","Failed to load: "+ref+" - "+e.getMessage());
			throw new IOException("Unable to load: "+ref);
		}
	}
	
	if (buffer == -1) {
		throw new IOException("Unable to load: "+ref);
	}
	
	return new AudioImpl(this, buffer);
}
 
Example 19
Source File: ParticleEditor.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Load a complete particle system XML description
 */
public void loadSystem() {
	chooser.setDialogTitle("Open");
	int resp = chooser.showOpenDialog(this);
	if (resp == JFileChooser.APPROVE_OPTION) {
		File file = chooser.getSelectedFile();
		File path = file.getParentFile();
		
		try {
			ParticleSystem system = ParticleIO.loadConfiguredSystem(file);
			game.setSystem(system);
			emitters.clear();
			
			for (int i=0;i<system.getEmitterCount();i++) {
				final ConfigurableEmitter emitter = (ConfigurableEmitter) system.getEmitter(i);
				
				if (emitter.getImageName() != null) {
					File possible = new File(path, emitter.getImageName());
					if (possible.exists()) {
						emitter.setImageName(possible.getAbsolutePath());
					} else {
						chooser.setDialogTitle("Locate the image: "+emitter.getImageName());
						FileFilter filter = new FileFilter() {
							public boolean accept(File f) {
								if (f.isDirectory()) {
									return true;
								}
								
								return (f.getName().equals(emitter.getImageName()));
							}

							public String getDescription() {
								return emitter.getImageName();
							}
						};
						
						chooser.addChoosableFileFilter(filter);
						resp = chooser.showOpenDialog(this);
						if (resp == JFileChooser.APPROVE_OPTION) {
							File image = chooser.getSelectedFile();
							emitter.setImageName(image.getAbsolutePath());
							path = image.getParentFile();
						}
						chooser.setDialogTitle("Open");
						chooser.resetChoosableFileFilters();
						chooser.addChoosableFileFilter(xmlFileFilter);
					}
				}
				
				emitters.add(emitter);
			}
			additive.setSelected(system.getBlendingMode() == ParticleSystem.BLEND_ADDITIVE);
			pointsEnabled.setSelected(system.usePoints());
			
			emitters.setSelected(0);
		} catch (IOException e) {
			Log.error(e);
			JOptionPane.showMessageDialog(this, e.getMessage());
		}
	}
}
 
Example 20
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get the Sound based on a specified WAV file
 * 
 * @param ref The reference to the WAV file in the classpath
 * @param in The stream to the WAV to load
 * @return The Sound read from the WAV file
 * @throws IOException Indicates a failure to load the WAV
 */
public Audio getWAV(String ref, InputStream in) throws IOException {
	if (!soundWorks) {
		return new NullAudio();
	}
	if (!inited) {
		throw new RuntimeException("Can't load sounds until SoundStore is init(). Use the container init() method.");
	}
	if (deferred) {
		return new DeferredSound(ref, in, DeferredSound.WAV);
	}
	
	int buffer = -1;
	
	if (loaded.get(ref) != null) {
		buffer = ((Integer) loaded.get(ref)).intValue();
	} else {
		try {
			IntBuffer buf = BufferUtils.createIntBuffer(1);
			
			WaveData data = WaveData.create(in);
			AL10.alGenBuffers(buf);
			AL10.alBufferData(buf.get(0), data.format, data.data, data.samplerate);
			
			loaded.put(ref,new Integer(buf.get(0)));
			buffer = buf.get(0);
		} catch (Exception e) {
			Log.error(e);
			IOException x = new IOException("Failed to load: "+ref);
			x.initCause(e);
			
			throw x;
		}
	}
	
	if (buffer == -1) {
		throw new IOException("Unable to load: "+ref);
	}
	
	return new AudioImpl(this, buffer);
}