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/04 20:51] – ackley | dev:element_tutorial [2014/09/17 20:00] (current) – [Create the C++ Compilation file] tsmall1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Creating an MFM Element ====== | ====== Creating an MFM Element ====== | ||
- | |||
- | **NOTE THESE INSTRUCTIONS ARE FOR THE SOON-TO-BE RELEASED v2.0.8! | ||
**You will need to have the MFM ready to build from source to do this.** Follow the instructions at [[Dev: | **You will need to have the MFM ready to build from source to do this.** Follow the instructions at [[Dev: | ||
Line 29: | Line 27: | ||
< | < | ||
- | MFMv2/ | + | MFMv2/ |
</ | </ | ||
Line 59: | 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 96: | Line 94: | ||
virtual void Behavior(EventWindow< | virtual void Behavior(EventWindow< | ||
{ | { | ||
- | | + | |
- | u32 cregCount | + | |
- | u32 fulli = 0, empti = 0; | + | |
- | | + | SPoint cregAtom; |
- | | + | s32 cregCount |
- | + | SPoint | |
- | for(u32 i = md.GetFirstIndex(1); i <= md.GetLastIndex(R); | + | s32 nonCregCount |
- | { | + | |
- | const SPoint& rel = md.GetPoint(i); | + | for(u32 i = md.GetFirstIndex(0); i <= md.GetLastIndex(R); |
- | const T& atom = window.GetRelativeAtom(rel); | + | { |
- | if(Atom< | + | const SPoint& rel = md.GetPoint(i); |
- | { | + | const T& atom = window.GetRelativeAtom(rel); |
- | cregCount++; | + | if(Atom< |
- | | + | { |
- | } | + | cregCount++; |
- | else | + | |
- | { | + | { |
- | | + | cregAtom |
+ | } | ||
+ | } | ||
+ | | ||
+ | { | ||
+ | | ||
+ | if(rand.OneIn(nonCregCount)) | ||
+ | { | ||
+ | nonCregAtom | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if(cregCount > m_targetDensity.GetValue()) | ||
+ | { | ||
+ | window.SetRelativeAtom(cregAtom, | ||
+ | Element_Empty< | ||
+ | } | ||
+ | else if(cregCount < m_targetDensity.GetValue()) | ||
+ | { | ||
+ | window.SetRelativeAtom(nonCregAtom, | ||
+ | Element_Creg< | ||
+ | } | ||
} | } | ||
- | } | ||
- | | ||
- | u32 nidx; | ||
- | if(cregCount > m_targetDensity.GetValue()) | ||
- | { | ||
- | nidx = window.GetRandom().Create(fulli); | ||
- | window.SetRelativeAtom(fulls[nidx], | ||
- | | ||
- | } | ||
- | else | ||
- | { | ||
- | nidx = window.GetRandom().Create(empti); | ||
- | window.SetRelativeAtom(empts[nidx], | ||
- | | ||
- | } | ||
} | } | ||
</ | </ | ||
Line 136: | Line 141: | ||
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. | 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 | + | |
+ | ===== Register Element | ||
Open: | Open: | ||
Line 144: | Line 150: | ||
</ | </ | ||
- | Add the line: | + | Put, at the end of the file: |
< | < | ||
#include " | #include " | ||
</ | </ | ||
- | This lets the driver know that there is a Creg element | + | This elemental include file is used by all drivers so they know about the elements |
- | Next, open: | + | ===== Register Element with a Driver ===== |
+ | |||
+ | Open: | ||
< | < |
dev/element_tutorial.1409863906.txt.gz · Last modified: 2014/09/04 20:51 by ackley