home *** CD-ROM | disk | FTP | other *** search
/ ring.yamanashi.ac.jp/pub/pc/freem/action/ / action.zip / a7xpg0_11.zip / a7xpg / src / abagames / util / ActorPool.d < prev    next >
Text File  |  2003-09-20  |  1KB  |  67 lines

  1. /*
  2.  * $Id: ActorPool.d,v 1.1.1.1 2003/09/19 14:55:49 kenta Exp $
  3.  *
  4.  * Copyright 2003 Kenta Cho. All rights reserved.
  5.  */
  6. module abagames.util.ActorPool;
  7.  
  8. import abagames.util.Actor;
  9.  
  10. /**
  11.  * Object pooling for actors.
  12.  */
  13. public class ActorPool {
  14.  public:
  15.   Actor[] actor;
  16.  protected:
  17.   int actorIdx;
  18.  
  19.   public this(int n, Actor act, ActorInitializer ini) {
  20.     actor = new Actor[n];
  21.     for (int i = 0; i < actor.length; i++) {
  22.       actor[i] = act.newActor();
  23.       actor[i].isExist = false;
  24.       actor[i].init(ini);
  25.     }
  26.     actorIdx = n;
  27.   }
  28.  
  29.   public Actor getInstance() {
  30.     for (int i = 0; i < actor.length; i++) {
  31.       actorIdx--;
  32.       if (actorIdx < 0)
  33.     actorIdx = actor.length - 1;
  34.       if (!actor[actorIdx].isExist) 
  35.     return actor[actorIdx];
  36.     }
  37.     return null;
  38.   }
  39.  
  40.   public Actor getInstanceForced() {
  41.     actorIdx--;
  42.     if (actorIdx < 0)
  43.       actorIdx = actor.length - 1;
  44.     return actor[actorIdx];
  45.   }
  46.  
  47.   public void move() {
  48.     for (int i = 0; i < actor.length; i++) {
  49.       if (actor[i].isExist)
  50.     actor[i].move();
  51.     }
  52.   }
  53.  
  54.   public void draw() {
  55.     for (int i = 0; i < actor.length; i++) {
  56.       if (actor[i].isExist)
  57.     actor[i].draw();
  58.     }
  59.   }
  60.  
  61.   public void clear() {
  62.     for (int i = 0; i < actor.length; i++) {
  63.       actor[i].isExist = false;
  64.     }
  65.   }
  66. }
  67.