diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-07-30 11:02:39 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-07-30 11:02:39 -0400 |
commit | b1f93a4f8a5a3e84db9f00d0b41749d4fb32ed26 (patch) | |
tree | 83016b80294f6b7681093ae46aa55840b6fb9ec1 | |
parent | 69768fdc5050bbe5877bf80108584400ea292a4f (diff) |
event feature work; ozone bgm redone
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | assets/music/ozone.ogg | bin | 0 -> 2907698 bytes | |||
-rw-r--r-- | assets/music/town.ogg | bin | 3159813 -> 1791610 bytes | |||
-rw-r--r-- | entityx/Event.h | 10 | ||||
-rw-r--r-- | entityx/Makefile | 7 | ||||
-rw-r--r-- | entityx/libentityx.a | bin | 435972 -> 549286 bytes | |||
-rw-r--r-- | entityx/out/Entity.o | bin | 317167 -> 0 bytes | |||
-rw-r--r-- | entityx/out/Event.o | bin | 23737 -> 0 bytes | |||
-rw-r--r-- | entityx/out/Pool.o | bin | 12428 -> 0 bytes | |||
-rw-r--r-- | entityx/out/System.o | bin | 21295 -> 0 bytes | |||
-rw-r--r-- | entityx/out/Timer.o | bin | 12317 -> 0 bytes | |||
-rw-r--r-- | include/attack.hpp | 2 | ||||
-rw-r--r-- | include/common.hpp | 4 | ||||
-rw-r--r-- | include/engine.hpp | 3 | ||||
-rw-r--r-- | include/inventory.hpp | 6 | ||||
-rw-r--r-- | include/player.hpp | 6 | ||||
-rw-r--r-- | include/systems/dialog.hpp | 2 | ||||
-rw-r--r-- | include/ui.hpp | 2 | ||||
-rw-r--r-- | include/ui_menu.hpp | 2 | ||||
-rw-r--r-- | include/window.hpp | 4 | ||||
-rw-r--r-- | include/world.hpp | 2 | ||||
-rw-r--r-- | lib/libentityx.a | bin | 0 -> 550610 bytes | |||
-rw-r--r-- | src/attack.cpp | 3 | ||||
-rw-r--r-- | src/inventory.cpp | 14 | ||||
-rw-r--r-- | src/player.cpp | 9 | ||||
-rw-r--r-- | src/systems/dialog.cpp | 3 | ||||
-rwxr-xr-x | src/tinyxml2.cpp | 6 | ||||
-rw-r--r-- | src/ui.cpp | 3 | ||||
-rw-r--r-- | src/ui_menu.cpp | 5 | ||||
-rw-r--r-- | src/window.cpp | 6 | ||||
-rw-r--r-- | src/world.cpp | 5 | ||||
-rw-r--r-- | xml/!town2.xml | 4 |
32 files changed, 63 insertions, 54 deletions
@@ -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 Binary files differnew file mode 100644 index 0000000..fd78f7b --- /dev/null +++ b/assets/music/ozone.ogg diff --git a/assets/music/town.ogg b/assets/music/town.ogg Binary files differindex 0cbe3a7..899f136 100644 --- a/assets/music/town.ogg +++ b/assets/music/town.ogg diff --git a/entityx/Event.h b/entityx/Event.h index cb7b3ab..988c9a1 100644 --- a/entityx/Event.h +++ b/entityx/Event.h @@ -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_; diff --git a/entityx/Makefile b/entityx/Makefile index 5deb756..58b18a7 100644 --- a/entityx/Makefile +++ b/entityx/Makefile @@ -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 diff --git a/entityx/libentityx.a b/entityx/libentityx.a Binary files differindex 643acc6..2196a18 100644 --- a/entityx/libentityx.a +++ b/entityx/libentityx.a diff --git a/entityx/out/Entity.o b/entityx/out/Entity.o Binary files differdeleted file mode 100644 index fde66e6..0000000 --- a/entityx/out/Entity.o +++ /dev/null diff --git a/entityx/out/Event.o b/entityx/out/Event.o Binary files differdeleted file mode 100644 index 8f83146..0000000 --- a/entityx/out/Event.o +++ /dev/null diff --git a/entityx/out/Pool.o b/entityx/out/Pool.o Binary files differdeleted file mode 100644 index 4d0bc5d..0000000 --- a/entityx/out/Pool.o +++ /dev/null diff --git a/entityx/out/System.o b/entityx/out/System.o Binary files differdeleted file mode 100644 index 6b38822..0000000 --- a/entityx/out/System.o +++ /dev/null diff --git a/entityx/out/Timer.o b/entityx/out/Timer.o Binary files differdeleted file mode 100644 index fc47589..0000000 --- a/entityx/out/Timer.o +++ /dev/null diff --git a/include/attack.hpp b/include/attack.hpp index 37025e1..941e3d7 100644 --- a/include/attack.hpp +++ b/include/attack.hpp @@ -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); }; diff --git a/include/common.hpp b/include/common.hpp index a03a888..9ecd912 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -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_ diff --git a/include/engine.hpp b/include/engine.hpp index 5824950..448c397 100644 --- a/include/engine.hpp +++ b/include/engine.hpp @@ -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; } }; diff --git a/include/inventory.hpp b/include/inventory.hpp index 475575c..448e27f 100644 --- a/include/inventory.hpp +++ b/include/inventory.hpp @@ -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); diff --git a/include/player.hpp b/include/player.hpp index 077e798..ffd2863 100644 --- a/include/player.hpp +++ b/include/player.hpp @@ -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. diff --git a/include/systems/dialog.hpp b/include/systems/dialog.hpp index 407f043..9fd3b90 100644 --- a/include/systems/dialog.hpp +++ b/include/systems/dialog.hpp @@ -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; }; diff --git a/include/ui.hpp b/include/ui.hpp index fa711d2..bfa2fdd 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -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; }; diff --git a/include/ui_menu.hpp b/include/ui_menu.hpp index cf7ffd6..2cbbefb 100644 --- a/include/ui_menu.hpp +++ b/include/ui_menu.hpp @@ -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; } }; diff --git a/include/window.hpp b/include/window.hpp index 36618e5..29ea76b 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -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_ diff --git a/include/world.hpp b/include/world.hpp index 570cc9d..059efa3 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -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 Binary files differnew file mode 100644 index 0000000..86e8ce5 --- /dev/null +++ b/lib/libentityx.a diff --git a/src/attack.cpp b/src/attack.cpp index e4b2671..720e2f2 100644 --- a/src/attack.cpp +++ b/src/attack.cpp @@ -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) diff --git a/src/inventory.cpp b/src/inventory.cpp index 95ab523..f200705 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -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) diff --git a/src/player.cpp b/src/player.cpp index 3606bc7..9611d0e 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -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; } diff --git a/src/systems/dialog.cpp b/src/systems/dialog.cpp index 87327ca..dd07ab8 100644 --- a/src/systems/dialog.cpp +++ b/src/systems/dialog.cpp @@ -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) diff --git a/src/tinyxml2.cpp b/src/tinyxml2.cpp index d765357..7473881 100755 --- a/src/tinyxml2.cpp +++ b/src/tinyxml2.cpp @@ -409,17 +409,17 @@ void XMLUtil::ConvertUTF32ToUTF8(unsigned long input, char* output, int* length) --output;
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
input >>= 6;
- [[fallthrough]];
+ //[[fallthrough]];
case 3:
--output;
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
input >>= 6;
- [[fallthrough]];
+ //[[fallthrough]];
case 2:
--output;
*output = (char)((input | BYTE_MARK) & BYTE_MASK);
input >>= 6;
- [[fallthrough]];
+ //[[fallthrough]];
case 1:
--output;
*output = (char)(input | FIRST_BYTE_MARK[*length]);
@@ -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) diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp index 11c10a7..a48182b 100644 --- a/src/ui_menu.cpp +++ b/src/ui_menu.cpp @@ -11,12 +11,12 @@ 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; diff --git a/src/window.cpp b/src/window.cpp index af0f63b..48c0f31 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -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) diff --git a/src/world.cpp b/src/world.cpp index af6f47b..7904c4f 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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) diff --git a/xml/!town2.xml b/xml/!town2.xml index 8df73a4..fcdf507 100644 --- a/xml/!town2.xml +++ b/xml/!town2.xml @@ -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> |