objiter.cc

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2002  The Exult Team
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #  include <config.h>
00027 #endif
00028 #include "objiter.h"
00029 #include "contain.h"
00030 #include "gamewin.h"
00031 #include "chunks.h"
00032 
00033 /*
00034  *  Create to start after/before a given object within a chunk.
00035  */
00036 
00037 template<class D> 
00038 D_Recursive_object_iterator<D>::D_Recursive_object_iterator
00039   (
00040   Game_object *start    // Start here.
00041   ) : elems(start->get_outermost()->get_chunk()->get_objects()), child(0)
00042   {
00043           // Get what obj. is in (or itself).
00044   Game_object *owner = start->get_outermost();
00045   Game_object *obj;   // Find owner within its chunk.
00046   while ((obj = get_next()) != 0 && obj != owner)
00047     ;
00048   if (!obj)
00049     return;     // Bad.  It wasn't found.
00050   if (obj != start)   // Given object contained?
00051           // Look within for it.
00052     while ((obj = get_next()) != 0 && obj != start)
00053       ;
00054   }
00055 
00056 /*
00057  *  Get next game object, going down recursively into containers.
00058  *
00059  *  Output: Next in world, or 0 if done.
00060  */
00061 
00062 template<class D> Game_object *D_Recursive_object_iterator<D>::get_next
00063   (
00064   )
00065   {
00066   Game_object *obj;
00067   if (child)      // Going through container?
00068     {
00069     obj = child->get_next();
00070     if (obj)
00071       return obj;
00072     delete child;
00073     child = 0;    // Child done.
00074     }
00075   obj = elems.get_next();   // Get next from our list.
00076   if (!obj)
00077     return 0;   // All done.
00078           // Is it a container?
00079   Container_game_object *c = obj->as_container();
00080   if (c)        // Container?  Set to go through it.
00081     child = new D_Recursive_object_iterator<D>(
00082               c->get_objects());
00083   return obj;
00084   }

Generated on Mon Jul 9 14:42:49 2007 for ExultEngine by  doxygen 1.5.1