MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EventWindow.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  EventWindow.h Main MFM event component
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
28 #ifndef EVENTWINDOW_H
29 #define EVENTWINDOW_H
30 
31 #include "Point.h"
32 #include "itype.h"
33 #include "MDist.h" /* for EVENT_WINDOW_SITES */
34 #include "PSym.h" /* For PointSymmetry, Map */
35 
36 namespace MFM
37 {
38 
39  // Forward declaration
40  template <class CC>
41  class Tile;
42 
48  template <class CC>
49  class EventWindow
50  {
51  private:
52  // Extract short names for parameter types
53  typedef typename CC::ATOM_TYPE T;
54  typedef typename CC::PARAM_CONFIG P;
55  enum { R = P::EVENT_WINDOW_RADIUS };
56  enum { W = P::TILE_WIDTH };
57  enum { B = P::ELEMENT_TABLE_BITS };
58 
59  Tile<CC> & m_tile;
60 
61  SPoint m_center;
62 
63  PointSymmetry m_sym;
64 
69  SPoint MapToTile(const SPoint & loc) const
70  {
71  return Map(loc,m_sym,loc)+m_center;
72  }
73 
74  public:
75 
87  bool InWindow(const SPoint & offset) const
88  {
89  // Ignores m_sym since point symmetries can't change this answer
90  return offset.GetManhattanLength() <= R;
91  }
92 
96  SPoint MapToTileValid(const SPoint & offset) const ;
97 
103  PointSymmetry GetSymmetry() const { return m_sym; }
104 
110  void SetSymmetry(const PointSymmetry psym)
111  {
112  m_sym = psym;
113  }
114 
123  {
124  return m_tile.GetRandom();
125  }
126 
133  {
134  return m_tile;
135  }
136 
148  bool IsLiveSite(const SPoint & location) const
149  {
150  return m_tile.IsLiveSite(MapToTile(location));
151  }
152 
159  EventWindow(Tile<CC> & tile) : m_tile(tile), m_sym(PSYM_NORMAL)
160  { }
161 
168  void SetCenterInTile(const SPoint& center)
169  {
170  m_center = center;
171  }
172 
180  const SPoint& GetCenterInTile() const
181  {
182  return m_center;
183  }
184 
189  { }
190 
198  {
199  return EVENT_WINDOW_SITES(R);
200  }
201 
209  const T& GetCenterAtom() const
210  {
211  return *m_tile.GetAtom(m_center);
212  }
213 
220  void SetCenterAtom(const T& atom)
221  {
222  return m_tile.PlaceAtom(atom, m_center);
223  }
224 
235  const T& GetRelativeAtom(const SPoint& offset) const;
236 
248  const T& GetRelativeAtom(const Dir mooreOffset) const;
249 
263  bool SetRelativeAtom(const SPoint& offset, const T & atom);
264 
273  void SwapAtoms(const SPoint& locA, const SPoint& locB);
274 
282  void SwapCenterAtom(const SPoint& relative);
283 
284  };
285 } /* namespace MFM */
286 
287 #include "EventWindow.tcc"
288 
289 #endif /*EVENTWINDOW_H*/
bool InWindow(const SPoint &offset) const
Definition: EventWindow.h:87
void SwapCenterAtom(const SPoint &relative)
Definition: EventWindow.tcc:52
Definition: Random.h:45
PointSymmetry GetSymmetry() const
Definition: EventWindow.h:103
void SetSymmetry(const PointSymmetry psym)
Definition: EventWindow.h:110
void SetCenterAtom(const T &atom)
Definition: EventWindow.h:220
Tile< CC > & GetTile()
Definition: EventWindow.h:132
void SetCenterInTile(const SPoint &center)
Definition: EventWindow.h:168
u32 GetAtomCount()
Definition: EventWindow.h:197
~EventWindow()
Definition: EventWindow.h:188
bool IsLiveSite(const SPoint &location) const
Definition: EventWindow.h:148
Random & GetRandom()
Definition: EventWindow.h:122
const T & GetRelativeAtom(const SPoint &offset) const
Definition: EventWindow.tcc:26
EventWindow(Tile< CC > &tile)
Definition: EventWindow.h:159
u32 GetManhattanLength() const
Definition: Point.tcc:46
const T & GetCenterAtom() const
Definition: EventWindow.h:209
const SPoint & GetCenterInTile() const
Definition: EventWindow.h:180
Definition: EventWindow.h:41
Definition: ElementTable.h:43
#define EVENT_WINDOW_SITES(radius)
Definition: MDist.h:46
SPoint MapToTileValid(const SPoint &offset) const
Definition: EventWindow.tcc:8
bool SetRelativeAtom(const SPoint &offset, const T &atom)
Definition: EventWindow.tcc:15
void SwapAtoms(const SPoint &locA, const SPoint &locB)
Definition: EventWindow.tcc:40