Java 类com.badlogic.gdx.utils.Pool 实例源码

项目:Polymorph    文件:PolyGame.java   
private void initEntities(TextureAtlas textureAtlas) {
    final float mobWidth = Polymorph.WORLD_WIDTH/4;
    player = new Player(new Vector2(Polymorph.WORLD_WIDTH/2 - mobWidth/2, Polymorph.WORLD_HEIGHT/3-mobWidth),
                        new Dimension(mobWidth, mobWidth));

    slots = new Array<Slot>();
    slotPool = new Pool<Slot>() {
        @Override
        protected Slot newObject() {
            return new Slot(new Vector2(SLOT_SPAWN_POINT),
                            new Vector2(slotVelocity),
                            new Dimension(mobWidth, mobWidth));
        }
    };

    Dimension mapSize = new Dimension(Polymorph.WORLD_WIDTH, (int)(Polymorph.WORLD_HEIGHT*1.1f));
    TextureRegion mapTexture = textureAtlas.findRegion("background");
    Map mapFront = new Map(new Vector2(0, 0), mapVelocity, mapSize, mapTexture);
    Map mapBack = new Map(new Vector2(0, -mapSize.height + 5), mapVelocity, mapSize, mapTexture);
    maps = new Map[]{mapFront, mapBack};
}
项目:arcadelegends-gg    文件:Character.java   
public Character() {
    this.cooldownTimer = new float[5];
    this.castTimer = new float[5];
    this.casting = new boolean[5];
    this.extraData = new Object[5];
    this.cooldowns = new float[5];
    this.costs = new float[5];
    this.random = new Random();

    finishedAttack = true;

    vectorPool = new Pool<Vector2>() {
        @Override
        protected Vector2 newObject() {
            return new Vector2();
        }

        @Override
        protected void reset(Vector2 object) {
            object.setZero();
        }
    };
}
项目:KyperBox    文件:QuadTree.java   
/**
 * create a quadtree collision manager with a default max_depth of 4 and a
 * max_object count of 10.
 * 
 * @param x
 * @param y
 * @param width
 * @param height
 */
public QuadTree(float x, float y, float width, float height) {
    check_object = new BasicGameObject();
    check_object.init(null);
    remove_objects = new IntArray();
    culling = true;
    follow_x  =0;
    follow_y  =0;
    bounds = new Rectangle(x - PAD, y - PAD, width + PAD * 2, height + PAD * 2);
    objects =  new Array<GameObject>();
    follow_view = false;
    final QuadTree m = this;
    quad_pool = new Pool<QuadTree.Quad>() {
        @Override
        protected Quad newObject() {
            return new Quad(m);
        }
    };
    max_depth = 4;
    max_objects = 10;
    root = quad_pool.obtain();
    root.init(null, 0, bounds.x, bounds.y, bounds.width, bounds.height);
    ret_list = new Array<GameObject>();
}
项目:TheEndlessCastle    文件:Segment.java   
/**
 * Segment constructor
 */
public Segment(Position pos, SegmentDescriptor segmentType, float difficulty, final Pool<ProjectileEntity> horizontalProjectilePool, final Pool<ProjectileEntity> fallingProjectilePool, final AssetsHandler assetsHndlr, final BodyEditorDAL bodyDAL, final World box2DWorld) {
    _assetsHndlr = assetsHndlr;
    _segmentEntities = new ArrayList<Entity>();
    _posX = pos.x;
    _segmentDescriptor = segmentType;
    _horizontalProjectilePool = horizontalProjectilePool;
    _fallingProjectilePool = fallingProjectilePool;

    _platformEntity = new PlatformEntity("Segment_PlatformEntity", pos, _SEGMENT_SCALE, segmentType.textureName, segmentType.bodyName, _assetsHndlr, bodyDAL, box2DWorld);
    _segmentEntities.add(_platformEntity);

    _activeProjectiles = new ArrayList<ProjectileEntity>();
    _projectilesSources = new ArrayList<Position>();

    if(!_segmentDescriptor.IsChangingHeight)
    {
        if( difficulty > 200)
            difficulty = 200;
        int sourceCount = 4 + (int)(Math.abs((Math.random()*_platformEntity.GetWidth()*_SEGMENT_SCALE - 5f)/4f)*(1f+difficulty/150f));
        for(int pIdx = 0; pIdx < sourceCount ; pIdx += 3f*Math.random())
            _projectilesSources.add(new Position(pos.x + 4*(int)pIdx, GameWorld.WORLD_VIEW_WIDTH));
    }
}
项目:freeze-fire-tag    文件:BlockPools.java   
public BlockPools(final Board board)
{
    icePool = new Pool<IceBlock>()
    {
        @Override
        protected IceBlock newObject()
        {
            return new IceBlock(iceTexture, board);
        }
    };

    firePool = new Pool<FireBlock>()
    {
        protected FireBlock newObject()
        {
            return new FireBlock(fireTexture, board);
        }
    };
    rangePool = new Pool<RangeBlock>()
    {
        protected RangeBlock newObject()
        {
            return new RangeBlock(rangeTexture, board);
        }
    };
}
项目:TopDown    文件:Weapon.java   
public Weapon(int animationId, int fireRate, int damage, int range, int bullSpeed, int knockback, boolean isMeele) {
    this.fireRate = fireRate;
    this.damage = damage;
    this.range = range;
    this.bullSpeed = bullSpeed;
    this.animationId = animationId;
    this.isMeele = isMeele;
    this.lastShoot = 0;
    this.isHitting = false;
    this.state = 0;
    this.knockBack = knockback;

    bullets = new ArrayList<Bullet>();
    bulletPool = new Pool<Bullet>() {
        @Override 
        public Bullet newObject() {
            return new Bullet();
        }
    };
}
项目:libgdxcn    文件:ParallelAction.java   
public boolean act (float delta) {
    if (complete) return true;
    complete = true;
    Pool pool = getPool();
    setPool(null); // Ensure this action can't be returned to the pool while executing.
    try {
        Array<Action> actions = this.actions;
        for (int i = 0, n = actions.size; i < n && actor != null; i++) {
            if (!actions.get(i).act(delta)) complete = false;
            if (actor == null) return true; // This action was removed.
        }
        return complete;
    } finally {
        setPool(pool);
    }
}
项目:libgdxcn    文件:TemporalAction.java   
public boolean act (float delta) {
    if (complete) return true;
    Pool pool = getPool();
    setPool(null); // Ensure this action can't be returned to the pool while executing.
    try {
        if (!began) {
            begin();
            began = true;
        }
        time += delta;
        complete = time >= duration;
        float percent;
        if (complete)
            percent = 1;
        else {
            percent = time / duration;
            if (interpolation != null) percent = interpolation.apply(percent);
        }
        update(reverse ? 1 - percent : percent);
        if (complete) end();
        return complete;
    } finally {
        setPool(pool);
    }
}
项目:libgdxcn    文件:VoxelWorld.java   
@Override
public void getRenderables (Array<Renderable> renderables, Pool<Renderable> pool) {
    renderedChunks = 0;
    for (int i = 0; i < chunks.length; i++) {
        VoxelChunk chunk = chunks[i];
        Mesh mesh = meshes[i];
        if (dirty[i]) {
            int numVerts = chunk.calculateVertices(vertices);
            numVertices[i] = numVerts / 4 * 6;
            mesh.setVertices(vertices, 0, numVerts * VoxelChunk.VERTEX_SIZE);
            dirty[i] = false;
        }
        if (numVertices[i] == 0) continue;
        Renderable renderable = pool.obtain();
        renderable.material = materials[i];
        renderable.mesh = mesh;
        renderable.meshPartOffset = 0;
        renderable.meshPartSize = numVertices[i];
        renderable.primitiveType = GL20.GL_TRIANGLES;
        renderables.add(renderable);
        renderedChunks++;
    }
}
项目:tafl    文件:TaflBoard.java   
public TaflBoard(int dimensions, int pieceTypes, ZorbistHash zorbistHash, RulesEngine rulesEngine, OrthographicCamera camera) {
    super(dimensions, pieceTypes, zorbistHash);
    this.rules = rulesEngine;
    this.boardType = BoardType.getBoardType(dimensions);

    this.movePool = new Pool<Move>() {
        @Override
        protected Move newObject() {
            return new Move(this, boardSize);
        }
    };

    this.camera = camera;

    initialize();
}
项目:gaiasky    文件:AbstractOctreeWrapper.java   
/**
 * Gets a copy of this object but does not copy its parent or children
 * 
 * @return The copied object
 */
@Override
public <T extends SceneGraphNode> T getSimpleCopy() {
    Class<? extends AbstractOctreeWrapper> clazz = this.getClass();
    Pool<? extends AbstractOctreeWrapper> pool = MyPools.get(clazz);
    try {
        AbstractOctreeWrapper instance = pool.obtain();
        instance.copy = true;
        instance.name = this.name;
        instance.transform.set(this.transform);
        instance.ct = this.ct;
        if (this.localTransform != null)
            instance.localTransform.set(this.localTransform);

        return (T) instance;
    } catch (Exception e) {
        Logger.error(e);
    }
    return null;
}
项目:gaiasky    文件:MyPools.java   
/** Frees the specified objects from the {@link #get(Class) pool}. Null objects within the array are silently ignored.
 * @param samePool If true, objects don't need to be from the same pool but the pool must be looked up for each object. */
static public void freeAll(Array objects, boolean samePool) {
    if (objects == null)
        throw new IllegalArgumentException("Objects cannot be null.");
    Pool pool = null;
    for (int i = 0, n = objects.size; i < n; i++) {
        Object object = objects.get(i);
        if (object == null)
            continue;
        if (pool == null) {
            pool = typePools.get(object.getClass().getName());
            if (pool == null)
                continue; // Ignore freeing an object that was never retained.
        }
        pool.free(object);
        if (!samePool)
            pool = null;
    }
}
项目:Scene3d    文件:ParallelAction.java   
@Override
public boolean act (float delta) {
        if (complete) return true;
        complete = true;
        Pool pool = getPool();
        setPool(null); // Ensure this action can't be returned to the pool while executing.
        try {
                Array<Action3d> actions = this.actions;
                for (int i = 0, n = actions.size; i < n && actor3d != null; i++) {
                        if (!actions.get(i).act(delta)) complete = false;
                        if (actor3d == null) return true; // This action was removed.
                }
                return complete;
        } finally {
                setPool(pool);
        }
}
项目:Scene3d    文件:SequenceAction.java   
@Override
public boolean act (float delta) {
        if (index >= actions.size) return true;
        Pool<Action3d> pool = getPool();
        setPool(null); // Ensure this action can't be returned to the pool while executings.
        try {
                if (actions.get(index).act(delta)) {
                        if (actor3d == null) return true; // This action was removed.
                        index++;
                        if (index >= actions.size) return true;
                }
                return false;
        } finally {
                setPool(pool);
        }
}
项目:Scene3d    文件:TemporalAction.java   
@Override
public boolean act (float delta) {
        if (complete) return true;
        Pool pool = getPool();
        setPool(null); // Ensure this action can't be returned to the pool while executing.
        try {
                if (!began) {
                        begin();
                        began = true;
                }
                time += delta;
                complete = time >= duration;
                float percent;
                if (complete)
                        percent = 1;
                else {
                        percent = time / duration;
                        if (interpolation != null) percent = interpolation.apply(percent);
                }
                update(reverse ? 1 - percent : percent);
                if (complete) end();
                return complete;
        } finally {
                setPool(pool);
        }
}
项目:SpaceChaos    文件:VectorPoolFactory.java   
public static Pool<Vector2> createRectanglePool() {
    if (Vector2Pool == null) {
        Vector2Pool = new Pool<Vector2>() {

            @Override
            protected Vector2 newObject() {
                return new Vector2();
            }

        };
    }

    return Vector2Pool;
}
项目:SpaceChaos    文件:VectorPoolFactory.java   
public static Pool<Vector2> createNewRectanglePool() {
    return new Pool<Vector2>() {

        @Override
        protected Vector2 newObject() {
            return new Vector2();
        }

    };
}
项目:SpaceChaos    文件:RangePoolFactory.java   
public static Pool<Range> createRectanglePool() {
    if (rangePool == null) {
        rangePool = new Pool<Range>() {

            @Override
            protected Range newObject() {
                return new Range();
            }

        };
    }

    return rangePool;
}
项目:SpaceChaos    文件:RangePoolFactory.java   
public static Pool<Range> createNewRectanglePool() {
    return new Pool<Range>() {

        @Override
        protected Range newObject() {
            return new Range();
        }

    };
}
项目:SpaceChaos    文件:LinePoolFactory.java   
public static Pool<Line> createLinePool() {
    if (LinePool == null) {
        LinePool = new Pool<Line>() {

            @Override
            protected Line newObject() {
                return new Line();
            }

        };
    }

    return LinePool;
}
项目:SpaceChaos    文件:LinePoolFactory.java   
public static Pool<Line> createNewLinePool() {
    return new Pool<Line>() {

        @Override
        protected Line newObject() {
            return new Line();
        }

    };
}
项目:SpaceChaos    文件:RectanglePoolPrototypeFactory.java   
public static Pool<Rectangle> createRectanglePool() {
    if (rectPool == null) {
        rectPool = new Pool<Rectangle>() {

            @Override
            protected Rectangle newObject() {
                return new Rectangle();
            }

        };
    }

    return rectPool;
}
项目:SpaceChaos    文件:RectanglePoolPrototypeFactory.java   
public static Pool<Rectangle> createNewRectanglePool() {
    return new Pool<Rectangle>() {

        @Override
        protected Rectangle newObject() {
            return new Rectangle();
        }

    };
}
项目:Cubes_2    文件:WorldGraphicsPools.java   
public static void init() {
    Pools.registerType(AreaRenderer.class, new Pool<AreaRenderer>() {
        @Override
        protected AreaRenderer newObject() {
            return new AreaRenderer();
        }
    });
    Pools.registerType(AreaMesh.class, new DisposablePool<AreaMesh>() {
        @Override
        protected AreaMesh newObject() {
            return new AreaMesh();
        }
    });
}
项目:Cubes_2    文件:AreaRenderer.java   
@Override
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
    if (area == null || !update() || meshs.size() == 0)
        return;
    renderedThisFrame++;
    for (AreaMesh mesh : meshs) {
        renderedMeshesThisFrame++;
        renderables.add(mesh.renderable(pool));
    }
}
项目:Cubes_2    文件:Pools.java   
public static <T> void registerType(Class<? extends T> c, Pool<T> aPool) {
    T obj = aPool.obtain();
    Class<?> objClass = obj.getClass();
    aPool.free(obj);
    if (objClass.equals(c)) {
        synchronized (Pools.pools) {
            if (!Pools.pools.containsKey(c)) {
                Pools.pools.put(c, aPool);
            }
        }
    } else {
        throw new CubesException("Calling obtain on " + aPool + " does not return " + c.getName());
    }
}
项目:Cubes_2    文件:Pools.java   
public static <T> T obtain(Class<T> c) {
    Pool<T> pool = pool(c);
    if (pool == null)
        return null;
    synchronized (pool) {
        return pool.obtain();
    }
}
项目:Cubes_2    文件:Pools.java   
public static void clearPool(Class<?> c) {
    Pool<?> pool = pool(c);
    if (pool == null)
        throw new IllegalStateException("No pool for " + c.getSimpleName());
    synchronized (pool) {
        pool.clear();
    }
}
项目:Cubes_2    文件:Pools.java   
public static <T> void free(Class<T> c, T obj) {
    Pool<T> pool = pool(c);
    if (pool == null)
        return;
    synchronized (pool) {
        pool.free(obj);
    }
}
项目:Cubes_2    文件:Pools.java   
public static <T> void free(T obj) {
    Pool pool = pool(obj);
    if (pool == null)
        return;
    synchronized (pool) {
        pool.free(obj);
    }
}
项目:Cubes_2    文件:Pools.java   
private static Pool pool(Object object) {
    Class<?> c = object.getClass();
    synchronized (Pools.pools) {
        boolean isC !c.equals(Object.class);
        while (c != null && isC) {
            Pool pool = Pools.pools.get(c);
            if (pool != null)
                return pool;
            c = c.getSuperclass();
            isC = !c.equals(Object.class);
        }
    }
    return null;
}
项目:Cubes_2    文件:Pools.java   
public static AreaReference obtainAreaReference() {
    Pool<AreaReference> pool = pool(AreaReference.class);
    if (pool == null)
        return null;
    synchronized (pool) {
        return pool.obtain();
    }
}
项目:Cubes_2    文件:Pools.java   
public static void free(AreaReference obj) {
    Pool pool = pool(AreaReference.class);
    if (pool == null)
        return;
    synchronized (pool) {
        pool.free(obj);
    }
}
项目:Cubes_2    文件:Pools.java   
public static BlockReference obtainBlockReference() {
    Pool<BlockReference> pool = pool(BlockReference.class);
    if (pool == null)
        return null;
    synchronized (pool) {
        return pool.obtain();
    }
}
项目:Cubes_2    文件:Pools.java   
public static void free(BlockReference obj) {
    Pool pool = pool(BlockReference.class);
    if (pool == null)
        return;
    synchronized (pool) {
        pool.free(obj);
    }
}
项目:arcadelegends-gg    文件:CharacterSystem.java   
public CharacterSystem(World world) {
    super(Aspect.all(CharacterComponent.class, PositionComponent.class, PhysicComponent.class, StatComponent.class));
    this.world = world;
    vectorPool = new Pool<Vector2>() {
        @Override
        protected Vector2 newObject() {
            return new Vector2();
        }

        @Override
        protected void reset(Vector2 vector) {
            vector.set(0, 0);
        }
    };
}
项目:KyperBox    文件:TilemapLayerObject.java   
@Override
public void init(MapProperties properties) {
    super.init(properties);
    tile_pool = new Pool<TilemapLayerObject.MapTile>() {
        @Override
        protected MapTile newObject() {
            return new MapTile();
        }
    };
    tiles = (TiledMapTileLayer) getState().getMapData().getLayers().get(properties.get("tile_layer", String.class));
    setSize(tiles.getWidth() * tiles.getTileWidth(), tiles.getHeight() * tiles.getTileHeight());
    render = new TileLayerRenderer(this);
    cell_arrays = new Array<Array<MapTile>>();

}
项目:KyperBox    文件:TilemapLayerObject.java   
private static Pool<Array<MapTile>> getTCAPool() {
    if (tile_col_arrays == null)
        tile_col_arrays = new Pool<Array<MapTile>>() {
            @Override
            protected Array<MapTile> newObject() {
                return new Array<MapTile>();
            }
        };
    return tile_col_arrays;
}
项目:KyperBox    文件:CollisionController.java   
public static Pool<CollisionData> getPool() {
    if (col_pool == null)
        col_pool = new Pool<CollisionController.CollisionData>() {
            @Override
            protected CollisionData newObject() {
                return new CollisionData();
            }
        };
    return col_pool;
}
项目:KyperBox    文件:TileCollisionController.java   
@Override
public void init(GameObject object) {
    solid_filter = new IntArray();
    solid_filter.add(WALL);
    current_collisions = new IntArray();
    collision_map_tiles = new Array<TilemapLayerObject.MapTile>();
    tile_pool = new Pool<TilemapLayerObject.MapTile>() {
        @Override
        protected MapTile newObject() {
            return new MapTile();
        }
    };
}