00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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();
00066 for (Obj_time_list::iterator it = keep.begin(); it != keep.end(); ++it)
00067 (*this)[(*it).obj] = (*it).ticks;
00068 }
00069