]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
killed common, more inventory, other random stuff
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 19 Jan 2017 21:20:13 +0000 (16:20 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 19 Jan 2017 21:20:13 +0000 (16:20 -0500)
43 files changed:
config/items.xml
include/brice.hpp
include/color.hpp [new file with mode: 0644]
include/common.hpp
include/components.hpp
include/config.hpp
include/debug.hpp [new file with mode: 0644]
include/engine.hpp
include/error.hpp [new file with mode: 0644]
include/events.hpp
include/fileio.hpp [new file with mode: 0644]
include/gametime.hpp
include/glm.hpp [new file with mode: 0644]
include/inventory.hpp
include/particle.hpp
include/player.hpp
include/quest.hpp
include/random.hpp [new file with mode: 0644]
include/render.hpp
include/shader_utils.hpp
include/texture.hpp
include/ui.hpp
include/ui_menu.hpp
include/ui_quest.hpp
include/vector2.hpp
include/vector3.hpp [new file with mode: 0644]
include/weather.hpp
include/world.hpp
main.cpp
src/brice.cpp
src/common.cpp
src/components.cpp
src/engine.cpp
src/gametime.cpp
src/inventory.cpp
src/quest.cpp
src/render.cpp
src/shader_utils.cpp
src/texture.cpp
src/ui.cpp
src/ui_menu.cpp
src/window.cpp
src/world.cpp

index 265dbf7973fa2dd812108eb1a3a46d70adc6673a..6767bc0cbac32f633672a6c8da27f4d913a18f85 100644 (file)
@@ -6,7 +6,7 @@
 <currency name="Barack Hussein Obama" value="100" sprite="assets/items/coin3.png"/>
 
 <!-- OLD ITEMS -->
-<item name="Debug"          type="Tool"         value="10" maxStackSize="1"   width="1"  height="1"  sprite="assets/items/ITEM_TEST.png" />
+<item name="Debug"          type="Tool"         value="10" maxStackSize="2"   width="1"  height="1"  sprite="assets/items/ITEM_TEST.png" />
 <item name="Dank MayMay"    type="Tool"         value="10" maxStackSize="420" width="10" height="10" sprite="assets/items/ITEM_TEST.png" />
 <item name="Your Bag"       type="Equip"        value="32" maxStackSize="1"   width="5"  height="5"  sprite="assets/items/ITEM_TEST.png" />
 <item name="Flashlight"     type="Tool"         value="1"  maxStackSize="1"   width="4"  height="8"  sprite="assets/items/flashlight_off.png" />
index 1c4eccfe0dc5397876e2c7347dd93c908646eaa2..96ec25efdab91e93381eb63f1f244006001c32bc 100644 (file)
@@ -2,7 +2,6 @@
  * @file brice.hpp
  * @brief A system for saving player information.
  */
-
 #ifndef BRICE_H_
 #define BRICE_H_
 
diff --git a/include/color.hpp b/include/color.hpp
new file mode 100644 (file)
index 0000000..2c89a1c
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef COLOR_HPP_
+#define COLOR_HPP_
+
+/**
+ * Keeps track of an RGBA color.
+ */
+class Color{
+public:
+       float red;   /**< The amount of red, 0-255 or 0.0-1.0 depending on usage */
+       float green; /**< The amount of green */
+       float blue;  /**< The amount of blue */
+       float alpha; /**< Transparency */
+
+       Color(float r = 0, float g = 0, float b = 0, float a = 255)
+               : red(r), green(g), blue(b), alpha(a) {}
+
+       Color operator-(const float& a) {
+               return Color(red - a, green - a, blue - a, alpha);
+       }
+
+       Color operator+(const float& a) {
+               return Color(red + a, green + a, blue + a, alpha);
+       }
+};
+
+#endif // COLOR_HPP_
index 12444647b10504375e8ad2c6d02bb852de2dd737..b9be83175f82a0927803a03fc994eb4bf01450fb 100644 (file)
@@ -1,46 +1,9 @@
-#ifndef COMMON_H
-#define COMMON_H
-
 /**
- * @file common.h
- * @brief Common items needed by most other files.
+ * @file common.hpp
+ * @brief Common things needed by all files, in theory.
  */
-
-// standard library includes
-#include <iostream>
-#include <string>
-#include <vector>
-#include <cmath>
-#include <algorithm>
-#include <list>
-#include <iterator>
-
-// alternative windows thread library
-#ifndef __WIN32__
-#include <thread>
-#else
-#include <win32thread.hpp>
-#endif // __WIN32__
-
-// local library includes
-#define GLEW_STATIC
-#include <GL/glew.h>
-
-#include <SDL2/SDL.h>
-#include <SDL2/SDL_opengl.h>
-#include <SDL2/SDL_image.h>
-#include <SDL2/SDL_mixer.h>
-
-#include <shader_utils.hpp>
-
-#define GLM_FORCE_RADIANS
-#include <glm/glm.hpp>
-#include <glm/gtc/matrix_transform.hpp>
-#include <glm/gtc/type_ptr.hpp>
-#include <glm/gtc/noise.hpp>
-
-// game library includes
-#include <config.hpp>
+#ifndef COMMON_HPP_
+#define COMMON_HPP_
 
 // windows stuff
 #ifdef __WIN32__
@@ -48,128 +11,15 @@ using uint = unsigned int;
 #undef near
 #endif
 
-/**
- * Prints a formatted string to the terminal with file and line number, for debugging
- */
-#define DEBUG_printf(message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__)
-
-#define coalesce(v1, v2) ((v1 != nullptr) ? v1 : v2)
-
-#include <vector2.hpp>
-
-using vec2 = vector2<float>;
-using dim2 = vector2<int>;
-
-/**
- * A structure for three-dimensional points.
- */
-struct vec3 {
-       float x; /**< The x coordinate */
-       float y; /**< The y coordinate */
-       float z; /**< The z coordinate */
-
-       vec3(float _x = 0.0f, float _y = 0.0f, float _z = 1.0f)
-               : x(_x), y(_y), z(_z) {}
-};
-
-/**
- * This structure contains two sets of coordinates for ray drawing.
- */
-
-typedef struct {
-       vec2 start; /**< The start coordinate of the ray */
-       vec2 end;   /**< The end coordinate of the ray */
-} Ray;
-
-/**
- * Keeps track of an RGBA color.
- */
-class Color{
-public:
-       float red;   /**< The amount of red, 0-255 or 0.0-1.0 depending on usage */
-       float green; /**< The amount of green */
-       float blue;  /**< The amount of blue */
-       float alpha; /**< Transparency */
-
-       Color(float r = 0, float g = 0, float b = 0, float a = 255)
-               : red(r), green(g), blue(b), alpha(a) {}
-
-       Color operator-(const float& a) {
-               return Color(red - a, green - a, blue - a, alpha);
-       }
-
-       Color operator+(const float& a) {
-               return Color(red + a, green + a, blue + a, alpha);
-       }
-};
-
-/**
- * The amount of game ticks that should occur each second.
- */
-constexpr unsigned int TICKS_PER_SEC = 20;
-
-/**
- * The amount of milliseconds it takes for a game tick to fire.
- */
-constexpr float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC;
-
-/**
- * Separates a string into tokens using the given delimiter.
- *
- * @param  the string to parse
- * @param  the delimiting character
- * @return a vector of the tokens
- */
-std::vector<std::string> StringTokenizer(const std::string& str, char delim);
-
-/**
- * Returns a measurement in HLINEs
- *
- * @param the number of HLINEs, integer or decimal
- * @return the number in HLINEs
- */
-template<typename T>
-inline T HLINES(const T &n)
-{
-       return (static_cast<T>(game::HLINE) * n);
-}
-
-/**
- * A generically-named function to start the random number generator.
- * This currently redirects to the library's default, but allows for
- * a custom generator to be easily implemented.
- */
-#define randInit srand
-
-/**
- * Gets a random number (is a function).
- */
-#define randGet rand
-
 // defines pi for calculations that need it.
 constexpr float PI = 3.1415926535f;
 
-// references the variable in main.cpp, used for drawing with the player
-extern vec2 offset;
-
 /**
- *     Prints a formatted debug message to the console, along with the callee's file and line
- *     number.
+ * Gets millisecond count since epoch.
+ * @return number of milliseconds
  */
-void DEBUG_prints(const char* file, int line, const char *s,...);
-
 unsigned int millis(void);
 
-// reads the names of files in a directory into the given string vector
-int getdir(std::string dir, std::list<std::string>& files);
-
-// reads the given file into a buffer and returns a pointer to the buffer
-std::string readFile(const std::string& path);
-std::vector<std::string> readFileA(const std::string& path);
-
-// aborts the program, printing the given error
-void UserError(std::string reason);
-
 namespace std {
        template<class T>
        constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
@@ -177,4 +27,4 @@ namespace std {
        }
 }
 
-#endif // COMMON_H
+#endif // COMMON_HPP_
index e0147b0e3898f67100e7d9b7b30ea400c59023ea..449f7c3712221dd101265716490f5e43cc2ad66a 100644 (file)
@@ -5,15 +5,18 @@
  * this allows the entity to change stats or skills on the go. This also allows every "object"
  * the be an entity, and it gives the game a much better customizability over xml.
  */
-
 #ifndef COMPONENTS_HPP
 #define COMPONENTS_HPP
 
-#include <entityx/entityx.h>
-#include <common.hpp>
-#include <texture.hpp>
+#include <string>
+#include <vector>
+
 #include <events.hpp>
-#include <atomic>
+#include <random.hpp>
+#include <texture.hpp>
+#include <vector2.hpp>
+
+#include <entityx/entityx.h>
 #include <tinyxml2.h>
 using namespace tinyxml2;
 
@@ -158,7 +161,7 @@ struct SpriteData {
        vec2 offset_tex;
        vec2 size_tex;
 
-       uint limb;
+       unsigned int limb;
 };
 
 using Frame = std::vector<std::pair<SpriteData, vec2>>;
index e17df24ad650af2a337036c48f8f71729a02725f..13596ffd45be57e7f733f3922f28894ab66174d8 100644 (file)
@@ -71,4 +71,26 @@ namespace game {
        }
 }
 
+/**
+ * The amount of game ticks that should occur each second.
+ */
+constexpr unsigned int TICKS_PER_SEC = 20;
+
+/**
+ * The amount of milliseconds it takes for a game tick to fire.
+ */
+constexpr float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC;
+
+/**
+ * Returns a measurement in HLINEs
+ *
+ * @param the number of HLINEs, integer or decimal
+ * @return the number in HLINEs
+ */
+template<typename T>
+inline T HLINES(const T &n)
+{
+       return (static_cast<T>(game::HLINE) * n);
+}
+
 #endif //CONFIG_H
diff --git a/include/debug.hpp b/include/debug.hpp
new file mode 100644 (file)
index 0000000..e773a51
--- /dev/null
@@ -0,0 +1,19 @@
+/**
+ * @file debug.hpp
+ * @brief Debugging utilities
+ */
+#ifndef DEBUG_HPP_
+#define DEBUG_HPP_
+
+/**
+ * Prints a formatted string to the terminal with file and line number, for debugging
+ */
+#define DEBUG_printf(message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__)
+
+/**
+ *     Prints a formatted debug message to the console, along with the callee's file and line
+ *     number.
+ */
+void DEBUG_prints(const char* file, int line, const char *s,...);
+
+#endif // DEBUG_HPP_
index 417522d9825f1bcabd9e4a7a6ce0d39354447c28..fda9980bc190c0b7a0d13dbaa422ddaf1b3cf065 100644 (file)
@@ -6,10 +6,12 @@
 #ifndef ENGINE_HPP_
 #define ENGINE_HPP_
 
+#include <atomic>
+#include <chrono>
+#include <thread>
+
 #include <entityx/entityx.h>
-#include <entityx/deps/Dependencies.h>
 
-#include <texture.hpp>
 #include <components.hpp>
 #include <events.hpp>
 
@@ -63,9 +65,6 @@ public:
        }
 };
 
-#include <atomic>
-#include <chrono>
-
 class LockableEntityManager : public entityx::EntityManager {
 private:
        std::atomic_bool locked;
diff --git a/include/error.hpp b/include/error.hpp
new file mode 100644 (file)
index 0000000..ef61c91
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef ERROR_HPP_
+#define ERROR_HPP_
+
+#include <string>
+#include <iostream>
+
+inline void UserError(const std::string& why)
+{
+       std::cout << "User error: " << why << "!\n";
+       abort();
+}
+
+#endif // ERROR_HPP_
index 1f06544e3ec21ce4b8923d56226caa7fafd5b0ac..5939c3daf8cfa68f77f1b56f343fee0721f2fa72 100644 (file)
@@ -8,7 +8,9 @@
 #include <SDL2/SDL.h>
 
 #include <string>
-#include <common.hpp>
+
+#include <config.hpp>
+#include <vector2.hpp>
 
 class World;
 
diff --git a/include/fileio.hpp b/include/fileio.hpp
new file mode 100644 (file)
index 0000000..c5e33ec
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef FILEIO_HPP_
+#define FILEIO_HPP_
+
+#include <string>
+#include <list>
+#include <vector>
+
+// reads the names of files in a directory into the given string vector
+int getdir(std::string dir, std::list<std::string>& files);
+
+// reads the given file into a buffer and returns a pointer to the buffer
+std::string readFile(const std::string& path);
+std::vector<std::string> readFileA(const std::string& path);
+
+#endif // FILEIO_HPP_
index 988533a244f7dc6c6ed7c02ea3a73295a455d3eb..e06a0d37498d735bf6d7c3f905fb70186dbab86b 100644 (file)
@@ -2,7 +2,6 @@
  * @file gametime.hpp
  * @brief Handles time related operations
  */
-
 #ifndef GAMETIME_H_
 #define GAMETIME_H_
 
diff --git a/include/glm.hpp b/include/glm.hpp
new file mode 100644 (file)
index 0000000..9fd533f
--- /dev/null
@@ -0,0 +1,14 @@
+/**
+ * @file glm.hpp
+ * @brief Includes needed GLM files.
+ */
+#ifndef GLM_HPP_
+#define GLM_HPP_
+
+#define GLM_FORCE_RADIANS
+#include <glm/glm.hpp>
+#include <glm/gtc/matrix_transform.hpp>
+#include <glm/gtc/type_ptr.hpp>
+#include <glm/gtc/noise.hpp>
+
+#endif // GLM_HPP_
index 44ed148c06fa655bd31cae56843a05d0f8970add..2e261ae0cfb642c22abfe4382d039df48a29ef7b 100644 (file)
@@ -1,21 +1,41 @@
+/**
+ * @file inventory.hpp
+ * @brief Provides an inventory for the player.
+ */
 #ifndef INVENTORY_HPP_
 #define INVENTORY_HPP_
 
+#include <GL/glew.h>
+#include <SDL2/SDL_opengl.h>
+
+#include <string>
+#include <vector>
+
 #include <entityx/entityx.h>
+#include <tinyxml2.h>
+using namespace tinyxml2;
 
-#include <components.hpp>
 #include <events.hpp>
+#include <texture.hpp>
 
+/**
+ * @struct Item
+ * Contains the information neccessary for an item.
+ */
 struct Item {
-       std::string name;
-       std::string type;
-       int value;
-       int stackSize;
-       Texture sprite;
+       std::string name; /**< The name of the item */
+       std::string type; /**< The type of the item */
+       int value;        /**< The value/worth of the item */
+       int stackSize;    /**< The stack size of the item */
+       Texture sprite;   /**< The texture for the item (in inventory) */
 
        Item(void)
                : value(0), stackSize(1) {}
 
+       /**
+        * Constructs an item from XML.
+        * @param the xml element (<item />)
+        */
        Item(XMLElement *e) {
                name = e->StrAttribute("name");
                type = e->StrAttribute("type");
@@ -29,35 +49,62 @@ struct Item {
        }
 };
 
+/**
+ * @struct InventoryEntry
+ * Describes a slot in the player's inventory.
+ */
 struct InventoryEntry {
-       Item* item;
-       int count;
-       vec2 loc;
+       Item* item; /**< Pointer to info on what item this slot contains */
+       int count;  /**< The quantity of this item stored here */
+
+       vec2 loc;   /**< Used by render, to determine slot location on screen */
 
        InventoryEntry(void)
                : item(nullptr), count(0) {}
 };
 
+/**
+ * @class InventorySystem
+ * Handles the player's inventory system.
+ */
 class InventorySystem : public entityx::System<InventorySystem>, public entityx::Receiver<InventorySystem> {
 private:
+       /**
+        * A vector for the player's inventory slots.
+        */
     std::vector<InventoryEntry> items;
 
+    void loadItems(void);
+
 public:
-    InventorySystem(int size = 4) {
+    InventorySystem(int size = 20) {
                items.resize(size);
                loadItems();
        }
 
     void configure(entityx::EventManager &ev);
-
-    void loadItems(void);
-
     void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
-
     void receive(const KeyDownEvent &kde);
+       void receive(const MouseClickEvent &mce);
+
        void render(void);
 
+       /**
+        * Adds 'count' 'name's to the inventory.
+        * @param name the name of the item
+        * @param count the quantity of the item to give
+        */
        void add(const std::string& name, int count);
+
+       /**
+        * Takes 'count' 'name's from the inventory.
+        * If the inventory does not contain enough of the item, no items are taken
+        * and false is returned.
+        * @param name the name of the item
+        * @param count the quantity of the item to take
+        * @return true if the operation could be completed
+        */
+       bool take(const std::string& name, int count);
 };
 
 #endif // INVENTORY_HPP_
index 48a89380fa908aee2b1615acd2a6bc39b0a27d6d..f49e055ebe48f5a64ba89e37537ed44ebee2a260 100644 (file)
@@ -1,10 +1,10 @@
 #ifndef PARTICLE_HPP_
 #define PARTICLE_HPP_
 
-#include <common.hpp>
 #include <texture.hpp>
+#include <vector2.hpp>
 
-#include <list>
+#include <vector>
 
 #include <entityx/entityx.h>
 
index 85dc8212a999a19bd5dcab69adbfa9b82eac4722..56886e33979b36b0c16491745f0de81690973976 100644 (file)
@@ -2,16 +2,15 @@
  * @file player.hpp
  * @brief The player system
  */
-
 #ifndef PLAYER_HPP_
 #define PLAYER_HPP_
 
 #include <entityx/entityx.h>
 
+#include <components.hpp>
 #include <events.hpp>
 #include <engine.hpp>
-#include <components.hpp>
-#include <common.hpp>
+#include <vector2.hpp>
 
 /**
  * The constant velocity the player is given when moved with the arrow keys.
index cb43ecac8b52c78d017bf023108e5e6024398627..27b533d8e2c44abc397998295ee9cd83b1d2fdf3 100644 (file)
@@ -2,7 +2,6 @@
  * @file quest.hpp
  * Quest handling.
  */
-
 #ifndef QUEST_HPP_
 #define QUEST_HPP_
 
diff --git a/include/random.hpp b/include/random.hpp
new file mode 100644 (file)
index 0000000..198861d
--- /dev/null
@@ -0,0 +1,20 @@
+/**
+ * @file random.hpp
+ * @brief Facilities to generate random numbers.
+ */
+#ifndef RANDOM_HPP_
+#define RANDOM_HPP_
+
+/**
+ * A generically-named function to start the random number generator.
+ * This currently redirects to the library's default, but allows for
+ * a custom generator to be easily implemented.
+ */
+#define randInit srand
+
+/**
+ * Gets a random number (is a function).
+ */
+#define randGet rand
+
+#endif // RANDOM_HPP_
index 997d7d0f67306c490413622fca1d67bfb2110421..a21fcdd9bb891ba7b4cb6eb436104adf67dccf65 100644 (file)
@@ -6,8 +6,8 @@
 #include <GL/glew.h>
 #include <SDL2/SDL_opengl.h>
 
-#include <common.hpp>
 #include <shader_utils.hpp>
+#include <vector2.hpp>
 
 /**
  * @class Shader
index 06ac318314a6b9bed0b46d5f260e53fde6569393..011b26586deefe9b7f976e4854b4e2a2cc5573f2 100644 (file)
@@ -13,6 +13,7 @@
 #include <GL/glew.h>
 
 #include <SDL2/SDL.h>
+#include <SDL2/SDL_opengl.h>
 
 char* file_read(const char* filename);
 void print_log(GLuint object);
index 43db1b6fc3d1332e25f91bb2611b1166eeb05488..fb4e588a18486b1537b2a4ee7d1128cfa7dea38b 100644 (file)
@@ -6,7 +6,14 @@
 #ifndef TEXTURE_HPP_
 #define TEXTURE_HPP_
 
-#include <common.hpp>
+#include <string>
+#include <vector>
+
+#include <GL/glew.h> // must
+#include <SDL2/SDL_opengl.h>
+
+#include <color.hpp>
+#include <vector2.hpp>
 
 /**
  * When defined, DEBUG allows extra messages to be printed to the terminal for
index 67c1010e0a1e63aea28ccefc440be3203b94ebbd..ac415f57fa1b8476185062a0f129da40b0b0ff82 100644 (file)
@@ -1,49 +1,27 @@
-/* ----------------------------------------------------------------------------
-** The user interface system.
-**
-** This file contains everything user-interface related.
-** --------------------------------------------------------------------------*/
-#ifndef UI_H
-#define UI_H
+/**
+ * @file ui.hpp
+ * @brief the user interface system.
+ */
+#ifndef UI_HPP_
+#define UI_HPP_
 
-#define DEBUG
-#define SDL_KEY e.key.keysym.sym
-
-/* ----------------------------------------------------------------------------
-** Includes section
-** --------------------------------------------------------------------------*/
-
-// standard library headers
 #include <cstdarg>
-#include <cstdint>
-#include <thread>
-
-// local game headers
-#include <common.hpp>
-#include <config.hpp>
-//#include <inventory.hpp>
-#include <ui_menu.hpp>
-#include <events.hpp>
+#include <string>
 
-// local library headers
+#include <entityx/entityx.h>
+#include <GL/glew.h>
 #include <SDL2/SDL_opengl.h>
 
-#include <ft2build.h>
-#include FT_FREETYPE_H
-
-#ifndef __WIN32__
-#      include <bmpimage.hpp>
-#endif // __WIN32__
+#include <color.hpp>
+#include <events.hpp>
+#include <vector2.hpp>
 
-/* ----------------------------------------------------------------------------
-** The UI namespace
-** --------------------------------------------------------------------------*/
+#define DEBUG
+#define SDL_KEY e.key.keysym.sym
 
 void setControl(int index, SDL_Keycode key);
 SDL_Keycode getControl(int index);
 
-#include <entityx/entityx.h>
-
 class InputSystem : public entityx::System<InputSystem>, public entityx::Receiver<InputSystem> {
 public:
        inline void configure(entityx::EventManager &ev) {
@@ -168,4 +146,4 @@ namespace ui {
        void takeScreenshot(GLubyte *pixels);
 }
 
-#endif // UI_H
+#endif // UI_HPP_
index b45a76d836e4ac95a0599e453a5f9b5691f30491..528816182880223ec2a958a4786abfb0c7f3b953 100644 (file)
@@ -1,56 +1,53 @@
 #ifndef UI_MENU_H_
 #define UI_MENU_H_
 
-#include <common.hpp>
+#include <string>
+#include <vector>
+
+#include <color.hpp>
 #include <config.hpp>
 #include <ui.hpp>
+#include <vector2.hpp>
 
-typedef void (*menuFunc)(void);
+using MenuAction = std::function<void(void)>;
 
 class Menu;
 
 class menuItem {
 public:
        int member;
-       Menu *child;
+       Menuchild;
 
        vec2 loc;
        dim2 dim;
        Color color;
        std::string text;
-       //union {
-               struct {
-                       menuFunc func;
-               } button;
-
-               struct {
-                       float minValue;
-                       float maxValue;
-            float sliderLoc;
-                       float *var;
-               } slider;
-       //};
-
-       menuItem(){}
-       ~menuItem(){
-               //button.text = NULL;
-               //slider.text = NULL;
-
-               //delete[] button.text;
-               //delete[] slider.text;
-               //delete slider.var;
-       }
+
+       struct {
+               MenuAction func;
+       } button;
+
+       struct {
+               float minValue;
+               float maxValue;
+        float sliderLoc;
+               float* var;
+       } slider;
+
+       menuItem(void) {}
+
+       menuItem(vec2 l, dim2 d, Color c, std::string t, Menu* ch = nullptr)
+               : child(ch), loc(l), dim(d), color(c), text(t) {}
 };
 
 class Menu {
 public:
        std::vector<menuItem> items;
-       Menu *parent;
+       Menuparent;
 
-       ~Menu()
-       {
+       ~Menu(void) {
                items.clear();
-               parent = NULL;
+               parent = nullptr;
        }
 
        void gotoParent(void);
@@ -58,7 +55,7 @@ public:
 
 namespace ui {
     namespace menu {
-        menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f);
+        menuItem createButton(vec2 l, dim2 d, Color c, const char* t, MenuAction f);
         menuItem createChildButton(vec2 l, dim2 d, Color c, const char* ti, Menu *_child);
         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);
index d770011ce67a4b8d9cec8da2f61e1f74a20889db..a46483a3314cc43c8deaa624da6787af00fae87d 100644 (file)
@@ -2,12 +2,13 @@
  * @file ui_quest.hpp
  * @brief Handles UI elements related to quests.
  */
-
 #ifndef UI_QUEST_HPP_
 #define UI_QUEST_HPP_
 
 #include <ui.hpp>
-#include <common.hpp>
+#include <vector2.hpp>
+
+extern vec2 offset;
 
 namespace ui {
        namespace quest {
index debaee98dcb29db790b55ebb1bd2a27b2e85ff5b..17e47d13db61fad953114646f9fb9b05d9087962 100644 (file)
@@ -77,4 +77,7 @@ struct vector2 {
        }
 };
 
+using vec2 = vector2<float>;
+using dim2 = vector2<int>;
+
 #endif // VECTOR2_HPP_
diff --git a/include/vector3.hpp b/include/vector3.hpp
new file mode 100644 (file)
index 0000000..ee09eae
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef VECTOR3_HPP_
+#define VECTOR3_HPP_
+
+/**
+ * A structure for three-dimensional points.
+ */
+template<typename T>
+struct vector3 {
+       T x; /**< The x coordinate */
+       T y; /**< The y coordinate */
+       T z; /**< The z coordinate */
+
+       vector3(T _x = 0, T _y = 0, T _z = 1)
+               : x(_x), y(_y), z(_z) {}
+};
+
+using vec3 = vector3<float>;
+
+#endif // VECTOR3_HPP_
index 8e148ddcd0f31ead4addd06ef48637e76e330fcb..58a0cfa2e93c7fc88f32e653e7cbd606ed9c247c 100644 (file)
@@ -1,11 +1,15 @@
 #ifndef WEATHER_HPP_
 #define WEATHER_HPP_
 
+#include <string>
+
 #include <entityx/entityx.h>
 
-#include <common.hpp>
+#include <config.hpp>
 #include <particle.hpp>
 
+extern vec2 offset;
+
 /**
  * The weather type enum.
  * This enum contains every type of weather currently implemented in the game.
index 9b683148cea99ff0878ab5b4c0f5644e70ac54e0..fe7d819b72b6f5b853d2b912c76df5f8e9e9232e 100644 (file)
@@ -2,23 +2,24 @@
  * @file  world.hpp
  * @brief The world system
  */
+#ifndef WORLD_HPP_
+#define WORLD_HPP_
 
-#ifndef WORLD_H
-#define WORLD_H
+#include <string>
+#include <thread>
+#include <vector>
 
-// library includes
+#include <SDL2/SDL_mixer.h>
 #include <entityx/entityx.h>
 
-// local game includes
-#include <common.hpp>
-#include <coolarray.hpp>
-#include <events.hpp>
-#include <texture.hpp>
-#include <components.hpp>
 #include <tinyxml2.h>
-
 using namespace tinyxml2;
 
+#include <components.hpp>
+#include <events.hpp>
+#include <texture.hpp>
+#include <vector2.hpp>
+
 /**
  * The background type enum.
  * Used to choose which set of background images should be used.
@@ -178,4 +179,4 @@ public:
        void load(const std::string& file);
 };
 
-#endif // WORLD_H
+#endif // WORLD_HPP_
index e17b9105a097ce4804fa94d2031734ef3c7cb6fb..4a41a3a89870059b2095060723d39f8c805edb84 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -15,6 +15,8 @@ using namespace std::literals::chrono_literals;
 #include <config.hpp>
 #include <common.hpp>
 #include <engine.hpp>
+#include <error.hpp>
+#include <fileio.hpp>
 #include <gametime.hpp>
 #include <window.hpp>
 #include <world.hpp>
@@ -51,11 +53,6 @@ public:
  */
 std::string xmlFolder = "xml/";
 
-/**
- * The current menu, if any are open (TODO why is this here)
- */
-Menu *currentMenu;
-
 /**
  * The current center of the screen, updated in main render.
  */
@@ -135,7 +132,7 @@ int main(int argc, char *argv[])
 
 
        game::engine.getSystem<InventorySystem>()->add("Debug", 3);
-
+       game::engine.getSystem<InventorySystem>()->take("Debug", 2);
 
        std::list<SDL_Event> eventQueue;
 
index 53b1431184f312be87d029f2ffdf3b7e9357e3e2..e1a5b3ed6336a15c6fffc3ca7393fb181f4428f2 100644 (file)
@@ -6,6 +6,10 @@
 #include <istream>
 
 #include <common.hpp>
+#include <error.hpp>
+#include <fileio.hpp>
+
+extern std::vector<std::string> StringTokenizer(const std::string& str, char delim);
 
 static std::unordered_map<std::string, std::string> brice;
 
index 2ec80a7d20f9626ebc0749eed0ccc23e49d99eaa..37f5c78fbe4c2c781a323ec709bcae74a5514ef9 100644 (file)
@@ -1,11 +1,16 @@
 #include <common.hpp>
 
 #include <cstring>
+#include <cstdarg>
 #include <cstdio>
 #include <chrono>
 #include <fstream>
+#include <iostream>
+#include <list>
 #include <sstream>
 
+#include <error.hpp>
+
 #ifndef __WIN32__
 
 #include <sys/types.h>
index 2bd93fcef4dbabb4aff8ab41a30576da00297e10..d8321f4b5f767fa4745ef4883d39b3372b379d03 100644 (file)
@@ -9,6 +9,8 @@
 #include <world.hpp>
 #include <brice.hpp>
 #include <quest.hpp>
+#include <glm.hpp>
+#include <fileio.hpp>
 
 #include <atomic>
 
index d334aea33afe65d3b2a794f9983e3356bff4ab93..ebf595377218db5bdadf78dcaf2e1cf4f0e78d4a 100644 (file)
@@ -4,6 +4,7 @@
 #include <world.hpp>
 #include <window.hpp>
 #include <ui.hpp>
+#include <ui_menu.hpp>
 #include <inventory.hpp>
 #include <components.hpp>
 #include <player.hpp>
index cb736ff2efb4a1468c17989f7a51b7ed805795d7..a5272e578c7b5b4b298daea9820cbec3ba6fe56b 100644 (file)
@@ -1,6 +1,7 @@
 #include <gametime.hpp>
 
 #include <common.hpp> // millis
+#include <config.hpp>
 
 static unsigned int tickCount = 0;
 static unsigned int deltaTime = 1;
index 354db9c2ecc9e63d4881b6ac98f2d444583f443b..f222ef14b88cc6a76fdcce2959a15507cc694078 100644 (file)
@@ -1,23 +1,32 @@
 #include <inventory.hpp>
 
 #include <common.hpp>
-#include <events.hpp>
-#include <texture.hpp>
+#include <error.hpp>
 #include <render.hpp>
 #include <ui.hpp>
 
+#include <forward_list>
 #include <unordered_map>
 
 #include <tinyxml2.h>
 using namespace tinyxml2;
 
-constexpr const char* itemsPath = "config/items.xml";
+extern vec2 offset;
 
 static std::unordered_map<std::string, Item> itemList;
+constexpr const char* itemsPath = "config/items.xml";
+
+static bool fullInventory = false;
+
+constexpr int          entrySize = 70;
+constexpr int          hotbarSize = 4;
+constexpr float        inventoryZ = -6.0f;
+constexpr unsigned int rowSize = 8;
 
 void InventorySystem::configure(entityx::EventManager &ev)
 {
     ev.subscribe<KeyDownEvent>(*this);
+       ev.subscribe<MouseClickEvent>(*this);
 }
 
 void InventorySystem::loadItems(void) {
@@ -43,24 +52,43 @@ void InventorySystem::update(entityx::EntityManager &en, entityx::EventManager &
 
 void InventorySystem::render(void)
 {
+       int size = items.size();
+
        // calculate positions
-       items.front().loc = vec2(offset.x - 35 * items.size(), offset.y - game::SCREEN_HEIGHT / 2);
-       for (unsigned int i = 1; i < items.size(); i++)
-               items[i].loc = vec2(items[i - 1].loc.x + 70, items[i - 1].loc.y);
+       items.front().loc = vec2(offset.x - entrySize / 2 * hotbarSize, offset.y + game::SCREEN_HEIGHT / 2 - entrySize);
+       for (unsigned int i = 1; i < hotbarSize; i++)
+               items[i].loc = vec2(items[i - 1].loc.x + entrySize, items[i - 1].loc.y);
+
+       ui::drawNiceBox(items[0].loc - 10, items[hotbarSize - 1].loc + vec2(entrySize + 4, entrySize + 10), inventoryZ);
+
+       if (fullInventory) {
+               vec2 start (offset.x - entrySize * rowSize / 2, offset.y + game::SCREEN_HEIGHT / 2 - 180);
+               for (unsigned int i = hotbarSize; i < items.size(); i++) {
+                       items[i].loc = vec2(start.x + entrySize * ((i - hotbarSize) % rowSize), start.y);
+                       if ((i - hotbarSize) % rowSize == rowSize - 1)
+                               start.y -= entrySize;
+               }
+
+               ui::drawNiceBox(items[items.size() - rowSize].loc - 10, items[hotbarSize + rowSize - 1].loc + (entrySize + 4), inventoryZ);
+       } else {
+               size = hotbarSize;
+       }
 
        // draw items
-       for (const auto& i : items) {
+       for (int n = 0; n < size; n++) {
+               auto &i = items[n];
+
                // draw the slot
                Render::textShader.use();
                Render::textShader.enable();
 
                Colors::black.use();
-               glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, .8);
+               glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, .6);
                glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, Colors::texCoord);
-               vec2 end = i.loc + 64;
+               vec2 end = i.loc + entrySize - 6;
                GLfloat coords[18] = {
-                       i.loc.x, i.loc.y, -7, end.x, i.loc.y, -7, end.x, end.y, -7,
-                       end.x, end.y, -7, i.loc.x, end.y, -7, i.loc.x, i.loc.y, -7
+                       i.loc.x, i.loc.y, inventoryZ - 0.1, end.x, i.loc.y, inventoryZ - 0.1, end.x, end.y, inventoryZ - 0.1,
+                       end.x, end.y, inventoryZ - 0.1, i.loc.x, end.y, inventoryZ - 0.1, i.loc.x, i.loc.y, inventoryZ - 0.1
                };
                glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords);
                glDrawArrays(GL_TRIANGLES, 0, 6);
@@ -73,12 +101,12 @@ void InventorySystem::render(void)
                        glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
                        vec2 end = i.loc + i.item->sprite.getDim();
                        GLfloat coords[18] = {
-                               i.loc.x, i.loc.y, -7.1, end.x, i.loc.y, -7.1, end.x, end.y, -7.1,
-                               end.x, end.y, -7.1, i.loc.x, end.y, -7.1, i.loc.x, i.loc.y, -7.1
+                               i.loc.x, i.loc.y, inventoryZ - 0.2, end.x, i.loc.y, inventoryZ - 0.2, end.x, end.y, inventoryZ - 0.2,
+                               end.x, end.y, inventoryZ - 0.2, i.loc.x, end.y, inventoryZ - 0.2, i.loc.x, i.loc.y, inventoryZ - 0.2
                        };
                        glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords);
                        glDrawArrays(GL_TRIANGLES, 0, 6);
-                       ui::setFontZ(-7.2);
+                       ui::setFontZ(-7.2); // TODO fix z's
                        ui::putText(i.loc.x, i.loc.y, std::to_string(i.count).c_str());
                        ui::setFontZ(-6);
                }
@@ -88,18 +116,81 @@ void InventorySystem::render(void)
        Render::textShader.unuse();
 }
 
+void InventorySystem::receive(const MouseClickEvent &mce)
+{
+       (void)mce;      
+}
+
 void InventorySystem::receive(const KeyDownEvent &kde)
 {
-    (void)kde;
+    if (kde.keycode == SDLK_e) {
+               fullInventory ^= true;
+       }
 }
 
 void InventorySystem::add(const std::string& name, int count)
 {
-       for (auto& i : items) {
-               if (i.count == 0) {
-                       i.item = &itemList[name];
-                       i.count = count;
+       auto i = std::find_if(items.begin(), items.end(),
+               [&name](const InventoryEntry& ie) {
+                       // either matching item that isn't filled, or empty slow
+                       return (ie.item != nullptr && ie.item->name == name && ie.count < ie.item->stackSize) || ie.count == 0;
+               });
+
+       if (i != items.end()) {
+               auto& ie = *i;
+
+               // update the slot
+               if (ie.item == nullptr) {
+                       ie.item = &itemList[name];
+                       ie.count = count;
+               } else {
+                       ie.count += count;
+               }
+
+               // handle overflow
+               if (ie.count > ie.item->stackSize) {
+                       int diff = ie.count - ie.item->stackSize;
+                       ie.count = ie.item->stackSize;
+                       add(name, diff);
+               }
+       }
+}
+
+bool InventorySystem::take(const std::string& name, int count)
+{
+       using InvIter = std::vector<InventoryEntry>::iterator;
+       std::forward_list<InvIter> toDelete;
+       InvIter next = items.begin();
+       int taken = 0;
+
+       while (taken < count) {
+               auto i = std::find_if(next, items.end(),
+                       [&name](const InventoryEntry& ie) {
+                               return ie.item != nullptr && ie.item->name == name;
+                       });
+
+               if (i == items.end())
+                       break;
+
+               toDelete.push_front(i);
+               taken += i->count;
+       }       
+
+       if (taken < count)
+               return false;
+
+       for (auto& ii : toDelete) {
+               if (count > ii->count) {
+                       ii->item = nullptr;
+                       count -= ii->count;
+                       ii->count = 0;
+               } else {
+                       ii->count -= count;
+                       if (ii->count == 0)
+                               ii->item = nullptr;
                        break;
                }
        }
+
+       return true;
 }
index 1e343a661ed099622d329a28d5439e90da78bb84..8107eb65d857460fd94fb830f4ee3ddc529eae80 100644 (file)
@@ -1,8 +1,9 @@
 #include <quest.hpp>
-#include <common.hpp>
 
 #include <algorithm>
 
+extern std::vector<std::string> StringTokenizer(const std::string& str, char delim);
+
 void QuestSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
 {
        (void)en;
index 5cbd11e15001e482b75acfd3193ee8936093a4d4..303ff1c40fc2bec7c6edc245e3ad0556aa83c646 100644 (file)
@@ -1,7 +1,14 @@
 #include <render.hpp>
 
+#include <iostream>
+
+#include <config.hpp>
+#include <error.hpp>
+#include <glm.hpp>
 #include <texture.hpp>
 
+extern vec2 offset;
+
 static Shader *currentShader = nullptr;
 
 void preRender(void);
index bc9375c7d7f4425c0dd48b94ed6139b65be8a098..85060e2798ec7888a52ef1c7c433cc5fba6e3a9f 100644 (file)
@@ -1,10 +1,9 @@
+#include <shader_utils.hpp>
+
 #include <iostream>
 #include <vector>
 using namespace std;
 
-#include <shader_utils.hpp>
-//#include <SDL_opengles2.h>
-
 /**
  * Store all the file's contents in memory, useful to pass shaders
  * source code to OpenGL.  Using SDL_RWops for Android asset support.
index 721e5cb7d9d69a04a46a9160174af2a92dec7aa9..ad069678596f49d385e426fb5f8124b92d2c9e5c 100644 (file)
@@ -1,7 +1,12 @@
+#include <texture.hpp>
+
 #include <algorithm>
 #include <string>
 
-#include <texture.hpp>
+#include <SDL2/SDL_image.h>
+
+#include <debug.hpp>
+#include <error.hpp>
 
 namespace Colors
 {
index 552884f2cdfca5868db8f8c933d9fc0160eb9376..dad9454641d5b4ae1c839a6448e5bc5491265968 100644 (file)
@@ -1,5 +1,14 @@
 #include <ui.hpp>
 
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+#include <bmpimage.hpp>
+#include <debug.hpp>
+#include <error.hpp>
+#include <ui_menu.hpp>
+#include <vector3.hpp>
+
 #include <ui_quest.hpp>
 #include <brice.hpp>
 #include <world.hpp>
@@ -12,6 +21,7 @@
 #include <player.hpp>
 
 #include <chrono>
+
 using namespace std::literals::chrono_literals;
 
 extern Menu *currentMenu;
@@ -40,24 +50,19 @@ SDL_Keycode getControl(int index)
 static FT_Library   ftl;
 static FT_Face      ftf;
 
-typedef struct {
+struct FT_Info {
        vec2 wh;
        vec2 bl;
        vec2 ad;
-} FT_Info;
+       GLuint tex;
 
-static std::vector<FT_Info> ftdat16 (93, { { 0, 0 }, { 0, 0 }, { 0, 0 } });
-static std::vector<GLuint>  ftex16  (93, 0);
-static bool ft16loaded = false;
-
-static std::vector<FT_Info> ftdat24 (93, { { 0, 0 }, { 0, 0 }, { 0, 0 } });
-static std::vector<GLuint>  ftex24  (93, 0);
-static bool ft24loaded = false;
+       FT_Info(void)
+               : tex(0) {}
+};
 
-static auto *ftdat = &ftdat16;
-static auto *ftex  = &ftex16;
+static std::vector<FT_Info> ftData (93);
 
-static Color fontColor (255, 255, 255, 255);
+static Color fontColor (255, 255, 255);
 
 /*
  *     Variables for dialog boxes / options.
@@ -87,13 +92,15 @@ Mix_Chunk *sanic;
 static GLuint pageTex = 0;
 static bool   pageTexReady = false;
 
-void loadFontSize(int size, std::vector<GLuint> &tex, std::vector<FT_Info> &dat)
+void loadFontSize(int size, std::vector<FT_Info> &data)
 {
-       FT_Set_Pixel_Sizes(ftf,0,size);
+       FT_Set_Pixel_Sizes(ftf, 0, size);
 
        // pre-render 'all' the characters
-       glDeleteTextures(93, tex.data());
-       glGenTextures(93, tex.data());          //      Generate new texture name/locations?
+       for (auto& d : data) {
+               glDeleteTextures(1, &d.tex);
+               glGenTextures(1, &d.tex);    // Generate new texture name/locations?
+       }
 
        for (char i = 33; i < 126; i++) {
                // load the character from the font family file
@@ -101,7 +108,7 @@ void loadFontSize(int size, std::vector<GLuint> &tex, std::vector<FT_Info> &dat)
                        UserError("Error! Unsupported character " + i);
 
                // transfer the character's bitmap (?) to a texture for rendering
-               glBindTexture(GL_TEXTURE_2D, tex[i - 33]);
+               glBindTexture(GL_TEXTURE_2D, data[i - 33].tex);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR);
@@ -118,7 +125,7 @@ void loadFontSize(int size, std::vector<GLuint> &tex, std::vector<FT_Info> &dat)
                for (auto j = buf.size(); j--;)
                        buf[j] ^= !g->bitmap.buffer[j] ? buf[j] : 0;
 
-               auto& d = dat[i - 33];
+               auto& d = data[i - 33];
                d.wh.x = g->bitmap.width;
                d.wh.y = g->bitmap.rows;
                d.bl.x = g->bitmap_left;
@@ -220,9 +227,6 @@ namespace ui {
 #ifdef DEBUG
                DEBUG_printf("Using font %s\n",ttf);
 #endif // DEBUG
-
-               ft16loaded = false;
-               ft24loaded = false;
        }
 
        /*
@@ -230,17 +234,8 @@ namespace ui {
        */
 
        void setFontSize(unsigned int size) {
-               auto& loaded = (size == 16) ? ft16loaded : ft24loaded;
-               auto& tex = (size == 16) ? ftex16 : ftex24;
-               auto& dat = (size == 16) ? ftdat16 : ftdat24;
-
-               if (!loaded) {
-                       loadFontSize(fontSize = size, tex, dat);
-                       loaded = true;
-               }
-               ftex = &tex;
-               ftdat = &dat;
                fontSize = size;
+               loadFontSize(size, ftData);
        }
 
        /*
@@ -261,7 +256,7 @@ namespace ui {
         *      Draws a character at the specified coordinates, aborting if the character is unknown.
         */
        vec2 putChar(float xx,float yy,char c){
-               const auto& ch = (*ftdat)[c - 33];
+               const auto& ch = ftData[c - 33];
                int x = xx, y = yy;
 
                // get dimensions of the rendered character
@@ -274,7 +269,7 @@ namespace ui {
 
                // draw the character
                glActiveTexture(GL_TEXTURE0);
-               glBindTexture(GL_TEXTURE_2D, (*ftex)[c - 33]);
+               glBindTexture(GL_TEXTURE_2D, ch.tex);
 
                Render::textShader.use();
                Render::textShader.enable();
@@ -381,7 +376,7 @@ namespace ui {
                                width += fontSize / 2;
                                break;
                        default:
-                               width += (*ftdat)[i].wh.x + fontSize * 0.1f;
+                               width += ftData[i].wh.x + fontSize * 0.1f;
                                break;
                        }
                } while(s[++i]);
@@ -974,8 +969,7 @@ namespace ui {
                        setFontColor(255,255,255,255);
                }
 
-               if (currentMenu != nullptr)
-                       menu::draw();
+               menu::draw();
 
                // draw the mouse
                static const Texture mouseTex ("assets/goodmouse.png");
@@ -1181,9 +1175,6 @@ using namespace ui;
 
 void InputSystem::receive(const MainSDLEvent& event)
 {
-       if (currentMenu != nullptr)
-               return;
-       
        const auto& e = event.event;
        auto& ev = game::events;
        
@@ -1213,9 +1204,6 @@ void InputSystem::receive(const MainSDLEvent& event)
 
        //case SDL_MOUSEBUTTONUP:
        case SDL_MOUSEBUTTONDOWN:
-               if (currentMenu != nullptr)
-                       break;
-
                ev.emit<MouseClickEvent>(mouse, e.button.button);
 
                // run actions?
index c0bd3fb8bd31c009d33996d829f63bd0e5776df6..6ef06c152f8aaa02ff104e0375fe1bbaf2fabaa7 100644 (file)
@@ -1,12 +1,16 @@
 #include <ui_menu.hpp>
 
+#include <common.hpp>
 #include <engine.hpp>
+#include <fileio.hpp>
 #include <render.hpp>
 #include <texture.hpp>
 
 #include <fstream>
 
-extern Menu *currentMenu;
+extern vec2 offset;
+
+static Menu* currentMenu = nullptr;
 
 static Menu pauseMenu;
 static Menu optionsMenu;
@@ -14,24 +18,10 @@ static Menu controlsMenu;
 
 void Menu::gotoParent(void)
 {
-       if (!parent) {
-               currentMenu = nullptr;
+       if (parent == nullptr)
                game::config::update();
-       } else {
+       else
                currentMenu = parent;
-       }
-}
-
-inline void segFault(void)
-{
-       ++*((int *)0);
-}
-
-void quitGame(void)
-{
-       game::config::update();
-       game::config::save();
-       game::endGame();
 }
 
 std::string& deleteWord(std::string& s)
@@ -106,93 +96,109 @@ void setControlF(unsigned int index, menuItem &m)
 
 namespace ui {
     namespace menu {
-        menuItem createButton(vec2 l, dim2 d, Color c, const char* t, menuFunc f) {
-            menuItem temp;
+        menuItem createButton(vec2 l, dim2 d, Color c, const char* t, MenuAction f) {
+            menuItem temp (l, d, c, t);
 
             temp.member = 0;
-            temp.loc = l;
-            temp.dim = d;
-            temp.color = c;
-            temp.text = t;
             temp.button.func = f;
-                       temp.child = nullptr;
 
             return temp;
         }
 
-        menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t, Menu *_child) {
-            menuItem temp;
+        menuItem createChildButton(vec2 l, dim2 d, Color c, const char* t, Menu_child) {
+            menuItem temp (l, d, c, t, _child);
 
             temp.member = -1;
-            temp.loc = l;
-            temp.dim = d;
-            temp.color = c;
-            temp.text = t;
             temp.button.func = nullptr;
-                       temp.child = _child;
 
             return temp;
         }
 
         menuItem createParentButton(vec2 l, dim2 d, Color c, const char* t) {
-            menuItem temp;
+            menuItem temp (l, d, c, t);
 
             temp.member = -2;
-            temp.loc = l;
-            temp.dim = d;
-            temp.color = c;
-            temp.text = t;
             temp.button.func = nullptr;
-                       temp.child = nullptr;
 
             return temp;
         }
 
         menuItem createSlider(vec2 l, dim2 d, Color c, float min, float max, const char* t, float* v) {
-            menuItem temp;
+            menuItem temp (l, d, c, t);
 
             temp.member = 1;
-            temp.loc = l;
-            temp.dim = d;
-            temp.color = c;
             temp.slider.minValue = min;
             temp.slider.maxValue = max;
-            temp.text = t;
             temp.slider.var = v;
             temp.slider.sliderLoc = *v;
-                       temp.child = nullptr;
 
             return temp;
         }
 
                void init(void) {
+                       dim2 obSize (256, 75);
+                       Color black (0, 0, 0);
                        // Create the main pause menu
-                       pauseMenu.items.push_back(ui::menu::createParentButton({-128,100},{256,75},{0.0f,0.0f,0.0f}, "Resume"));
-                       pauseMenu.items.push_back(ui::menu::createChildButton({-128, 0},{256,75},{0.0f,0.0f,0.0f}, "Options", &optionsMenu));
-                       pauseMenu.items.push_back(ui::menu::createChildButton({-128,-100},{256,75},{0.0f,0.0f,0.0f}, "Controls", &controlsMenu));
-                       pauseMenu.items.push_back(ui::menu::createButton({-128,-200},{256,75},{0.0f,0.0f,0.0f}, "Save and Quit", quitGame));
-                       pauseMenu.items.push_back(ui::menu::createButton({-128,-300},{256,75},{0.0f,0.0f,0.0f}, "Segfault", segFault));
+                       pauseMenu.items.push_back(ui::menu::createParentButton(
+                               vec2(-128, 100), obSize, black, "Resume"));
+
+                       pauseMenu.items.push_back(ui::menu::createChildButton(
+                               vec2(-128, 0), obSize, black, "Options", &optionsMenu));
+
+                       pauseMenu.items.push_back(ui::menu::createChildButton(
+                               vec2(-128, -100), obSize, black, "Controls", &controlsMenu));
+
+                       pauseMenu.items.push_back(ui::menu::createButton(
+                               vec2(-128, -200), obSize, black, "Save and Quit",
+                               []() {
+                                       game::config::update(); // TODO necessary?
+                                       game::config::save();
+                                       game::endGame();
+                               } ));
+
+                       pauseMenu.items.push_back(ui::menu::createButton(
+                               vec2(-128, -300), obSize, black, "Segfault",
+                               []() { ++*((int *)0); } ));
 
                        // Create the options (sound) menu
-                       optionsMenu.items.push_back(ui::menu::createSlider({0-static_cast<float>(game::SCREEN_WIDTH)/4,0-(512/2)}, {50,512}, {0.0f, 0.0f, 0.0f}, 0, 100, "Master", &game::config::VOLUME_MASTER));
-                       optionsMenu.items.push_back(ui::menu::createSlider({-200,100}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "Music", &game::config::VOLUME_MUSIC));
-                       optionsMenu.items.push_back(ui::menu::createSlider({-200,000}, {512,50}, {0.0f, 0.0f, 0.0f}, 0, 100, "SFX", &game::config::VOLUME_SFX));
+                       optionsMenu.items.push_back(ui::menu::createSlider(
+                               vec2(-static_cast<float>(game::SCREEN_WIDTH) / 4, -(512/2)), dim2(50, 512),
+                               black, 0, 100, "Master", &game::config::VOLUME_MASTER));
+                       optionsMenu.items.push_back(ui::menu::createSlider(
+                               vec2(-200, 100), dim2(512, 50), black, 0, 100, "Music", &game::config::VOLUME_MUSIC));
+                       optionsMenu.items.push_back(ui::menu::createSlider(
+                               vec2(-200, 0), dim2(512, 50), black, 0, 100, "SFX", &game::config::VOLUME_SFX));
+
                        optionsMenu.parent = &pauseMenu;
 
                        // Create the controls menu
-                       controlsMenu.items.push_back(ui::menu::createButton({-450,300}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Up: ", nullptr));
-                       controlsMenu.items.back().button.func = [](){ setControlF(0, controlsMenu.items[0]); };
-                       controlsMenu.items.push_back(ui::menu::createButton({-450,200}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Left: ", nullptr));
-                       controlsMenu.items.back().button.func = [](){ setControlF(1, controlsMenu.items[1]); };
-                       controlsMenu.items.push_back(ui::menu::createButton({-450,100}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Right: ", nullptr));
-                       controlsMenu.items.back().button.func = [](){ setControlF(2, controlsMenu.items[2]); };
-                       controlsMenu.items.push_back(ui::menu::createButton({-450,0}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Sprint: ", nullptr));
-                       controlsMenu.items.back().button.func = [](){ setControlF(3, controlsMenu.items[3]); };
-                       controlsMenu.items.push_back(ui::menu::createButton({-450,-100}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Creep: ", nullptr));
-                       controlsMenu.items.back().button.func = [](){ setControlF(4, controlsMenu.items[4]); };
-                       controlsMenu.items.push_back(ui::menu::createButton({-450,-200}, {400, 75}, {0.0f, 0.0f, 0.0f}, "Inventory: ", nullptr));
-                       controlsMenu.items.back().button.func = [](){ setControlF(5, controlsMenu.items[5]); };
+                       dim2 cbSize (400, 75);
+                       controlsMenu.items.push_back(ui::menu::createButton(
+                               vec2(-450, 300), cbSize, black, "Up: ",
+                               []() { setControlF(0, controlsMenu.items[0]); } ));
+
+                       controlsMenu.items.push_back(ui::menu::createButton(
+                               vec2(-450, 200), cbSize, black, "Left: ",
+                               []() { setControlF(1, controlsMenu.items[1]); } ));
+
+                       controlsMenu.items.push_back(ui::menu::createButton(
+                               vec2(-450, 100), cbSize, black, "Right: ",
+                               []() { setControlF(2, controlsMenu.items[2]); } ));
+
+                       controlsMenu.items.push_back(ui::menu::createButton(
+                               vec2(-450, 0), cbSize, black, "Sprint: ",
+                               []() { setControlF(3, controlsMenu.items[3]); } ));
+
+                       controlsMenu.items.push_back(ui::menu::createButton(
+                               vec2(-450, -100), cbSize, black, "Creep: ",
+                               []() { setControlF(4, controlsMenu.items[4]); } ));
+
+                       controlsMenu.items.push_back(ui::menu::createButton(
+                               vec2(-450, -200), cbSize, black, "Inventory: ",
+                               []() { setControlF(5, controlsMenu.items[5]); } ));
+
                        controlsMenu.parent = &pauseMenu;
+
                        initControls(&controlsMenu);
                }
 
@@ -201,8 +207,11 @@ namespace ui {
                }
 
         void draw(void) {
-                       auto SCREEN_WIDTH = game::SCREEN_WIDTH;
-                       auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
+                       if (currentMenu == nullptr)
+                               return;
+
+                       auto& SCREEN_WIDTH = game::SCREEN_WIDTH;
+                       auto& SCREEN_HEIGHT = game::SCREEN_HEIGHT;
 
             SDL_Event e;
 
index 992e3c1a88fafabbffe4094bc3996b7906fc7ccd..f2c250b4e213541b516f040114d18b425013be53 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <config.hpp>
 
+#include <GL/glew.h>
 #include <SDL2/SDL_opengl.h>
 #include <SDL2/SDL_image.h>
 #include <SDL2/SDL_mixer.h>
index 1d29bfe7c6335b10d95690e70d694e176569e6cf..4f2f99c4771182ed54312eb4b08f94d7deb277ce 100644 (file)
 #include <chrono>
 using namespace std::literals::chrono_literals;
 
+#include <common.hpp>
+#include <debug.hpp>
+#include <error.hpp>
+#include <fileio.hpp>
+#include <vector3.hpp>
+
 // local game headers
 #include <ui.hpp>
 #include <gametime.hpp>
@@ -369,7 +375,8 @@ void WorldSystem::load(const std::string& file)
 
                                                entity.assign<Physics>(g);
                                        } else if (tname == "Name") {
-                                               entity.assign<Name>(coalesce(wxml->Attribute("name"), abcd->Attribute("value")));
+                                               auto name = wxml->Attribute("name");
+                                               entity.assign<Name>( name != nullptr ? name : abcd->Attribute("value"));
                                        } else if (tname == "Dialog") {
                                                entity.assign<Dialog>((wxml->BoolAttribute("hasDialog") ? 0 : 9999));
                                        } else if (tname == "Grounded") {