dev:element_tutorial
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dev:element_tutorial [2014/09/03 19:49] – [Write behavior method] tsmall1 | dev:element_tutorial [2014/09/17 20:00] (current) – [Create the C++ Compilation file] tsmall1 | ||
---|---|---|---|
Line 27: | Line 27: | ||
< | < | ||
- | MFMv2/ | + | MFMv2/ |
</ | </ | ||
Line 46: | Line 46: | ||
</ | </ | ||
- | Which supply you with renaming instructions. | + | Which supply you with renaming instructions. |
===== Set up the Configurable Parameter ===== | ===== Set up the Configurable Parameter ===== | ||
Line 57: | Line 57: | ||
m_targetDensity(this, | m_targetDensity(this, | ||
"The Creg will try to fill this many spots in its event " | "The Creg will try to fill this many spots in its event " | ||
- | " | + | " |
</ | </ | ||
Line 94: | Line 94: | ||
virtual void Behavior(EventWindow< | virtual void Behavior(EventWindow< | ||
{ | { | ||
- | | + | const MDist< |
+ | Random& rand = window.GetRandom(); | ||
+ | |||
+ | SPoint cregAtom; | ||
+ | s32 cregCount = 0; | ||
+ | SPoint nonCregAtom; | ||
+ | s32 nonCregCount = 0; | ||
+ | |||
+ | for(u32 i = md.GetFirstIndex(0); | ||
+ | { | ||
+ | const SPoint& rel = md.GetPoint(i); | ||
+ | const T& atom = window.GetRelativeAtom(rel); | ||
+ | if(Atom< | ||
+ | { | ||
+ | cregCount++; | ||
+ | if(rand.OneIn(cregCount)) | ||
+ | { | ||
+ | cregAtom = rel; | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | nonCregCount++; | ||
+ | if(rand.OneIn(nonCregCount)) | ||
+ | { | ||
+ | nonCregAtom = rel; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if(cregCount > m_targetDensity.GetValue()) | ||
+ | { | ||
+ | window.SetRelativeAtom(cregAtom, | ||
+ | Element_Empty< | ||
+ | } | ||
+ | else if(cregCount < m_targetDensity.GetValue()) | ||
+ | { | ||
+ | window.SetRelativeAtom(nonCregAtom, | ||
+ | Element_Creg< | ||
+ | } | ||
+ | } | ||
} | } | ||
</ | </ | ||
+ | |||
+ | The first loop scans the event window. If it finds an atom of the same type as itself, it keeps track of where it is located and increments the count of Cregs. If not, it keeps track of where other elements are located. | ||
+ | |||
+ | If the number of Cregs is greater than the thresold, it will delete one of the elements that isn't a Creg. Otherwise, it will delete one that is a Creg. | ||
+ | |||
+ | ===== Register Element witn StdElement.inc ===== | ||
+ | |||
+ | Open: | ||
+ | |||
+ | < | ||
+ | MFMv2/ | ||
+ | </ | ||
+ | |||
+ | Put, at the end of the file: | ||
+ | < | ||
+ | #include " | ||
+ | </ | ||
+ | |||
+ | This elemental include file is used by all drivers so they know about the elements to use. | ||
===== Register Element with a Driver ===== | ===== Register Element with a Driver ===== |
dev/element_tutorial.1409773775.txt.gz · Last modified: 2014/09/03 19:49 by tsmall1