User Tools

Site Tools


dev:abstract_elements

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:abstract_elements [2014/09/23 19:10] tsmall1dev:abstract_elements [2014/09/23 19:35] (current) – [Create abstract class] tsmall1
Line 19: Line 19:
  
 We should also not define ''GetDefaultPhysicsColor'', since the children will want to be different colors. We should also not define ''GetDefaultPhysicsColor'', since the children will want to be different colors.
 +
 +We also cannot define **THE_INSTANCE**, since an abstract class cannot be instantiated.
  
 We need a behavior method which wanders the same for all children. This looks like: We need a behavior method which wanders the same for all children. This looks like:
Line 29: Line 31:
   MDist<R> md = MDist<R>::get();   MDist<R> md = MDist<R>::get();
   Dir d = (Dir)rand.Create(Dirs::DIR_COUNT);   Dir d = (Dir)rand.Create(Dirs::DIR_COUNT);
-  u32 maxWanderDist = Dirs::IsCorner(d) ? R : (R / 2); 
-   
-  maxWanderDist = MAX(GetWanderDistance(), maxWanderDist); 
  
-  Dirs::FillPoint(wanderPt, d);+  Dirs::FillDir(wanderPt, d);
  
-  wanderPt *= maxWanderDist;+  wanderPt *= Dirs::IsCorner(d) ? (GetWanderDistance() / 2) : GetWanderDistance();
  
-  if(window.GetRelativeAtom(wanderPt).GetType() == +  if(window.IsLiveSite(wanderPt))
-     Element_Empty<CC>::THE_INSTANCE.GetType())+
   {   {
-    window.SwapAtoms(wanderPt, SPoint(0, 0));+    if(window.GetRelativeAtom(wanderPt).GetType() == 
 +       Element_Empty<CC>::THE_INSTANCE.GetType()) 
 +       { 
 +         window.SwapAtoms(wanderPt, SPoint(0, 0)); 
 +       } 
 +    }
   }   }
 } }
Line 54: Line 57:
 Next, we need some child classes to inherit from this one. We will create two classes, which are nearly identical, to do this. Next, we need some child classes to inherit from this one. We will create two classes, which are nearly identical, to do this.
  
-First, each of these classes gets an ''ElementParameterS32'' named ''m_wanderDistance''. **These need to be initialized with unique tags!''+First, each of these classes gets an ''ElementParameterS32'' named ''m_wanderDistance''. **These need to be initialized with unique tags!**
  
-Next, change the class definition and the constructor to use ''AbstractElement_Wanderer<CC>'' instead of ''Elemetn<CC>''.+Next, change the class definition and the constructor to use ''AbstractElement_Wanderer<CC>'' instead of ''Element<CC>''. 
 + 
 +Next, define ''DefaultPhysicsColor'' to return ''0xff00ffff'' for the Cyan element, and ''0xffff00ff'' for the Magenta element. 
 + 
 +Finally, define ''GetWanderDistance'' as such: 
 + 
 +<code> 
 +protected: 
 + virtual u32 GetWanderDistance() const 
 + { 
 +    return (u32)m_wanderDistance.GetValue(); 
 + } 
 +</code>
dev/abstract_elements.1411499434.txt.gz · Last modified: 2014/09/23 19:10 by tsmall1