commit 7a17f5e2c194996a7529b932b15e264ea43bd063
parent d84338912130e13f747cf3a752e73256013012a8
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Mon, 5 Dec 2011 19:36:09 +0100
Merge branch 'master' of http://github.com/jsmaniac/2011-m2s3-city-builder
Diffstat:
| A | lod.cpp | | | 62 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | lod.hh | | | 26 | ++++++++++++++++++++++++++ |
2 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/lod.cpp b/lod.cpp
@@ -0,0 +1,62 @@
+#include "all_includes.hh"
+
+Abr::Abr() {
+}
+
+Abr::insert(int key, Chose* value) {
+ map.insert(key,value);
+}
+
+Abr::remove(int key, Chose* value) {
+ pair<multimap<int,Chose*>::iterator,multimap<int,Chose*>::iterator> ret;
+ ret = map.equal_range(key);
+ for (it=ret.first; it!=ret.second; ++it) {
+ if ((*it).second == value) {
+ map.erase(it);
+ break;
+ }
+ }
+}
+
+Abr::popIfLessThan(int key) {
+ std::multimap<int,Chose*>::iterator it = map.begin();
+
+ if((*it).first < key) {
+ map.erase(it);
+ return (*it).second;
+ } else {
+ return NULL;
+ }
+}
+
+
+#define NegateEven(v, i) ((v)*(((i)&1) ? 1 : -1))
+
+Lod::Lod(float[3] camera) {
+ this->camera = camera;
+}
+
+void Lod::setCamera(float[3] camera) {
+ this->camera = camera;
+
+ for(int i = 0; i < 5; i++) {
+ Chose* c;
+ int pos = NegateEven(camera[i>>1], i);
+ while(c = merge[i].popIfLessThan(pos)) {
+ for(int j = 0; j < 5; j++) {
+ if(i == j) break;
+ // TODO : sera merge[j].remove(c->mergeCube[j]);
+ merge[j].remove(NegateEven(c->mergeCube[j], j), c);
+ }
+ }
+ }
+}
+
+void Lod::addMergeCube(Chose* chose, int[6] limits) {
+ for(int i = 0; i < 5; i++)
+ merge.insert(NegateEven(limits[i], i), chose);
+}
+
+void Lod::addSplitCube(int[6] limits) {
+
+}
diff --git a/lod.hh b/lod.hh
@@ -0,0 +1,26 @@
+#include "all_includes.hh"
+
+class Abr {
+ private :
+ std::multimap<int, Chose*> map;
+
+ public :
+ Abr();
+ void insert(int key, Chose* value); //TODO Retourne un item*.
+ void remove(int key, Chose* value); //TODO Prend un item*.
+ Chose* popIfLessThan(int key);
+};
+
+
+class Lod {
+ private :
+ Abr merge[6];
+ Abr split[12];
+ float camera[3];
+
+ public :
+ Lod(float[3] camera);
+ void addMergeCube(Chose* chose, int[6] limits);
+ void addSplitCube(Chose* chose, int[6] limits);
+ void setCamera(float[3] camera);
+};