Android Open Source - DivisionByZero Drawable Collection






From Project

Back to project page DivisionByZero.

License

The source code is released under:

Apache License

If you think the Android project DivisionByZero listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ggstudios.divisionbyzero;
/*w  w w.  ja  v a 2s  .co  m*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * This collection has a very important purpose.
 * Once all drawables are added to it, it attempts
 * to not invoke any form of gc by removing elements
 * in the following way:
 * 
 * To remove an element, it swaps it with the last 
 * non-deleted element and the decrements the size of
 * the list. This way the element isn't removed...
 * it is simply excluded from draw/refresh loops.
 * 
 * When new elements are added, they will overwrite
 * previously deleted elements.
 * 
 * @author iDunnololz
 *
 */
public class DrawableCollection<T extends Drawable> extends Drawable{
  protected List<T> drawables = new ArrayList<T>();
  protected int len = 0;

  public void addDrawable(T d) {
    if(drawables.size() == len) {
      drawables.add(d);
    } else {
      drawables.set(len, d);
    }

    len++;
  }

  public void addDrawableToTop(T d) {
    drawables.add(0, d);

    len++;
  }

  public void removeDrawable(int index) {
    Collections.swap(drawables, index, len - 1);

    onObjectRemoved();
  }

  public void removeDrawable(T enemySprite) {
    final int index = drawables.indexOf(enemySprite);
    if(index != -1) {
      removeDrawable(index);
    }
  }

  /**
   * Removes the specified drawable while retaining the order
   * of the list.
   * @param enemySprite
   */
  public synchronized void removeDrawableStrict(T enemySprite) {
    onObjectRemoved();
    drawables.remove(enemySprite);
    //toRemove.add(enemySprite);
  }
  
  protected void onObjectRemoved() {
    len--;
  }

  public void clear() {
    len = 0;
    drawables.clear();
  }

  @Override
  public synchronized void draw(float offX, float offY) {
    for(int i = len - 1; i >= 0; i--) {
      drawables.get(i).draw(offX, offY);
    }
  }

  @Override
  public void refresh() {
    for(int i = len - 1; i >= 0; i--) {
      drawables.get(i).refresh();
    }
  }

  public List<T> getRawList() {
    return drawables;
  }

  public int size() {
    return len;
  }

  public T get(int index) {
    return drawables.get(index);
  }

  public int indexOf(T t) {
    return drawables.indexOf(t);
  }
}




Java Source Code List

com.ggstudios.divisionbyzero.ActivityAbout.java
com.ggstudios.divisionbyzero.ActivityLevelSelection.java
com.ggstudios.divisionbyzero.ActivityMainMenu.java
com.ggstudios.divisionbyzero.ActivitySettings.java
com.ggstudios.divisionbyzero.ActivitySplashScreen.java
com.ggstudios.divisionbyzero.ApplicationMain.java
com.ggstudios.divisionbyzero.BaseActivity.java
com.ggstudios.divisionbyzero.BaseDialog.java
com.ggstudios.divisionbyzero.BulletManager.java
com.ggstudios.divisionbyzero.Bullet.java
com.ggstudios.divisionbyzero.Button.java
com.ggstudios.divisionbyzero.Circle.java
com.ggstudios.divisionbyzero.ClickableCollection.java
com.ggstudios.divisionbyzero.Clickable.java
com.ggstudios.divisionbyzero.ConfirmDialog.java
com.ggstudios.divisionbyzero.Core.java
com.ggstudios.divisionbyzero.CustomGLSurfaceView.java
com.ggstudios.divisionbyzero.DialogManager.java
com.ggstudios.divisionbyzero.DrawableCollection.java
com.ggstudios.divisionbyzero.DrawableString.java
com.ggstudios.divisionbyzero.Drawable.java
com.ggstudios.divisionbyzero.EndDialog.java
com.ggstudios.divisionbyzero.Event.java
com.ggstudios.divisionbyzero.ExplosionGenerator.java
com.ggstudios.divisionbyzero.ExtrasManager.java
com.ggstudios.divisionbyzero.FontManager.java
com.ggstudios.divisionbyzero.GameRenderer.java
com.ggstudios.divisionbyzero.GameUpdater.java
com.ggstudios.divisionbyzero.Game.java
com.ggstudios.divisionbyzero.Grid.java
com.ggstudios.divisionbyzero.Hud.java
com.ggstudios.divisionbyzero.InGameMenu.java
com.ggstudios.divisionbyzero.InfoDialog.java
com.ggstudios.divisionbyzero.Label.java
com.ggstudios.divisionbyzero.LevelManager.java
com.ggstudios.divisionbyzero.LevelMap.java
com.ggstudios.divisionbyzero.LineGuide.java
com.ggstudios.divisionbyzero.MainActivity.java
com.ggstudios.divisionbyzero.Map.java
com.ggstudios.divisionbyzero.MessageDialog.java
com.ggstudios.divisionbyzero.ParticleEngine.java
com.ggstudios.divisionbyzero.PathFinder.java
com.ggstudios.divisionbyzero.PauseMenu.java
com.ggstudios.divisionbyzero.PictureBox.java
com.ggstudios.divisionbyzero.Player.java
com.ggstudios.divisionbyzero.PopupMenu.java
com.ggstudios.divisionbyzero.Rectangle.java
com.ggstudios.divisionbyzero.Shader.java
com.ggstudios.divisionbyzero.SpawnManager.java
com.ggstudios.divisionbyzero.SpriteAnimation.java
com.ggstudios.divisionbyzero.SpriteManager.java
com.ggstudios.divisionbyzero.Sprite.java
com.ggstudios.divisionbyzero.Statbar.java
com.ggstudios.divisionbyzero.StateManager.java
com.ggstudios.divisionbyzero.TargetRectangle.java
com.ggstudios.divisionbyzero.TextureManager.java
com.ggstudios.divisionbyzero.TowerInfoDialog.java
com.ggstudios.divisionbyzero.TowerLibrary.java
com.ggstudios.divisionbyzero.TowerManager.java
com.ggstudios.divisionbyzero.TowerMenu.java
com.ggstudios.divisionbyzero.Tower.java
com.ggstudios.divisionbyzero.UpdatableCollection.java
com.ggstudios.divisionbyzero.Updatable.java
com.ggstudios.divisionbyzero.UpgradeDialog.java
com.ggstudios.divisionbyzero.Utils.java
com.ggstudios.divisionbyzero.VBO.java
com.ggstudios.divisionbyzero.WaveControlDialog.java
com.ggstudios.divisionbyzero.WaveControlHud.java
com.ggstudios.divisionbyzero.ZoomControl.java
com.ggstudios.utils.BitmapUtils.java
com.ggstudios.utils.BufferUtils.java
com.ggstudios.utils.DebugLog.java
com.ggstudios.utils.ShaderUtils.java
com.ggstudios.widget.LevelMapBackground.java
fix.android.opengl.GLES20.java