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 20:30] – [Register Element with a Driver] 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< | ||
| { | { | ||
| - | | + | |
| - | u32 cregCount | + | |
| - | u32 fulli = 0, empti = 0; | + | |
| - | | + | SPoint cregAtom; |
| - | | + | s32 cregCount |
| - | + | SPoint | |
| - | for(u32 i = md.GetFirstIndex(i); 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 134: | 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 142: | 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.1409776211.txt.gz · Last modified: 2014/09/03 20:30 by tsmall1
