]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
event feature work; ozone bgm redone
authorClyne Sullivan <tullivan99@gmail.com>
Sun, 30 Jul 2017 15:02:39 +0000 (11:02 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sun, 30 Jul 2017 15:02:39 +0000 (11:02 -0400)
32 files changed:
Makefile
assets/music/ozone.ogg [new file with mode: 0644]
assets/music/town.ogg
entityx/Event.h
entityx/Makefile
entityx/libentityx.a
entityx/out/Entity.o [deleted file]
entityx/out/Event.o [deleted file]
entityx/out/Pool.o [deleted file]
entityx/out/System.o [deleted file]
entityx/out/Timer.o [deleted file]
include/attack.hpp
include/common.hpp
include/engine.hpp
include/inventory.hpp
include/player.hpp
include/systems/dialog.hpp
include/ui.hpp
include/ui_menu.hpp
include/window.hpp
include/world.hpp
lib/libentityx.a [new file with mode: 0644]
src/attack.cpp
src/inventory.cpp
src/player.cpp
src/systems/dialog.cpp
src/tinyxml2.cpp
src/ui.cpp
src/ui_menu.cpp
src/window.cpp
src/world.cpp
xml/!town2.xml

index a8904db56929aa2d6b1d3f40ad52cf7a9d6ac509..59158de3948d9181ccee2599a1940b56db321804 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ CC  = gcc
 CXX = g++
 
 ifeq ($(TARGET_OS),linux)
-       LIBS = -Llib -lgif -lpthread -lGL -lGLEW -lfreetype \
+       LIBS = -Llib -lgif -lentityx -lpthread -lGL -lGLEW -lfreetype \
               -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2main
 endif
 ifeq ($(TARGET_OS),win32)
@@ -40,13 +40,6 @@ clean:
        @mkdir out/components
 
 $(EXEC): $(CXXOUTDIR)/$(CXXOBJ) main.cpp
-       @echo "  CXX     entityx"
-       @g++ -I. -std=c++11 -c entityx/help/Pool.cc -o out/Pool.o
-       @g++ -I. -std=c++11 -c entityx/help/Timer.cc -o out/Timer.o
-       @g++ -I. -std=c++11 -c entityx/Event.cc -o out/Event.o
-       @g++ -I. -std=c++11 -c entityx/Entity.cc -o out/Entity.o
-       @g++ -I. -std=c++11 -c entityx/System.cc -o out/System.o
-       
        @echo "  CXX/LD  main"
        @$(CXX) $(SPECIAL) $(CXXFLAGS) $(CXXINC) $(CXXWARN) -o $(EXEC) main.cpp out/components/*.o out/systems/*.o out/*.o $(LIBS)
        @rm -rf xml/*.dat
diff --git a/assets/music/ozone.ogg b/assets/music/ozone.ogg
new file mode 100644 (file)
index 0000000..fd78f7b
Binary files /dev/null and b/assets/music/ozone.ogg differ
index 0cbe3a7ec2ca9f6d86d1c2ea81193eb2570123d1..899f1360aaf5cfdd7d2ac2996d8ac8ec3f2c827c 100644 (file)
Binary files a/assets/music/town.ogg and b/assets/music/town.ogg differ
index cb7b3ab46dab2d27031e5c0b0f1afacd946dfd14..988c9a193a8044893b5d1ee4651a4267d5a32e99 100644 (file)
@@ -37,7 +37,7 @@ class BaseEvent {
 };
 
 
-typedef Simple::Signal<void (const void*)> EventSignal;
+typedef Simple::Signal<bool (const void*)> EventSignal;
 typedef std::shared_ptr<EventSignal> EventSignalPtr;
 typedef std::weak_ptr<EventSignal> EventSignalWeakPtr;
 
@@ -123,7 +123,7 @@ class EventManager : entityx::help::NonCopyable {
    */
   template <typename E, typename Receiver>
   void subscribe(Receiver &receiver) {
-    void (Receiver::*receive)(const E &) = &Receiver::receive;
+    bool (Receiver::*receive)(const E &) = &Receiver::receive;
     auto sig = signal_for(Event<E>::family());
     auto wrapper = EventCallbackWrapper<E>(std::bind(receive, &receiver, std::placeholders::_1));
     auto connection = sig->connect(wrapper);
@@ -205,9 +205,9 @@ class EventManager : entityx::help::NonCopyable {
   // Functor used as an event signal callback that casts to E.
   template <typename E>
   struct EventCallbackWrapper {
-    explicit EventCallbackWrapper(std::function<void(const E &)> callback) : callback(callback) {}
-    void operator()(const void *event) { callback(*(static_cast<const E*>(event))); }
-    std::function<void(const E &)> callback;
+    explicit EventCallbackWrapper(std::function<bool(const E &)> callback) : callback(callback) {}
+    bool operator()(const void *event) { return callback(*(static_cast<const E*>(event))); }
+    std::function<bool(const E &)> callback;
   };
 
   std::vector<EventSignalPtr> handlers_;
index 5deb7561abec35a9214dc2c077603c84b641e47a..58b18a73c28a78398e08cb5acab1ce5d8c3753c2 100644 (file)
@@ -1,3 +1,5 @@
+# gamedev CHANGE - changed output of libentityx to ../lib/
+
 INC = -I..
 FLG = -std=gnu++11
 
@@ -12,5 +14,6 @@ all:
        g++ $(INC) $(FLG) -c Event.cc -o out/Event.o
        g++ $(INC) $(FLG) -c Entity.cc -o out/Entity.o
        g++ $(INC) $(FLG) -c System.cc -o out/System.o
-       ar rvs libentityx.a out/*.o
-#      g++ out/*.o -shared -o ../entityx.so
\ No newline at end of file
+       ar rvs ../lib/libentityx.a out/*.o
+#      g++ out/*.o -shared -o ../entityx.so
+       rm -rf out
index 643acc69d0e399960ddfa91424e318573e2e69f7..2196a18cc93054099d3ea312b205500f49c4e50d 100644 (file)
Binary files a/entityx/libentityx.a and b/entityx/libentityx.a differ
diff --git a/entityx/out/Entity.o b/entityx/out/Entity.o
deleted file mode 100644 (file)
index fde66e6..0000000
Binary files a/entityx/out/Entity.o and /dev/null differ
diff --git a/entityx/out/Event.o b/entityx/out/Event.o
deleted file mode 100644 (file)
index 8f83146..0000000
Binary files a/entityx/out/Event.o and /dev/null differ
diff --git a/entityx/out/Pool.o b/entityx/out/Pool.o
deleted file mode 100644 (file)
index 4d0bc5d..0000000
Binary files a/entityx/out/Pool.o and /dev/null differ
diff --git a/entityx/out/System.o b/entityx/out/System.o
deleted file mode 100644 (file)
index 6b38822..0000000
Binary files a/entityx/out/System.o and /dev/null differ
diff --git a/entityx/out/Timer.o b/entityx/out/Timer.o
deleted file mode 100644 (file)
index fc47589..0000000
Binary files a/entityx/out/Timer.o and /dev/null differ
index 37025e1ca84dc1f60a20fcd9a6727905c27a9baf..941e3d75f72d6d7fcd925b8164e50103dd67c5b9 100644 (file)
@@ -47,7 +47,7 @@ public:
                ev.subscribe<AttackEvent>(*this);
        }
 
-       void receive(const AttackEvent& ae);
+       bool receive(const AttackEvent& ae);
        void update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt) override;
        static void render(void);
 };
index a03a8880cd4d11b4385a8180bcfa1b4318bb2ea3..9ecd912e6d18783af6e6cb0813996b373e784d10 100644 (file)
@@ -23,11 +23,11 @@ constexpr float PI = 3.1415926535f;
  */
 unsigned int millis(void);
 
-/*namespace std {
+namespace std {
        template<class T>
        constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
                return (v > hi) ? hi : ((v > lo) ? v : lo);
        }
-}*/
+}
 
 #endif // COMMON_HPP_
index 582495025d8918b19b06f58ccdf310fd56f43ad8..448c3970e44a2571183e7f687b537eb2bd8460e1 100644 (file)
@@ -60,8 +60,9 @@ public:
         * A handler for the game ending event.
         * @param gee game end event data
         */
-       inline void receive(const GameEndEvent &gee) {
+       inline bool receive(const GameEndEvent &gee) {
                shouldRun = !(gee.really);
+               return false;
        }
 };
 
index 475575c79f33890296d1184e46203af911abccb7..448e27f254071a186dc7785a98d01b4d35a9364a 100644 (file)
@@ -96,9 +96,9 @@ public:
 
        void configure(entityx::EventManager &ev);
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
-       void receive(const KeyDownEvent &kde);
-       void receive(const MouseClickEvent &mce);
-       void receive(const MouseReleaseEvent &mce);
+       bool receive(const KeyDownEvent &kde);
+       bool receive(const MouseClickEvent &mce);
+       bool receive(const MouseReleaseEvent &mce);
 
        static void render(void);
 
index 077e798a83b261fdcf40133743f4a3b2b69bb919..ffd2863a234edc7a003c7ce25e8d0360a99fe15a 100644 (file)
@@ -53,15 +53,15 @@ public:
         * Handles key up events for the player.
         * @param kue key up event data
         */
-    void receive(const KeyUpEvent&);
+    bool receive(const KeyUpEvent&);
 
        /**
         * Handles key down events for the player.
         * @param kde key down event data
         */
-    void receive(const KeyDownEvent&);
+    bool receive(const KeyDownEvent&);
 
-       void receive(const UseItemEvent&);
+       bool receive(const UseItemEvent&);
 
        /**
         * Gets the player's position.
index 407f04327322805fe184f711bba1367f24194594..9fd3b9006285c00139882480461a62d81640b9e2 100644 (file)
@@ -8,7 +8,7 @@
 class DialogSystem : public entityx::System<DialogSystem>, public entityx::Receiver<DialogSystem> {
 public:
        void configure(entityx::EventManager&);
-       void receive(const MouseClickEvent&);
+       bool receive(const MouseClickEvent&);
        void update(entityx::EntityManager&, entityx::EventManager&, entityx::TimeDelta) override;
 };
 
index fa711d260df774d167b35b7a6c9babc8907d62f8..bfa2fdd981bc62af68abf7affb452af7a9db209d 100644 (file)
@@ -28,7 +28,7 @@ public:
                ev.subscribe<MainSDLEvent>(*this);
        }
 
-       void receive(const MainSDLEvent& event);
+       bool receive(const MainSDLEvent& event);
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
 };
 
index cf7ffd6e5ac098082594805af9b1ef7f30976284..2cbbefb9a16bc804024e03fdb1b983b26e46f6e7 100644 (file)
@@ -60,7 +60,7 @@ public:
 
        void configure(entityx::EventManager& ev)
        { ev.subscribe<MainSDLEvent>(*this); }
-       void receive(const MainSDLEvent& mse);
+       bool receive(const MainSDLEvent& mse);
        void update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt) override 
        { (void)en, (void)ev, (void)dt; }
 };
index 36618e525f720ddeef362c416703d0c69151a97a..29ea76bfe868cc1a1c0947eeebbb31e0a1300323 100644 (file)
@@ -41,8 +41,8 @@ public:
 
        static void render(void);
 
-       void receive(const WindowResizeEvent&); 
-       void receive(const ScreenshotEvent&);
+       bool receive(const WindowResizeEvent&); 
+       bool receive(const ScreenshotEvent&);
 };
 
 #endif // WINDOW_HPP_
index 570cc9d693970bd4cd6f10599df243470372812c..059efa3d87ed1acf4ecb877c18e92f8d5cb31239 100644 (file)
@@ -148,7 +148,7 @@ public:
 
        static float isAboveGround(const vec2& p); //const;
 
-       void receive(const BGMToggleEvent &bte);
+       bool receive(const BGMToggleEvent &bte);
        void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
        static void render(void);
 
diff --git a/lib/libentityx.a b/lib/libentityx.a
new file mode 100644 (file)
index 0000000..86e8ce5
Binary files /dev/null and b/lib/libentityx.a differ
index e4b2671aed3a3635a91e926dd998ef305d0d1649..720e2f222ac306dc922e7e7d70ce236d9226742b 100644 (file)
@@ -28,9 +28,10 @@ bool inrange(float point, float left, float right)
 
 std::vector<AttackSystem::AttackAnimation> AttackSystem::effects;
 
-void AttackSystem::receive(const AttackEvent& ae)
+bool AttackSystem::receive(const AttackEvent& ae)
 {
        attacks.emplace_front(ae);
+       return true;
 }
 
 void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev, entityx::TimeDelta dt)
index 95ab523c52e0b269c1eb8e7e9b2d689a94d4a2d6..f200705f21be8f2ecb39d46c4ad07213c5c93c81 100644 (file)
@@ -212,7 +212,7 @@ void InventorySystem::render(void)
        Render::textShader.unuse();
 }
 
-void InventorySystem::receive(const MouseClickEvent &mce)
+bool InventorySystem::receive(const MouseClickEvent &mce)
 {
        if (mce.button == SDL_BUTTON_RIGHT) {
                game::entities.each<ItemDrop>([&](entityx::Entity e, ItemDrop& id) {
@@ -248,9 +248,10 @@ void InventorySystem::receive(const MouseClickEvent &mce)
                                game::events.emit<UseItemEvent>(mce.position, items[0].item, &attack->second);
                }
        }
+       return true;
 }
 
-void InventorySystem::receive(const MouseReleaseEvent &mre)
+bool InventorySystem::receive(const MouseReleaseEvent &mre)
 {
        if (movingItem != -1) {
                int end = fullInventory ? items.size() : hotbarSize;
@@ -265,7 +266,7 @@ void InventorySystem::receive(const MouseReleaseEvent &mre)
                                }
 
                                movingItem = -1;
-                               return;
+                               return true;
                        }
                }
 
@@ -274,6 +275,7 @@ void InventorySystem::receive(const MouseReleaseEvent &mre)
                items[movingItem].count = 0;
                movingItem = -1;
        }
+       return true;
 }
 
 void InventorySystem::makeDrop(const vec2& p, InventoryEntry& ie)
@@ -308,11 +310,11 @@ void InventorySystem::makeDrop(const vec2& p, const std::string& s, int c)
        e.assign<Physics>();
 }
 
-void InventorySystem::receive(const KeyDownEvent &kde)
+bool InventorySystem::receive(const KeyDownEvent &kde)
 {
-    if (kde.keycode == SDLK_e) {
+    if (kde.keycode == SDLK_e)
                fullInventory ^= true;
-       }
+       return true;
 }
 
 void InventorySystem::add(const std::string& name, int count)
index 3606bc713ee424c0e593318d5d0b4f249b3704df..9611d0e68196ee4b7a703271c8cc7ea980c63e2f 100644 (file)
@@ -132,7 +132,7 @@ void PlayerSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
                vel.x /= 2.0f;
 }
 
-void PlayerSystem::receive(const KeyUpEvent &kue)
+bool PlayerSystem::receive(const KeyUpEvent &kue)
 {
        auto kc = kue.keycode;
 
@@ -145,9 +145,10 @@ void PlayerSystem::receive(const KeyUpEvent &kue)
        } else if (kc == getControl(5)) {
                // TODO ...?
        }
+       return true;
 }
 
-void PlayerSystem::receive(const KeyDownEvent &kde)
+bool PlayerSystem::receive(const KeyDownEvent &kde)
 {
        auto kc = kde.keycode;
        auto& loc = *player.component<Position>().get();
@@ -192,6 +193,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
        } else if (kc == SDLK_t) {
                game::time::tick(50);
        }
+       return true;
 }
 
 vec2 PlayerSystem::getPosition(void) 
@@ -211,7 +213,7 @@ float PlayerSystem::getWidth(void)
        return width;
 }
 
-void PlayerSystem::receive(const UseItemEvent& uie)
+bool PlayerSystem::receive(const UseItemEvent& uie)
 {
        static std::atomic_bool cool (true);
 
@@ -254,4 +256,5 @@ void PlayerSystem::receive(const UseItemEvent& uie)
                        cool.store(true);
                }, uie.item->cooldown).detach();
        }
+       return true;
 }
index 87327cab29e6c92291a1111a32b270822fe9a7f1..dd07ab88ebcbf05cbbc0d8e9446e2fe5a5d71c77 100644 (file)
@@ -25,7 +25,7 @@ void DialogSystem::configure(entityx::EventManager &ev)
        ev.subscribe<MouseClickEvent>(*this);
 }
 
-void DialogSystem::receive(const MouseClickEvent &mce)
+bool DialogSystem::receive(const MouseClickEvent &mce)
 {
        game::entities.each<Position, Solid, Dialog, Name>(
                [&](entityx::Entity e, Position &pos, Solid &dim, Dialog &d, Name &name) {
@@ -144,6 +144,7 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                        }
                }
        });
+       return true;
 }
 
 void DialogSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
index d76535740d7909bc66f5567c1e4a0ee049317b38..7473881482196c7701253f0d58428b7b1e760623 100755 (executable)
@@ -409,17 +409,17 @@ void XMLUtil::ConvertUTF32ToUTF8(unsigned long input, char* output, int* length)
             --output;\r
             *output = (char)((input | BYTE_MARK) & BYTE_MASK);\r
             input >>= 6;\r
-           [[fallthrough]];\r
+           //[[fallthrough]];\r
         case 3:\r
             --output;\r
             *output = (char)((input | BYTE_MARK) & BYTE_MASK);\r
             input >>= 6;\r
-           [[fallthrough]];\r
+           //[[fallthrough]];\r
         case 2:\r
             --output;\r
             *output = (char)((input | BYTE_MARK) & BYTE_MASK);\r
             input >>= 6;\r
-           [[fallthrough]];\r
+           //[[fallthrough]];\r
         case 1:\r
             --output;\r
             *output = (char)(input | FIRST_BYTE_MARK[*length]);\r
index 35de60c6493b06f454d8cda3b5323296638cfcc6..7a10b20a6325de3c196cdde635980975f74bf74a 100644 (file)
@@ -631,7 +631,7 @@ namespace ui {
 
 using namespace ui;
 
-void InputSystem::receive(const MainSDLEvent& event)
+bool InputSystem::receive(const MainSDLEvent& event)
 {
        const auto& e = event.event;
        auto& ev = game::events;
@@ -730,6 +730,7 @@ void InputSystem::receive(const MainSDLEvent& event)
                break;
                
        }
+       return true;
 }
 
 void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
index 11c10a7298e6be39fd05c287588e9f861d1ebc0e..a48182b6308dd5b65b90f0eb0b250adc47dd867b 100644 (file)
 
 static Menu* currentMenu = nullptr;
 
-void SDLReceiver::receive(const MainSDLEvent& mse)
+bool SDLReceiver::receive(const MainSDLEvent& mse)
 {
        switch (mse.event.type) {
        case SDL_QUIT:
                game::endGame();
-               return;
+               return true;
                break;
        case SDL_MOUSEMOTION:
                //ui::premouse.x = e.motion.x;
@@ -36,6 +36,7 @@ void SDLReceiver::receive(const MainSDLEvent& mse)
        default:
                break;
        }
+       return true;
 }
 
 bool SDLReceiver::clicked = false;
index af0f63b444a8dfbed0bf8fa70efa263f8427dd76..48c0f31c2637a535856d3f8b05bca565908de424 100644 (file)
@@ -75,13 +75,14 @@ void WindowSystem::configure(entityx::EventManager &ev)
 }
 
 
-void WindowSystem::receive(const WindowResizeEvent &wre)
+bool WindowSystem::receive(const WindowResizeEvent &wre)
 {
        game::SCREEN_WIDTH = wre.x;
        game::SCREEN_HEIGHT = wre.y;
 
        glViewport(0, 0, wre.x, wre.y);
        SDL_SetWindowSize(window, wre.x, wre.y);
+       return true;
 }
 
 #include <ui.hpp>
@@ -90,10 +91,11 @@ void WindowSystem::receive(const WindowResizeEvent &wre)
 
 static std::atomic_bool doScreenshot;
 
-void WindowSystem::receive(const ScreenshotEvent &scr)
+bool WindowSystem::receive(const ScreenshotEvent &scr)
 {
        (void)scr;
        doScreenshot.store(true);
+       return true;
 }
 
 void WindowSystem::render(void)
index af6f47b1f249f94e2c7a0d58b810909d2e9c1f34..7904c4fcffcf50c208d4c460f98e4847a042ab5b 100644 (file)
@@ -758,11 +758,11 @@ void WorldSystem::render(void)
        waitToSwap = false;
 }
 
-void WorldSystem::receive(const BGMToggleEvent &bte)
+bool WorldSystem::receive(const BGMToggleEvent &bte)
 {
        if (bte.world == nullptr || world.bgm != bte.file) {
                if (bgmCurrent == world.bgm)
-                       return;
+                       return true;
 
                Mix_FadeOutMusic(800);
 
@@ -773,6 +773,7 @@ void WorldSystem::receive(const BGMToggleEvent &bte)
                bgmObj = Mix_LoadMUS(world.bgm.c_str());
                Mix_PlayMusic(bgmObj, -1);
        }
+       return true;
 }
 
 void WorldSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
index 8df73a4bca27436851c4d631df49442268bb842c..fcdf507c4a9a419bac4ac80168a9cebe00ef103b 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <World>
-       <style bgm="assets/music/embark.wav" folder="assets/style/classic/">
+       <style bgm="assets/music/ozone.ogg" folder="assets/style/classic/">
                <layer path="bg/bg.png"/>
                <layer path="bg/bgFarMountain.png"/>
                <layer path="bg/forestTileFar.png"/>
@@ -10,7 +10,7 @@
                <layer path="bg/dirt.png"/>
                <layer path="bg/grass.png"/>
        </style>
-       <generation width="600"/>
+       <generation width="1000"/>
        <time>6000</time>
        <link left="!town.xml"/>
 </World>