diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/common.h | 3 | ||||
-rw-r--r-- | include/entities.h | 37 | ||||
-rw-r--r-- | include/threadpool.h | 53 | ||||
-rw-r--r-- | include/ui.h | 10 | ||||
-rw-r--r-- | include/world.h | 8 |
5 files changed, 102 insertions, 9 deletions
diff --git a/include/common.h b/include/common.h index 71335f2..557e582 100644 --- a/include/common.h +++ b/include/common.h @@ -18,6 +18,7 @@ #include <thread> #include <mutex> #include <future> +#include <threadpool.h> #define GLEW_STATIC #include <GL/glew.h> @@ -118,6 +119,8 @@ extern unsigned int SCREEN_WIDTH; extern unsigned int SCREEN_HEIGHT; extern bool FULLSCREEN; +extern bool uiLoop; +extern std::mutex mtx; /** * Define the length of a single HLINE. diff --git a/include/entities.h b/include/entities.h index 926eeae..545f0a4 100644 --- a/include/entities.h +++ b/include/entities.h @@ -22,13 +22,13 @@ enum _TYPE { STRUCTURET, PLAYERT, NPCT, + MERCHT, MOBT }; enum GENDER{ MALE, - FEMALE, - TRANSBULLSHIT + FEMALE }; enum MOB_SUB { @@ -47,7 +47,27 @@ enum BUILD_SUB{ HOUSE4 = 4, FOUNTAIN = 5, LAMP_POST = 6, - FIRE_PIT = 7 + FIRE_PIT = 7, + STALL_MARKET = 70, + STALL_TRADER = 71 +}; + +class BuySell{ +public: + int member; + union{ + struct{ + std::string item1; + std::string item2; + }trade; + struct{ + enum type{BUY,SELL}; + std::string item; + int price; + }cost; + }; + BuySell(){} + ~BuySell(){} }; class World; @@ -191,10 +211,19 @@ public: void addAIFunc(int (*func)(NPC *),bool preload); void clearAIFunc(void); - void interact(); + virtual void interact(); void wander(int); }; +class Merchant : public NPC{ +public: + std::vector<BuySell>bsinv; + void interact(); + + Merchant(); + ~Merchant(); +}; + class Structures : public Entity{ public: BUILD_SUB bsubtype; diff --git a/include/threadpool.h b/include/threadpool.h new file mode 100644 index 0000000..c341673 --- /dev/null +++ b/include/threadpool.h @@ -0,0 +1,53 @@ +#ifndef THREADPOOL_H +#define THREADPOOL_H + +#include <vector> +#include <queue> +#include <thread> +#include <mutex> +#include <condition_variable> +#include <iostream> +#include <unistd.h> + +using namespace std; + +class ThreadPool +{ +public: + + // Constructor. + ThreadPool(int threads); + + // Destructor. + ~ThreadPool(); + + // Adds task to a task queue. + void Enqueue(function<void()> f); + + // Shut down the pool. + void ShutDown(); + +private: + // Thread pool storage. + vector<thread> threadPool; + + // Queue to keep track of incoming tasks. + queue<function<void()>> tasks; + + // Task queue mutex. + mutex tasksMutex; + + // Condition variable. + condition_variable condition; + + // Indicates that pool needs to be shut down. + bool terminate; + + // Indicates that pool has been terminated. + bool stopped; + + // Function that will be invoked by our threads. + void Invoke(); +}; + +#endif //THRE
\ No newline at end of file diff --git a/include/ui.h b/include/ui.h index 3e4fc8a..667a581 100644 --- a/include/ui.h +++ b/include/ui.h @@ -22,7 +22,6 @@ typedef void(*menuFunc)(); struct menuItem{ int member; union{ - struct{ vec2 loc; dim2 dim; @@ -30,7 +29,6 @@ struct menuItem{ const char* text; menuFunc func; }button; - struct{ vec2 loc; dim2 dim; @@ -108,9 +106,9 @@ namespace ui { extern bool posFlag; extern unsigned char dialogOptChosen; - extern bool dialogBoxExists; - extern bool dialogImportant; - extern bool dialogPassive; + extern bool dialogBoxExists; + extern bool dialogImportant; + extern bool dialogPassive; extern unsigned int textWrapLimit; @@ -148,6 +146,8 @@ namespace ui { */ void dialogBox(const char *name,const char *opt,bool passive,const char *text,...); + void merchantBox(const char *name, std::vector<BuySell> *items, const char *opt,bool passive,const char *text,...); + void merchantBox(); void waitForDialog(void); /* diff --git a/include/world.h b/include/world.h index 56f1577..228defa 100644 --- a/include/world.h +++ b/include/world.h @@ -131,6 +131,8 @@ public: Village(const char *meme, World *w); }; +extern Player *player; + /** * The world class. This class does everything a world should do. */ @@ -243,6 +245,10 @@ public: char *setToRight(const char *file); + void callUpdate(){ + this->update(player,deltaTime); + } + /** * A vector of pointers to every NPC, Structure, Mob, and Object in this @@ -256,6 +262,7 @@ public: */ std::vector<NPC *> npc; + std::vector<Merchant *> merchant; /** * A vector of all Structures in this world. @@ -340,6 +347,7 @@ public: */ void addNPC(float x,float y); + void addMerchant(float x, float y); /** * Adds an object to the world with the specified item id and coordinates. |