Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

AngelScript auto subscribe to events. #2529

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

orefkov
Copy link
Contributor

@orefkov orefkov commented Oct 23, 2019

Allow autosubscribe to events methods in instances of ScriptObject-derived classes, based on their names.

@ArnisLielturks ArnisLielturks added the улучшение Улучшение существующих вещей label Feb 3, 2020
Copy link
Contributor

@ArnisLielturks ArnisLielturks left a 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,
Copy link
Contributor

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
Copy link
Contributor

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.

Comment on lines +70 to +80
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'
};
Copy link
Contributor

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)
Copy link
Contributor

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?

@github-actions
Copy link

github-actions bot commented Mar 9, 2020

Marking this stale since there has been no activity for 30 days.
It will be closed if there is no activity for another 15 days.

@github-actions github-actions bot added the stale label Mar 9, 2020
@weitjong weitjong added backlog and removed stale labels Mar 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backlog улучшение Улучшение существующих вещей
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants