aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2016-04-15 08:49:26 -0400
committerdrumsetmonkey <abelleisle@roadrunner.com>2016-04-15 08:49:26 -0400
commit56fd6a9d86ac57580ec2b91cc98db31dda5f5770 (patch)
tree359c86e617b993a07465dfc020a26704753a5320 /include
parent8b0f74445b509d8e59ec89854f2e149ad1948d4e (diff)
Fixed segfaults
Diffstat (limited to 'include')
-rw-r--r--include/common.hpp23
-rw-r--r--include/entities.hpp25
-rw-r--r--include/inventory.hpp40
-rw-r--r--include/ui.hpp35
-rw-r--r--include/ui_menu.hpp34
-rw-r--r--include/world.hpp8
6 files changed, 101 insertions, 64 deletions
diff --git a/include/common.hpp b/include/common.hpp
index 65ac47b..5968272 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -48,6 +48,11 @@ typedef unsigned int uint;
#define MSEC_PER_TICK (1000 / TICKS_PER_SEC)
+/**
+ * This flag lets the compuler know that we are testing for segfault locations.
+ * If this flag is enabled, the function C(x) will print 'x' to terminal
+ */
+
//#define SEGFAULT
/**
@@ -57,17 +62,17 @@ typedef unsigned int uint;
#define SHADERS
template<typename N>
-N abso(N v){
- if(v < 0){
+N abso(N v) {
+ if (v < 0) {
return v * -1;
}else
return v;
}
template<class A>
-float averagef(A v){
+float averagef(A v) {
float avg = 0;
- for(auto &a : v){
+ for(auto &a : v) {
avg += a;
}
avg /= v.size();
@@ -112,16 +117,16 @@ struct col {
float red;
float green;
float blue;
- col operator-=(float a){
+ col operator-=(float a) {
red-=a;
green-=a;
blue-=a;
return{red+a,green+a,blue+a};
}
- col operator+=(float a){
+ col operator+=(float a) {
return{red+a,green+a,blue+a};
}
- col operator=(float a){
+ col operator=(float a) {
return{red=a,green=a,blue=a};
}
};
@@ -195,7 +200,7 @@ extern float VOLUME_SFX;
#define DEBUG_printf(message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__)
#ifdef SEGFAULT
-#define C(x) std::cout << m << std::endl
+#define C(x) std::cout << x << std::endl
#else
#define C(x)
#endif
@@ -268,7 +273,7 @@ const char *readFile(const char *path);
int strCreateFunc(const char *equ);
template<typename N, size_t s>
-size_t arrAmt(N (&)[s]){return s;}
+size_t arrAmt(N (&)[s]) {return s;}
void UserError(std::string reason);
diff --git a/include/entities.hpp b/include/entities.hpp
index 6cd5731..ae23714 100644
--- a/include/entities.hpp
+++ b/include/entities.hpp
@@ -58,7 +58,7 @@ public:
std::string item[2];
int quantity[2];
Trade(int qo, std::string o, int qt, std::string t);
- Trade(){}
+ Trade() {}
};
class World;
@@ -77,7 +77,7 @@ public:
bool gravity;
bool behind;
bool bounce;
- Particles(float x, float y, float w, float h, float vx, float vy, Color c, float d){
+ Particles(float x, float y, float w, float h, float vx, float vy, Color c, float d) {
loc.x = x;
loc.y = y;
vel.x = vx;
@@ -92,9 +92,9 @@ public:
bounce = false;
index = Texture::getIndex(c);
}
- ~Particles(){
+ ~Particles() {
}
- void draw(){
+ void draw() {
glColor3ub(255,255,255);
glBegin(GL_QUADS);
glTexCoord2f(.25*index.x, .125*index.y); glVertex2i(loc.x, loc.y);
@@ -117,7 +117,7 @@ public:
} else if (gravity && vel.y > -1)
vel.y -= _gravity * deltaTime;
}
- bool kill(float delta){
+ bool kill(float delta) {
return (duration -= delta) <= 0;
}
};
@@ -184,15 +184,15 @@ public:
int ticksToUse; // Used by wander()
- virtual void wander(int){}
- virtual void interact(){}
+ virtual void wander(int) {}
+ virtual void interact() {}
void follow(Entity *e);
bool isNear(Entity e);
bool isInside(vec2 coord) const;
- virtual ~Entity(){}
+ virtual ~Entity() {}
};
class Player : public Entity{
@@ -234,11 +234,18 @@ public:
virtual void wander(int);
};
-class Merchant : public NPC {
+class Merchant : public NPC{
public:
std::vector<Trade>trade;
uint currTrade;
+ std::string text[4];
+ std::string *toSay;
+ //greeting
+ //accept
+ //deny
+ //farewell
+
void interact();
Structures *inside;
diff --git a/include/inventory.hpp b/include/inventory.hpp
index e38f89a..4fb45f9 100644
--- a/include/inventory.hpp
+++ b/include/inventory.hpp
@@ -10,7 +10,7 @@
class Item{
public:
- std::string name,type;
+ std::string name, type;
float width;
float height;
@@ -20,7 +20,26 @@ public:
std::string texloc;
Texturec *tex;
- GLuint rtex(){
+ GLuint rtex()
+ {
+ return tex->image[0];
+ }
+};
+
+class Currency{
+public:
+ std::string name;
+
+ float width;
+ float height;
+
+ std::string texloc;
+ Texturec *tex;
+
+ float value;
+
+ GLuint rtex()
+ {
return tex->image[0];
}
};
@@ -32,17 +51,18 @@ struct item_t{
class Inventory {
private:
- unsigned int size;
+ unsigned int size; //how many slots our inventory has
+ unsigned int sel; //what item is currently selected
int os = 0;
public:
std::vector<item_t> items;
- unsigned int sel;
- bool invOpen = false;
- bool invOpening = false;
- bool invHover = false;
- bool selected = false;
- bool mouseSel = false;
- bool usingi = false;
+
+ bool invOpen = false; //is the inventory open
+ bool invOpening = false; //is the opening animation playing
+ bool invHover = false; //are we using the fancy hover inventory
+ bool selected = false; //used in hover inventory to show which item has been selected
+ bool mouseSel = false; //the location of the temperary selection for the hover inv
+ bool usingi = false; //bool used to tell if inventory owner is using selected item
Inventory(unsigned int s); // Creates an inventory of size 's'
~Inventory(void); // Free's allocated memory
diff --git a/include/ui.hpp b/include/ui.hpp
index 5281d31..df81bab 100644
--- a/include/ui.hpp
+++ b/include/ui.hpp
@@ -22,30 +22,25 @@
#define DEBUG
-typedef uint8_t BYTE;
-typedef uint16_t WORD;
-typedef uint32_t DWORD;
-typedef int32_t LONG;
-
typedef struct{
- WORD bfType;
- DWORD bfSize;
- WORD bfReserved1, bfReserved2;
- DWORD bfOffBits; //how many bytes before the image data
+ uint16_t bfType;
+ uint32_t bfSize;
+ uint16_t bfReserved1, bfReserved2;
+ uint32_t bfOffBits; //how many bytes before the image data
} __attribute__ ((packed)) BITMAPFILEHEADER;
typedef struct{
- DWORD biSize; //size of header in bytes
- LONG biWidth;
- LONG biHeight;
- WORD biPlanes;
- WORD biBitCount; //how many bits are in a pixel
- DWORD biCompression;
- DWORD biSizeImage; //size of image in bytes
- LONG biXPelsPerMeter;
- LONG biYPelsPerMeter;
- DWORD biClrUsed; //how many colors there are
- DWORD biClrImportant; //important colors
+ uint32_t biSize; //size of header in bytes
+ int32_t biWidth;
+ int32_t biHeight;
+ uint16_t biPlanes;
+ uint16_t biBitCount; //how many bits are in a pixel
+ uint32_t biCompression;
+ uint32_t biSizeImage; //size of image in bytes
+ int32_t biXPelsPerMeter;
+ int32_t biYPelsPerMeter;
+ uint32_t biClrUsed; //how many colors there are
+ uint32_t biClrImportant; //important colors
} __attribute__ ((packed)) BITMAPINFOHEADER;
namespace ui {
diff --git a/include/ui_menu.hpp b/include/ui_menu.hpp
index bfeecba..7c6f2ad 100644
--- a/include/ui_menu.hpp
+++ b/include/ui_menu.hpp
@@ -6,14 +6,15 @@
typedef void (*menuFunc)(void);
-struct menuItem {
+class menuItem {
+public:
int member;
union {
struct {
vec2 loc;
dim2 dim;
Color color;
-
+
const char *text;
menuFunc func;
} button;
@@ -21,28 +22,37 @@ struct menuItem {
vec2 loc;
dim2 dim;
Color color;
-
+
float minValue;
float maxValue;
float sliderLoc;
-
+
const char *text;
float *var;
} slider;
};
+ ~menuItem(){
+ //button.text = NULL;
+ //slider.text = NULL;
+
+ //delete[] button.text;
+ //delete[] slider.text;
+ //delete slider.var;
+ }
};
class Menu {
public:
std::vector<menuItem> items;
- Menu *child, *parent;
-
- ~Menu() {
- // TODO you CANNOT delete null pointers!
- /*child = NULL;
+ Menu *parent, *child;
+
+ ~Menu()
+ {
+ items.clear();
+ //delete child;
+ //delete parent;
+ child = NULL;
parent = NULL;
- delete child;
- delete parent;*/
}
void gotoChild(void);
@@ -55,7 +65,7 @@ namespace ui {
menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t);
menuItem createParentButton(vec2 l, dim2 d, Color c, const char* t);
menuItem createSlider(vec2 l, dim2 d, Color c, float min, float max, const char* t, float* v);
-
+
void draw(void);
}
}
diff --git a/include/world.hpp b/include/world.hpp
index bee2bcf..3625849 100644
--- a/include/world.hpp
+++ b/include/world.hpp
@@ -102,7 +102,7 @@ public:
float fireFlicker;
vec2 fireLoc;
- Light(vec2 l, Color c, float r){
+ Light(vec2 l, Color c, float r) {
loc = l;
color = c;
radius = r;
@@ -113,11 +113,11 @@ public:
flame = false;
}
- void makeFlame(void){
+ void makeFlame(void) {
flame = true;
}
- void follow(Entity *f){
+ void follow(Entity *f) {
following=f;
belongsTo = true;
}
@@ -137,7 +137,7 @@ public:
std::vector<Structures *> build;
Village(const char *meme, World *w);
- ~Village(void){}
+ ~Village(void) {}
};
/**