diff --git a/docs/message-passing.md b/docs/message-passing.md index 9106f972..4179846b 100644 --- a/docs/message-passing.md +++ b/docs/message-passing.md @@ -17,8 +17,6 @@ This system is currently in development and most of the content here was generat - **Swizzler**: A utility that allows you to dynamically replace (swizzle) methods on objects at runtime, enabling dynamic behavior changes. - **Reflectable**: An interface that allows for runtime inspection and manipulation of objects' properties. - **ObjectFactory**: A factory for creating instances of `Reflectable` objects dynamically based on type names. -- **Notification**: A specialized message used to broadcast events to multiple observers. -- **NotificationCenter**: A central hub for managing notifications and observers. ### Getting Started @@ -126,40 +124,3 @@ yaze::app::core::ObjectFactory factory; factory.RegisterType("MyObject"); auto my_object = factory.CreateObject("MyObject"); ``` - - -### Using the Notification System - -The yaze notification system that allows for broadcasting events to multiple observers. This is particularly useful when you need to inform several parts of the editor about a state change or event without tightly coupling them. - -#### 1. **Setting Up the Notification Center** - -To use notifications, create an instance of `NotificationCenter`. - -```cpp -yaze::app::core::NotificationCenter notification_center; -``` - -#### 2. **Adding and Removing Observers** - -Observers, which are typically components implementing the `IMessageListener` interface, can register themselves to listen for specific notifications. - -```cpp -MyListener observer; -notification_center.AddObserver("MyNotificationType", &observer); -``` - -If an observer no longer needs to listen for notifications, it can be removed: - -```cpp -notification_center.RemoveObserver("MyNotificationType", &observer); -``` - -#### 3. **Posting Notifications** - -To broadcast a notification, create a `Notification` object and post it through the `NotificationCenter`. All registered observers will receive the notification. - -```cpp -yaze::app::core::Notification notification("MyNotificationType", this, some_payload); -notification_center.PostNotification(notification); -``` diff --git a/src/app/core/constants.h b/src/app/core/constants.h index 467fa7bc..f318664c 100644 --- a/src/app/core/constants.h +++ b/src/app/core/constants.h @@ -1,9 +1,7 @@ #ifndef YAZE_APP_CORE_CONSTANTS_H #define YAZE_APP_CORE_CONSTANTS_H -#include - -#include "absl/strings/string_view.h" +#include #define TAB_BAR(w) if (ImGui::BeginTabBar(w)) { #define END_TAB_BAR() \ diff --git a/src/app/core/notification.h b/src/app/core/notification.h deleted file mode 100644 index 9fbd9814..00000000 --- a/src/app/core/notification.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef YAZE_APP_CORE_NOTIFICATION_H -#define YAZE_APP_CORE_NOTIFICATION_H - -#include -#include -#include -#include - -#include "app/core/message.h" - -namespace yaze { -namespace app { -namespace core { - -struct Notification : public Message { - Notification(const std::string& type, void* sender, std::any payload) - : Message{type, sender, payload} {} -}; - -class NotificationCenter { - public: - void AddObserver(const std::string& notificationType, - IMessageListener* observer) { - observers[notificationType].push_back(observer); - } - - void RemoveObserver(const std::string& notificationType, - IMessageListener* observer) { - auto& observerList = observers[notificationType]; - observerList.erase( - std::remove(observerList.begin(), observerList.end(), observer), - observerList.end()); - } - - void PostNotification(const Notification& notification) { - const auto& observerList = observers[notification.type]; - for (auto observer : observerList) { - observer->OnMessageReceived(notification); - } - } - - private: - std::unordered_map> observers; -}; - -} // namespace core -} // namespace app -} // namespace yaze \ No newline at end of file diff --git a/src/app/editor/overworld/entity.cc b/src/app/editor/overworld/entity.cc index 9873d81b..ca3098c2 100644 --- a/src/app/editor/overworld/entity.cc +++ b/src/app/editor/overworld/entity.cc @@ -384,7 +384,7 @@ void DrawSpriteTable(std::function onSpriteSelect) { // Initialize items if empty if (items.empty()) { for (int i = 0; i < 256; ++i) { - items.push_back(SpriteItem{i, kSpriteDefaultNames[i].data()}); + items.push_back(SpriteItem{i, zelda3::kSpriteDefaultNames[i].data()}); } } diff --git a/src/app/editor/sprite/sprite_editor.cc b/src/app/editor/sprite/sprite_editor.cc index 06d3388e..5c0cd211 100644 --- a/src/app/editor/sprite/sprite_editor.cc +++ b/src/app/editor/sprite/sprite_editor.cc @@ -4,6 +4,7 @@ #include "app/editor/sprite/zsprite.h" #include "app/gui/icons.h" #include "app/gui/input.h" +#include "app/zelda3/sprite/sprite.h" namespace yaze { namespace app { @@ -71,13 +72,13 @@ void SpriteEditor::DrawVanillaSpriteEditor() { for (int n = 0; n < active_sprites_.Size;) { bool open = true; - if (active_sprites_[n] > sizeof(kSpriteDefaultNames) / 4) { + if (active_sprites_[n] > sizeof(zelda3::kSpriteDefaultNames) / 4) { active_sprites_.erase(active_sprites_.Data + n); continue; } if (ImGui::BeginTabItem( - kSpriteDefaultNames[active_sprites_[n]].data(), &open, + zelda3::kSpriteDefaultNames[active_sprites_[n]].data(), &open, ImGuiTabItemFlags_None)) { DrawSpriteCanvas(); ImGui::EndTabItem(); @@ -188,10 +189,10 @@ void SpriteEditor::DrawSpritesList() { ImVec2(ImGui::GetContentRegionAvail().x, 0), true, ImGuiWindowFlags_NoDecoration)) { int i = 0; - for (const auto each_sprite_name : kSpriteDefaultNames) { + for (const auto each_sprite_name : zelda3::kSpriteDefaultNames) { rom()->resource_label()->SelectableLabelWithNameEdit( current_sprite_id_ == i, "Sprite Names", core::UppercaseHexByte(i), - kSpriteDefaultNames[i].data()); + zelda3::kSpriteDefaultNames[i].data()); if (ImGui::IsItemClicked()) { current_sprite_id_ = i; if (!active_sprites_.contains(i)) { diff --git a/src/app/gfx/snes_tile.cc b/src/app/gfx/snes_tile.cc index 2707258d..3b0a0895 100644 --- a/src/app/gfx/snes_tile.cc +++ b/src/app/gfx/snes_tile.cc @@ -1,8 +1,9 @@ #include "snes_tile.h" +#include #include -#include #include +#include #include "app/core/constants.h" @@ -148,7 +149,8 @@ std::vector Convert4bppTo3bpp(const std::vector& tiles) { return ConvertBpp(tiles, 4, 3); } -std::vector SnesTo8bppSheet(const std::vector& sheet, int bpp) { +std::vector SnesTo8bppSheet(const std::vector& sheet, + int bpp) { int xx = 0; // positions where we are at on the sheet int yy = 0; int pos = 0; @@ -200,7 +202,8 @@ std::vector SnesTo8bppSheet(const std::vector& sheet, int bpp) return sheet_buffer_out; } -std::vector Bpp8SnesToIndexed(std::vector data, uint64_t bpp) { +std::vector Bpp8SnesToIndexed(std::vector data, + uint64_t bpp) { // 3BPP // [r0,bp1],[r0,bp2],[r1,bp1],[r1,bp2],[r2,bp1],[r2,bp2],[r3,bp1],[r3,bp2] // [r4,bp1],[r4,bp2],[r5,bp1],[r5,bp2],[r6,bp1],[r6,bp2],[r7,bp1],[r7,bp2] diff --git a/src/app/zelda3/music/spc700.def b/src/app/zelda3/music/spc700.def deleted file mode 100644 index 4781c5ef..00000000 --- a/src/app/zelda3/music/spc700.def +++ /dev/null @@ -1,26 +0,0 @@ -LIBRARY snes_spc -DESCRIPTION "snes_spc 0.9.0" -EXPORTS - spc_new @1 - spc_delete @2 - spc_init_rom @3 - spc_set_output @4 - spc_sample_count @5 - spc_reset @6 - spc_soft_reset @7 - spc_read_port @8 - spc_write_port @9 - spc_end_frame @10 - spc_mute_voices @11 - spc_disable_surround @12 - spc_set_tempo @13 - spc_load_spc @14 - spc_clear_echo @15 - spc_play @16 - spc_skip @17 - spc_filter_new @18 - spc_filter_delete @19 - spc_filter_run @20 - spc_filter_clear @21 - spc_filter_set_gain @22 - spc_filter_set_bass @23 \ No newline at end of file