delobjs.cc

Go to the documentation of this file.
00001 /*
00002  *  delobjs.cc - Game objects that have been removed, but need deleting.
00003  *
00004  *  Copyright (C) 2000-2001  The Exult Team
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #  include <config.h>
00023 #endif
00024 
00025 #include <vector>
00026 #include "objs.h"
00027 #include <SDL_timer.h>
00028 #include "delobjs.h"
00029 
00030 using std::vector;
00031 
00032 struct Obj_with_time
00033   {
00034   Game_object *obj;
00035   unsigned int ticks;
00036   Obj_with_time(Game_object *o, unsigned int t) : obj(o), ticks(t)
00037     {  }
00038   };
00039 
00040 /*
00041  *  Remove and delete all objects.
00042  */
00043 void Deleted_objects::flush
00044   (
00045   )
00046   {
00047   typedef vector<Obj_with_time> Obj_time_list;
00048 
00049   if (empty())
00050     return;
00051   Obj_time_list keep;
00052   keep.reserve(100);
00053           // Wait at least 3 minutes.
00054   unsigned int curtime = SDL_GetTicks();
00055   for(std::map<Game_object *,unsigned int,Less_objs>::iterator X = 
00056           begin(); X != end(); ++X)
00057     {
00058     Game_object *obj = (*X).first;
00059     int ticks = (*X).second;
00060     if (ticks < curtime)
00061       delete obj;
00062     else
00063       keep.push_back(Obj_with_time(obj, ticks));
00064     }
00065   clear();      // Clear map.
00066   for (Obj_time_list::iterator it = keep.begin(); it != keep.end(); ++it)
00067     (*this)[(*it).obj] = (*it).ticks;
00068   }
00069 

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