User Tools

Site Tools


dev:element_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:element_tutorial [2014/09/03 19:43] tsmall1dev:element_tutorial [2014/09/17 20:00] (current) – [Create the C++ Compilation file] tsmall1
Line 27: Line 27:
  
 <code> <code>
-MFMv2/src/elements/src/Element_Creg.h+MFMv2/src/elements/src/Element_Creg.cpp
 </code> </code>
  
Line 46: Line 46:
 </code> </code>
  
-Which supply you with renaming instructions. Whe are more or less going to rename everything we find called "Template" with "Creg". When you are done following the tags, search the file an make sure there is nothing called "Template".+Which supply you with renaming instructions. We are more or less going to rename everything we find called "Template" with "Creg". When you are done following the tags, search the file an make sure there is nothing called "Template".
  
 ===== Set up the Configurable Parameter ===== ===== Set up the Configurable Parameter =====
Line 57: Line 57:
 m_targetDensity(this, "density", "Target Density", m_targetDensity(this, "density", "Target Density",
                       "The Creg will try to fill this many spots in its event "                       "The Creg will try to fill this many spots in its event "
-                      "window with other Creg.", 0, 3, 45, 1)+                      "window with other Creg.", 0, 3, 41, 1)
 </code> </code>
  
Line 94: Line 94:
 virtual void Behavior(EventWindow<CC>& window) const virtual void Behavior(EventWindow<CC>& window) const
 { {
-  +      const MDist<R> md = MDist<R>::get(); 
 +      Random& rand = window.GetRandom(); 
 + 
 +      SPoint cregAtom; 
 +      s32 cregCount = 0; 
 +      SPoint nonCregAtom; 
 +      s32 nonCregCount = 0; 
 + 
 +      for(u32 i = md.GetFirstIndex(0); i <= md.GetLastIndex(R); i++) 
 +      { 
 +        const SPoint& rel = md.GetPoint(i); 
 +        const T& atom = window.GetRelativeAtom(rel); 
 +        if(Atom<CC>::IsType(atom, Element<CC>::GetType())) 
 +        { 
 +          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<CC>::THE_INSTANCE.GetDefaultAtom()); 
 +      } 
 +      else if(cregCount < m_targetDensity.GetValue()) 
 +      { 
 +        window.SetRelativeAtom(nonCregAtom, 
 +        Element_Creg<CC>::THE_INSTANCE.GetDefaultAtom()); 
 +      } 
 +    }
 } }
 </code> </code>
 +
 +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:
 +
 +<code>
 +MFMv2/src/drivers/mfmc/include/main.h
 +</code>
 +
 +Put, at the end of the file:
 +<code>
 +#include "Element_Creg.h"
 +</code>
 +
 +This elemental include file is used by all drivers so they know about the elements to use.
 +
 +===== Register Element with a Driver =====
 +
 +Open:
 +
 +<code>
 +MFMv2/src/drivers/mfmc/src/main.cpp
 +</code>
 +
 +In the bottom of the method "DefineNeededElements", put the line:
 +
 +<code>
 +NeedElement(&Element_Creg<OurCoreConfig>::THE_INSTANCE);
 +</code>
 +
 +This places the Element into the toolbox, among other things.
 +
 +===== Rebuild the MFM =====
 +
 +Go to the root of the project and type 
 +<code>
 +make
 +</code>
 +
 +Sometimes make doesn't work so well and you may need to type:
 +
 +<code>
 +make realclean; make
 +</code>
 +
 +This will rebuild the entire project from scratch.
dev/element_tutorial.1409773408.txt.gz · Last modified: 2014/09/03 19:43 by tsmall1