Angelscript/docs/manual/doc_addon_grid.html

199 lines
13 KiB
HTML

<!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: grid template object</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_grid.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">grid template object </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scriptgrid/</p>
<p>The <code>grid</code> type is a <a class="el" href="doc_adv_template.html">template object</a> that allow the scripts to declare 2D grids of any type. In many ways it is similar to the <a class="el" href="doc_addon_array.html">array template object</a>, but it is specialized for use with areas.</p>
<p>The type is registered with <code>RegisterScriptGrid(asIScriptEngine *engine)</code>.</p>
<h1><a class="anchor" id="doc_addon_grid_1"></a>
Public C++ interface</h1>
<div class="fragment"><div class="line"><span class="keyword">class </span>CScriptGrid</div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line"> <span class="comment">// Set the memory functions that should be used by all CScriptGrids</span></div>
<div class="line"> <span class="keyword">static</span> <span class="keywordtype">void</span> SetMemoryFunctions(<a class="code" href="angelscript_8h.html#ac69a827822c73771cd972bff270cefc7">asALLOCFUNC_t</a> allocFunc, <a class="code" href="angelscript_8h.html#adeecc934971e695fc4441a47694860fb">asFREEFUNC_t</a> freeFunc);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Factory functions</span></div>
<div class="line"> <span class="keyword">static</span> CScriptGrid *Create(<a class="code" href="classas_i_type_info.html">asITypeInfo</a> *gridType);</div>
<div class="line"> <span class="keyword">static</span> CScriptGrid *Create(<a class="code" href="classas_i_type_info.html">asITypeInfo</a> *gridType, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> width, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> height);</div>
<div class="line"> <span class="keyword">static</span> CScriptGrid *Create(<a class="code" href="classas_i_type_info.html">asITypeInfo</a> *gridType, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> width, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> height, <span class="keywordtype">void</span> *defaultValue);</div>
<div class="line"> <span class="keyword">static</span> CScriptGrid *Create(<a class="code" href="classas_i_type_info.html">asITypeInfo</a> *gridType, <span class="keywordtype">void</span> *listBuffer);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Memory management</span></div>
<div class="line"> <span class="keywordtype">void</span> AddRef() <span class="keyword">const</span>;</div>
<div class="line"> <span class="keywordtype">void</span> Release() <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Type information</span></div>
<div class="line"> <a class="code" href="classas_i_type_info.html">asITypeInfo</a> *GetGridObjectType() <span class="keyword">const</span>;</div>
<div class="line"> <span class="keywordtype">int</span> GetGridTypeId() <span class="keyword">const</span>;</div>
<div class="line"> <span class="keywordtype">int</span> GetElementTypeId() <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Size</span></div>
<div class="line"> <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> GetWidth() <span class="keyword">const</span>;</div>
<div class="line"> <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> GetHeight() <span class="keyword">const</span>;</div>
<div class="line"> <span class="keywordtype">void</span> Resize(<a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> width, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> height);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Get a pointer to an element. Returns 0 if out of bounds</span></div>
<div class="line"> <span class="keywordtype">void</span> *At(<a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> x, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> y);</div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">void</span> *At(<a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> x, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> y) <span class="keyword">const</span>;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set value of an element. </span></div>
<div class="line"> <span class="comment">// The value arg should be a pointer to the value that will be copied to the element.</span></div>
<div class="line"> <span class="comment">// Remember, if the grid holds handles the value parameter should be the </span></div>
<div class="line"> <span class="comment">// address of the handle. The refCount of the object will also be incremented</span></div>
<div class="line"> <span class="keywordtype">void</span> SetValue(<a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> x, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> y, <span class="keywordtype">void</span> *value);</div>
<div class="line">};</div>
</div><!-- fragment --><h1><a class="anchor" id="doc_addon_grid_2"></a>
Public script interface</h1>
<pre>
class grid&lt;T&gt;
{
grid();
grid(uint width, uint height);
grid(uint width, uint height, const T &amp;in fillValue);</pre><pre> uint width() const;
uint height() const;
void resize(uint w, uint h);</pre><pre> T &amp;opIndex(uint x, uint y);
const T &amp;opIndex(uint x, uint y) const;
}
</pre><p><b>grid()</b><br />
<b>grid(uint width, uint height)</b><br />
<b>grid(uint width, height, const T &amp;in fillValue)</b><br />
</p>
<p>The constructors initializes the grid object. The default constructor will create an zero sized grid.</p>
<p><b>uint width() const</b><br />
<b>uint height() const</b><br />
</p>
<p>Returns the width and height of the grid.</p>
<p><b>void resize(uint w, uint h)</b></p>
<p>Resizes the grid to the new dimension. The elements that still fit in the grid will keep their values.</p>
<p><b>T &amp;opIndex(uint x, uint y)</b><br />
<b>const T &amp;opIndex(uint x, uint y) const</b><br />
</p>
<p>The index operator returns a reference to one of the elements. If the index is out of bounds a script exception will be raised.</p>
<h1><a class="anchor" id="doc_addon_grid_3"></a>
Example usage in script</h1>
<pre>
// Initialize a 5x5 map
grid&lt;int&gt; map = {{1,0,1,1,1},
{0,0,1,0,0},
{0,1,1,0,1},
{0,1,1,0,1},
{0,0,0,0,1}};</pre><pre> // A function to verify if the next area is walkable
bool canWalk(uint x, uint y)
{
// If the map in the destination is
// clear, it is possible to wark there
return map[x,y] == 0;
}
</pre> </div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<div class="ttc" id="aclassas_i_type_info_html"><div class="ttname"><a href="classas_i_type_info.html">asITypeInfo</a></div><div class="ttdoc">The interface for describing types This interface is used to describe the types in the script engine.</div><div class="ttdef"><b>Definition:</b> angelscript.h:3527</div></div>
<div class="ttc" id="aangelscript_8h_html_adeecc934971e695fc4441a47694860fb"><div class="ttname"><a href="angelscript_8h.html#adeecc934971e695fc4441a47694860fb">asFREEFUNC_t</a></div><div class="ttdeci">void(* asFREEFUNC_t)(void *)</div><div class="ttdoc">The function signature for the custom memory deallocation function.</div><div class="ttdef"><b>Definition:</b> angelscript.h:637</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>
<div class="ttc" id="aangelscript_8h_html_ac69a827822c73771cd972bff270cefc7"><div class="ttname"><a href="angelscript_8h.html#ac69a827822c73771cd972bff270cefc7">asALLOCFUNC_t</a></div><div class="ttdeci">void *(* asALLOCFUNC_t)(size_t)</div><div class="ttdoc">The function signature for the custom memory allocation function.</div><div class="ttdef"><b>Definition:</b> angelscript.h:635</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>