Please give constructive criticism, since I did all of this with minimal knowledge of openAL, and it is my first try at a 'resource manager.' This file is just so that I can load resources, and not have to make a new Object for every single entity I have. Like say I had an entity: I do not want to initialize the same texture/sound for every single entity! I want to load it once, and then reference it later!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| package com.wessles.MERCury;
import java.io.*; import java.util.Vector;
import org.newdawn.slick.openal.*; import org.newdawn.slick.opengl.Texture; import org.newdawn.slick.opengl.TextureLoader;
import static org.lwjgl.openal.AL10.*;
public class ResourceManager { private Vector<Texture> textures = new Vector<Texture>();
public int loadSound(String location) throws FileNotFoundException { WaveData data = WaveData.create(new BufferedInputStream(new FileInputStream(location))); int buffer = alGenBuffers(); alBufferData(buffer, data.format, data.data, data.samplerate); data.dispose(); int source = alGenSources(); alSourcei(source, AL_BUFFER, buffer); return source; }
public void playSound(int src) { alSourcePlay(src); }
public void pauseSound(int src) { alSourcePause(src); }
public void stopSound(int src) { alSourceStop(src); }
public void rewindSound(int src) { alSourceRewind(src); }
public int loadTexture(String format, String location) throws IOException { textures.add(TextureLoader.getTexture(format, this.getClass().getResourceAsStream(location))); return textures.size()-1; } public Texture getTexture(int src) { return textures.get(src); } } |
And yes, I am not doing all this from scratch

I am using slick-util, and wrapping it.
Dont judge!