From fcf6abaccec7c7ed2fd306a9cf1ec378f303297c Mon Sep 17 00:00:00 2001 From: majortom6 Date: Sun, 19 Feb 2017 10:41:00 -0600 Subject: -refractoring of includes --- inc/constants.hpp | 14 +++++++++- inc/creature.hpp | 3 +-- inc/entity.hpp | 9 +++---- inc/functions.hpp | 2 ++ inc/list.hpp | 20 ++++++-------- inc/main.hpp | 13 +++++---- inc/opengl/camera.hpp | 39 ++++++++++++++------------- inc/opengl/geoshader.hpp | 9 +++---- inc/opengl/graphicsdata.hpp | 66 +++++++++++++++++---------------------------- inc/quadtree.hpp | 48 ++++++++++++++++----------------- inc/resource.hpp | 20 ++++++++------ 11 files changed, 119 insertions(+), 124 deletions(-) (limited to 'inc') diff --git a/inc/constants.hpp b/inc/constants.hpp index 7d53134..8cf4edd 100644 --- a/inc/constants.hpp +++ b/inc/constants.hpp @@ -1,15 +1,18 @@ #ifndef constants_h #define constants_h +// General const int CREATURES = 10; const int RESOURCES = 100; -const int MINIMUM_RESOURCES = 800; +const int MINIMUM_RESOURCES = 80; const int WINDOW_X = 1000; const int WINDOW_Y = 1000; +// Types const int CREATURE_TYPE = 1; const int RESOURCE_TYPE = 2; +// Creatures const int CREATURE_MAX_HEALTH = 1000; const int CREATURE_REACH = 1; const int CREATURE_BEST_SENSE = 10; @@ -20,13 +23,22 @@ const int CREATURE_EXP_AGE = 1000000; const int CREATURE_SIZE_MAX = 10; const float CREATURE_SPEED = .1; +// Resource const int RESOURCE_SIZE_STAR = 1; const int RESOURCE_SIZE_MAX = 4; const int RESOURCE_AMOUNT_START = 100; const int RESOURCE_AMOUNT_MAX = 200; const int RESOURCE_GROW = 1; +// Opengl const int NUM_SHADERS = 3; const int NUM_UNIFORMS = 3; +// Quadtree +const int MAX_OBJECTS = 5; +const int MAX_LEVELS = 6; + +// Camera +const float MOVE_AMOUNT = .2; + #endif diff --git a/inc/creature.hpp b/inc/creature.hpp index 99226b3..0f9128f 100644 --- a/inc/creature.hpp +++ b/inc/creature.hpp @@ -1,12 +1,11 @@ #ifndef creature_h #define creature_h -#include +#include #include #include "entity.hpp" #include "functions.hpp" -#include "dna.hpp" class Creature: public Entity { diff --git a/inc/entity.hpp b/inc/entity.hpp index c47ef00..20c87aa 100644 --- a/inc/entity.hpp +++ b/inc/entity.hpp @@ -1,12 +1,11 @@ #ifndef entity_h #define entity_h -#include - #include "dna.hpp" -#include "opengl/graphicsdata.hpp" #include "rectangle.hpp" +#include "opengl/graphicsdata.hpp" + class Entity { public: @@ -18,7 +17,7 @@ class Entity int getType(){return type;}; virtual bool getGender(void){}; virtual int getAmount(void){}; - Rectangle getRectangle(){return L;}; + Rectangle getRectangle(){return rect;}; GraphicsData getGFXD(){return gfxData;}; @@ -26,7 +25,7 @@ class Entity int type; int gender; bool pregnate; - Rectangle L; + Rectangle rect; GraphicsData gfxData; }; diff --git a/inc/functions.hpp b/inc/functions.hpp index 15cb94a..7ce9f8d 100644 --- a/inc/functions.hpp +++ b/inc/functions.hpp @@ -1,6 +1,8 @@ #ifndef functions_h #define functions_h +#include + #include "rectangle.hpp" static double Distance(Rectangle A, Rectangle B){ diff --git a/inc/list.hpp b/inc/list.hpp index aff57a2..872d5fa 100644 --- a/inc/list.hpp +++ b/inc/list.hpp @@ -1,16 +1,12 @@ #ifndef list_h #define list_h -#include #include #include -#include "functions.hpp" +#include "constants.hpp" #include "creature.hpp" #include "resource.hpp" -#include "sdl/window.hpp" -#include "constants.hpp" -#include "rectangle.hpp" #include "quadtree.hpp" class List @@ -19,14 +15,14 @@ class List List(); void Behavior(); void Place(); - void Remove(); - std::list getNear(Creature C); - std::list R; - std::list C; + void Remove(); + + std::list getNear(Creature c); + std::list resources; + std::list creatures; - Quadtree tree; - std::vector drawQuadTree(); - Rectangle R1; + Quadtree tree; + std::vector drawQuadTree(); }; #endif diff --git a/inc/main.hpp b/inc/main.hpp index 3fe405f..2a8ac44 100644 --- a/inc/main.hpp +++ b/inc/main.hpp @@ -1,16 +1,15 @@ #ifndef main_h #define main_h -#include -#include +#include "constants.hpp" +#include "list.hpp" + +#include "sdl/timer.hpp" +#include "sdl/event.hpp" +#include "sdl/window.hpp" #include "opengl/geoshader.hpp" #include "opengl/rectdrawer.hpp" #include "opengl/spritebatch.hpp" -#include "sdl/window.hpp" -#include "sdl/event.hpp" -#include "list.hpp" -#include "sdl/timer.hpp" -#include "constants.hpp" #endif diff --git a/inc/opengl/camera.hpp b/inc/opengl/camera.hpp index 62ae837..06a5a88 100644 --- a/inc/opengl/camera.hpp +++ b/inc/opengl/camera.hpp @@ -1,57 +1,58 @@ #ifndef camera_h #define camera_h +#include "constants.hpp" + struct Camera { public: Camera(const glm::vec3& pos, float fov, float aspect, float zNear, float zFar){ - this->pos = pos; - this->forward = glm::vec3(0.0f, 0.0f, -1.0f); - this->up = glm::vec3(0.0f, 1.0f, 0.0f); - this->projection = glm::perspective(fov, aspect, zNear, zFar); + this->pos = pos; + this->forward = glm::vec3(0.0f, 0.0f, -1.0f); + this->up = glm::vec3(0.0f, 1.0f, 0.0f); + this->projection = glm::perspective(fov, aspect, zNear, zFar); } inline glm::mat4 GetViewProjection() const { - return projection * glm::lookAt(pos, pos + forward, up); + return projection * glm::lookAt(pos, pos + forward, up); } void MoveForward(){ - pos += forward * amt; + pos += forward * MOVE_AMOUNT; } void MoveBackward(){ - pos += forward * -amt; + pos += forward * -MOVE_AMOUNT; } void MoveRight(){ - pos += -glm::cross(up, forward) * amt; + pos += -glm::cross(up, forward) * MOVE_AMOUNT; } void MoveLeft(){ - pos += glm::cross(up, forward) * amt; + pos += glm::cross(up, forward) * MOVE_AMOUNT; } void MoveUp(){ - pos += glm::vec3(0,.2,0); + pos += glm::vec3(0,MOVE_AMOUNT,0); } void MoveDown(){ - pos -= glm::vec3(0,.2,0); + pos -= glm::vec3(0,MOVE_AMOUNT,0); } void Pitch(float angle){ - glm::vec3 right = glm::normalize(glm::cross(up, forward)); + glm::vec3 right = glm::normalize(glm::cross(up, forward)); - forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0))); - up = glm::normalize(glm::cross(forward, right)); + forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0))); + up = glm::normalize(glm::cross(forward, right)); } private: - float amt = .2; - glm::mat4 projection; - glm::vec3 pos; - glm::vec3 forward; - glm::vec3 up; + glm::mat4 projection; + glm::vec3 pos; + glm::vec3 forward; + glm::vec3 up; }; #endif diff --git a/inc/opengl/geoshader.hpp b/inc/opengl/geoshader.hpp index 2619a92..d068a55 100644 --- a/inc/opengl/geoshader.hpp +++ b/inc/opengl/geoshader.hpp @@ -5,7 +5,6 @@ #include #include "constants.hpp" -#include "graphicsdata.hpp" #include "transform.hpp" class GeoShader @@ -13,10 +12,10 @@ class GeoShader public: GeoShader(const std::string& fileName); - void Bind(); - void Update(const Transform& transform, const Camera& camera); - virtual ~GeoShader(); - GLuint m_program; + void Bind(); + void Update(const Transform& transform, const Camera& camera); + virtual ~GeoShader(); + GLuint m_program; private: std::string LoadShader(const std::string& fileName); diff --git a/inc/opengl/graphicsdata.hpp b/inc/opengl/graphicsdata.hpp index df8d76e..a0398dc 100644 --- a/inc/opengl/graphicsdata.hpp +++ b/inc/opengl/graphicsdata.hpp @@ -1,49 +1,33 @@ #ifndef graphicsdata_h #define graphicsdata_h -#include -#include - -#include "camera.hpp" - class GraphicsData { - public: - - float x; - float y; - float r; - float g; - float b; - float sides; - - GraphicsData(){ - this->x = 0; - this->y = 0; - this->r = 0; - this->g = 0; - this->b = 0; - this->sides = 0; - } - - - GraphicsData(float x,float y,float r,float g,float b,float sides){ - this->x = 0; - this->y = 0; - this->r = 0; - this->g = 0; - this->b = 0; - this->sides = 0; - } - - float getX(){ - return x; - } - - float getY(){ - return y; - } - + public: + GraphicsData(){ + this->x = 0; + this->y = 0; + this->r = 0; + this->g = 0; + this->b = 0; + this->sides = 0; + } + + GraphicsData(float x1, float y1, float r1, float g1, float b1, float sides1){ + this->x = x1; + this->y = y1; + this->r = r1; + this->g = g1; + this->b = b1; + this->sides = sides1; + } + + float x; + float y; + float r; + float g; + float b; + float sides; }; #endif diff --git a/inc/quadtree.hpp b/inc/quadtree.hpp index 8da34aa..2b07103 100644 --- a/inc/quadtree.hpp +++ b/inc/quadtree.hpp @@ -4,38 +4,38 @@ #include #include -#include "sdl/window.hpp" +#include "constants.hpp" #include "creature.hpp" #include "resource.hpp" #include "entity.hpp" #include "rectangle.hpp" + #include "opengl/graphicsdata.hpp" +#include "sdl/window.hpp" class Quadtree { + public: + Quadtree(); + Quadtree(int pLevel,Rectangle pBounds); + + void clear(); + void insert(Entity* iter); + + std::list retrieve(std::list returnObject, GraphicsData obj); + std::list objects; + + Quadtree* nodes; + + std::vector Draw(); + + private: + void split(); + int getIndex(GraphicsData object); + int level; + bool isNull = true; - public: - Quadtree(); - Quadtree(int pLevel, Rectangle pBounds); - void clear(); - void insert(Entity* iter); - std::list retrieve(std::list returnObject, GraphicsData obj); - - std::list objects; - - Quadtree* nodes; - - std::vector Draw(); - - private: - void split(); - int getIndex(GraphicsData object); - int MAX_OBJECTS = 5; - int MAX_LEVELS = 6; - int level; - bool isNull = true; - - GraphicsData gfxDataRect; - Rectangle bounds; + GraphicsData gfxDataRect; + Rectangle bounds; }; #endif diff --git a/inc/resource.hpp b/inc/resource.hpp index 252b086..07d42d4 100644 --- a/inc/resource.hpp +++ b/inc/resource.hpp @@ -1,20 +1,24 @@ #ifndef resource_h #define resource_h +#include + #include "entity.hpp" #include "functions.hpp" class Resource: public Entity { - public: - Resource(Rectangle t); - int getAmount(){return amount;}; - void grow(); - void eat(int bite); + public: + Resource(Rectangle t); + + void grow(); + void eat(int bite); + + int getAmount(){return amount;}; - private: - int amount; - int growAmount; + private: + int amount; + int growAmount; }; #endif -- cgit v1.2.3