From 74c6854fd8dcbaee736ac0421805ff1e03c4a1e2 Mon Sep 17 00:00:00 2001 From: iamn1ck Date: Sun, 19 Feb 2017 07:00:34 -0600 Subject: -quadtree and opengl rendering are now in the master branch ! -using sdl_rect for location and size ended up being not so great due to it not having floats, so we reverted back to using location -much, much refractoring is now needed --- src/list.cpp | 78 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 36 deletions(-) (limited to 'src/list.cpp') diff --git a/src/list.cpp b/src/list.cpp index afe51a3..fab5813 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -1,30 +1,33 @@ #include "list.hpp" -List::List(Window m) +List::List() { - main = m; + int i; + Dna defaultDNA; + //SDL_Rect rect = {0,0,defaultDNA.sizeMax/5,defaultDNA.sizeMax/5}; + Location tmp; + tmp.x = tmp.y = 0; + for(i=0;i::iterator it = C.begin(); it!=C.end(); it++) if(it->getHealth()<=0){ - SDL_Rect Rect = it->getRect(); - Resource r = Resource(main,Rect); + Location tmp = it->getLocation(); + Resource r = Resource(tmp); R.push_back(r); C.erase(it--); } @@ -37,15 +40,14 @@ void List::Remove() void List::Behavior() { for(std::list::iterator it = C.begin(); it!=C.end(); it++){ - std::vector N = getNear(*it); + std::list N = getNear(*it); it->giveN(N); it->Behavior(); if(it->getPregnancyReady()){ Dna D = it->getChildDNA(); - SDL_Rect rect = it->getRect(); - rect.h = rect.w = D.sizeMax / 5; - Creature X(main,rect,D); + Location tmp = it->getLocation(); + Creature X(tmp,D); C.push_back(X); it->hadPregnancy(); } @@ -57,34 +59,38 @@ void List::Behavior() void List::Place() { - SDL_Rect rect = {0,0,RESOURCE_SIZE_START,RESOURCE_SIZE_START}; + tree.clear(); + + Location tmp; + tmp.x = tmp.y = 0; while(R.size() < MINIMUM_RESOURCES){ - Resource Y(main,rect); + Resource Y(tmp); R.push_back(Y); } - for(std::list::iterator it = C.begin(); it!=C.end(); it++) + for(std::list::iterator it = C.begin(); it!=C.end(); it++){ it->Place(); + tree.insert(&(*it));; + } - for(std::list::iterator it = R.begin(); it!=R.end(); it++) + for(std::list::iterator it = R.begin(); it!=R.end(); it++){ it->Place(); + tree.insert(&(*it));; + } } -std::vector List::getNear(Creature nC) +std::list List::getNear(Creature nC) { - std::vector N; - - for(std::list::iterator it = R.begin(); it!=R.end(); it++) - if(nC.getBestSense() > Distance(nC.getRect(),it->getRect())) - N.push_back(&(*it)); - - for(std::list::iterator it = C.begin(); it!=C.end(); it++) - if(&nC == &(*it)) - continue; - else if(nC.getBestSense() > Distance(nC.getRect(),it->getRect())) - N.push_back(&(*it)); + std::list N; + N.clear(); + N = tree.retrieve(N, nC.getGFXD()); + //std::vector x{std::begin(N),std::begin(N)}; return N; } +std::vector List::drawQuadTree(){ + return tree.Draw(); +} + -- cgit v1.2.3