diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-10-10 19:17:19 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-10-10 19:17:19 -0500 |
commit | b19265bfa91e55c564b75aadcabd212ac89cf349 (patch) | |
tree | fab3a34fc96d52fc634ca0d507fdbaf5d3546b8e /include | |
parent | 1f762f82f929cfd21222739a627a32e6199c34a9 (diff) |
the revival, entityx
Diffstat (limited to 'include')
-rw-r--r-- | include/common.hpp | 23 | ||||
-rw-r--r-- | include/entities.hpp | 26 | ||||
-rw-r--r-- | include/events.hpp | 31 | ||||
-rw-r--r-- | include/inventory.hpp | 11 | ||||
-rw-r--r-- | include/render.hpp | 79 | ||||
-rw-r--r-- | include/ui.hpp | 11 | ||||
-rw-r--r-- | include/window.hpp | 20 |
7 files changed, 176 insertions, 25 deletions
diff --git a/include/common.hpp b/include/common.hpp index 12a7a50..8d74cda 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -50,15 +50,6 @@ typedef unsigned int uint; #undef near #endif -// Enables special message printing in the case of segfault debugging (unnecessary?) -//#define SEGFAULT - -#ifdef SEGFAULT -#define C(x) std::cout << x << '\n' -#else -#define C(x) -#endif - /** * Prints a formatted string to the terminal with file and line number, for debugging */ @@ -68,7 +59,7 @@ typedef unsigned int uint; * Creates a coordinate of integers. */ typedef struct { - int x; /**< The x coordinate */ + int x; /**< The x coordinate */ int y; /**< The y coordinate */ } ivec2; @@ -215,18 +206,6 @@ constexpr const float MSEC_PER_TICK = 1000.0f / TICKS_PER_SEC; std::vector<std::string> StringTokenizer(const std::string& str, char delim); /** - * A function used to tell the program what shader, attributes, and uniforms - * we want to draw our rectangles to. - * - * @see drawRect - * @param the shader - * @param the 'texture uniform' - * @param the 'coord attribute' - * @param the 'texture coord attribute' - */ -void useShader(GLuint *sh, GLint *tu, GLint *ca, GLint *ta); - -/** * A function to draw a colored box for OpenGL. * To use it, the lower left hand and upper right hand coords are given. * diff --git a/include/entities.hpp b/include/entities.hpp index 1bb2924..5f85c26 100644 --- a/include/entities.hpp +++ b/include/entities.hpp @@ -134,7 +134,7 @@ public: belongsTo = false; following = nullptr; - flame = false; + flame = false; } Light(vec2 l, float r, Color c) @@ -159,7 +159,7 @@ public: { flame = true; } - + void createFromXML(XMLElement *e); }; @@ -303,7 +303,7 @@ public: virtual void createFromXML(XMLElement *e, World *w=nullptr) =0; virtual void saveToXML(void) =0; -/* Entity +/* Entity ** * Forces the given entity to follow this one. @@ -498,6 +498,26 @@ constexpr Merchant *Merchantp(Entity *e) { return (Merchant *)e; } +#include <entityx/entityx.h> +#include <events.hpp> + +class PlayerSystem : public entityx::System<PlayerSystem>, public entityx::Receiver<PlayerSystem> { +private: + Player **m_Player; + bool m_MoveLeft, m_MoveRight; + +public: + PlayerSystem(Player **p) + : m_Player(p), m_MoveLeft(false), m_MoveRight(false) {} + + void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; + + void configure(entityx::EventManager &ev); + void receive(const KeyDownEvent &kde); + void receive(const KeyUpEvent &kue); +}; + + #endif // ENTITIES_H /** diff --git a/include/events.hpp b/include/events.hpp new file mode 100644 index 0000000..aa3ca07 --- /dev/null +++ b/include/events.hpp @@ -0,0 +1,31 @@ +#ifndef EVENTS_HPP_ +#define EVENTS_HPP_ + +/** + * A place for events to live, while gamedev slowly dies from rewriting. + */ + +#include <SDL2/SDL.h> + + struct MouseScrollEvent { + MouseScrollEvent(int sd) + : scrollDistance(sd) {} + + int scrollDistance; + }; + +struct KeyDownEvent { + KeyDownEvent(SDL_Keycode kc) + : keycode(kc) {} + + SDL_Keycode keycode; +}; + +struct KeyUpEvent { + KeyUpEvent(SDL_Keycode kc) + : keycode(kc) {} + + SDL_Keycode keycode; +}; + +#endif // EVENTS_HPP_ diff --git a/include/inventory.hpp b/include/inventory.hpp index ca402b3..9a42aa4 100644 --- a/include/inventory.hpp +++ b/include/inventory.hpp @@ -5,6 +5,7 @@ #include <string.h> #include <texture.hpp> +#include <events.hpp> #define DEBUG @@ -268,4 +269,14 @@ GLuint getItemTexture(std::string name); float getItemWidth(std::string name); float getItemHeight(std::string name); +#include <entityx/entityx.h> + +class InventorySystem : public entityx::System<InventorySystem>, public entityx::Receiver<InventorySystem> { +public: + void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; + + void configure(entityx::EventManager &em); + void receive(const MouseScrollEvent &mse); +}; + #endif // INVENTORY_H diff --git a/include/render.hpp b/include/render.hpp new file mode 100644 index 0000000..0a2adcd --- /dev/null +++ b/include/render.hpp @@ -0,0 +1,79 @@ +#ifndef RENDER_HPP_ +#define RENDER_HPP_ + +#include <vector> + +#include <GL/glew.h> +#include <SDL2/SDL_opengl.h> + +#include <common.hpp> +#include <shader_utils.hpp> + +/** + * @class Shader + * @brief Handles a texture shader, allowing it's use in the program. + */ +class Shader { +public: + GLuint shader; + GLint coord; + GLint tex; + std::vector<GLint> uniform; + + void create(const char *vert, const char *frag) { + shader = create_program(vert, frag); + coord = get_attrib(shader, "coord2d"); + tex = get_attrib(shader, "tex_coord"); + } + + inline void addUniform(const char *name) { + uniform.push_back(get_uniform(shader, name)); + } + + inline void use(void) { + glUseProgram(shader); + } + + inline void unuse(void) { + glUseProgram(0); + } + + inline void enable(void) { + glEnableVertexAttribArray(coord); + glEnableVertexAttribArray(tex); + } + + inline void disable(void) { + glDisableVertexAttribArray(coord); + glDisableVertexAttribArray(tex); + } + + ~Shader(void) { + uniform.clear(); + } +}; + +typedef enum { + WU_texture = 0, + WU_ortho, + WU_tex_color, + WU_transform, + WU_ambient, + WU_light_impact, + WU_light, + WU_light_color, + WU_light_size +} WorldUniform; + +namespace Render { + extern Shader worldShader; + extern Shader textShader; + + void initShaders(void); + + void useShader(Shader *s); + + void drawRect(vec2 ll, vec2 ur, float z); +} + +#endif // RENDER_HPP_ diff --git a/include/ui.hpp b/include/ui.hpp index 56c484c..f276882 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -43,8 +43,18 @@ void setControl(unsigned int index, SDL_Keycode key); SDL_Keycode getControl(unsigned int index); +#include <entityx/entityx.h> + +class InputSystem : public entityx::System<InputSystem> { +public: + void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; +}; + namespace ui { + extern bool fadeEnable; + extern int fadeIntensity; + // the pixel-coordinates of the mouse extern vec2 mouse; @@ -155,6 +165,7 @@ namespace ui { void toggleWhite(void); void toggleWhiteFast(void); void waitForCover(void); + void waitForUncover(void); } diff --git a/include/window.hpp b/include/window.hpp new file mode 100644 index 0000000..b642835 --- /dev/null +++ b/include/window.hpp @@ -0,0 +1,20 @@ +#ifndef WINDOW_HPP_ +#define WINDOW_HPP_ + +#include <entityx/entityx.h> + +#include <SDL2/SDL.h> + +class WindowSystem : public entityx::System<WindowSystem> { +private: + SDL_Window *window; + SDL_GLContext glContext; + +public: + WindowSystem(void); + ~WindowSystem(void); + + void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override; +}; + +#endif // WINDOW_HPP_ |