/** Adds or replaces tile with that id * * @param id the id of the {@link TiledMapTile} to add or replace. * @param tile the {@link TiledMapTile} to add or replace. */ public void putTile (int id, TiledMapTile tile) { tiles.put(id, tile); }
private void gatherControllers(boolean sendEvent) { // gather all joysticks and gamepads, remove any disconnected ones IntMap<AndroidController> removedControllers = new IntMap<AndroidController>(); removedControllers.putAll(controllerMap); for(int deviceId: InputDevice.getDeviceIds()) { InputDevice device = InputDevice.getDevice(deviceId); AndroidController controller = controllerMap.get(deviceId); if(controller != null) { removedControllers.remove(deviceId); } else { addController(deviceId, sendEvent); } } for(Entry<AndroidController> entry: removedControllers.entries()) { removeController(entry.key); } }
public static void pollGamepads() { JsArray<Gamepad> currentGamepads = nativePollGamepads(); if (currentGamepads != null) { gamepadsTemp.clear(); gamepadsTemp.putAll(gamepads); for (int i = 0, j = currentGamepads.length(); i < j; i++) { Gamepad gamepad = currentGamepads.get(i); if (gamepad != null) { if (!gamepadsTemp.containsKey(gamepad.getIndex())) { onGamepadConnect(gamepad); } gamepadsTemp.remove(gamepad.getIndex()); } } for (Gamepad gamepad : gamepadsTemp.values()) { onGamepadDisconnect(gamepad); } } }
public long getSoundId (int sourceId) { if (!sourceToSoundId.containsKey(sourceId)) return -1; return sourceToSoundId.get(sourceId); }
int obtainSource (boolean isMusic) { if (noDevice) return 0; for (int i = 0, n = idleSources.size; i < n; i++) { int sourceId = idleSources.get(i); int state = alGetSourcei(sourceId, AL_SOURCE_STATE); if (state != AL_PLAYING && state != AL_PAUSED) { if (isMusic) { idleSources.removeIndex(i); } else { if (sourceToSoundId.containsKey(sourceId)) { long soundId = sourceToSoundId.get(sourceId); sourceToSoundId.remove(sourceId); soundIdToSource.remove(soundId); } long soundId = nextSoundId++; sourceToSoundId.put(sourceId, soundId); soundIdToSource.put(soundId, sourceId); } alSourceStop(sourceId); alSourcei(sourceId, AL_BUFFER, 0); AL10.alSourcef(sourceId, AL10.AL_GAIN, 1); AL10.alSourcef(sourceId, AL10.AL_PITCH, 1); AL10.alSource3f(sourceId, AL10.AL_POSITION, 0, 0, 1f); return sourceId; } } return -1; }
void freeSource (int sourceID) { if (noDevice) return; alSourceStop(sourceID); alSourcei(sourceID, AL_BUFFER, 0); if (sourceToSoundId.containsKey(sourceID)) { long soundId = sourceToSoundId.remove(sourceID); soundIdToSource.remove(soundId); } idleSources.add(sourceID); }
int real = touch.getIdentifier(); int touchId; touchMap.put(real, touchId = getAvailablePointer()); touched[touchId] = true; touchX[touchId] = getRelativeX(touch, canvas); Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; deltaY[touchId] = getRelativeY(touch, canvas) - touchY[touchId]; Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); touchMap.remove(real); touched[touchId] = false; deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); touchMap.remove(real); touched[touchId] = false; deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId];
/** Constructs a Tile Set layout. The tile set image contained in the baseDir should be the original tile set images before * being processed by {@link TiledMapPacker} (the ones actually read by Tiled). * @param tileset the tile set to process * @param baseDir the directory in which the tile set image is stored */ protected TileSetLayout (int firstgid, TiledMapTileSet tileset, FileHandle baseDir) throws IOException { int tileWidth = tileset.getProperties().get("tilewidth", Integer.class); int tileHeight = tileset.getProperties().get("tileheight", Integer.class); int margin = tileset.getProperties().get("margin", Integer.class); int spacing = tileset.getProperties().get("spacing", Integer.class); this.firstgid = firstgid; image = ImageIO.read(baseDir.child(tileset.getProperties().get("imagesource", String.class)).read()); imageTilePositions = new IntMap<Vector2>(); // fill the tile regions int x, y, tile = 0; numRows = 0; numCols = 0; int stopWidth = image.getWidth() - tileWidth; int stopHeight = image.getHeight() - tileHeight; for (y = margin; y <= stopHeight; y += tileHeight + spacing) { for (x = margin; x <= stopWidth; x += tileWidth + spacing) { if (y == margin) numCols++; imageTilePositions.put(tile, new Vector2(x, y)); tile++; } numRows++; } numTiles = numRows * numCols; }
/** Returns the location of the tile in {@link TileSetLayout#image} */ public Vector2 getLocation (int tile) { return imageTilePositions.get(tile - firstgid); } }
/** Creates empty tileset */ public TiledMapTileSet () { tiles = new IntMap<TiledMapTile>(); properties = new MapProperties(); }
/** Remove a plug from the strategy * @param group Group to remove the plug from * @return removed plug, null if there was none for that group */ public GroupPlug unPlug (int group) { return plugs.remove(group); } }
public void dispose () { if (noDevice) return; for (int i = 0, n = allSources.size; i < n; i++) { int sourceID = allSources.get(i); int state = alGetSourcei(sourceID, AL_SOURCE_STATE); if (state != AL_STOPPED) alSourceStop(sourceID); alDeleteSources(sourceID); } sourceToSoundId.clear(); soundIdToSource.clear(); AL.destroy(); while (AL.isCreated()) { try { Thread.sleep(10); } catch (InterruptedException e) { } } }
/** Registers a provider for the specified message code. * @param msg the message code * @param provider the provider to add */ public void addProvider (TelegramProvider provider, int msg) { Array<TelegramProvider> providers = msgProviders.get(msg); if (providers == null) { // Associate an empty unordered array with the message code providers = new Array<TelegramProvider>(false, 16); msgProviders.put(msg, providers); } providers.add(provider); }
/** @return iterator to tiles in this tileset */ @Override public Iterator<TiledMapTile> iterator () { return tiles.values().iterator(); }
private void update() { IntArray disconnectedControllers = new IntArray(indexToController.size); for (Tuple tuple : indexToController.values()) { JamepadController controller = tuple.controller; boolean connected = controller.update(); if (!connected) { listener.disconnected(tuple.controller); disconnectedControllers.add(tuple.index.getIndex()); } } for (int i = 0; i < disconnectedControllers.size; i++) { indexToController.remove(disconnectedControllers.get(i)); } }
int obtainSource (boolean isMusic) { if (noDevice) return 0; for (int i = 0, n = idleSources.size; i < n; i++) { int sourceId = idleSources.get(i); int state = alGetSourcei(sourceId, AL_SOURCE_STATE); if (state != AL_PLAYING && state != AL_PAUSED) { if (isMusic) { idleSources.removeIndex(i); } else { if (sourceToSoundId.containsKey(sourceId)) { long soundId = sourceToSoundId.get(sourceId); sourceToSoundId.remove(sourceId); soundIdToSource.remove(soundId); } long soundId = nextSoundId++; sourceToSoundId.put(sourceId, soundId); soundIdToSource.put(soundId, sourceId); } alSourceStop(sourceId); alSourcei(sourceId, AL_BUFFER, 0); AL10.alSourcef(sourceId, AL10.AL_GAIN, 1); AL10.alSourcef(sourceId, AL10.AL_PITCH, 1); AL10.alSource3f(sourceId, AL10.AL_POSITION, 0, 0, 1f); return sourceId; } } return -1; }
void freeSource (int sourceID) { if (noDevice) return; alSourceStop(sourceID); alSourcei(sourceID, AL_BUFFER, 0); if (sourceToSoundId.containsKey(sourceID)) { long soundId = sourceToSoundId.remove(sourceID); soundIdToSource.remove(soundId); } idleSources.add(sourceID); }