[Avida-SVN] r3303 - branches/matt/CompeteInstSet/source/cpu
ruppmatt at myxo.css.msu.edu
ruppmatt at myxo.css.msu.edu
Tue Jun 9 13:40:38 PDT 2009
Author: ruppmatt
Date: 2009-06-09 16:40:38 -0400 (Tue, 09 Jun 2009)
New Revision: 3303
Modified:
branches/matt/CompeteInstSet/source/cpu/cHardwareBase.h
branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc
Log:
Enable hot-swapping of instruction sets properly... correctly replacing deprecated instruction set pointers.
Modified: branches/matt/CompeteInstSet/source/cpu/cHardwareBase.h
===================================================================
--- branches/matt/CompeteInstSet/source/cpu/cHardwareBase.h 2009-06-09 19:30:35 UTC (rev 3302)
+++ branches/matt/CompeteInstSet/source/cpu/cHardwareBase.h 2009-06-09 20:40:38 UTC (rev 3303)
@@ -102,6 +102,7 @@
// -------- Organism ---------
cOrganism* GetOrganism() { return organism; }
const cInstSet& GetInstSet() { return *m_inst_set; }
+ cInstSet* GetInstSetPtr() { return m_inst_set; }
// -------- Core Functionality --------
Modified: branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc
===================================================================
--- branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc 2009-06-09 19:30:35 UTC (rev 3302)
+++ branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc 2009-06-09 20:40:38 UTC (rev 3303)
@@ -34,6 +34,8 @@
#include "cWorld.h"
#include "cWorldDriver.h"
#include "cOrganism.h"
+#include "cPopulation.h"
+#include "cPopulationCell.h"
#include "tDictionary.h"
#include "cStats.h"
@@ -106,8 +108,15 @@
if (m_inst_sets.GetSize() == 0 || (*m_inst_sets[0] == *new_inst_set) ){
if (id <= m_inst_sets.GetSize() - 1){ //If our array is large enough
- if (m_inst_sets[id] != NULL) //Old instruction set exists, delete it
+ if (m_inst_sets[id] != NULL){ //Old instruction set exists, migrate hardware and delete it
+ int sz = m_world->GetPopulation().GetSize();
+ for (int k = 0; k < sz; k++){ //Go through every organism and see if it's using the depricated instruction set
+ cInstSet* old = (m_world->GetPopulation().GetCell(k).IsOccupied()) ? m_world->GetPopulation().GetCell(k).GetHardware()->GetInstSetPtr() : NULL;
+ if (old != NULL && old == m_inst_sets[id])
+ old = new_inst_set; //replace it if necessary
+ }
delete m_inst_sets[id];
+ }
m_inst_sets[id] = new_inst_set;
} else{ //If we have to resize the array to accomodate the ID
m_inst_sets.Resize(id+1, NULL);
@@ -128,7 +137,7 @@
assert(in_org != NULL);
int inst_id = in_org->GetInstSetID();
- assert(inst_id <= m_inst_sets.GetSize()-1);
+ assert(inst_id <= m_inst_sets.GetSize()-1 && m_inst_sets[inst_id] != NULL);
switch (m_type)
{
case HARDWARE_TYPE_CPU_ORIGINAL:
More information about the Avida-cvs
mailing list