summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormajortom6 <tombarrett@siu.edu>2017-03-03 15:18:22 -0600
committerTom Barrett <tombarrett@siu.edu>2017-03-07 13:23:42 -0600
commitdfda3f2a5e555d3173359134f4994bcd12d129f8 (patch)
treeadc9d75f1e28332b8c5208fdb3c4685667816dda /src
parent3c78d411760beb9332e7282e4ec49a199998c67d (diff)
-removed the Graphics Data class
-replaced with already implemented Rectangle, and put color and side variables in dna (can potentially remove the side variable if it does nothing important)
Diffstat (limited to 'src')
-rw-r--r--src/dna.cpp12
-rw-r--r--src/list.cpp15
-rw-r--r--src/main.cpp4
-rw-r--r--src/organism.cpp16
-rw-r--r--src/quadtree.cpp33
-rw-r--r--src/spritebatch.cpp35
6 files changed, 52 insertions, 63 deletions
diff --git a/src/dna.cpp b/src/dna.cpp
index 8cef6e0..ac2d500 100644
--- a/src/dna.cpp
+++ b/src/dna.cpp
@@ -14,6 +14,10 @@ DNA::DNA(std::string s)
speed = CREATURE_SPEED;
mutationPercent = CREATURE_MUTATION_PERCENT;
mutationChance = CREATURE_MUTATION_CHANCE;
+ appearance.sides = CREATURE_SIDES;
+ appearance.red = 0;
+ appearance.green = 1;
+ appearance.blue = 1;
}
else if(s == "resource"){
type = RESOURCE_TYPE;
@@ -27,6 +31,10 @@ DNA::DNA(std::string s)
speed = 0;
mutationPercent = 0;
mutationChance = 0;
+ appearance.sides = RESOURCE_SIDES;
+ appearance.red = 0;
+ appearance.green = 1;
+ appearance.blue = 0;
}
}
@@ -44,6 +52,10 @@ DNA DNA::combine(DNA D)
N.speed = (speed + D.speed)/2;
N.mutationPercent = (mutationPercent + D.mutationPercent)/2;
N.mutationChance = (mutationChance + D.mutationChance)/2;
+ N.appearance.sides = CREATURE_SIDES;
+ N.appearance.red = 0;
+ N.appearance.green = 1;
+ N.appearance.blue = 1;
if(roll(mutationChance)){
float pn;
diff --git a/src/list.cpp b/src/list.cpp
index 826208e..d4b9529 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -64,21 +64,18 @@ void List::Place()
resources.push_back(X);
}
- for(std::list<Organism>::iterator it = creatures.begin(); it!= creatures.end(); it++){
- it->Place();
+ for(std::list<Organism>::iterator it = creatures.begin(); it!= creatures.end(); it++)
tree.insert(&(*it));;
- }
-
- for(std::list<Organism>::iterator it = resources.begin(); it!=resources.end(); it++){
- it->Place();
+
+ for(std::list<Organism>::iterator it = resources.begin(); it!=resources.end(); it++)
tree.insert(&(*it));;
- }
+
}
std::vector<Organism*> List::getNear(Organism c)
{
std::vector<Organism*> near;
- near = tree.retrieve(near, c.getGFXD());
+ near = tree.retrieve(near, c.getRectangle());
for(std::vector<Organism*>::iterator it = near.begin(); it!= near.end(); it++)
if(c.getBestSense() < Distance(c.getRectangle(),(*it)->getRectangle()))
@@ -87,7 +84,7 @@ std::vector<Organism*> List::getNear(Organism c)
return near;
}
-std::vector<GraphicsData> List::drawQuadTree()
+std::vector<Rectangle> List::drawQuadTree()
{
return tree.Draw();
}
diff --git a/src/main.cpp b/src/main.cpp
index 43ec1e4..cacd612 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -48,10 +48,10 @@ int main()
_spriteBatch.begin();
for(std::list<Organism>::iterator it = L.creatures.begin(); it != L.creatures.end(); it++)
- _spriteBatch.draw(it->getGFXD());
+ _spriteBatch.draw(it->getRectangle(),it->getVisuals());
for(std::list<Organism>::iterator it = L.resources.begin(); it != L.resources.end(); it++)
- _spriteBatch.draw(it->getGFXD());
+ _spriteBatch.draw(it->getRectangle(),it->getVisuals());
_spriteBatch.end();
_spriteBatch.renderBatch();
diff --git a/src/organism.cpp b/src/organism.cpp
index 27f6f8a..ee9f849 100644
--- a/src/organism.cpp
+++ b/src/organism.cpp
@@ -18,15 +18,6 @@ Organism::Organism(Rectangle r, DNA d)
pregnate = false;
hasTarget = false;
wander = false;
-
- if(myDNA.type == CREATURE_TYPE){
- if(gender)
- gfxData = GraphicsData(rect.x, rect.y, 1, 0, 0, CREATURE_SIDES);
- else
- gfxData = GraphicsData(rect.x, rect.y, 0, 0, 1, CREATURE_SIDES);
- }
- else
- gfxData = GraphicsData(rect.x, rect.y, 0, 1, 0, RESOURCE_SIDES);
}
void Organism::Behavior()
@@ -100,7 +91,6 @@ void Organism::checkTarget()
hasTarget = false;
}
-
void Organism::Action()
{
if(hasTarget){
@@ -185,9 +175,3 @@ void Organism::takeBite(int bite)
{
health-=bite;
}
-
-void Organism::Place()
-{
- gfxData.x = rect.x;
- gfxData.y = rect.y;
-}
diff --git a/src/quadtree.cpp b/src/quadtree.cpp
index ada839a..6366b4e 100644
--- a/src/quadtree.cpp
+++ b/src/quadtree.cpp
@@ -8,12 +8,8 @@ Quadtree::Quadtree(int pLevel,Rectangle pBounds){
bounds = pBounds;
isNull=false;
nodes = new Quadtree[4];
- gfxDataRect.x = pBounds.x * 1.01;
- gfxDataRect.y = pBounds.y * 1.05;
- gfxDataRect.r = 255;
- gfxDataRect.g = 0;
- gfxDataRect.b = 255;
- gfxDataRect.sides = pBounds.h;
+ rect.x = pBounds.x * 1.01;
+ rect.y = pBounds.y * 1.05;
}
void Quadtree::clear(){
@@ -53,8 +49,7 @@ void Quadtree::clear(){
nodes[3] = Q3;
}
-
-int Quadtree::getIndex(GraphicsData object) {
+int Quadtree::getIndex(Rectangle object) {
int index = -1;
bool topQuadrant = (object.y > bounds.y);
@@ -78,7 +73,7 @@ int Quadtree::getIndex(GraphicsData object) {
void Quadtree::insert(Organism* iter){
if (!nodes[0].isNull) {
- int index = getIndex((*iter).getGFXD());
+ int index = getIndex((*iter).getRectangle());
if (index != -1) {
nodes[index].insert(iter);
return;
@@ -93,7 +88,7 @@ void Quadtree::insert(Organism* iter){
int index;
for(std::vector<Organism*>::iterator it = objects.begin(); it!=objects.end();it++){
- index = getIndex((*it)->getGFXD());
+ index = getIndex((*it)->getRectangle());
if (index != -1) {
nodes[index].insert(*it);
objects.erase(it--);
@@ -102,31 +97,31 @@ void Quadtree::insert(Organism* iter){
}
}
-std::vector<GraphicsData> Quadtree::Draw(){
- std::vector<GraphicsData> retdat;
+std::vector<Rectangle> Quadtree::Draw(){
+ std::vector<Rectangle> retdat;
int i;
for (i = 0; i < 4; i++) {
if (!nodes[i].isNull) {
- std::vector<GraphicsData> temp = nodes[i].Draw();
+ std::vector<Rectangle> temp = nodes[i].Draw();
retdat.insert(retdat.end(), temp.begin(), temp.end());
}
}
if (!nodes[0].isNull)
- retdat.emplace_back(nodes[0].gfxDataRect);
+ retdat.emplace_back(nodes[0].rect);
if (!nodes[1].isNull)
- retdat.emplace_back(nodes[1].gfxDataRect);
+ retdat.emplace_back(nodes[1].rect);
if (!nodes[2].isNull)
- retdat.emplace_back(nodes[2].gfxDataRect);
+ retdat.emplace_back(nodes[2].rect);
if (!nodes[3].isNull)
- retdat.emplace_back(nodes[3].gfxDataRect);
+ retdat.emplace_back(nodes[3].rect);
- retdat.emplace_back(gfxDataRect);
+ retdat.emplace_back(rect);
return retdat;
}
-std::vector<Organism*> Quadtree::retrieve(std::vector<Organism*> returnObjects, GraphicsData obj) {
+std::vector<Organism*> Quadtree::retrieve(std::vector<Organism*> returnObjects, Rectangle obj) {
int index = getIndex(obj);
if (index != -1 && !nodes[0].isNull)
returnObjects = nodes[index].retrieve(returnObjects, obj);
diff --git a/src/spritebatch.cpp b/src/spritebatch.cpp
index f0a82e6..c756494 100644
--- a/src/spritebatch.cpp
+++ b/src/spritebatch.cpp
@@ -27,9 +27,9 @@ void SpriteBatch::end()
createRenderBatches();
}
-void SpriteBatch::draw(const GraphicsData& gfxData)
+void SpriteBatch::draw(Rectangle r, DNA::Visuals v)
{
- _gfx.emplace_back(gfxData);
+ _gfx.emplace_back(std::make_pair(r,v));
}
void SpriteBatch::renderBatch()
@@ -62,12 +62,12 @@ void SpriteBatch::createRenderBatches()
//Add the first batch
_renderBatches.emplace_back(offset, 6);
- vertices[cv++] = _gfxPtr[0]->x;
- vertices[cv++] = _gfxPtr[0]->y;
- vertices[cv++] = _gfxPtr[0]->r;
- vertices[cv++] = _gfxPtr[0]->g;
- vertices[cv++] = _gfxPtr[0]->b;
- vertices[cv++] = _gfxPtr[0]->sides;
+ vertices[cv++] = _gfxPtr[0]->first.x;
+ vertices[cv++] = _gfxPtr[0]->first.y;
+ vertices[cv++] = _gfxPtr[0]->second.red;
+ vertices[cv++] = _gfxPtr[0]->second.green;
+ vertices[cv++] = _gfxPtr[0]->second.blue;
+ vertices[cv++] = _gfxPtr[0]->second.sides;
offset += 6;
@@ -82,12 +82,12 @@ void SpriteBatch::createRenderBatches()
// If its part of the current batch, just increase numVertices
_renderBatches.back().numVertices += 6;
//}
- vertices[cv++] = _gfxPtr[cg]->x;
- vertices[cv++] = _gfxPtr[cg]->y;
- vertices[cv++] = _gfxPtr[cg]->r;
- vertices[cv++] = _gfxPtr[cg]->g;
- vertices[cv++] = _gfxPtr[cg]->b;
- vertices[cv++] = _gfxPtr[cg]->sides;
+ vertices[cv++] = _gfxPtr[cg]->first.x;
+ vertices[cv++] = _gfxPtr[cg]->first.y;
+ vertices[cv++] = _gfxPtr[cg]->second.red;
+ vertices[cv++] = _gfxPtr[cg]->second.green;
+ vertices[cv++] = _gfxPtr[cg]->second.blue;
+ vertices[cv++] = _gfxPtr[cg]->second.sides;
offset += 6;
}
@@ -98,7 +98,6 @@ void SpriteBatch::createRenderBatches()
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), nullptr, GL_DYNAMIC_DRAW);
// Upload the data
glBufferSubData(GL_ARRAY_BUFFER, 0, vertices.size() * sizeof(float), vertices.data());
-
// Unbind the VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
@@ -131,8 +130,10 @@ void SpriteBatch::createVertexArray()
//glEnableVertexAttribArray(2);
//This is the position attribute pointer
- glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 6*sizeof(float), 0); //This is the color attribute pointer
- glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), (void*) (2 * sizeof(float))); //This is the UV attribute pointer
+ glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 6*sizeof(float), 0);
+ //This is the color attribute pointer
+ glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), (void*) (2 * sizeof(float)));
+ //This is the UV attribute pointer
glVertexAttribPointer(sidesAttrib, 1, GL_FLOAT, GL_FALSE,6*sizeof(float), (void*) (5 * sizeof(float)));
glBindVertexArray(0);
}