📄 swarm.space.discrete2d.protocol.html
字号:
<HTML><HEAD><TITLE>Discrete2d</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.53"><LINKREL="HOME"TITLE="Documentation Set for Swarm 2.1.1"HREF="set.html"><LINKREL="UP"TITLE="Space Library"HREF="swarm.space.sgml.reference.html"><LINKREL="PREVIOUS"TITLE="Diffuse2d"HREF="swarm.space.diffuse2d.protocol.html"><LINKREL="NEXT"TITLE="Grid2d"HREF="swarm.space.grid2d.protocol.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Documentation Set for Swarm 2.1.1</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="swarm.space.diffuse2d.protocol.html">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Reference X. Space Library</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="swarm.space.grid2d.protocol.html">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="SWARM.SPACE.DISCRETE2D.PROTOCOL">Discrete2d</A></H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN22954"></A><H2>Name</H2>Discrete2d -- Root class of all 2d discrete spaces.</DIV><DIVCLASS="REFSECT1"><ANAME="AEN22957"></A><H2>Description</H2><P> A Discrete2d is basically a 2d array of ids. Subclasses add particular space semantics onto this. Currently Discrete2d grids are accessed by integer pairs of X and Y coordinates. </P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN22960"></A><H2>Protocols adopted by Discrete2d</H2><P> <AHREF="swarm.objectbase.swarmobject.protocol.html">SwarmObject</A> <AHREF="swarm.defobj.creatable.protocol.html">CREATABLE</A></P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN22965"></A><H2>Methods</H2><DIVCLASS="REFSECT2"><ANAME="AEN22967"></A><H3>Phase: Creating</H3><P></P><UL><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PC.M41"></A><P></P>+ <BCLASS="FUNCPROTOTYPE">create:</B> (id <Zone>)<VARCLASS="PDPARAM">aZone</VAR> <BCLASS="FUNCPROTOTYPE">setSizeX:</B> (unsigned)<VARCLASS="PDPARAM">x</VAR> <BCLASS="FUNCPROTOTYPE">Y:</B> (unsigned)<VARCLASS="PDPARAM">y</VAR> <BR> Convenience constructor for Discrete2d lattice<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PC.M857"></A><P></P>- <BCLASS="FUNCPROTOTYPE">setSizeX:</B> (unsigned)<VARCLASS="PDPARAM">x</VAR> <BCLASS="FUNCPROTOTYPE">Y:</B> (unsigned)<VARCLASS="PDPARAM">y</VAR> <BR> Set the world size.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PC.M121"></A><P></P>- (id *)<BCLASS="FUNCPROTOTYPE">allocLattice</B><BR> Allocate memory for the lattice. <P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PC.M577"></A><P></P>- <BCLASS="FUNCPROTOTYPE">makeOffsets</B><BR> Given an array size, compute the offsets array that caches the multiplication by ysize. See the discrete2dSiteAt macro. <P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PC.M228"></A><P></P>- <BCLASS="FUNCPROTOTYPE">createEnd</B><BR> Create the lattice, precompute the offsets based on Y coordinate.<P></P></DIV></LI></UL></DIV><DIVCLASS="REFSECT2"><ANAME="AEN23018"></A><H3>Phase: Setting</H3><P></P><UL><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PS.M790"></A><P></P>- <BCLASS="FUNCPROTOTYPE">setLattice:</B> (id *)<VARCLASS="PDPARAM">lattice</VAR> <BR><P></P></DIV></LI></UL></DIV><DIVCLASS="REFSECT2"><ANAME="AEN23030"></A><H3>Phase: Using</H3><P></P><UL><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M489"></A><P></P>- (unsigned)<BCLASS="FUNCPROTOTYPE">getSizeX</B><BR> Get the size of the lattice in the X dimension.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M490"></A><P></P>- (unsigned)<BCLASS="FUNCPROTOTYPE">getSizeY</B><BR> Get the size of the lattice in the Y dimension.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M441"></A><P></P>- <BCLASS="FUNCPROTOTYPE">getObjectAtX:</B> (unsigned)<VARCLASS="PDPARAM">x</VAR> <BCLASS="FUNCPROTOTYPE">Y:</B> (unsigned)<VARCLASS="PDPARAM">y</VAR> <BR> Return the pointer stored at (x,y).<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M521"></A><P></P>- (long)<BCLASS="FUNCPROTOTYPE">getValueAtX:</B> (unsigned)<VARCLASS="PDPARAM">x</VAR> <BCLASS="FUNCPROTOTYPE">Y:</B> (unsigned)<VARCLASS="PDPARAM">y</VAR> <BR> Return the integer stored at (x,y). <P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M621"></A><P></P>- <BCLASS="FUNCPROTOTYPE">putObject:</B> <VARCLASS="PDPARAM">anObject</VAR> <BCLASS="FUNCPROTOTYPE">atX:</B> (unsigned)<VARCLASS="PDPARAM">x</VAR> <BCLASS="FUNCPROTOTYPE">Y:</B> (unsigned)<VARCLASS="PDPARAM">y</VAR> <BR> Put the given pointer to (x,y) overwriting whatever was there.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M628"></A><P></P>- <BCLASS="FUNCPROTOTYPE">putValue:</B> (long)<VARCLASS="PDPARAM">v</VAR> <BCLASS="FUNCPROTOTYPE">atX:</B> (unsigned)<VARCLASS="PDPARAM">x</VAR> <BCLASS="FUNCPROTOTYPE">Y:</B> (unsigned)<VARCLASS="PDPARAM">y</VAR> <BR> Put the given integer to (x,y) overwriting whatever was there.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M275"></A><P></P>- <BCLASS="FUNCPROTOTYPE">fastFillWithValue:</B> (long)<VARCLASS="PDPARAM">aValue</VAR> <BR> Directly fills the lattice with a value.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M274"></A><P></P>- <BCLASS="FUNCPROTOTYPE">fastFillWithObject:</B> <VARCLASS="PDPARAM">anObj</VAR> <BR> Directly fills the lattice with an object.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M279"></A><P></P>- <BCLASS="FUNCPROTOTYPE">fillWithValue:</B> (long)<VARCLASS="PDPARAM">aValue</VAR> <BR> Fills the space using putValue.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M278"></A><P></P>- <BCLASS="FUNCPROTOTYPE">fillWithObject:</B> <VARCLASS="PDPARAM">anObj</VAR> <BR> Fills the space using putObject.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M411"></A><P></P>- (id *)<BCLASS="FUNCPROTOTYPE">getLattice</B><BR> Returns the lattice pointer - use this for fast access. <P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M736"></A><P></P>- (int)<BCLASS="FUNCPROTOTYPE">setDiscrete2d:</B> (id <Discrete2d>)<VARCLASS="PDPARAM">a</VAR> <BCLASS="FUNCPROTOTYPE">toFile:</B> (const char *)<VARCLASS="PDPARAM">filename</VAR> <BR> This method reads a PGM formatted file and pipes the data into a Discrete2d object. <P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M203"></A><P></P>- <BCLASS="FUNCPROTOTYPE">copyDiscrete2d:</B> (id <Discrete2d>)<VARCLASS="PDPARAM">a</VAR> <BCLASS="FUNCPROTOTYPE">toDiscrete2d:</B> (id <Discrete2d>)<VARCLASS="PDPARAM">b</VAR> <BR> This method copies the data in one Discrete2d object to another Discrete2d object. It assumes that both objects already exist.<P></P></DIV></LI><LI><DIVCLASS="FUNCSYNOPSIS"><ANAME="SWARM.SPACE.DISCRETE2D.METHOD.PU.M444"></A><P></P>- (long *)<BCLASS="FUNCPROTOTYPE">getOffsets</B><BR><P></P></DIV></LI></UL></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN23171"></A><H2>Examples</H2><DIVCLASS="EXAMPLE"><ANAME="SWARM.SPACE.DISCRETE2D.GENERIC.2.EXAMPLE"></A><P><B>Example space/Discrete2d/1. </B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"> Discrete2d instances can now serialize themselves (without needing additional classes such as Int2dFiler). The result of value (shallow) Lisp serialization of a 4x3 Discrete2d consisting of long values might be: (list (cons 'myDiscrete2d (make-instance 'Discrete2d #:xsize 4 #:ysize 3 #:lattice (parse #2((1000 1000 1000 1000) (1000 1000 1000 1000) (1000 1000 10 1000)))))) For object (deep) Lisp serialization of the same 4x3 lattice with identical instances of MyClass at each point (except at (2,2) which has an instance of MyClassOther) would look like: (list (cons 'myDiscrete2d (make-instance 'Discrete2d #:xsize 4 #:ysize 3 #:lattice (parse (cons '(0 . 0) (make-instance 'MyClass #:strVal "Hello World")) (cons '(0 . 1) (make-instance 'MyClass #:strVal "Hello World")) (cons '(0 . 2) (make-instance 'MyClass #:strVal "Hello World")) (cons '(1 . 0) (make-instance 'MyClass #:strVal "Hello World")) (cons '(1 . 1) (make-instance 'MyClass #:strVal "Hello World")) (cons '(1 . 2) (make-instance 'MyClass #:strVal "Hello World")) (cons '(2 . 0) (make-instance 'MyClass #:strVal "Hello World")) (cons '(2 . 1) (make-instance 'MyClass #:strVal "Hello World")) (cons '(2 . 2) (make-instance 'MyClassOther #:strVal "Other World")) (cons '(3 . 0) (make-instance 'MyClass #:strVal "Hello World")) (cons '(3 . 1) (make-instance 'MyClass #:strVal "Hello World")) (cons '(3 . 2) (make-instance 'MyClass #:strVal "Hello World"))))))</PRE></TD></TR></TABLE></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="swarm.space.diffuse2d.protocol.html">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="set.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="swarm.space.grid2d.protocol.html">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Diffuse2d</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="swarm.space.sgml.reference.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Grid2d</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -