Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
12-02-2003 02:25
I'd like to extend Xylor's proposal for an llWaitForMessage() event, for all events. list llWaitForEvent(integer EVENT_CONSTANT, float maxWaitTime); This function returns a list containing the return values of the event defined by EVENT_CONSTANT. It blocks the script execution until it gets the values of the specified event, or maxWaitTime (a time in seconds) is reached. Passing a negative value (ex. -1) to maxWaitTIme causes the script to wait indefinitely, passing 0 could be a statement asking the script to wait for the event in the shortest amount of time possible, which could be about 250 ms (if it's at the end of it's timeslice) or 0 ms (if it's getting its timeslice now). Event constants: EVENT_LISTEN; EVENT_LINK_MESSAGE; EVENT_COTNROL; EVENT_CHANGED; EVENT_ON_REZ; EVENT_STATE_ENTRY; EVENT_STATE_EXIT; EVENT_TOUCH; EVENT_TOUCH_START; EVENT_TOUCH_END; EVENT_COLLISION; EVENT_COLLISION_START; EVENT_COLLISION_END; and well... you get the picture  This could optimize script execution on the server. Lets say I made a simple script like:
default { state_entry() { llSay(0,"Hello Avatar!"); llWaitForEvent(EVENT_TOUCH_START,-1); } touch_start(integer n) { llSay(0,"Touched."); llWaitForEvent(EVENT_TOUCH_START,-1); } }
Implimenting this would cause the server to ignore the script until the object is touched, allowing time slice distribution optimization. Unless I have the idea of time slices kind of mixed up, I think the implimentation of something like this would help encapsulation *alot*, and allow the server to optimize time slice usage.
|
Mezzanine Peregrine
Senior Member
Join date: 14 Nov 2003
Posts: 113
|
12-02-2003 02:53
dont' events already get waited for?
Touch-start doesnt occur until you touch it. If you need to wait for touch to occor, put the stuff that you need done when touched, in touch start.
What I'm trying to say is I dont really see the usefulness of this - scripts are not multithreaded - so it basically is ALREADY waiting for touch to occur... (ie, its basically already waiting for all events).
Unless you mean to dos omething like this:
do something wait for touch do something else
but surely 'do something else' in the above could could simply go in the touch event function?
|
Xylor Baysklef
Scripting Addict
Join date: 4 May 2003
Posts: 109
|
12-02-2003 03:43
I like the idea =) Could be useful for simplifying functions. However, Mezzanine is correct in that the example given wouldn't really be beneficial. When an event is not being run, there really isn't any server overhead. The event is probably put into a data structure associated with the object it is attached to, and whenever the object is touched this data structure is check for registered touch handles. (Similar mechanism for other events, I assume). So no time slices are being used outside of events.
That being said, having this function could be useful in other instances, such as waiting for a certain listen event to use a globally available library function call in the vicinity. However, perhaps a llWaitForListen() (much like llWaitForMessage()) would be good enough?
Xylor
|