Vp wait: Difference between revisions

From Virtual Paradise Wiki
Jump to navigation Jump to search
(Created page with "{{sdk method page|wait|Pumps incoming and outgoing network activity and fires any world server events. Required for most in-world method calls (e.g. {{sdk method|say}}) and ev...")
 
No edit summary
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{sdk method page|wait|Pumps incoming and outgoing network activity and fires any world server events. Required for most in-world method calls (e.g. {{sdk method|say}}) and events to actually happen.
{{sdk method page|wait|Pumps incoming and outgoing network traffic and fires any registered callbacks and events.
|paramex=1000
|paramex=1000
|parameters=
|parameters=
   {{sdk parameter row|int|milliseconds|Maximum amount of time to pump (in milliseconds)}}
   {{sdk parameter row|int|milliseconds|Maximum amount of time to pump (in milliseconds)}}
|returncodes=
|returncodes=
   {{sdk return code row|NOT_INITIALIZED|SDK not initialized with {{sdk method|init}} yet}}
   {{sdk return code row|not_supported    |vp_wait is not supported by this instance, for example a custom vp_net_config was passed to {{sdk method|create}}}}
  {{sdk return code row|recursive_wait  |vp_wait was called recursively on the same instance (calling it from within an event/callback handler)}}
  {{sdk return code row|connection_error |Waiting for data failed or there are no connections to wait for events on}}
|behavior=
|behavior=
* This will only pump for up to the amount of milliseconds, with no predictable count of how much data is sent
* This method will attempt to send all pending messages and receive all pending data within the given time limit
* All [[:Category:SDK events|SDK events]] are fired from this method call
** It will wait for the full number of milliseconds if no network messages are received (or are already waiting to be processed)
* If a value of {{code|0}} is passed, it will at least pump once or fire any event once
** If one or more messages are received while waiting (or were received since the last call to vp_wait), then it will return after processing them and firing any registered event/callback handler functions.
* If there is nothing left to pump (e.g. no events to fire or data to send), it will immediately return and not sleep for the remainder of the given time
** If a value of {{code|0}} milliseconds is passed, it will process any messages that have been received since the last call to vp_wait (i.e. "polling")
 
* All [[:Category:SDK events|SDK events]] and [[:Category:SDK callbacks|SDK callbacks]] are fired from this method call. Consequently, they are fired on the same thread as the caller
|caveats=
|caveats=
This method should never be called inside an event handler originating from a previous {{sdk method|wait}} call. Doing so is undefined behavior and may break the internal SDK state. For example:
This method should never be called inside an event handler originating from a previous {{sdk method|wait}} call. Note: The current SDK will simply return {{code|VP_RC_RECURSIVE_WAIT}}. For example:
<C>
<syntaxhighlight lang="c">
...
...
vp_event_set(instance, VP_EVENT_AVATAR_ADD, event_avatar_add);
vp_event_set(instance, VP_EVENT_AVATAR_ADD, event_avatar_add);
while(vp_wait(instance, 1000) == 0){}
while(vp_wait(instance, 1000) == 0){}
...
...
void event_avatar_add(VPInstance sdk)
void event_avatar_add(VPInstance instance)
{
{
     char message[100];
     char message[300];
     sprintf((char*)&message, "Hello, %s!", vp_string(sdk, VP_AVATAR_NAME));
     sprintf((char*)&message, "Hello, %s!", vp_string(sdk, VP_AVATAR_NAME));
     vp_say(sdk, (char*)&message);
     vp_say(instance, (char*)&message);
     vp_wait(instance, 1000); // Undefined behavior
     vp_wait(instance, 1000); // Undefined behavior
}
}
</C>
</syntaxhighlight>
 
The millisecond parameter should not be used for any sort of timekeeping,
 
<syntaxhighlight lang="c">
while (vp_wait(instance, 5000)) {
  vp_say(instance, "5 seconds have passed!"); // this is not guaranteed to occur every 5 seconds (if any message is received while waiting)
}
</syntaxhighlight>
|seealso=
* {{sdk method|event_set}}
}}
}}

Latest revision as of 21:58, 20 August 2018

Method call snippet vp_wait(instance, 1000);

Pumps incoming and outgoing network traffic and fires any registered callbacks and events.

Parameters

These are the parameters that this method requires:

Parameter Usage
VPInstance
instance
Pointer to the instance this method call is intended for
int
milliseconds
Maximum amount of time to pump (in milliseconds)

Returns

This method returns a return code integer, which indicates whether the call was successful or errored for any reason:

Return code Cause
VP_RC_SUCCESS Successful call (for methods that have a registered callback, it only means the request has been sent)
VP_RC_NOT_SUPPORTED vp_wait is not supported by this instance, for example a custom vp_net_config was passed to vp_create()
VP_RC_RECURSIVE_WAIT vp_wait was called recursively on the same instance (calling it from within an event/callback handler)
VP_RC_CONNECTION_ERROR Waiting for data failed or there are no connections to wait for events on

Behavior

  • This method will attempt to send all pending messages and receive all pending data within the given time limit
    • It will wait for the full number of milliseconds if no network messages are received (or are already waiting to be processed)
    • If one or more messages are received while waiting (or were received since the last call to vp_wait), then it will return after processing them and firing any registered event/callback handler functions.
    • If a value of 0 milliseconds is passed, it will process any messages that have been received since the last call to vp_wait (i.e. "polling")
  • All SDK events and SDK callbacks are fired from this method call. Consequently, they are fired on the same thread as the caller

Caveats

This method should never be called inside an event handler originating from a previous vp_wait() call. Note: The current SDK will simply return VP_RC_RECURSIVE_WAIT. For example:

...
vp_event_set(instance, VP_EVENT_AVATAR_ADD, event_avatar_add);
while(vp_wait(instance, 1000) == 0){}
...
void event_avatar_add(VPInstance instance)
{
    char message[300];
    sprintf((char*)&message, "Hello, %s!", vp_string(sdk, VP_AVATAR_NAME));
    vp_say(instance, (char*)&message);
    vp_wait(instance, 1000); // Undefined behavior
}

The millisecond parameter should not be used for any sort of timekeeping,

while (vp_wait(instance, 5000)) {
  vp_say(instance, "5 seconds have passed!"); // this is not guaranteed to occur every 5 seconds (if any message is received while waiting)
}

Examples

This method has no usage examples; please add at least one to this page

See also