#ifndef NXS_QUEUE_PSERVER_H #define NXS_QUEUE_PSERVER_H #include #include #include #include #include #include "pserver.h" namespace nxs { class QueuePServer: public PServer { public: enum Action { DRAW = 1, FLUSH = 0 }; struct Data { Patch *patch; unsigned int vbo_array; unsigned int vbo_element; Data(): patch(NULL), vbo_array(0), vbo_element(0) {} }; pt::jobqueue queue; unsigned int vbo_used; typedef std::pair Item; std::list items; typedef std::list Items; std::map index; QueuePServer(): queue(64000), vbo_used(0) {} ~QueuePServer() { Flush(); } Data &Lookup(unsigned int patch, unsigned short nv, unsigned short nf, std::vector &flush) { if(index.count(patch)) { Items::iterator &i = index[patch]; Item item = *i; items.erase(i); items.push_front(item); i = items.begin(); return ((*i).second); } else { while(ram_used > ram_max) { Data &data = items.back().second; //TODO i should not flush current extraction! index.erase(items.back().first); FlushPatch(items.back().first, data.patch); flush.push_back(data); items.pop_back(); } Item item; item.first = patch; item.second.patch = LoadPatch(patch, nv, nf); items.push_front(item); Items::iterator i = items.begin(); index[patch] = i; return ((*i).second); } } //return flushing too. //Data &Lookup(unsigned int patch, unsigned short nv, unsigned short nf, float priority, // std::vector &data); //bool IsLoaded(unsigned int patch); //float MaxPriority(); bool IsLoaded(unsigned int patch) { return index.count(patch); } void Flush() { std::map::iterator i; for(i = index.begin(); i != index.end(); i++) { Item &item = *((*i).second); FlushVbo(item.second); FlushPatch((*i).first, item.second.patch); } for(int k = 0; k < entries.size(); k++) entries[k].patch = NULL; items.clear(); index.clear(); } void LoadVbo(Data &data); void FlushVbo(Data &data); }; } #endif