Open iThorgrim opened 1 month ago
Modifying a global unordered_map is not threadsafe
I think a better approach would be to implement something like a topic based asynchronous message queue, where each state would have a consumer to just consume messages from the queue at the start of the state update cycle. It would probably be relatively easy to implement something like AMQP and just use an external message queue server.
I think a better approach would be to implement something like a topic based asynchronous message queue, where each state would have a consumer to just consume messages from the queue at the start of the state update cycle. It would probably be relatively easy to implement something like AMQP and just use an external message queue server.
Integrating AMQP would be an excellent idea, especially as it would also allow you to “chat” with Eluna via external applications, but I think that's a bit too advanced for me ^^.
However, I've taken note of your messages and tried to make the code a bit ""cleaner"", I've used ChatGPT for some things (especially on the mutex issue), I took the opportunity to comment my code, so that it's a bit more readable.
There's the beginnings of a message system that I think is better than the old one, at least better than my first draft.
Thread issues are still there, for example this map modification is still completely unprotected https://github.com/ElunaLuaEngine/Eluna/pull/496/files#diff-292f7269c07f69f285305bde0d329bf6235c448853ba6fd0df6e67590f8176acR34
From what I see this is also broken if you use RegisterStateEvent with a instance map id, only the last instance registered will be receiving events with multistate
This system introduces a Mediator pattern to Eluna, allowing communication between different Lua states based on "mapId". It enables the registration and notification of events across states, such as player logins or custom actions.
How It Works:
Little Example
This system can be expanded in the future to support additional data types and more complex interactions between Lua states.