home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2004 August / GSSH0804.iso / Action / TumikiFighters / tf0_2.exe / tf / src / abagames / util / actorpool.d < prev    next >
Text File  |  2004-05-15  |  1KB  |  67 lines

  1. /*
  2.  * $Id: actorpool.d,v 1.2 2004/05/14 14:35:38 kenta Exp $
  3.  *
  4.  * Copyright 2003 Kenta Cho. All rights reserved.
  5.  */
  6. module abagames.util.actorpool;
  7.  
  8. private 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.     foreach (inout Actor a; actor) {
  22.       a = act.newActor();
  23.       a.isExist = false;
  24.       a.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.     foreach (Actor ac; actor) {
  49.       if (ac.isExist)
  50.     ac.move();
  51.     }
  52.   }
  53.  
  54.   public void draw() {
  55.     foreach (Actor ac; actor) {
  56.       if (ac.isExist)
  57.     ac.draw();
  58.     }
  59.   }
  60.  
  61.   public void clear() {
  62.     foreach (Actor ac; actor) {
  63.       ac.isExist = false;
  64.     }
  65.   }
  66. }
  67.