Angelscript/docs/manual/doc_addon_ctxmgr.html

183 lines
12 KiB
HTML
Raw Permalink Normal View History

2021-04-12 18:25:02 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.18"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Context manager</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="aslogo_small.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">AngelScript
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('doc_addon_ctxmgr.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">Context manager </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/contextmgr/</p>
<p>The <code>CContextMgr</code> is a class designed to aid the management of multiple simultaneous scripts executing in parallel. It supports both <a class="el" href="doc_adv_concurrent.html">concurrent script threads</a> and <a class="el" href="doc_adv_coroutine.html">co-routines</a>.</p>
<p>If the application doesn't need multiple contexts, i.e. all scripts that are executed always complete before the next script is executed, then this class is not necessary.</p>
<p>The context manager uses <a class="el" href="classas_i_script_engine.html#a32391ee83e58083b406ba068ab2ee049">asIScriptEngine::RequestContext</a> to take advantage of any context callbacks registered with the engine, e.g. for debugging or pooling.</p>
<p>Multiple context managers can be used, for example when you have a group of scripts controlling in-game objects, and another group of scripts controlling GUI elements, then each of these groups may be managed by different context managers.</p>
<p>Observe that the context manager class hasn't been designed for multi-threading, so you need to be careful if your application needs to execute scripts from multiple threads.</p>
<dl class="section see"><dt>See also</dt><dd>The samples <a class="el" href="doc_samples_concurrent.html">Concurrent scripts</a> and <a class="el" href="doc_samples_corout.html">Co-routines</a> for uses</dd></dl>
<h1><a class="anchor" id="doc_addon_ctxmgr_1"></a>
Public C++ interface</h1>
<div class="fragment"><div class="line"><span class="keyword">class </span>CContextMgr</div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line"> CContextMgr();</div>
<div class="line"> ~CContextMgr();</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set the function that the manager will use to obtain the time in milliseconds.</span></div>
<div class="line"> <span class="keywordtype">void</span> SetGetTimeCallback(TIMEFUNC_t func);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Registers the following:</span></div>
<div class="line"> <span class="comment">//</span></div>
<div class="line"> <span class="comment">// void sleep(uint milliseconds)</span></div>
<div class="line"> <span class="comment">//</span></div>
<div class="line"> <span class="comment">// The application must set the get time callback for this to work</span></div>
<div class="line"> <span class="keywordtype">void</span> RegisterThreadSupport(<a class="code" href="classas_i_script_engine.html">asIScriptEngine</a> *engine);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Registers the following:</span></div>
<div class="line"> <span class="comment">//</span></div>
<div class="line"> <span class="comment">// funcdef void coroutine(dictionary@)</span></div>
<div class="line"> <span class="comment">// void createCoRoutine(coroutine @func, dictionary @args)</span></div>
<div class="line"> <span class="comment">// void yield()</span></div>
<div class="line"> <span class="keywordtype">void</span> RegisterCoRoutineSupport(<a class="code" href="classas_i_script_engine.html">asIScriptEngine</a> *engine);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Create a new context, prepare it with the function, then return </span></div>
<div class="line"> <span class="comment">// it so that the application can pass the argument values. The context</span></div>
<div class="line"> <span class="comment">// will be released by the manager after the execution has completed.</span></div>
<div class="line"> <span class="comment">// Set keepCtxAfterExecution to true if the application needs to retrieve</span></div>
<div class="line"> <span class="comment">// information from the context after it the script has finished. </span></div>
<div class="line"> <a class="code" href="classas_i_script_context.html">asIScriptContext</a> *AddContext(<a class="code" href="classas_i_script_engine.html">asIScriptEngine</a> *engine, <a class="code" href="classas_i_script_context.html">asIScriptContext</a> *func, <span class="keywordtype">bool</span> keepCtxAfterExecution = <span class="keyword">false</span>);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// If the context was kept after the execution, this method must be </span></div>
<div class="line"> <span class="comment">// called when the application is done with the context so it can be</span></div>
<div class="line"> <span class="comment">// returned to the pool for reuse.</span></div>
<div class="line"> <span class="keywordtype">void</span> DoneWithContext(<a class="code" href="classas_i_script_context.html">asIScriptContext</a> *ctx);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Create a new context, prepare it with the function, then return</span></div>
<div class="line"> <span class="comment">// it so that the application can pass the argument values. The context</span></div>
<div class="line"> <span class="comment">// will be added as a co-routine in the same thread as the currCtx.</span></div>
<div class="line"> <a class="code" href="classas_i_script_context.html">asIScriptContext</a> *AddContextForCoRoutine(<a class="code" href="classas_i_script_context.html">asIScriptContext</a> *currCtx, <a class="code" href="classas_i_script_context.html">asIScriptContext</a> *func);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Execute each script that is not currently sleeping. The function returns after </span></div>
<div class="line"> <span class="comment">// each script has been executed once. The application should call this function</span></div>
<div class="line"> <span class="comment">// for each iteration of the message pump, or game loop, or whatever.</span></div>
<div class="line"> <span class="comment">// Returns the number of scripts still in execution.</span></div>
<div class="line"> <span class="keywordtype">int</span> ExecuteScripts();</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Put a script to sleep for a while</span></div>
<div class="line"> <span class="keywordtype">void</span> SetSleeping(<a class="code" href="classas_i_script_context.html">asIScriptContext</a> *ctx, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> milliSeconds);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Switch the execution to the next co-routine in the group.</span></div>
<div class="line"> <span class="comment">// Returns true if the switch was successful.</span></div>
<div class="line"> <span class="keywordtype">void</span> NextCoRoutine();</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Abort all scripts</span></div>
<div class="line"> <span class="keywordtype">void</span> AbortAll();</div>
<div class="line">};</div>
</div><!-- fragment --><h1><a class="anchor" id="doc_addon_ctxmgr_2"></a>
Public script interface</h1>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="doc_script_stdlib_coroutine.html">Co-routines</a> </dd></dl>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<div class="ttc" id="aclassas_i_script_context_html"><div class="ttname"><a href="classas_i_script_context.html">asIScriptContext</a></div><div class="ttdoc">The interface to the virtual machine.</div><div class="ttdef"><b>Definition:</b> angelscript.h:2717</div></div>
<div class="ttc" id="aclassas_i_script_engine_html"><div class="ttname"><a href="classas_i_script_engine.html">asIScriptEngine</a></div><div class="ttdoc">The engine interface.</div><div class="ttdef"><b>Definition:</b> angelscript.h:1092</div></div>
<div class="ttc" id="aangelscript_8h_html_ac8186f029686800b7ce36bde4a55c815"><div class="ttname"><a href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a></div><div class="ttdeci">unsigned int asUINT</div><div class="ttdoc">32 bit unsigned integer</div><div class="ttdef"><b>Definition:</b> angelscript.h:600</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Sat Dec 5 2020 23:20:24 for AngelScript by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.18 </li>
</ul>
</div>
</body>
</html>