From 1297f2096b2ddc8eb9834131d5aff88896227af9 Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 14 Nov 2024 13:27:42 -0500 Subject: [PATCH] Update documentation --- docs/message-passing.md | 126 ---------------------------------------- docs/yaze.org | 54 ++++++++--------- 2 files changed, 27 insertions(+), 153 deletions(-) delete mode 100644 docs/message-passing.md diff --git a/docs/message-passing.md b/docs/message-passing.md deleted file mode 100644 index 4179846b..00000000 --- a/docs/message-passing.md +++ /dev/null @@ -1,126 +0,0 @@ -# Message Passing - -## Overview - -yaze includes a message passing and notification system as part of its core library. Supports message filtering, dynamic method binding, swizzling, and reflection. This message system was inspired by Objective-C and Cocoa's message passing system. It aims to overcome some of the difficulties with handling events in ImGui. - -This system is currently in development and most of the content here was generated using ChatGPT to help me organize my thoughts. I will be updating this document as I continue to develop the system. - -### Key Components - -- **Message**: A basic unit of communication between components. It contains a type, sender, and an optional payload. -- **IMessageListener**: An interface for objects that want to receive messages. Implement this interface to handle incoming messages. -- **MessageDispatcher**: The central hub that registers listeners, dispatches messages, and manages protocols, filters, and dynamic handlers. -- **AsyncMessageDispatcher**: An extension of `MessageDispatcher` that supports asynchronous message dispatching via a queue. -- **IMessageProtocol**: An interface for defining custom protocols that can filter or handle messages based on specific criteria. -- **MessageFilter**: A class used to filter which messages a listener should receive. -- **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. - -### Getting Started - -#### 1. **Setting Up the Message Dispatcher** - -To start using the message passing system, first create an instance of `MessageDispatcher` or `AsyncMessageDispatcher` depending on whether you need synchronous or asynchronous message handling. - -```cpp -yaze::app::core::MessageDispatcher dispatcher; -// or for asynchronous: -yaze::app::core::AsyncMessageDispatcher async_dispatcher; -async_dispatcher.Start(); -``` - -The EditorManager in the main yaze app will have a MessageDispatcher instance which can be injected into the various Editor components. This will allow the components to communicate with each other without needing to know about each other. - -#### 2. **Registering Listeners** - -Components that need to listen for messages must implement the `IMessageListener` interface and register themselves with the dispatcher. - -```cpp -class MyListener : public yaze::app::core::IMessageListener { - public: - void OnMessageReceived(const yaze::app::core::Message& message) override { - // Handle the message - } -}; - -MyListener listener; -dispatcher.RegisterListener("MyMessageType", &listener); -``` - -#### 3. **Sending Messages** - -To communicate between components, create a `Message` and send it through the dispatcher. - -```cpp -yaze::app::core::Message message("MyMessageType", this, some_payload); -dispatcher.SendMessage(message); -``` - -#### 4. **Using Protocols and Filters** - -For more advanced message handling, you can define custom protocols and filters. Protocols can determine if they can handle a message, while filters can refine which messages are received by a listener. - -```cpp -class MyProtocol : public yaze::app::core::IMessageProtocol { - public: - bool CanHandleMessage(const yaze::app::core::Message& message) const override { - // Define criteria for handling - return message.type == "MyMessageType"; - } -}; - -dispatcher.RegisterProtocol(new MyProtocol()); - -class MyFilter : public yaze::app::core::MessageFilter { - public: - bool ShouldReceiveMessage(const yaze::app::core::Message& message) const override { - // Filter logic - return true; // Receive all messages of this type - } -}; - -dispatcher.RegisterFilteredListener("MyMessageType", &listener, std::make_unique()); -``` - -#### 5. **Dynamic Method Binding and Swizzling** - -To dynamically bind methods to message types or change the behavior of methods at runtime, use the `Swizzler` and `BindHandler` methods. - -```cpp -dispatcher.BindHandler("MyMessageType", [](const yaze::app::core::Message& message) { - // Handle the message dynamically -}); - -Swizzler swizzler; -swizzler.Swizzle(&some_object, &SomeClass::OriginalMethod, []() { - // New method behavior -}); -``` - -#### 6. **Reflection and Object Creation** - -For systems that require dynamic inspection and manipulation of objects, implement the `Reflectable` interface and use the `ObjectFactory` to create instances dynamically. - -```cpp -class MyObject : public yaze::app::core::Reflectable { - public: - std::string GetTypeName() const override { return "MyObject"; } - std::vector GetPropertyNames() const override { return {"property"}; } - std::any GetPropertyValue(const std::string& property_name) const override { - if (property_name == "property") return property_; - return {}; - } - void SetPropertyValue(const std::string& property_name, const std::any& value) override { - if (property_name == "property") property_ = std::any_cast(value); - } - - private: - int property_; -}; - -yaze::app::core::ObjectFactory factory; -factory.RegisterType("MyObject"); -auto my_object = factory.CreateObject("MyObject"); -``` diff --git a/docs/yaze.org b/docs/yaze.org index 60f4a2ae..df78744e 100644 --- a/docs/yaze.org +++ b/docs/yaze.org @@ -3,14 +3,23 @@ #+AUTHOR: @scawful #+TODO: TODO ACTIVE FEEDBACK VERIFY | DONE -* Infrastructure -** File Handling -*** TODO Update recent files manager to bundle the recent files list with the application -*** TODO Create a util for handling file operations from the bundled resources. -** Font Loading -*** TODO Make font sizes variables so they can be reloaded by the user. -** ZEML -*** TODO Package layout files with the executable to avoid relative file lookup +* Daily Log + +<2024-11-14 Thu> +Been making lots of adjustments and cleaning up old code. Primarily improving the dungeon map editor and supporting bin graphics for my Oracle of Secrets dungeon maps. Additionally, working to support saving for resources like graphics sheets and expanded the project file system. + +<2024-09-07 Sat> +Various header cleanup using the LSP in emacs to detect unused includes. +Making adjustments to font loading so the editor can be opened from terminal/emacs. +Currently the font files and the zeml files require the binary to be relative to `assets/layouts` and `assets/fonts` +I've set it up so that the macOS app bundles the resources into the `yaze.app` so that the binary can be run from anywhere. This will need to be adjusted for other platforms. + +<2024-09-02 Mon> +Extracted the DisplayPalette function out of the PaletteEditor and into its own standalone function. + +<2024-09-01 Sun> +Started learning spacemacs and org-mode. + * Editors ** Overworld *** TODO ZSCustomOverworld implementation. @@ -38,26 +47,17 @@ *** TODO Persist color changes for saving to ROM. ** Screens +*** ACTIVE Dungeon Maps +*** ACTIVE Inventory Menu *** TODO Overworld Map - -*** TODO Dungeon Maps - -*** TODO Inventory Menu - *** TODO Title Screen - *** TODO Naming Screen -* Daily Log - -<2024-09-01 Sun> -Started learning spacemacs and org-mode. - -<2024-09-02 Mon> -Extracted the DisplayPalette function out of the PaletteEditor and into its own standalone function. - -<2024-09-07 Sat> -Various header cleanup using the LSP in emacs to detect unused includes. -Making adjustments to font loading so the editor can be opened from terminal/emacs. -Currently the font files and the zeml files require the binary to be relative to `assets/layouts` and `assets/fonts` -I've set it up so that the macOS app bundles the resources into the `yaze.app` so that the binary can be run from anywhere. This will need to be adjusted for other platforms. +* Infrastructure +** File Handling +*** TODO Update recent files manager to bundle the recent files list with the application +*** DONE Create a util for handling file operations from the bundled resources. +** Font Loading +*** TODO Make font sizes variables so they can be reloaded by the user. +** ZEML +*** DONE Package layout files with the executable to avoid relative file lookup