File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MovementMap Class Reference

Movement maps are used for rapid computing of animal movement. This version uses values of 0-3 only. More...

#include <MovementMap.h>

Public Member Functions

int GetMapValue (unsigned x, unsigned y)
 
void SetMapValue (unsigned x, unsigned y, unsigned value)
 
void SetMapValue0 (unsigned x, unsigned y)
 
void SetMapValue1 (unsigned x, unsigned y)
 
void SetMapValue2 (unsigned x, unsigned y)
 
void SetMapValue3 (unsigned x, unsigned y)
 
 MovementMap (Landscape *L, int spref)
 
 ~MovementMap ()
 

Public Attributes

uint32m_TheMap
 
uint32 maxx
 
uint32 maxy
 

Protected Member Functions

void Init (int spref)
 

Protected Attributes

Landscapem_ALandscape
 

Detailed Description

Movement maps are used for rapid computing of animal movement. This version uses values of 0-3 only.

Constructor & Destructor Documentation

◆ MovementMap()

MovementMap::MovementMap ( Landscape L,
int  spref 
)
86 {
87  m_ALandscape = L;
88  // must make sure that we have whole words
91  m_TheMap = new uint32[ maxx*maxy ];
92 
93  Init(spref);
94 }

References Init(), m_ALandscape, m_TheMap, maxx, maxy, Landscape::SupplySimAreaHeight(), and Landscape::SupplySimAreaWidth().

◆ ~MovementMap()

MovementMap::~MovementMap ( )
98 {
99  delete[] m_TheMap;
100 }

References m_TheMap.

Member Function Documentation

◆ GetMapValue()

int MovementMap::GetMapValue ( unsigned  x,
unsigned  y 
)
198 {
199  uint32 theBit=x & 15;
200  // Multiply by two
201  theBit=theBit<<1;
202  // divide by 16
203  uint32 index= (x>>4)+(maxx*y);
204  return ((m_TheMap[index] >> theBit) & 0x03); // 0-3
205 }

References m_TheMap, and maxx.

◆ Init()

void MovementMap::Init ( int  spref)
protected
105 {
106 
107  for (int y=0; y<m_ALandscape->SupplySimAreaHeight(); y++)
108  {
109  for (int x=0; x<m_ALandscape->SupplySimAreaWidth(); x++)
110  {
111  uint32 colour=0;
112  if (spref==0)
113  {
114  // Beetle
115  colour = beetle_tole_movemap_init(m_ALandscape, x, y);
116  }
117  else if (spref==1)
118  {
119  // Partridge
120  colour = partridge_tole_movemap_init(m_ALandscape, x, y);
121  }
122  SetMapValue(x,y,colour);
123  }
124  }
125 }

References beetle_tole_movemap_init(), m_ALandscape, SetMapValue(), Landscape::SupplySimAreaHeight(), and Landscape::SupplySimAreaWidth().

Referenced by MovementMap().

◆ SetMapValue()

void MovementMap::SetMapValue ( unsigned  x,
unsigned  y,
unsigned  value 
)
130 {
131 
132  uint32 theBit= x & 15; // Identify the bit within 16 possibilities
133 
134  // Multiply by two
135  theBit=theBit<<1; // Double it because we use two bits per location
136 
137  // divide by 16
138  // Calculate index:
139  uint32 index= (x>>4)+(y*maxx); // maxx is the number of uints per row + x/16 because there are 16 locations per uint
140 
141  value &= 0x03;
142  uint32 NewVal = m_TheMap[index] & ~( 0x03 << theBit ); // Make a hole two bits wide at the right location
143  m_TheMap[index] = NewVal | (value << theBit); // Fill the hole
144 
145 }

References m_TheMap, and maxx.

Referenced by Init().

◆ SetMapValue0()

void MovementMap::SetMapValue0 ( unsigned  x,
unsigned  y 
)
150 {
151  uint32 theBit=x & 15;
152  theBit=theBit<<1; // Multiply by two
153  // divide by 16
154  uint32 index= (x>>4)+(y*maxx);
155  m_TheMap[index] &= ~(0x03<< theBit);
156 }

References m_TheMap, and maxx.

◆ SetMapValue1()

void MovementMap::SetMapValue1 ( unsigned  x,
unsigned  y 
)
161 {
162  uint32 theBit=x & 15;
163  theBit=theBit<<1; // Multiply by two
164  // divide by 16
165  uint32 index= (x>>4)+(maxx*y);
166  m_TheMap[index] &= ~(0x03 << theBit);
167  m_TheMap[index] |= (0x01 << theBit);
168 }

References m_TheMap, and maxx.

◆ SetMapValue2()

void MovementMap::SetMapValue2 ( unsigned  x,
unsigned  y 
)
173 {
174  uint32 theBit=x & 15;
175  // Multiply by two
176  theBit=theBit<<1;
177  // divide by 16
178  uint32 index= (x>>4)+(maxx*y);
179  m_TheMap[index] &= ~(0x03 << theBit);
180  m_TheMap[index] |= (0x02 << theBit);
181 }

References m_TheMap, and maxx.

◆ SetMapValue3()

void MovementMap::SetMapValue3 ( unsigned  x,
unsigned  y 
)
186 {
187  uint32 theBit=x & 15;
188  // Multiply by two
189  theBit=theBit<<1;
190  // divide by 16
191  uint32 index= (x>>4)+(maxx*y);
192  m_TheMap[index] |= (0x03 << theBit);
193 }

References m_TheMap, and maxx.

Member Data Documentation

◆ m_ALandscape

Landscape* MovementMap::m_ALandscape
protected

Referenced by Init(), and MovementMap().

◆ m_TheMap

◆ maxx

◆ maxy

uint32 MovementMap::maxy

Referenced by MovementMap().


The documentation for this class was generated from the following files:
beetle_tole_movemap_init
int beetle_tole_movemap_init(Landscape *m_OurLandscape, int x, int y)
Definition: Beetle_toletov.cpp:21
uint32
unsigned int uint32
Definition: ALMaSS_Setup.h:34
MovementMap::m_TheMap
uint32 * m_TheMap
Definition: MovementMap.h:91
MovementMap::SetMapValue
void SetMapValue(unsigned x, unsigned y, unsigned value)
Definition: MovementMap.cpp:129
Landscape::SupplySimAreaHeight
int SupplySimAreaHeight(void)
Gets the simulation landscape height.
Definition: Landscape.h:2302
Landscape::SupplySimAreaWidth
int SupplySimAreaWidth(void)
Gets the simulation landscape width.
Definition: Landscape.h:2297
MovementMap::maxy
uint32 maxy
Definition: MovementMap.h:93
MovementMap::Init
void Init(int spref)
Definition: MovementMap.cpp:104
MovementMap::m_ALandscape
Landscape * m_ALandscape
Definition: MovementMap.h:103
MovementMap::maxx
uint32 maxx
Definition: MovementMap.h:92