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 21:30] – [Write behavior method] 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(); +      const MDist<R> md = MDist<R>::get(); 
-  u32 cregCount 0+      Random& rand window.GetRandom()
-  u32 fulli = 0, empti = 0; + 
-  SPoint fulls[50] = {SPoint(-1, -1)}+      SPoint cregAtom; 
-  SPoint empts[50] {SPoint(-1, -1)}+      s32 cregCount = 0; 
-   +      SPoint nonCregAtom
-  for(u32 i = md.GetFirstIndex(1); i <= md.GetLastIndex(R); i++) +      s32 nonCregCount 0
-  + 
-    const SPoint& rel = md.GetPoint(i); +      for(u32 i = md.GetFirstIndex(0); i <= md.GetLastIndex(R); i++) 
-    const T& atom = window.GetRelativeAtom(rel); +      
-    if(Atom<CC>::IsType(atom, Element<CC>::GetType())) +        const SPoint& rel = md.GetPoint(i); 
-    +        const T& atom = window.GetRelativeAtom(rel); 
-      cregCount++; +        if(Atom<CC>::IsType(atom, Element<CC>::GetType())) 
-      fulls[fulli++] = rel; +        
-    +          cregCount++; 
-    else +          if(rand.OneIn(cregCount)) 
-    +          { 
-      empts[empti++= rel;+            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()); 
 +      }
     }     }
-  } 
-   
-  u32 nidx; 
-  if(cregCount > m_targetDensity.GetValue()) 
-  { 
-    nidx = window.GetRandom().Create(fulli); 
-    window.SetRelativeAtom(fulls[nidx], 
-                           Element_Empty<CC>::THE_INSTANCE.GetDefaultAtom()); 
-  } 
-  else 
-  { 
-    nidx = window.GetRandom().Create(empti); 
-    window.SetRelativeAtom(empts[nidx], 
-                           Element_Empty<CC>::THE_INSTANCE.GetDefaultAtom()); 
-  } 
 } }
 </code> </code>
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 with a Driver =====+ 
 +===== Register Element witn StdElement.inc =====
  
 Open: Open:
Line 142: Line 150:
 </code> </code>
  
-Add the line: +Put, at the end of the file:
 <code> <code>
 #include "Element_Creg.h" #include "Element_Creg.h"
 </code> </code>
  
-This lets the driver know that there is a Creg element to use.+This elemental include file is used by all drivers so they know about the elements to use.
  
-Next, open:+===== Register Element with a Driver ===== 
 + 
 +Open:
  
 <code> <code>
dev/element_tutorial.1409779857.txt.gz · Last modified: 2014/09/03 21:30 by tsmall1