[Avida-SVN] r2995 - in development/source: cpu main
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Tue Dec 2 20:56:03 PST 2008
Author: brysonda
Date: 2008-12-02 23:56:03 -0500 (Tue, 02 Dec 2008)
New Revision: 2995
Modified:
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.cc
development/source/main/cStateGrid.h
development/source/main/cTaskContext.h
Log:
Adjust state grid move to track movement history. Change extended memory object in cHardwareBase to a tSmartArray to better support usage patterns such as the state grid movement tracking.
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2008-12-03 03:44:31 UTC (rev 2994)
+++ development/source/cpu/cHardwareBase.h 2008-12-03 04:56:03 UTC (rev 2995)
@@ -35,6 +35,9 @@
#ifndef tBuffer_h
#include "tBuffer.h"
#endif
+#ifndef tSmartArray_h
+#include "tSmartArray.h"
+#endif
using namespace std;
@@ -69,7 +72,7 @@
bool m_has_energy_costs;
// -------- Base Hardware Feature Support ---------
- tArray<int> m_ext_mem;
+ tSmartArray<int> m_ext_mem;
cHardwareBase(); // @not_implemented
@@ -137,7 +140,7 @@
virtual int GetMemSize(int value) const = 0;
virtual int GetNumMemSpaces() const = 0;
- const tArray<int>& GetExtendedMemory() const { return m_ext_mem; }
+ const tSmartArray<int>& GetExtendedMemory() const { return m_ext_mem; }
// -------- Register Manipulation --------
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-12-03 03:44:31 UTC (rev 2994)
+++ development/source/cpu/cHardwareCPU.cc 2008-12-03 04:56:03 UTC (rev 2995)
@@ -4522,7 +4522,11 @@
assert(facing >= 0 && facing <= 7);
}
+ // Increment state observed count
m_ext_mem[3 + sg.GetStateAt(x, y)]++;
+
+ // Save this location in the movement history
+ m_ext_mem.Push(sg.GetIDFor(x, y));
return true;
}
Modified: development/source/main/cStateGrid.h
===================================================================
--- development/source/main/cStateGrid.h 2008-12-03 03:44:31 UTC (rev 2994)
+++ development/source/main/cStateGrid.h 2008-12-03 04:56:03 UTC (rev 2995)
@@ -58,7 +58,9 @@
inline int GetInitialFacing() const { return m_init_facing; }
inline int GetNumStates() const { return m_states.GetSize(); }
- inline int GetStateAt(int x, int y) const { return m_grid[x * m_w + y]; }
+ inline int GetIDFor(int x, int y) const { return (x * m_w + y); }
+ inline int GetStateAt(int grid_id) const { return m_grid[grid_id]; }
+ inline int GetStateAt(int x, int y) const { return m_grid[GetIDFor(x,y)]; }
inline int SenseStateAt(int x, int y) const { return m_sense_values[GetStateAt(x, y)]; }
};
Modified: development/source/main/cTaskContext.h
===================================================================
--- development/source/main/cTaskContext.h 2008-12-03 03:44:31 UTC (rev 2994)
+++ development/source/main/cTaskContext.h 2008-12-03 04:56:03 UTC (rev 2995)
@@ -37,6 +37,9 @@
#ifndef tHashTable_h
#include "tHashTable.h"
#endif
+#ifndef tSmartArray_h
+#include "tSmartArray.h"
+#endif
class cTaskEntry;
class cTaskState;
@@ -50,7 +53,7 @@
const tBuffer<int>& m_output_buffer;
const tList<tBuffer<int> >& m_other_input_buffers;
const tList<tBuffer<int> >& m_other_output_buffers;
- const tArray<int>& m_ext_mem;
+ const tSmartArray<int>& m_ext_mem;
tBuffer<int>* m_received_messages;
int m_logic_id;
bool m_on_divide;
@@ -66,7 +69,7 @@
public:
cTaskContext(cOrganism* organism, const tBuffer<int>& inputs, const tBuffer<int>& outputs,
const tList<tBuffer<int> >& other_inputs, const tList<tBuffer<int> >& other_outputs,
- const tArray<int>& ext_mem, bool in_on_divide = false,
+ const tSmartArray<int>& ext_mem, bool in_on_divide = false,
tBuffer<int>* in_received_messages = NULL)
: m_organism(organism)
, m_input_buffer(inputs)
@@ -88,7 +91,7 @@
inline const tBuffer<int>& GetOutputBuffer() { return m_output_buffer; }
inline const tList<tBuffer<int> >& GetNeighborhoodInputBuffers() { return m_other_input_buffers; }
inline const tList<tBuffer<int> >& GetNeighborhoodOutputBuffers() { return m_other_output_buffers; }
- inline const tArray<int>& GetExtendedMemory() const { return m_ext_mem; }
+ inline const tSmartArray<int>& GetExtendedMemory() const { return m_ext_mem; }
inline tBuffer<int>* GetReceivedMessages() { return m_received_messages; }
inline int GetLogicId() const { return m_logic_id; }
inline void SetLogicId(int v) { m_logic_id = v; }
More information about the Avida-cvs
mailing list