diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Texture.h | 7 | ||||
-rw-r--r-- | include/common.h | 41 | ||||
-rw-r--r-- | include/entities.h | 47 | ||||
-rw-r--r-- | include/freetype/config/ftconfig.h (renamed from include/freetype2/config/ftconfig.h) | 0 | ||||
-rw-r--r-- | include/freetype/config/ftheader.h (renamed from include/freetype2/config/ftheader.h) | 0 | ||||
-rw-r--r-- | include/freetype/config/ftmodule.h (renamed from include/freetype2/config/ftmodule.h) | 0 | ||||
-rw-r--r-- | include/freetype/config/ftoption.h (renamed from include/freetype2/config/ftoption.h) | 0 | ||||
-rw-r--r-- | include/freetype/config/ftstdlib.h (renamed from include/freetype2/config/ftstdlib.h) | 0 | ||||
-rw-r--r-- | include/freetype/freetype.h (renamed from include/freetype2/freetype.h) | 0 | ||||
-rw-r--r-- | include/freetype/ft2build.h (renamed from include/freetype2/ft2build.h) | 4 | ||||
-rw-r--r-- | include/freetype/ftadvanc.h (renamed from include/freetype2/ftadvanc.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftautoh.h (renamed from include/freetype2/ftautoh.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftbbox.h (renamed from include/freetype2/ftbbox.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftbdf.h (renamed from include/freetype2/ftbdf.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftbitmap.h (renamed from include/freetype2/ftbitmap.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftbzip2.h (renamed from include/freetype2/ftbzip2.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftcache.h (renamed from include/freetype2/ftcache.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftcffdrv.h (renamed from include/freetype2/ftcffdrv.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftchapters.h (renamed from include/freetype2/ftchapters.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftcid.h (renamed from include/freetype2/ftcid.h) | 0 | ||||
-rw-r--r-- | include/freetype/fterrdef.h (renamed from include/freetype2/fterrdef.h) | 0 | ||||
-rw-r--r-- | include/freetype/fterrors.h (renamed from include/freetype2/fterrors.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftgasp.h (renamed from include/freetype2/ftgasp.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftglyph.h (renamed from include/freetype2/ftglyph.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftgxval.h (renamed from include/freetype2/ftgxval.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftgzip.h (renamed from include/freetype2/ftgzip.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftimage.h (renamed from include/freetype2/ftimage.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftincrem.h (renamed from include/freetype2/ftincrem.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftlcdfil.h (renamed from include/freetype2/ftlcdfil.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftlist.h (renamed from include/freetype2/ftlist.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftlzw.h (renamed from include/freetype2/ftlzw.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftmac.h (renamed from include/freetype2/ftmac.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftmm.h (renamed from include/freetype2/ftmm.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftmodapi.h (renamed from include/freetype2/ftmodapi.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftmoderr.h (renamed from include/freetype2/ftmoderr.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftotval.h (renamed from include/freetype2/ftotval.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftoutln.h (renamed from include/freetype2/ftoutln.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftpfr.h (renamed from include/freetype2/ftpfr.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftrender.h (renamed from include/freetype2/ftrender.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftsizes.h (renamed from include/freetype2/ftsizes.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftsnames.h (renamed from include/freetype2/ftsnames.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftstroke.h (renamed from include/freetype2/ftstroke.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftsynth.h (renamed from include/freetype2/ftsynth.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftsystem.h (renamed from include/freetype2/ftsystem.h) | 0 | ||||
-rw-r--r-- | include/freetype/fttrigon.h (renamed from include/freetype2/fttrigon.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftttdrv.h (renamed from include/freetype2/ftttdrv.h) | 0 | ||||
-rw-r--r-- | include/freetype/fttypes.h (renamed from include/freetype2/fttypes.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftwinfnt.h (renamed from include/freetype2/ftwinfnt.h) | 0 | ||||
-rw-r--r-- | include/freetype/ftxf86.h (renamed from include/freetype2/ftxf86.h) | 0 | ||||
-rw-r--r-- | include/freetype/t1tables.h (renamed from include/freetype2/t1tables.h) | 0 | ||||
-rw-r--r-- | include/freetype/ttnameid.h (renamed from include/freetype2/ttnameid.h) | 0 | ||||
-rw-r--r-- | include/freetype/tttables.h (renamed from include/freetype2/tttables.h) | 0 | ||||
-rw-r--r-- | include/freetype/tttags.h (renamed from include/freetype2/tttags.h) | 0 | ||||
-rw-r--r-- | include/freetype/ttunpat.h (renamed from include/freetype2/ttunpat.h) | 0 | ||||
-rw-r--r-- | include/inventory.h | 1 | ||||
-rw-r--r-- | include/threadpool.h | 53 | ||||
-rwxr-xr-x | include/tinyxml2.h | 7 | ||||
-rw-r--r-- | include/ui.h | 11 | ||||
-rw-r--r-- | include/world.h | 211 |
59 files changed, 244 insertions, 138 deletions
diff --git a/include/Texture.h b/include/Texture.h index c6376cb..7201a4c 100644 --- a/include/Texture.h +++ b/include/Texture.h @@ -27,13 +27,13 @@ namespace Texture{ * later referencing of the texture. */ - GLuint loadTexture(const char *fileName); + GLuint loadTexture(std::string fileName); void freeTextures(void); void initColorIndex(); vec2 getIndex(Color c); - dim2 imageDim(const char *fileName); + dim2 imageDim(std::string fileName); } /** @@ -58,7 +58,7 @@ public: * Contains an array of the GLuints returned from Texture::loadTexture(). */ - GLuint *image = NULL; + std::vector<GLuint> image; /** * Populates the image array from a list of strings, with each string as a @@ -73,6 +73,7 @@ public: Texturec(uint amt,const char **paths); Texturec(std::vector<std::string>vec); + Texturec( std::initializer_list<std::string> l ); /** * Frees memory taken by the image array. diff --git a/include/common.h b/include/common.h index a99e352..58d561f 100644 --- a/include/common.h +++ b/include/common.h @@ -8,16 +8,18 @@ #ifndef COMMON_H #define COMMON_H +// holy moly #include <iostream> #include <cstdlib> #include <string> #include <vector> -#include <math.h> #include <string> #include <fstream> #include <thread> #include <mutex> #include <future> +#include <math.h> +#include <threadpool.h> #define GLEW_STATIC #include <GL/glew.h> @@ -46,13 +48,18 @@ N abso(N v){ return v; } -extern GLuint colorIndex; +extern GLuint colorIndex; // Texture.cpp? /** * This structure contains a set of coordinates for ease of coding. */ typedef struct { + int x; + int y; +} ivec2; + +typedef struct { float x; float y; } vec2; @@ -63,7 +70,7 @@ typedef struct { float z; } vec3; -typedef vec2 dim2; +typedef ivec2 dim2; /** * This structure contains two sets of coordinates for ray drawing. @@ -74,7 +81,7 @@ typedef struct { vec2 end; } Ray; -struct col{ +struct col { float red; float green; float blue; @@ -98,7 +105,7 @@ typedef col Color; * Define the game's name (displayed in the window title). */ -#define GAME_NAME "Independent Study v.0.5 alpha - NOW WITH SOUND!" +#define GAME_NAME "Independent Study v.0.6 alpha - NOW WITH more c++" /** * The desired width of the game window. @@ -113,6 +120,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. @@ -143,6 +152,9 @@ extern float VOLUME_SFX; #define getRand() rand() +#define randGet rand +#define randInit srand + /** * Included in common.h is a prototype for DEBUG_prints, which writes a formatted * string to the console containing the callee's file and line number. This macro simplifies @@ -181,23 +193,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. */ @@ -239,6 +234,6 @@ int strCreateFunc(const char *equ); template<typename N, size_t s> size_t arrAmt(N (&)[s]){return s;} -extern void *NULLPTR; +void UserError(std::string reason); #endif // COMMON_H diff --git a/include/entities.h b/include/entities.h index 926eeae..ef421f5 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,25 @@ enum BUILD_SUB{ HOUSE4 = 4, FOUNTAIN = 5, LAMP_POST = 6, - FIRE_PIT = 7 + FIRE_PIT = 7, + STALL_MARKET = 70, + STALL_TRADER = 71 +}; + +class Trade{ +public: + std::string item[2]; + int quantity[2]; + Trade(int qo, const char* o, int qt, const char* t){ + item[0] = o; + item[1] = t; + + quantity[0] = qo; + quantity[1] = qt; + + std::cout << "Trading: " << quantity[0] << " " << item[0] << " for " << quantity[1] << " " << item[1] << std::endl; + } + Trade(){} }; class World; @@ -112,6 +130,7 @@ void initEntity(); class Entity{ public: + Entity *followee; Inventory *inv; /* @@ -166,6 +185,8 @@ public: virtual void wander(int){} virtual void interact(){} + + void follow(Entity *e); virtual ~Entity(){} }; @@ -191,16 +212,26 @@ 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<Trade>trade; + + void interact(); + + Merchant(); + ~Merchant(); +}; + class Structures : public Entity{ public: BUILD_SUB bsubtype; World *inWorld; - char *inside; - char *textureLoc; + std::string inside; + std::string textureLoc; Structures(); ~Structures(); @@ -225,11 +256,11 @@ class Object : public Entity{ private: std::string iname; public: - char *pickupDialog; + std::string pickupDialog; bool questObject = false; Object(); - Object(std::string in,const char *pd); + Object(std::string in,std::string pd); ~Object(); void reloadTexture(void); diff --git a/include/freetype2/config/ftconfig.h b/include/freetype/config/ftconfig.h index 11d5d95..11d5d95 100644 --- a/include/freetype2/config/ftconfig.h +++ b/include/freetype/config/ftconfig.h diff --git a/include/freetype2/config/ftheader.h b/include/freetype/config/ftheader.h index b623629..b623629 100644 --- a/include/freetype2/config/ftheader.h +++ b/include/freetype/config/ftheader.h diff --git a/include/freetype2/config/ftmodule.h b/include/freetype/config/ftmodule.h index d1b938b..d1b938b 100644 --- a/include/freetype2/config/ftmodule.h +++ b/include/freetype/config/ftmodule.h diff --git a/include/freetype2/config/ftoption.h b/include/freetype/config/ftoption.h index 84eb8d0..84eb8d0 100644 --- a/include/freetype2/config/ftoption.h +++ b/include/freetype/config/ftoption.h diff --git a/include/freetype2/config/ftstdlib.h b/include/freetype/config/ftstdlib.h index b940efc..b940efc 100644 --- a/include/freetype2/config/ftstdlib.h +++ b/include/freetype/config/ftstdlib.h diff --git a/include/freetype2/freetype.h b/include/freetype/freetype.h index 39a18af..39a18af 100644 --- a/include/freetype2/freetype.h +++ b/include/freetype/freetype.h diff --git a/include/freetype2/ft2build.h b/include/freetype/ft2build.h index 6f8eb7f..419b80a 100644 --- a/include/freetype2/ft2build.h +++ b/include/freetype/ft2build.h @@ -4,7 +4,7 @@ /* */ /* FreeType 2 build and setup macros. */ /* */ -/* Copyright 1996-2001, 2006, 2013 by */ +/* Copyright 1996-2015 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -34,7 +34,7 @@ #ifndef __FT2BUILD_H__ #define __FT2BUILD_H__ -#include <config/ftheader.h> +#include <freetype/config/ftheader.h> #endif /* __FT2BUILD_H__ */ diff --git a/include/freetype2/ftadvanc.h b/include/freetype/ftadvanc.h index 8f7e2fc..8f7e2fc 100644 --- a/include/freetype2/ftadvanc.h +++ b/include/freetype/ftadvanc.h diff --git a/include/freetype2/ftautoh.h b/include/freetype/ftautoh.h index bf97b3f..bf97b3f 100644 --- a/include/freetype2/ftautoh.h +++ b/include/freetype/ftautoh.h diff --git a/include/freetype2/ftbbox.h b/include/freetype/ftbbox.h index 8938841..8938841 100644 --- a/include/freetype2/ftbbox.h +++ b/include/freetype/ftbbox.h diff --git a/include/freetype2/ftbdf.h b/include/freetype/ftbdf.h index 4f8baf8..4f8baf8 100644 --- a/include/freetype2/ftbdf.h +++ b/include/freetype/ftbdf.h diff --git a/include/freetype2/ftbitmap.h b/include/freetype/ftbitmap.h index 7dbf5ba..7dbf5ba 100644 --- a/include/freetype2/ftbitmap.h +++ b/include/freetype/ftbitmap.h diff --git a/include/freetype2/ftbzip2.h b/include/freetype/ftbzip2.h index 1bf81b1..1bf81b1 100644 --- a/include/freetype2/ftbzip2.h +++ b/include/freetype/ftbzip2.h diff --git a/include/freetype2/ftcache.h b/include/freetype/ftcache.h index a5d7100..a5d7100 100644 --- a/include/freetype2/ftcache.h +++ b/include/freetype/ftcache.h diff --git a/include/freetype2/ftcffdrv.h b/include/freetype/ftcffdrv.h index e4d039d..e4d039d 100644 --- a/include/freetype2/ftcffdrv.h +++ b/include/freetype/ftcffdrv.h diff --git a/include/freetype2/ftchapters.h b/include/freetype/ftchapters.h index 4b1059a..4b1059a 100644 --- a/include/freetype2/ftchapters.h +++ b/include/freetype/ftchapters.h diff --git a/include/freetype2/ftcid.h b/include/freetype/ftcid.h index 203a30c..203a30c 100644 --- a/include/freetype2/ftcid.h +++ b/include/freetype/ftcid.h diff --git a/include/freetype2/fterrdef.h b/include/freetype/fterrdef.h index 76c7b9e..76c7b9e 100644 --- a/include/freetype2/fterrdef.h +++ b/include/freetype/fterrdef.h diff --git a/include/freetype2/fterrors.h b/include/freetype/fterrors.h index 0fa3e4d..0fa3e4d 100644 --- a/include/freetype2/fterrors.h +++ b/include/freetype/fterrors.h diff --git a/include/freetype2/ftgasp.h b/include/freetype/ftgasp.h index 453d4fa..453d4fa 100644 --- a/include/freetype2/ftgasp.h +++ b/include/freetype/ftgasp.h diff --git a/include/freetype2/ftglyph.h b/include/freetype/ftglyph.h index 2d30ed9..2d30ed9 100644 --- a/include/freetype2/ftglyph.h +++ b/include/freetype/ftglyph.h diff --git a/include/freetype2/ftgxval.h b/include/freetype/ftgxval.h index 6d38e32..6d38e32 100644 --- a/include/freetype2/ftgxval.h +++ b/include/freetype/ftgxval.h diff --git a/include/freetype2/ftgzip.h b/include/freetype/ftgzip.h index 78e7269..78e7269 100644 --- a/include/freetype2/ftgzip.h +++ b/include/freetype/ftgzip.h diff --git a/include/freetype2/ftimage.h b/include/freetype/ftimage.h index b66f036..b66f036 100644 --- a/include/freetype2/ftimage.h +++ b/include/freetype/ftimage.h diff --git a/include/freetype2/ftincrem.h b/include/freetype/ftincrem.h index aaf689f..aaf689f 100644 --- a/include/freetype2/ftincrem.h +++ b/include/freetype/ftincrem.h diff --git a/include/freetype2/ftlcdfil.h b/include/freetype/ftlcdfil.h index 39206f0..39206f0 100644 --- a/include/freetype2/ftlcdfil.h +++ b/include/freetype/ftlcdfil.h diff --git a/include/freetype2/ftlist.h b/include/freetype/ftlist.h index 241e21e..241e21e 100644 --- a/include/freetype2/ftlist.h +++ b/include/freetype/ftlist.h diff --git a/include/freetype2/ftlzw.h b/include/freetype/ftlzw.h index 00d4016..00d4016 100644 --- a/include/freetype2/ftlzw.h +++ b/include/freetype/ftlzw.h diff --git a/include/freetype2/ftmac.h b/include/freetype/ftmac.h index 42874fe..42874fe 100644 --- a/include/freetype2/ftmac.h +++ b/include/freetype/ftmac.h diff --git a/include/freetype2/ftmm.h b/include/freetype/ftmm.h index 837975a..837975a 100644 --- a/include/freetype2/ftmm.h +++ b/include/freetype/ftmm.h diff --git a/include/freetype2/ftmodapi.h b/include/freetype/ftmodapi.h index 22878f8..22878f8 100644 --- a/include/freetype2/ftmodapi.h +++ b/include/freetype/ftmodapi.h diff --git a/include/freetype2/ftmoderr.h b/include/freetype/ftmoderr.h index 5a27db1..5a27db1 100644 --- a/include/freetype2/ftmoderr.h +++ b/include/freetype/ftmoderr.h diff --git a/include/freetype2/ftotval.h b/include/freetype/ftotval.h index bb52dc4..bb52dc4 100644 --- a/include/freetype2/ftotval.h +++ b/include/freetype/ftotval.h diff --git a/include/freetype2/ftoutln.h b/include/freetype/ftoutln.h index 8c7c57d..8c7c57d 100644 --- a/include/freetype2/ftoutln.h +++ b/include/freetype/ftoutln.h diff --git a/include/freetype2/ftpfr.h b/include/freetype/ftpfr.h index 0b7b7d4..0b7b7d4 100644 --- a/include/freetype2/ftpfr.h +++ b/include/freetype/ftpfr.h diff --git a/include/freetype2/ftrender.h b/include/freetype/ftrender.h index dd0229b..dd0229b 100644 --- a/include/freetype2/ftrender.h +++ b/include/freetype/ftrender.h diff --git a/include/freetype2/ftsizes.h b/include/freetype/ftsizes.h index 4167045..4167045 100644 --- a/include/freetype2/ftsizes.h +++ b/include/freetype/ftsizes.h diff --git a/include/freetype2/ftsnames.h b/include/freetype/ftsnames.h index 88af440..88af440 100644 --- a/include/freetype2/ftsnames.h +++ b/include/freetype/ftsnames.h diff --git a/include/freetype2/ftstroke.h b/include/freetype/ftstroke.h index a498e4a..a498e4a 100644 --- a/include/freetype2/ftstroke.h +++ b/include/freetype/ftstroke.h diff --git a/include/freetype2/ftsynth.h b/include/freetype/ftsynth.h index 839ab5e..839ab5e 100644 --- a/include/freetype2/ftsynth.h +++ b/include/freetype/ftsynth.h diff --git a/include/freetype2/ftsystem.h b/include/freetype/ftsystem.h index e07460c..e07460c 100644 --- a/include/freetype2/ftsystem.h +++ b/include/freetype/ftsystem.h diff --git a/include/freetype2/fttrigon.h b/include/freetype/fttrigon.h index 65143cb..65143cb 100644 --- a/include/freetype2/fttrigon.h +++ b/include/freetype/fttrigon.h diff --git a/include/freetype2/ftttdrv.h b/include/freetype/ftttdrv.h index 70ad3d5..70ad3d5 100644 --- a/include/freetype2/ftttdrv.h +++ b/include/freetype/ftttdrv.h diff --git a/include/freetype2/fttypes.h b/include/freetype/fttypes.h index bd944a4..bd944a4 100644 --- a/include/freetype2/fttypes.h +++ b/include/freetype/fttypes.h diff --git a/include/freetype2/ftwinfnt.h b/include/freetype/ftwinfnt.h index 0b67351..0b67351 100644 --- a/include/freetype2/ftwinfnt.h +++ b/include/freetype/ftwinfnt.h diff --git a/include/freetype2/ftxf86.h b/include/freetype/ftxf86.h index 493cccd..493cccd 100644 --- a/include/freetype2/ftxf86.h +++ b/include/freetype/ftxf86.h diff --git a/include/freetype2/t1tables.h b/include/freetype/t1tables.h index a14255e..a14255e 100644 --- a/include/freetype2/t1tables.h +++ b/include/freetype/t1tables.h diff --git a/include/freetype2/ttnameid.h b/include/freetype/ttnameid.h index 9711d1d..9711d1d 100644 --- a/include/freetype2/ttnameid.h +++ b/include/freetype/ttnameid.h diff --git a/include/freetype2/tttables.h b/include/freetype/tttables.h index bb49dc0..bb49dc0 100644 --- a/include/freetype2/tttables.h +++ b/include/freetype/tttables.h diff --git a/include/freetype2/tttags.h b/include/freetype/tttags.h index d59aa19..d59aa19 100644 --- a/include/freetype2/tttags.h +++ b/include/freetype/tttags.h diff --git a/include/freetype2/ttunpat.h b/include/freetype/ttunpat.h index a016275..a016275 100644 --- a/include/freetype2/ttunpat.h +++ b/include/freetype/ttunpat.h diff --git a/include/inventory.h b/include/inventory.h index 8225ab2..69cf073 100644 --- a/include/inventory.h +++ b/include/inventory.h @@ -62,6 +62,7 @@ void initInventorySprites(void); void destroyInventory(void); const char *getItemTexturePath(std::string name); +GLuint getItemTexture(std::string name); float getItemWidth(std::string name); float getItemHeight(std::string name); 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/tinyxml2.h b/include/tinyxml2.h index fb7464a..4282642 100755 --- a/include/tinyxml2.h +++ b/include/tinyxml2.h @@ -38,6 +38,8 @@ distribution. # include <cstring>
#endif
+#include <string>
+
/*
TODO: intern strings instead of allocation.
*/
@@ -1187,6 +1189,11 @@ public: */
const char* Attribute( const char* name, const char* value=0 ) const;
+ /** Functions the same as Attribute(), but returns the result
+ as a std::string.
+ */
+ std::string StrAttribute( const char* name, const char* value=0 ) const;
+
/** Given an attribute name, IntAttribute() returns the value
of the attribute interpreted as an integer. 0 will be
returned if there is an error. For a method with error
diff --git a/include/ui.h b/include/ui.h index 6a81ff8..ed9fb94 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,Trade trade,const char *opt,bool passive,const char *text,...); + void merchantBox(); void waitForDialog(void); /* @@ -186,7 +186,6 @@ namespace ui { void toggleWhiteFast(void); void waitForCover(void); - void waitForNothing(unsigned int); } #endif // UI_H diff --git a/include/world.h b/include/world.h index f9e952e..a60eab6 100644 --- a/include/world.h +++ b/include/world.h @@ -11,24 +11,11 @@ #include <common.h> #include <entities.h> -/** - * Defines at what interval y values should be calculated for the array 'line'. - */ - -#define GEN_INC 10 - -/** - * Defines the lowest possible y value for a world line. - */ - -#define GEN_MIN 80 - -/** - * Defines the highest possible y value for a randomly generated world line. - */ - -#define GEN_MAX 110 +#define GROUND_HEIGHT_INITIAL 80 +#define GROUND_HEIGHT_MINIMUM 60 +#define GROUND_HEIGHT_MAXIMUM 110 +#define GROUND_HILLINESS 10 /** * Defines how many game ticks it takes for a day to elapse. @@ -42,10 +29,10 @@ * in World::setBackground() to select the appropriate images. */ -typedef enum { - BG_FOREST, /**< A forest theme. */ - BG_WOODHOUSE /**< An indoor wooden house theme. */ -} WORLD_BG_TYPE; +enum class WorldBGType : unsigned char { + Forest, /**< A forest theme. */ + WoodHouse /**< An indoor wooden house theme. */ +}; /** * The weather type enum. @@ -53,11 +40,11 @@ typedef enum { * Weather is set by the world somewhere. */ -typedef enum { - SUNNY = 0, /**< Sunny/daytime */ - DARK, /**< Nighttime */ - RAIN /**< Rain (to be implemented)*/ -} WEATHER; +enum class WorldWeather : unsigned char { + Sunny = 0, /**< Sunny/daytime */ + Dark, /**< Nighttime */ + Rain /**< Rain (to be implemented)*/ +}; /** * The light structure, used to store light coordinates and color. @@ -74,31 +61,43 @@ typedef struct { * lines. Dirt color and grass properties are also kept track of here. */ -typedef struct line_t { - float y; /**< Height of this vertical line */ - bool gs; /**< Show grass */ - float gh[2]; /**< Height of glass (2 blades per line) */ - unsigned char color; /**< Lightness of dirt (brown) */ -} line_t; +typedef struct { + bool grassUnpressed; + float grassHeight[2]; + float groundHeight; + unsigned char groundColor; +} WorldData; -/* - * Handle all logic that has to do with villages +/** + * A value used by World::draw() for shading, ranges from -50 to 50 depending + * on the current time of day. */ +extern int worldShade; + +/** + * The path to the currently loaded XML file. + */ -struct Village{ +extern std::string currentXML; + +// prototype so Village can reference it +class World; + +/** + * The village class, used to group structures into villages. + */ + +class Village { +public: std::string name; vec2 start; vec2 end; bool in; - std::vector<Structures *> build; - Village(const char *meme){ - name = meme; - end.x = -0xffffffff; - start.x = 0xffffffff; - in = false; - } + + Village(const char *meme, World *w); + ~Village(void){} }; /** @@ -113,7 +112,7 @@ protected: * of elements provided by the function. */ - struct line_t *line; + std::vector<WorldData> worldData; /** * Starting x coordinate. @@ -121,7 +120,7 @@ protected: * calculate the width of the world. */ - int x_start; + int worldStart; /** * Handle physics for a single entity. @@ -132,8 +131,6 @@ protected: */ void singleDetect(Entity *e); - - static void villageLogic(World *world); /** * Empties all entity vectors. @@ -159,7 +156,7 @@ protected: * An array of star coordinates. */ - vec2 *star; + std::vector<vec2> star; /** * The Texturec object that holds the background sprites for this world. @@ -171,7 +168,7 @@ protected: * Defines the set of background images that should be used for this world. */ - WORLD_BG_TYPE bgType; + WorldBGType bgType; /** * The Mix_Music object that holds the background soundtrack for the world. @@ -183,7 +180,8 @@ protected: * The file path of the song wished to be loaded by bgmObj. */ - char *bgm; + std::string bgm; + std::vector<std::string>bgFiles; std::vector<std::string>bgFilesIndoors; @@ -215,7 +213,6 @@ public: char *setToRight(const char *file); - /** * A vector of pointers to every NPC, Structure, Mob, and Object in this * world. @@ -228,6 +225,7 @@ public: */ std::vector<NPC *> npc; + std::vector<Merchant *> merchant; /** * A vector of all Structures in this world. @@ -251,22 +249,22 @@ public: * A vector of all particles in this world. */ - std::vector<Particles *> particles; + std::vector<Particles> particles; + + + std::vector<Village *> village; /** * A vector of all light elements in this world. */ - std::vector<Light > light; + std::vector<Light> light; /** * Vector of all building textures for the current world style */ - std::vector<std::string > sTexLoc; - - std::vector<Village>village; - + std::vector<std::string> sTexLoc; /** * NULLifies pointers and allocates necessary memory. This should be @@ -274,7 +272,7 @@ public: * generate(). */ - World(void); + World( void ); /** * Frees resources taken by the world. @@ -289,8 +287,7 @@ public: * the structure. */ - void addStructure(BUILD_SUB subtype,float x,float y, char* tex, const char *inside); - //void addVillage(int buildingCount, int npcMin, int npcMax,const char *inside); + void addStructure(BUILD_SUB subtype,float x,float y, std::string tex, std::string inside); /** * Adds a Mob to the world with the specified type and coordinates. @@ -312,12 +309,18 @@ public: void addNPC(float x,float y); /** + * Adds a Merchant to the world at the specified coordinates. + */ + + void addMerchant(float x, float y); + + /** * Adds an object to the world with the specified item id and coordinates. * If `pickupDialog` is not NULL, that string will display in a dialog box * upon object interaction. */ - void addObject(/*ITEM_ID id*/std::string in,const char *pickupDialog, float x, float y); + void addObject( std::string in, std::string pickupDialog, float x, float y); /** * Adds a particle to the world with the specified coordinates, dimensions, @@ -331,13 +334,6 @@ public: */ void addLight(vec2 xy, Color color); - - /** - * Get the next NPC in the NPC vector that currently lacks a written dialog. - * Could be used to assign random NPCs non-random dialogs. - */ - - NPC *getAvailableNPC(void); /** * Updates the coordinates of everything in the world that has coordinates @@ -355,19 +351,11 @@ public: virtual void generate(unsigned int width); /** - * Generates a world of the provided width using the given function to - * determine ground coordinates. The given y coordinates from the function - * are limited to a certain range, most likely from GEN_MIN to 2000. - */ - - void generateFunc(unsigned int width,float(*func)(float)); - - /** * Sets the background theme, collecting the required textures into a * Texturec object. */ - void setBackground(WORLD_BG_TYPE bgt); + void setBackground(WorldBGType bgt); /** * Sets the background music for the world, required for the world to be @@ -380,14 +368,14 @@ public: * Sets the worlds style folder */ - void setStyle(const char* pre); + void setStyle(std::string pre); /** * Plays/stops this world's BGM. If `prev` is not NULL, that world's BGM * will be faded out followed by the fading in of this world's BGM. */ - void bgmPlay(World *prev); + void bgmPlay(World *prev) const; /** * Draw the world and entities based on the player's coordinates. @@ -437,20 +425,14 @@ public: * Get's the world's width. */ - int getTheWidth(void); + int getTheWidth(void) const; void save(void); void load(void); }; /* - * Gets a good base y value for background rendering. -*/ - -float worldGetYBase(World *w); - -/* - * IndoorWorld - Indoor settings stored in a World class ;) + * IndoorWorld - Indoor settings stored in a World class */ class IndoorWorld : public World { @@ -462,21 +444,58 @@ public: void draw(Player *p); // Draws the world (ignores layers) }; +/** + * The arena class - creates an arena. + * + * This world, when created, expects a pointer to a Mob. This mob will be + * transported to a temporary world with the player, and the Mob will be + * killed upon exiting the arena. + */ + class Arena : public World { private: - //vec2 pxy; - //World *exit; - Mob *mmob; + + /** + * The mob that the player is fighting. + */ + + Mob *mmob; + public: - Arena(World *leave,Player *p,Mob *m); - ~Arena(void); - World *exitArena(Player *p); + + /** + * Creates a world with the player and mob, returning the player to the + * world `leave` upon exit. + */ + + Arena( World *leave, Player *p, Mob *m ); + + /** + * Frees resources taken by the arena. + */ + + ~Arena( void ); + + /** + * Attempts to exit the world, returning the player to the world they were + * last in. + */ + + World *exitArena( Player *p ); }; -extern int worldShade; -extern char *currentXML; +/** + * Loads the player into the world created by the given XML file. If a world is + * already loaded it will be saved before the transition is made. + */ + +World *loadWorldFromXML(std::string path); + +/** + * Loads the player into the XML-scripted world, but does not save data from the + * previous world if one was loaded. + */ -World *loadWorldFromXML(const char *path); -World *loadWorldFromXMLNoSave(const char *path); +World *loadWorldFromXMLNoSave(std::string path); #endif // WORLD_H |