AngelScript auto subscribe to events. #2529
base: master
Are you sure you want to change the base?
Conversation
…to events based on their name.
…ated from script's Node.CreateScriptObject.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I think this is a very nice feature. Will test it out to see how it actually handles few cases.
globalVars["GlobalName"] must be object handle to Object-derived class | ||
and GlobalName may not contain '_'. | ||
|
||
When script object created by deserialization of scene, subscription occurs at the moment after setting the attributes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When script object is
created by deserialization of a
scene
object is created and its Start method is called. If child nodes not exists, or script object attributes are not set, | ||
then their events are not subscribed. | ||
|
||
If script object created from C++ code by ScriptInstance::CreateObject, subscription not maked, and you must |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subscription not maked, and you must call ScriptInstance::SubscribeToAutoEvents.
change to something like
automatic subscription will not be made, so you must call ScriptInstance::SubscribeToAutoEvents.
enum SubscribeType { | ||
sCommon, // to all sources with this event, 'on_EventName' | ||
sNode, // to events from that node, 'onNode_EventName' | ||
sScene, // to events from scene, 'onScene_EventName' | ||
sParent, // to events from parent node, 'onParent_EventName' | ||
sModule, // to events from script file 'onModule_EventName' | ||
sChild, // to events from child node, 'onChild_ChildName_EventName' | ||
sAttr, // to events from attribute, 'onAttr_AttributeName_EventName' | ||
sVar, // to events from script global var 'onVar_VariableName_EventName' | ||
sGlobal, // to events from context global var'onGlobal_KeyName_EventName' | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
padding should be fixed
@@ -961,6 +995,195 @@ void ScriptInstance::HandleScriptFileReloadFinished(StringHash eventType, Varian | |||
} | |||
} | |||
|
|||
static bool isMethodCanBeEventHandler(asIScriptFunction* pFunc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isMethodCanBeEventHandler
sounds wrong. Can we rename it to something like canMethodBeEventHandler
?
Marking this stale since there has been no activity for 30 days. |
Allow autosubscribe to events methods in instances of ScriptObject-derived classes, based on their names.