Teardown-Issue-Tracker-Maintainers / Teardown-Issue-Tracker

A public repo for the community to track issues/bugs/feature requests in Teardown.
11 stars 6 forks source link

[Feature] Let the TriggerEvent/RegisterListener be able to receive any kind of datatype. #522

Open DimasVoxel opened 3 months ago

DimasVoxel commented 3 months ago

Is your feature request related to a problem (if not, explain why you think this feature should be added)? Please describe.

The event system is an awesome addition to the game which enables direct mod to mod communication, avoiding the registry as a whole. The advantage being that the receiving script doesn't have to constantly check for arriving registry messages.

Currently, this system is limited to strings. While strings are versatile, they still do limit how much data you're able to share. I would like to request being able to send any Lua datatype. This would enable us to have far more sophisticated inter script communication.

Describe the solution you'd like

Currently, Trigger Event is limited to strings being its args. I would like to see that changed in the future, enabling to send, ints, tables and any Lua datatype there is. Why? Being able to send tables would enable us to send Transforms Vectors, and anything one could image quickly from one script to another.

Currently, I am working on Bird mod. Bird mod uses the event system for communication with my pathfinding system.

a message looks like this:

birdRequest = {
startPos = Vec(),
endPos = Vec(),
RequestID = int, 
BirdType = int,
}

and the response

looks like this:

response = {
     pathPoints = {
        1  =  Vec(),
        2  =  Vec(),
        .......
        20 = Vec()
        ......
     },
     RequestID = int, 
     startPos = Vec()
     endPos = Vec()
}     

Ideally I could send this table as is over the event system, but unfortunately I have to serialize it into a string right now. This requires: Create Request -> Serialize -> RecieveRequest and convert Back to table -> CreateResponse -> Serialize -> RecieveResponse.

Unfortunately, doing this with large tables can become very performance intensive very quick: image

Being able to cut down the Process to Create Request -> Recieve -> CreateResponse -> RecieveResponse Would be a massive help.

Describe alternatives you've considered

Right now, the only alternative I can see is to serialize all datatype into strings and convert them back. Usually it works fine for bools, or a number, but it becomes an issue really quick once you have to send large amounts of data.

Additional context

No response

DimasVoxel commented 3 months ago

image

Autumnagnificent commented 3 months ago

While I would say that this borders into another issue that should be created (metatables surviving quicksave & quickload): Supporting metatables and metamethods would be incredibly useful for sending and receiving classes in an object-oriented based workflow.

MathiasElgaard commented 3 months ago

I support this feature request! A mod that I'm working on relies extensively on the event functionality, for communication between instanced/spawned scripts. Being able to send a variety of data types like numbers, vectors and transforms would be immensely convenient. Currently the only other alternative for cross-script communication is reading and writing to the registry, but it undergoes the same limitations of having to serialize more complicated data types like vectors and transforms. Additionally, the event pattern is very practical on its own, and I would like to see more support for it. It avoids having to query the registry for changes every frame, and instead lets you observe changes and do work only whenever they occur.

Gregory-Gregory commented 3 months ago

@DimasVoxel hi!

Thanks for the detailed request feedback! We appreciate the time you took to outline your ideas, and I've added this to our request list.