InvisibleEntityCache.h
00001 #ifndef ERIS_INVISIBLE_ENTITY_CACHE_H
00002 #define ERIS_INVISIBLE_ENTITY_CACHE_H
00003
00004 #include <Eris/Timestamp.h>
00005 #include <Eris/Log.h>
00006 #include <Eris/Entity.h>
00007
00008 #include <cassert>
00009 #include <deque>
00010 #include <set>
00011
00012 namespace Eris {
00013
00014 typedef std::set<Entity*> EntitySet;
00015
00016 class InvisibleEntityCache
00017 {
00018 public:
00019 InvisibleEntityCache(unsigned long width, unsigned long life) :
00020 _bucketWidthMsec(width),
00021 _bucketLifetimeMsec(life)
00022 {
00023 }
00024
00025 void add(Entity *e);
00026
00027 void remove(Entity *e)
00028 {
00029 assert(e);
00030 for (BucketQueue::iterator B=_buckets.begin(); B!=_buckets.end();++B)
00031 if (B->remove(e)) return;
00032
00033 Eris::log(LOG_ERROR, "Entity %s not found in InvisibleEntityCache doing ::remove",
00034 e->getID().c_str());
00035 }
00036
00037 void flush();
00038
00039 protected:
00040 class _Bucket
00041 {
00042 public:
00043 void add(Entity *e)
00044 {
00045 if (contents.empty())
00046 stamp = Time::Stamp::now();
00047 contents.insert(e);
00048 }
00049
00050 bool remove(Entity *e)
00051 {
00052 EntitySet::iterator C = contents.find(e);
00053 if (C != contents.end())
00054 contents.erase(C);
00055 return (C != contents.end());
00056 }
00057
00058 Time::Stamp stamp;
00059 EntitySet contents;
00060 };
00061
00062 typedef std::deque<_Bucket> BucketQueue;
00063 BucketQueue _buckets;
00064
00065 unsigned long _bucketWidthMsec,
00066 _bucketLifetimeMsec;
00067 };
00068
00069 }
00070
00071 #endif
Generated on Tue Jul 27 21:00:43 2004 for Eris by
1.3.7