From 8f4cada7bf1068a9a3063636f7008cbe52875924 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 25 Feb 2016 09:26:45 -0500 Subject: ui.cpp neatinization --- include/common.h | 7 ++++++- include/ui.h | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/common.h b/include/common.h index a99e352..ff8d361 100644 --- a/include/common.h +++ b/include/common.h @@ -52,6 +52,11 @@ extern GLuint colorIndex; * This structure contains a set of coordinates for ease of coding. */ +typedef struct { + int x; + int y; +} ivec2; + typedef struct { float x; float y; @@ -74,7 +79,7 @@ typedef struct { vec2 end; } Ray; -struct col{ +struct col { float red; float green; float blue; diff --git a/include/ui.h b/include/ui.h index 6a81ff8..3e4fc8a 100644 --- a/include/ui.h +++ b/include/ui.h @@ -186,7 +186,6 @@ namespace ui { void toggleWhiteFast(void); void waitForCover(void); - void waitForNothing(unsigned int); } #endif // UI_H -- cgit v1.2.3 From 26d71799f37bc325b6db0214268f4e72eb970ee9 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 26 Feb 2016 07:49:33 -0500 Subject: village cleanup? --- include/common.h | 19 ------------------- include/world.h | 58 ++++++++++++++++++++++++++++++++++++++++++-------------- src/common.cpp | 18 ------------------ src/world.cpp | 36 ++++++++++++++++++++++------------- 4 files changed, 67 insertions(+), 64 deletions(-) (limited to 'include') diff --git a/include/common.h b/include/common.h index ff8d361..71335f2 100644 --- a/include/common.h +++ b/include/common.h @@ -185,23 +185,6 @@ extern unsigned int loops; extern GLuint shaderProgram; -/** - * This class contains a string for identification and a value. It can be used to - * save certain events for and decisions so that they can be recalled later. - */ - -class Condition { -private: - char *id; - void *value; -public: - Condition(const char *_id,void *val); - ~Condition(); - - bool sameID(const char *s); - void *getValue(void); -}; - /** * Prints a formatted debug message to the console, along with the callee's file and line * number. @@ -244,6 +227,4 @@ int strCreateFunc(const char *equ); template size_t arrAmt(N (&)[s]){return s;} -extern void *NULLPTR; - #endif // COMMON_H diff --git a/include/world.h b/include/world.h index f9e952e..56f1577 100644 --- a/include/world.h +++ b/include/world.h @@ -81,24 +81,54 @@ typedef struct line_t { unsigned char color; /**< Lightness of dirt (brown) */ } line_t; -/* - * Handle all logic that has to do with villages +class World; + +/** + * The village class, used to group structures into villages. */ +class Village { +public: + + /** + * The name of the village. + */ -struct Village{ std::string name; + + /** + * The coordinate of where the village starts. + * + * This is used to check if the player has entered the village's area. + */ + vec2 start; + + /** + * The coordinate of where the village ends. + * + * This is used to check if the player has entered the village's area. + */ + vec2 end; + + /** + * TODO + */ + bool in; + /** + * A vector of all structures that are associated with this village. + */ + std::vector build; - Village(const char *meme){ - name = meme; - end.x = -0xffffffff; - start.x = 0xffffffff; - in = false; - } + + /** + * Creates a village of name `meme` in the world `w`. + */ + + Village(const char *meme, World *w); }; /** @@ -132,8 +162,6 @@ protected: */ void singleDetect(Entity *e); - - static void villageLogic(World *world); /** * Empties all entity vectors. @@ -253,6 +281,11 @@ public: std::vector particles; + + + + std::vector village; + /** * A vector of all light elements in this world. */ @@ -264,9 +297,6 @@ public: */ std::vector sTexLoc; - - std::vectorvillage; - /** * NULLifies pointers and allocates necessary memory. This should be diff --git a/src/common.cpp b/src/common.cpp index faa7012..01c8779 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -10,8 +10,6 @@ #include #endif // __WIN32__ -void *NULLPTR = NULL; - #ifndef __WIN32__ unsigned int millis(void){ @@ -21,22 +19,6 @@ unsigned int millis(void){ #endif // __WIN32__ -Condition::Condition(const char *_id,void *val){ - id = new char[strlen(_id)+1]; - strcpy(id,_id); - value = val; -} -Condition::~Condition(){ - delete[] id; -} - -bool Condition::sameID(const char *s){ - return !strcmp(id,s); -} -void *Condition::getValue(void){ - return value; -} - void DEBUG_prints(const char* file, int line, const char *s,...){ va_list args; printf("%s:%d: ",file,line); diff --git a/src/world.cpp b/src/world.cpp index 2df0712..303d53b 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -999,13 +999,13 @@ void World::detect(Player *p){ } for(auto &v : village){ - if(p->loc.x > v.start.x && p->loc.x < v.end.x){ - if(!v.in){ - ui::passiveImportantText(5000,"Welcome to %s",v.name.c_str()); - v.in = true; + if(p->loc.x > v->start.x && p->loc.x < v->end.x){ + if(!v->in){ + ui::passiveImportantText(5000,"Welcome to %s",v->name.c_str()); + v->in = true; } }else{ - v.in = false; + v->in = false; } } @@ -1614,8 +1614,11 @@ World *loadWorldFromXMLNoSave(const char *path){ wxml = wxml->NextSiblingElement(); } + Village *vptr; + if(vil){ - tmp->village.push_back(vil->Attribute("name")); + tmp->village.push_back(new Village(vil->Attribute("name"), tmp)); + vptr = tmp->village.back(); vil = vil->FirstChildElement(); } @@ -1627,22 +1630,22 @@ World *loadWorldFromXMLNoSave(const char *path){ /** * READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE */ + if(!strcmp(name,"structure")){ ptr = vil->Attribute("inside"); tmp->addStructure((BUILD_SUB)vil->UnsignedAttribute("type"), - vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ? - randx : spawnx, + vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ? randx : spawnx, 100, (char*)vil->Attribute("texture"), ptr); - tmp->village.back().build.push_back(tmp->build.back()); + vptr->build.push_back(tmp->build.back()); } - if(tmp->village.back().build.back()->loc.x < tmp->village.back().start.x){ - tmp->village.back().start.x = tmp->village.back().build.back()->loc.x; + if(vptr->build.back()->loc.x < vptr->start.x){ + vptr->start.x = vptr->build.back()->loc.x; } - if(tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width > tmp->village.back().end.x){ - tmp->village.back().end.x = tmp->village.back().build.back()->loc.x + tmp->village.back().build.back()->width; + if(vptr->build.back()->loc.x + vptr->build.back()->width > vptr->end.x){ + vptr->end.x = vptr->build.back()->loc.x + vptr->build.back()->width; } //go to the next element in the village block @@ -1657,3 +1660,10 @@ World *loadWorldFromXMLNoSave(const char *path){ return tmp; } + +Village::Village(const char *meme, World *w){ + name = meme; + start.x = w->getTheWidth() / 2.0f; + end.x = -start.x; + in = false; +} -- cgit v1.2.3