]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
made all formatting match
authorClyne Sullivan <clyne@bitgloo.com>
Sun, 1 Sep 2019 18:45:42 +0000 (14:45 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sun, 1 Sep 2019 18:45:42 +0000 (14:45 -0400)
19 files changed:
src/components/Component.hpp
src/components/Name.hpp
src/components/Player.hpp
src/components/Position.hpp
src/components/Render.hpp
src/components/Script.hpp
src/components/Velocity.hpp
src/engine.cpp
src/engine.hpp
src/gamerun.hpp
src/input.hpp
src/main.cpp
src/player.cpp
src/player.hpp
src/render.cpp
src/render.hpp
src/script.cpp
src/script.hpp
src/shader.hpp

index 98095ba942b47a242ebce52f5e29d351416f781a..5a062bd4406513d432093832ba6db8e5e674c9c5 100644 (file)
 
 #include <sol/sol.hpp>
 
-template <typename T>
+template<typename T>
 class Component 
 {
-    public:
-    Component(){};
-
+public:
     virtual T FromLua(sol::object) = 0;
 };
 
-#endif//COMPONENT_HPP_
+#endif // COMPONENT_HPP_
+
index c472cbb4c0c527dba7ab87424b464a47730fc778..94b7531ed23651da1859c89157615a09ac2b0c9e 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef NAME_HPP_
-#define NAME_HPP_
+#ifndef COMPONENT_NAME_HPP_
+#define COMPONENT_NAME_HPP_
 
-#include "components/Component.hpp"
+#include "Component.hpp"
 #include <string>
 
 struct Name : Component<Name>, entityx::Component<Name>
 {
-    public:
-        std::string name;
-        Name(std::string _name) : name(_name) {}
-        Name(void): name() {};
-
-        Name FromLua(sol::object ref)
-        {
-            if (ref.get_type() == sol::type::string) {
-                this->name = ref.as<std::string>();
-            } else {
-                throw std::string("Name component not formatted properly");
-            }
-            return *this;
-        }
+public:
+    std::string name;
 
+    Name(std::string _name = std::string()) :
+        name(_name) {}
+
+    Name FromLua(sol::object ref)
+    {
+        if (ref.get_type() == sol::type::string)
+            this->name = ref.as<std::string>();
+        else
+            throw std::string("Name component not formatted properly");
+
+        return *this;
+    }
 };
 
-#endif//NAME_HPP_
+#endif // COMPONENT_NAME_HPP_
+
index 6fb631117f3ff2e7b70bc25253e36e368651cec4..5c1e870f934f6b6478614170116c4f4152fd787d 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef PLAYER_HPP_
-#define PLAYER_HPP_
+#ifndef COMPONENT_PLAYER_HPP_
+#define COMPONENT_PLAYER_HPP_
 
 #include "Component.hpp"
 
 struct Player : Component<Player>, entityx::Component<Player>
 {
-        Player FromLua([[maybe_unused]] sol::object ref)
-        {
-               return *this;
-        }
+public:
+    Player FromLua([[maybe_unused]] sol::object ref)
+    {
+        return *this;
+    }
 };
 
-#endif // PLAYER_HPP_
+#endif // COMPONENT_PLAYER_HPP_
+
index 8a6bd74c0408ccea4da893fe7204c78a934401e2..c80199809c08dd8efb5cd761b54403d65b0c3552 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef POSITION_HPP_
-#define POSITION_HPP_
+#ifndef COMPONENT_POSITION_HPP_
+#define COMPONENT_POSITION_HPP_
 
-#include "components/Component.hpp"
+#include "Component.hpp"
 
 struct Position : Component<Position>, entityx::Component<Position>
 {
-    public:
-        double x, y;
-        Position(double _x, double _y): x(_x), y(_y) {}
-        Position(void): x(0), y(0) {}
-
-        Position FromLua(sol::object ref)
-        {
-            if (ref.get_type() == sol::type::table) {
-                sol::table tab = ref;
-                if (tab["x"] != nullptr)
-                    this->x = tab["x"];
-                if (tab["y"] != nullptr)
-                    this->y = tab["y"];
-            } else {
-                throw std::string("Position table not formatted properly");
-            }
-            return *this;
+public:
+    double x, y;
+
+    Position(double _x = 0, double _y = 0) :
+        x(_x), y(_y) {}
+
+    Position FromLua(sol::object ref)
+    {
+        if (ref.get_type() == sol::type::table) {
+            sol::table tab = ref;
+            if (tab["x"] != nullptr)
+                this->x = tab["x"];
+            if (tab["y"] != nullptr)
+                this->y = tab["y"];
+        } else {
+            throw std::string("Position table not formatted properly");
         }
+        return *this;
+    }
 };
 
-#endif//POSITION_HPP_
+#endif // COMPONENT_POSITION_HPP_
+
index 5a9b1a48c0a92a95f7e76e043b0b1a8f7716d84b..451f2d1885a25e2269a31a781b885dae01c99f5e 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef RENDERC_HPP_
-#define RENDERC_HPP_
+#ifndef COMPONENT_RENDER_HPP_
+#define COMPONENT_RENDER_HPP_
 
-#include <components/Component.hpp>
+#include "Component.hpp"
 
 struct Render : Component<Render>, entityx::Component<Render>
 {
-    public:
-        std::string texture;
-        bool visible;
+public:
+    std::string texture;
+    bool visible;
 
-        Render(std::string _file): texture(_file), visible(true) {}
-        Render(): texture(), visible(false) {}
+    Render(std::string _file) :
+        texture(_file), visible(true) {}
+    Render(void) :
+        texture(), visible(false) {}
 
-        Render FromLua(sol::object ref)
-        {
-            if (ref.get_type() == sol::type::table) {
-                sol::table tab = ref;
-                if (tab["visible"].get_type() == sol::type::boolean) {
-                    this->visible = tab["visible"];
-                }
-                if (tab["texture"].get_type() == sol::type::string) {
-                    this->texture = tab["texture"];
-                }
-            } else {
-                throw std::string(
-                    "Render component table formatted incorrectly"
-                );
-            }
-            return *this;
+    Render FromLua(sol::object ref)
+    {
+        if (ref.get_type() == sol::type::table) {
+            sol::table tab = ref;
+            if (tab["visible"].get_type() == sol::type::boolean)
+                this->visible = tab["visible"];
+            if (tab["texture"].get_type() == sol::type::string)
+                this->texture = tab["texture"];
+        } else {
+            throw std::string(
+                "Render component table formatted incorrectly"
+            );
         }
-
+        return *this;
+    }
 };
 
-#endif//RENDERC_HPP_
+#endif // COMPONENT_RENDER_HPP_
+
index 75708025c03738312a2e0142e442cc9c1df23529..66addc87e192c9f350dc56f583672d6ee072cd2d 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef SCRIPT_COMPONENT_HPP_
-#define SCRIPT_COMPONENT_HPP_
+#ifndef COMPONENT_SCRIPT_HPP_
+#define COMPONENT_SCRIPT_HPP_
 
-#include <components/Component.hpp>
+#include "Component.hpp"
 
 struct Scripted : Component<Scripted>, entityx::Component<Scripted>
 {
-    public:
-        sol::table caller;
-        Scripted() {}
-        Scripted(sol::table call): caller(call) {}
-
-
-        ~Scripted()
-        {}
-
-        void cleanup()
-        {
-            caller = sol::nil;
-        }
-
-        Scripted FromLua(sol::object)
-        {
-            return *this;
-        }
-
-        void exec() {
-            if (caller["Idle"] == sol::type::function)
-                caller["Idle"](caller); // Call idle function and pass itself
-                                        //  in or to fulfill the 'self' param
-        }
+public:
+    sol::table caller;
+
+    Scripted(void) {}
+    Scripted(sol::table call) :
+        caller(call) {}
+
+    ~Scripted() {}
+
+    void cleanup(void)
+    {
+        caller = sol::nil;
+    }
+
+    Scripted FromLua([[maybe_unused]] sol::object ref)
+    {
+        return *this;
+    }
+
+    void exec(void) {
+        if (caller["Idle"] == sol::type::function)
+            caller["Idle"](caller); // Call idle function and pass itself
+                                    //  in or to fulfill the 'self' param
+    }
 };
 
-#endif//SCRIPT_COMPONENT_HPP_
+#endif // COMPONENT_SCRIPT_HPP_
+
index c2b85e8ed9e19a78772feda4f94e8cd838ad36c4..29c0e5cd5d92cbab0f3d3427b1159459127d0b85 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef VELOCITY_HPP_
-#define VELOCITY_HPP_
+#ifndef COMPONENT_VELOCITY_HPP_
+#define COMPONENT_VELOCITY_HPP_
 
-#include <components/Component.hpp>
+#include "Component.hpp"
 
 struct Velocity : Component<Velocity>, entityx::Component<Velocity>
 {
-    public:
-        double x, y;
-        Velocity(): x(0), y(0) {}
-        Velocity(double _x, double _y): x(_x), y(_y) {}
+public:
+    double x, y;
 
-        Velocity FromLua(sol::object ref)
-        {
-            if (ref.get_type() == sol::type::table) {
-                sol::table tab = ref;
-                if (tab["x"] != nullptr)
-                    this->x = tab["x"];
-                if (tab["y"] != nullptr)
-                    this->y = tab["y"];
-            } else {
-                throw std::string("Velocity table not formatted properly");
-            }
-            return *this;
+    Velocity(double _x = 0, double _y = 0) :
+        x(_x), y(_y) {}
+
+    Velocity FromLua(sol::object ref)
+    {
+        if (ref.get_type() == sol::type::table) {
+            sol::table tab = ref;
+            if (tab["x"] != nullptr)
+                this->x = tab["x"];
+            if (tab["y"] != nullptr)
+                this->y = tab["y"];
+        } else {
+            throw std::string("Velocity table not formatted properly");
         }
+        return *this;
+    }
 };
 
-#endif//VELOCITY_HPP_
+#endif // COMPONENT_VELOCITY_HPP_
+
index 26dcd0a1589114c43586b397c1c9d80710134ccd..f23565152fdd99a4368a35569dd684c8d0ba458d 100644 (file)
 
 int Engine::init(void)
 {
-       systems.add<GameRunSystem>();
-       systems.add<InputSystem>();
-       systems.add<PlayerSystem>();
+    systems.add<GameRunSystem>();
+    systems.add<InputSystem>();
+    systems.add<PlayerSystem>();
     systems.add<RenderSystem>();
     systems.add<ScriptSystem>();
+    systems.configure();
 
-       systems.configure();
+    systems.system<ScriptSystem>()->init();
 
-       systems.system<ScriptSystem>()->init();
-
-       return 0;
+    return 0;
 }
 
 void Engine::logicLoop(void)
 {
-       using namespace std::chrono_literals;
+    using namespace std::chrono_literals;
     namespace cr = std::chrono;
     typedef std::chrono::high_resolution_clock mc;
 
     entityx::TimeDelta dt = 0; /**< Elapsed milliseconds since each loop */
     double elapsed = 0;
 
-       while (shouldRun()) {
-
+    while (shouldRun()) {
         auto start = mc::now();
 
         /***********************
@@ -68,7 +66,7 @@ void Engine::logicLoop(void)
             p.y += (v.y * dt/1000.0);
         });
 
-               systems.update<InputSystem>(dt);
+        systems.update<InputSystem>(dt);
 
         /*******************
         *  LOGIC UPDATES  *
@@ -88,10 +86,10 @@ void Engine::logicLoop(void)
         auto diff = end - start;
         auto micros = cr::duration_cast<cr::microseconds>(diff);
         auto msc = micros.count();
-        dt = static_cast<double>(msc)/1000.0;
+        dt = static_cast<double>(msc) / 1000.0;
         elapsed += dt;
-               std::this_thread::yield();
-       }
+        std::this_thread::yield();
+    }
 
     // Remove all Lua references from entities
     entities.each<Scripted>([](entityx::Entity, Scripted &f){ f.cleanup(); });
@@ -99,29 +97,29 @@ void Engine::logicLoop(void)
 
 void Engine::renderLoop(void)
 {
-       while (shouldRun()) {
-               systems.update<RenderSystem>(0);
-               std::this_thread::yield();
-       }
+    while (shouldRun()) {
+        systems.update<RenderSystem>(0);
+        std::this_thread::yield();
+    }
 }
 
 void Engine::run(void)
 {
-       // Start logic thread
-       logicThread = std::thread([this](void) {
-               logicLoop();
-       });
+    // Start logic thread
+    logicThread = std::thread([this](void) {
+        logicLoop();
+    });
 
-       // Keep render loop on main thread
-       renderLoop();
+    // Keep render loop on main thread
+    renderLoop();
 
-       // Done, bring logic thread back
-       logicThread.join();
+    // Done, bring logic thread back
+    logicThread.join();
 }
 
 bool Engine::shouldRun(void)
 {
-       auto grs = systems.system<GameRunSystem>();
-       return grs ? grs->shouldRun() : true;
+    auto grs = systems.system<GameRunSystem>();
+    return grs ? grs->shouldRun() : true;
 }
 
index fb1409319ff687c9141ef17e6b076725b121311c..26b1c451af50104ce39129df2a1b8138481ed333 100644 (file)
 class Engine
 {
 private:
-       entityx::EventManager events;
-       entityx::EntityManager entities;
-       entityx::SystemManager systems;
+    entityx::EventManager events;
+    entityx::EntityManager entities;
+    entityx::SystemManager systems;
 
-       std::thread logicThread;
+    std::thread logicThread;
 
-       void logicLoop(void);
-       void renderLoop(void);
+    void logicLoop(void);
+    void renderLoop(void);
 
-       bool shouldRun(void);
+    bool shouldRun(void);
 
 public:
-       Engine(void) :
-               entities(events),
-               systems(entities, events) {}
+    Engine(void) :
+        entities(events),
+        systems(entities, events) {}
 
-       /**
-        * Initializes the game engine.
-        * @return Zero on success, non-zero otherwise
-        */
-       int init(void);
+    /**
+     * Initializes the game engine.
+     * @return Zero on success, non-zero otherwise
+     */
+    int init(void);
 
-       /**
-        * Runs the game engine.
-        * Function returns when game is told to end/exit.
-        */
-       void run(void);
+    /**
+     * Runs the game engine.
+     * Function returns when game is told to end/exit.
+     */
+    void run(void);
 };
 
 #endif // ENGINE_HPP_
index efe6ed9bedbd2754c82ec27ea1f0621fae16fca2..ceb07164586ad9c978b2e04b7f0447b671b12b02 100644 (file)
@@ -18,8 +18,8 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#ifndef GAMERUN_HPP_
-#define GAMERUN_HPP_
+#ifndef SYSTEM_GAMERUN_HPP_
+#define SYSTEM_GAMERUN_HPP_
 
 #include "input.hpp"
 
  * Listens for a key event to tell the game to exit.
  */
 class GameRunSystem : public entityx::System<GameRunSystem>,
-       public entityx::Receiver<GameRunSystem> {
+                      public entityx::Receiver<GameRunSystem>
+{
 private:
-       std::atomic_bool shouldRunFlag;
+    std::atomic_bool shouldRunFlag;
 
 public:
-       /**
-        * Configures the system to wait for the exit event.
-        */
-       void configure([[maybe_unused]] entityx::EntityManager& entities,
-               entityx::EventManager& events) {
-               shouldRunFlag.store(true);
+    /**
+     * Configures the system to wait for the exit event.
+     */
+    void configure([[maybe_unused]] entityx::EntityManager& entities,
+                   entityx::EventManager& events)
+    {
+        shouldRunFlag.store(true);
 
-               events.subscribe<KeyUpEvent>(*this);
+        events.subscribe<KeyUpEvent>(*this);
 
-               std::cout << "Press escape to exit." << std::endl;
-       }
+        std::cout << "Press escape to exit." << std::endl;
+    }
 
-       // Unused
-       void update([[maybe_unused]] entityx::EntityManager& entities,
-               [[maybe_unused]] entityx::EventManager& events,
-               [[maybe_unused]] entityx::TimeDelta dt) final {}
+    // Unused
+    void update([[maybe_unused]] entityx::EntityManager& entities,
+                [[maybe_unused]] entityx::EventManager& events,
+                [[maybe_unused]] entityx::TimeDelta dt) final {}
 
-       /**
-        * Receiver for key release events, used to listen for game exit key.
-        */
-       void receive(const KeyUpEvent& kue) {
-               if (kue.sym == SDLK_ESCAPE)
-                       shouldRunFlag.store(false);
-       }
+    /**
+     * Receiver for key release events, used to listen for game exit key.
+     */
+    void receive(const KeyUpEvent& kue)
+    {
+        if (kue.sym == SDLK_ESCAPE)
+            shouldRunFlag.store(false);
+    }
 
-       /**
-        * Checks if the game exit key has been pressed.
-        * @return True if the game should exit
-        */
-       inline bool shouldRun(void) const {
-               return shouldRunFlag.load();
-       }
+    /**
+     * Checks if the game exit key has been pressed.
+     * @return True if the game should exit
+     */
+    bool shouldRun(void) const
+    {
+        return shouldRunFlag.load();
+    }
 };
 
-#endif // GAMERUN_HPP_
+#endif // SYSTEM_GAMERUN_HPP_
 
index 39d4045d652b903805b9e808f72cba4006a41d25..fa92c393291c717aa9032eb654008951cd300dc9 100644 (file)
@@ -18,8 +18,8 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#ifndef INPUT_HPP_
-#define INPUT_HPP_
+#ifndef SYSTEM_INPUT_HPP_
+#define SYSTEM_INPUT_HPP_
 
 #include <entityx/entityx.h>
 #include <SDL2/SDL.h>
  * @class KeyUpEvent
  * Stores info regarding key releases.
  */
-struct KeyUpEvent {
-       KeyUpEvent(const SDL_Keysym& keysym) :
-               sym(keysym.sym), mod(keysym.mod) {}
+struct KeyUpEvent
+{
+    SDL_Keycode sym;
+    Uint16 mod;
 
-       SDL_Keycode sym;
-       Uint16 mod;
+    KeyUpEvent(const SDL_Keysym& keysym) :
+        sym(keysym.sym), mod(keysym.mod) {}
 };
 
 /**
@@ -41,48 +42,49 @@ struct KeyUpEvent {
  * Stores info regarding key presses.
  */
 struct KeyDownEvent {
-       KeyDownEvent(const SDL_Keysym& keysym) :
-               sym(keysym.sym), mod(keysym.mod) {}
+    SDL_Keycode sym;
+    Uint16 mod;
 
-       SDL_Keycode sym;
-       Uint16 mod;
+    KeyDownEvent(const SDL_Keysym& keysym) :
+        sym(keysym.sym), mod(keysym.mod) {}
 };
 
 /**
  * @class InputSystem
  * Listens for user input from SDL, and emits input events accordingly.
  */
-class InputSystem : public entityx::System<InputSystem> {
+class InputSystem : public entityx::System<InputSystem>
+{
 public:
-       /**
-        * Prepares the system for running.
-        */
-       void configure([[maybe_unused]] entityx::EntityManager& entities,
-               [[maybe_unused]] entityx::EventManager& events) final {
-       }
+    /**
+     * Prepares the system for running.
+     */
+    void configure([[maybe_unused]] entityx::EntityManager& entities,
+                   [[maybe_unused]] entityx::EventManager& events) final {}
 
-       /**
-        * Updates the system by checking for SDL events.
-        */
-       void update([[maybe_unused]] entityx::EntityManager& entities,
-               [[maybe_unused]] entityx::EventManager& events,
-               [[maybe_unused]] entityx::TimeDelta dt) final {
-               for (SDL_Event event; SDL_PollEvent(&event);) {
-                       switch (event.type) {
-                       case SDL_KEYUP:
-                               if (auto key = event.key; key.repeat == 0)
-                                       events.emit<KeyUpEvent>(key.keysym);
-                               break;
-                       case SDL_KEYDOWN:
-                               if (auto key = event.key; key.repeat == 0)
-                                       events.emit<KeyDownEvent>(key.keysym);
-                               break;
-                       default:
-                               break;
-                       }
-               }
-       }
+    /**
+     * Updates the system by checking for SDL events.
+     */
+    void update([[maybe_unused]] entityx::EntityManager& entities,
+                [[maybe_unused]] entityx::EventManager& events,
+                [[maybe_unused]] entityx::TimeDelta dt) final
+    {
+        for (SDL_Event event; SDL_PollEvent(&event);) {
+            switch (event.type) {
+            case SDL_KEYUP:
+                if (auto key = event.key; key.repeat == 0)
+                    events.emit<KeyUpEvent>(key.keysym);
+                break;
+            case SDL_KEYDOWN:
+                if (auto key = event.key; key.repeat == 0)
+                    events.emit<KeyDownEvent>(key.keysym);
+                break;
+            default:
+                break;
+            }
+        }
+    }
 };
 
-#endif // INPUT_HPP_
+#endif // SYSTEM_INPUT_HPP_
 
index c56fd796b3f3715f6a3b1da5439a62708a0aa439..7876f8a47594c24b0fe5d85cd25cff6d32b772e2 100644 (file)
 
 int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[])
 {
-       // Initialize SDL
-       if (SDL_Init(0) != 0) {
-               std::cerr << "SDL failed to initialize: " << SDL_GetError()
-                       << std::endl;
-               return -1;
-       } else {
-               atexit(SDL_Quit);
-       }
-
-    //LuaTest();
-
-       // Create the engine
-       Engine engine;
-       engine.init();
-
-       // Go go go!
-       engine.run();
-
-       return 0;
+    // Initialize SDL
+    if (SDL_Init(0) != 0) {
+        std::cerr << "SDL failed to initialize: " << SDL_GetError()
+            << std::endl;
+        return -1;
+    } else {
+        atexit(SDL_Quit);
+    }
+
+    // Create the engine
+    Engine engine;
+    engine.init();
+
+    // Go go go!
+    engine.run();
+
+    return 0;
 }
+
index 22bd0ef08c870b9477ccae1ac6dff21c893f6d17..7d1653ea8f0d039ed7958d9fce062c418706ed6c 100644 (file)
 #include "components/Velocity.hpp"
 
 void PlayerSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
-    entityx::EventManager& events)
+                             entityx::EventManager& events)
 {
-       events.subscribe<entityx::ComponentAddedEvent<Player>>(*this);
-       events.subscribe<entityx::ComponentRemovedEvent<Player>>(*this);
-       events.subscribe<KeyUpEvent>(*this);
-       events.subscribe<KeyDownEvent>(*this);
+    events.subscribe<entityx::ComponentAddedEvent<Player>>(*this);
+    events.subscribe<entityx::ComponentRemovedEvent<Player>>(*this);
+    events.subscribe<KeyUpEvent>(*this);
+    events.subscribe<KeyDownEvent>(*this);
 }
 
 void PlayerSystem::update([[maybe_unused]] entityx::EntityManager& entites,
-    [[maybe_unused]] entityx::EventManager& events,
-    [[maybe_unused]] entityx::TimeDelta dt)
+                          [[maybe_unused]] entityx::EventManager& events,
+                          [[maybe_unused]] entityx::TimeDelta dt)
 {
 }
 
 void PlayerSystem::receive(const entityx::ComponentAddedEvent<Player>& cae)
 {
-       player = cae.entity;
+    player = cae.entity;
 }
 
 void PlayerSystem::receive(const entityx::ComponentRemovedEvent<Player>& cre)
 {
-       if (player == cre.entity)
-               player.invalidate();
+    if (player == cre.entity)
+        player.invalidate();
 }
 
 void PlayerSystem::receive(const KeyDownEvent& kue)
 {
-       if (player.valid()) {
-               if (kue.sym == SDLK_a) {
-                       if (auto vel = player.component<Velocity>(); vel)
-                               vel->x += GROUND_VELOCITY;
-               } else if (kue.sym == SDLK_d) {
-                       if (auto vel = player.component<Velocity>(); vel)
-                               vel->x -= GROUND_VELOCITY;
-               }
-       }
+    if (player.valid()) {
+        if (kue.sym == SDLK_a) {
+            if (auto vel = player.component<Velocity>(); vel)
+                vel->x += GROUND_VELOCITY;
+        } else if (kue.sym == SDLK_d) {
+            if (auto vel = player.component<Velocity>(); vel)
+                vel->x -= GROUND_VELOCITY;
+        }
+    }
 }
 
 void PlayerSystem::receive(const KeyUpEvent& kue)
 {
-       if (player.valid()) {
-               if (kue.sym == SDLK_a) {
-                       if (auto vel = player.component<Velocity>(); vel)
-                               vel->x -= GROUND_VELOCITY;
-               } else if (kue.sym == SDLK_d) {
-                       if (auto vel = player.component<Velocity>(); vel)
-                               vel->x += GROUND_VELOCITY;
-               }
-       }
+    if (player.valid()) {
+        if (kue.sym == SDLK_a) {
+            if (auto vel = player.component<Velocity>(); vel)
+                vel->x -= GROUND_VELOCITY;
+        } else if (kue.sym == SDLK_d) {
+            if (auto vel = player.component<Velocity>(); vel)
+                vel->x += GROUND_VELOCITY;
+        }
+    }
 }
+
index 4469745604c13da61f28bd4e2d437fbbc8ef2c21..b1821c58d24f42bba13541917df4bd431902f645 100644 (file)
@@ -18,8 +18,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef PLAYERSYSTEM_HPP_
-#define PLAYERSYSTEM_HPP_
+#ifndef SYSTEM_PLAYER_HPP_
+#define SYSTEM_PLAYER_HPP_
 
 #include <SDL2/SDL.h>
 #include <entityx/entityx.h>
  * Controls player entity movement.
  */
 class PlayerSystem : public entityx::System<PlayerSystem>,
-       public entityx::Receiver<PlayerSystem>
+                     public entityx::Receiver<PlayerSystem>
 {
-    private:
-       /**
-        * Defines player's horizontal movement velocity.
-        */
-        constexpr static double GROUND_VELOCITY = 100;
+private:
+    /**
+     * Defines player's horizontal movement velocity.
+     */
+    constexpr static double GROUND_VELOCITY = 100;
 
-       entityx::Entity player;
+    entityx::Entity player;
 
-    public:
-        /**
-         * Prepares the system for running.
-         */
-        void configure([[maybe_unused]] entityx::EntityManager& entities,
-                       entityx::EventManager& events) final;
+public:
+    /**
+     * Prepares the system for running.
+     */
+    void configure(entityx::EntityManager& entities,
+                   entityx::EventManager& events) final;
 
-        /**
-         * Updates the scripting system.
-         */
-        void update([[maybe_unused]] entityx::EntityManager& entites,
-                    [[maybe_unused]] entityx::EventManager& events,
-                    [[maybe_unused]] entityx::TimeDelta dt) final;
+    /**
+     * Updates the scripting system.
+     */
+    void update(entityx::EntityManager& entites,
+                entityx::EventManager& events,
+                entityx::TimeDelta dt) final;
 
-       /**
-        * Captures the player entity.
-        */
-       void receive(const entityx::ComponentAddedEvent<Player>& cae);
+    /**
+     * Captures the player entity.
+     */
+    void receive(const entityx::ComponentAddedEvent<Player>& cae);
 
-       /**
-        * Invalidates the system's player entity (assume player is gone).
-        */
-       void receive(const entityx::ComponentRemovedEvent<Player>& cre);
+    /**
+     * Invalidates the system's player entity (assume player is gone).
+     */
+    void receive(const entityx::ComponentRemovedEvent<Player>& cre);
 
-       /**
-        * Applies velocity based on key press.
-        */
-       void receive(const KeyDownEvent& kue);
+    /**
+     * Applies velocity based on key press.
+     */
+    void receive(const KeyDownEvent& kue);
 
-       /**
-        * Removes applied velocity
-        */
-       void receive(const KeyUpEvent& kue);
+    /**
+     * Removes applied velocity
+     */
+    void receive(const KeyUpEvent& kue);
 };
 
-#endif // PLAYERSYSTEM_HPP_
+#endif // SYSTEM_PLAYER_HPP_
+
index 7c047f66637dce552abf3b866ca0531758bc5dc5..27715357edc0cdb612e9adfbdb31455912dcb588 100644 (file)
@@ -22,8 +22,8 @@
 #include <components/Render.hpp>
 #include <components/Position.hpp>
 
-void RenderSystem::configure([[maybe_unused]]entityx::EntityManager& entities,
-                             [[maybe_unused]]entityx::EventManager& events)
+void RenderSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
+                             [[maybe_unused]] entityx::EventManager& events)
 {
     init();
 }
@@ -80,7 +80,7 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
     *************/
 
     entities.each<Render, Position>(
-            [this, a](entityx::Entity, Render &r, Position &p){
+        [this, a](entityx::Entity, Render &r, Position &p) {
 
         if (!r.visible)
             return;
@@ -174,3 +174,4 @@ int RenderSystem::init(void)
 
     return 0;
 }
+
index 21869a3fb4c37df91b46695c649616d1885fa520..6362d6355e7b41f05f7a590d0cf15e87eca49300 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef RENDER_HPP_
-#define RENDER_HPP_
+#ifndef SYSTEM_RENDER_HPP_
+#define SYSTEM_RENDER_HPP_
 
-#include <entityx/entityx.h>
+#include "shader.hpp"
 
-#include <shader.hpp>
+#include <entityx/entityx.h>
 
 #include <SDL2/SDL.h>
 
 class RenderSystem : public entityx::System<RenderSystem>
 {
 private:
-       constexpr static const char *title = "gamedev2";
-       constexpr static int width = 640;
-       constexpr static int height = 480;
+    constexpr static const char *title = "gamedev2";
+    constexpr static int width = 640;
+    constexpr static int height = 480;
 
-       std::unique_ptr<SDL_Window, void (*)(SDL_Window *)> window;
-       SDL_GLContext context;
+    std::unique_ptr<SDL_Window, void (*)(SDL_Window *)> window;
+    SDL_GLContext context;
 
     Shader worldShader;
+
 public:
-    RenderSystem(void):
-           window(nullptr, SDL_DestroyWindow)
-    {}
+    RenderSystem(void) :
+        window(nullptr, SDL_DestroyWindow) {}
 
     ~RenderSystem(void)
     {
-           SDL_GL_DeleteContext(context);
+        SDL_GL_DeleteContext(context);
         SDL_Quit();
     }
 
     /**
      * Prepares the system for running.
      */
-    void configure([[maybe_unused]]entityx::EntityManager& entities,
-                   [[maybe_unused]]entityx::EventManager& events) final;
+    void configure(entityx::EntityManager& entities,
+                   entityx::EventManager& events) final;
     
     /**
      * Updates the render system.
      */
-    void update([[maybe_unused]] entityx::EntityManager& entities,
-                [[maybe_unused]] entityx::EventManager& events,
-                [[maybe_unused]] entityx::TimeDelta dt) final;
+    void update(entityx::EntityManager& entities,
+                entityx::EventManager& events,
+                entityx::TimeDelta dt) final;
 
     /**
      * Initializes the rendering system
@@ -76,4 +76,5 @@ public:
     int init(void);
 };
 
-#endif//RENDER_HPP_
+#endif // SYSTEM_RENDER_HPP_
+
index ffefb1de411ebe89e5f292f1ad82e27fe7aa534c..80ac53858cd955e0cc49bab7465ac0df7d3637d9 100644 (file)
 *  SYSTEM SPECIFIC  *
 *********************/
 
-void ScriptSystem::configure([[maybe_unused]]entityx::EntityManager& entities,
-                             [[maybe_unused]]entityx::EventManager& events)
+void ScriptSystem::configure(entityx::EntityManager& entities,
+                             entityx::EventManager& events)
 {
     this->manager = &entities;
     this->events = &events;
 
     events.subscribe<EntitySpawnEvent>(*this);
 
+    // Init after systems.configure() in engine.cpp
     //init();
 }
 
@@ -39,7 +40,6 @@ void ScriptSystem::update([[maybe_unused]] entityx::EntityManager& entites,
                           [[maybe_unused]] entityx::EventManager& events,
                           [[maybe_unused]] entityx::TimeDelta dt)
 {
-
 }
 
 
@@ -81,9 +81,8 @@ void ScriptSystem::doFile(void)
 #include <components/Script.hpp>
 #include <components/Velocity.hpp>
 
-void ScriptSystem::scriptExport()
+void ScriptSystem::scriptExport(void)
 {
-
     std::function<sol::table(sol::table)> func = 
         [this](sol::table t){ return spawn(t);};
 
@@ -174,3 +173,4 @@ sol::table ScriptSystem::spawn(sol::object param)
 
     return *toRet;
 }
+
index be02542873fa75d3bcd6fdc0f2966232b7f85096..84c698c229138a007473cb8b552eef295170e253 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef SCRIPT_HPP_
-#define SCRIPT_HPP_
+#ifndef SYSTEM_SCRIPT_HPP_
+#define SYSTEM_SCRIPT_HPP_
 
 #include <entityx/entityx.h>
 #include <sol/sol.hpp>
 
-struct EntitySpawnEvent {
-    EntitySpawnEvent (sol::object ref)
-        : ref(ref) {}
-
+struct EntitySpawnEvent
+{
     sol::object ref;
+
+    EntitySpawnEvent(sol::object _ref) :
+        ref(_ref) {}
 };
 
 /**
  * @class ScriptSystem
  * Handles all the game's scripting requests
  */
-class ScriptSystem : public entityx::System<ScriptSystem>
-                   , public entityx::Receiver<ScriptSystem>
+class ScriptSystem : public entityx::System<ScriptSystem>,
+                     public entityx::Receiver<ScriptSystem>
 {
-    private:
-        /**
-         * The script systems internal lua state that handles all
-         * interactions between C and Lua
-         */
-        sol::state lua;
-
-        entityx::EventManager* events;
-        entityx::EntityManager* manager;
-
-    public:
-        ScriptSystem(void)
-        {}
-
-        ~ScriptSystem(void)
-        {}
-
-        /**
-         * Prepares the system for running.
-         */
-        void configure([[maybe_unused]]entityx::EntityManager& entities,
-                       [[maybe_unused]]entityx::EventManager& events) final;
-        
-        /**
-         * Updates the scripting system.
-         */
-        void update([[maybe_unused]] entityx::EntityManager& entites,
-                    [[maybe_unused]] entityx::EventManager& events,
-                    [[maybe_unused]] entityx::TimeDelta dt) final;
-
-        /**
-         * Receives all entity spawning events and manages the
-         * script counterpart.
-         */
-        void receive (const EntitySpawnEvent &toSpawn);
-
-        /**
-         * Initializes the lua states and libraries.
-         * @return Zero on success, non-zero on error
-         */
-        int init(void);
-
-        /**
-         * Run the initialization file.
-         */
-        void doFile(void);
-
-        /**
-         * The function called by lua scripts in order to spawn an entity.
-         * @param param The table that must be passed in by Lua. This is a
-         * sol2 object instead of a sol2 table because this allows us to handle
-         * errors easier instead of letting sol2 do the error handling.
-         */
-        sol::table spawn(sol::object param);
-
-        /**
-         * Contains all calls that export components/functions to lua.
-         */
-        void scriptExport();
+private:
+    /**
+     * The script systems internal lua state that handles all
+     * interactions between C and Lua
+     */
+    sol::state lua;
+
+    entityx::EventManager* events;
+    entityx::EntityManager* manager;
+
+public:
+    ScriptSystem(void) {}
+
+    ~ScriptSystem(void) {}
+
+    /**
+     * Prepares the system for running.
+     */
+    void configure(entityx::EntityManager& entities,
+                   entityx::EventManager& events) final;
+    
+    /**
+     * Updates the scripting system.
+     */
+    void update(entityx::EntityManager& entites,
+                entityx::EventManager& events,
+                entityx::TimeDelta dt) final;
+
+    /**
+     * Receives all entity spawning events and manages the
+     * script counterpart.
+     */
+    void receive(const EntitySpawnEvent &toSpawn);
+
+    /**
+     * Initializes the lua states and libraries.
+     * @return Zero on success, non-zero on error
+     */
+    int init(void);
+
+    /**
+     * Run the initialization file.
+     */
+    void doFile(void);
+
+    /**
+     * The function called by lua scripts in order to spawn an entity.
+     * @param param The table that must be passed in by Lua. This is a
+     * sol2 object instead of a sol2 table because this allows us to handle
+     * errors easier instead of letting sol2 do the error handling.
+     */
+    sol::table spawn(sol::object param);
+
+    /**
+     * Contains all calls that export components/functions to lua.
+     */
+    void scriptExport(void);
 };
 
-#endif//SCRIPT_HPP_
+#endif // SYSTEM_SCRIPT_HPP_
+
index e67a4a08be2e8e28a65dd9d17e4be8e8b219804f..8691ab04bd1f544d1df942f2fb3a482c42ee5d75 100644 (file)
@@ -17,8 +17,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef SHADER_HPP
-#define SHADER_HPP
+#ifndef SYSTEM_SHADER_HPP_
+#define SYSTEM_SHADER_HPP_
 
 #include <string>
 #include <unordered_map>
 
 class Shader
 {
-    private:
-        /**
-         * Reads the contents of a shader file and returns a c++ string
-         * object representing the contents
-         * @param The file path
-         * @return The shader contents
-         */
-        std::string readShader(std::string); 
-
-        /**
-         * Creates a shader from a filename and a shader type
-         * @param The file path containing the shader data
-         * @param What type of shader to create
-         * @return Memory address of shader location
-         */
-        GLuint createShader(std::string, GLenum);
-
-        GLuint program; /**< GPU Memory address of shader program */
-
-        /**
-         * Name of shader attributes and their corresponding memory
-         * locations in which the data exists
-         */
-        std::unordered_map<std::string, GLuint> attributes;
-        
-        /**
-         * Name of shader uniforms in and their corresponding memory
-         * locations in which the data exists
-         */
-        std::unordered_map<std::string, GLuint> uniforms;
-    public:
-        Shader(): program(-1) {}
-        /**
-         * Given the file paths of two shaders, create a shader program.
-         * @param v The file path of the vertex shader file.
-         * @param f The file path of the fragment shader file.
-         * @return The GPU Memory location of the shader program
-         */
-        GLuint createProgram(std::string v, std::string f); 
-
-        /**
-         * Finds and binds an attribute to the current shader if possible
-         * @param The attribute to bind in the shader
-         * @return The memory address of the new attribute, or -1 if the
-         * attribute doesn't exist in the shader
-         */
-        GLint addAttribute(std::string);
-        /**
-         * Finds and binds a uniform to the current shader if possible
-         * @param The uniform to bind in the shader
-         * @return The memory address of the new uniform, or -1 if the
-         * uniform doesn't exist in the shader
-         */
-        GLint addUniform(std::string);
-
-        /**
-         * Finds the GPU memory address of the given attribute in the shader
-         * program
-         * @param The attribute to find
-         * @return The attribute memory location, or -1 if it doesn't exist
-         */
-        GLint getAttribute(std::string);
-        /**
-         * Finds the GPU memory address of the given uniform in the shader
-         * program
-         * @param The uniform to find
-         * @return The uniform memory location, or -1 if it doesn't exist
-         */
-        GLint getUniform(std::string);
-
-        /**
-         * Gets the memory address of the program stored in this object
-         * @return The GPU memory address of the shader program stored
-         */
-        GLuint getProgram();
+private:
+    /**
+     * Reads the contents of a shader file and returns a c++ string
+     * object representing the contents
+     * @param The file path
+     * @return The shader contents
+     */
+    std::string readShader(std::string); 
+
+    /**
+     * Creates a shader from a filename and a shader type
+     * @param The file path containing the shader data
+     * @param What type of shader to create
+     * @return Memory address of shader location
+     */
+    GLuint createShader(std::string, GLenum);
+
+    GLuint program; /**< GPU Memory address of shader program */
+
+    /**
+     * Name of shader attributes and their corresponding memory
+     * locations in which the data exists
+     */
+    std::unordered_map<std::string, GLuint> attributes;
+    
+    /**
+     * Name of shader uniforms in and their corresponding memory
+     * locations in which the data exists
+     */
+    std::unordered_map<std::string, GLuint> uniforms;
+
+public:
+    Shader(void) :
+        program(-1) {}
+
+    /**
+     * Given the file paths of two shaders, create a shader program.
+     * @param v The file path of the vertex shader file.
+     * @param f The file path of the fragment shader file.
+     * @return The GPU Memory location of the shader program
+     */
+    GLuint createProgram(std::string v, std::string f); 
+
+    /**
+     * Finds and binds an attribute to the current shader if possible
+     * @param The attribute to bind in the shader
+     * @return The memory address of the new attribute, or -1 if the
+     * attribute doesn't exist in the shader
+     */
+    GLint addAttribute(std::string);
+
+    /**
+     * Finds and binds a uniform to the current shader if possible
+     * @param The uniform to bind in the shader
+     * @return The memory address of the new uniform, or -1 if the
+     * uniform doesn't exist in the shader
+     */
+    GLint addUniform(std::string);
+
+    /**
+     * Finds the GPU memory address of the given attribute in the shader
+     * program
+     * @param The attribute to find
+     * @return The attribute memory location, or -1 if it doesn't exist
+     */
+    GLint getAttribute(std::string);
+
+    /**
+     * Finds the GPU memory address of the given uniform in the shader
+     * program
+     * @param The uniform to find
+     * @return The uniform memory location, or -1 if it doesn't exist
+     */
+    GLint getUniform(std::string);
+
+    /**
+     * Gets the memory address of the program stored in this object
+     * @return The GPU memory address of the shader program stored
+     */
+    GLuint getProgram();
 };
 
-#endif // SHADER_HPP
+#endif // SYSTEM_SHADER_HPP_
+