[Avida-SVN] r2004 - in development: Avida.xcodeproj source/cpu source/main

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Fri Aug 24 12:37:41 PDT 2007


Author: dknoester
Date: 2007-08-24 15:37:40 -0400 (Fri, 24 Aug 2007)
New Revision: 2004

Added:
   development/source/main/cOrgMessage.h
Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/cpu/cTestCPUInterface.h
   development/source/main/cOrgInterface.h
   development/source/main/cOrganism.cc
   development/source/main/cOrganism.h
   development/source/main/cPopulationInterface.cc
   development/source/main/cPopulationInterface.h
   development/source/main/cStats.cc
   development/source/main/cStats.h
   development/source/main/cTaskContext.h
Log:
First merge of messaging support from coopcoom:  

New file, cOrgMessage, added cOrganism::Send-
/Receive/RetrieveMessage, refactored cOrganism::DoOutput, added 
cOrganism pointer to cTaskContext, new instructions to cHardwareCPU for 
sending and receiving messages, skeleton code for messages tracking in cStats.



Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/Avida.xcodeproj/project.pbxproj	2007-08-24 19:37:40 UTC (rev 2004)
@@ -354,6 +354,7 @@
 		423335880BC067E3000DF681 /* cHardwareGX.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cHardwareGX.cc; sourceTree = "<group>"; };
 		423335890BC067E3000DF681 /* cHardwareGX.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cHardwareGX.h; sourceTree = "<group>"; };
 		42490EFE0BE2472800318058 /* cGermline.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cGermline.h; sourceTree = "<group>"; };
+		42777E5B0C7F123600AFA4ED /* cOrgMessage.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cOrgMessage.h; sourceTree = "<group>"; };
 		5629D80D0C3EE13500C5F152 /* cTextWindow.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cTextWindow.cc; sourceTree = "<group>"; };
 		5629D80E0C3EE13500C5F152 /* cTextWindow.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cTextWindow.h; sourceTree = "<group>"; };
 		5629D80F0C3EE13500C5F152 /* ncurses-defs.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = "ncurses-defs.h"; sourceTree = "<group>"; };
@@ -1397,6 +1398,7 @@
 				70B0864F08F4972600FC65FE /* cMxCodeArray.h */,
 				70B0868708F49EA800FC65FE /* cOrganism.cc */,
 				70B0868308F49E9700FC65FE /* cOrganism.h */,
+				42777E5B0C7F123600AFA4ED /* cOrgMessage.h */,
 				70B0869C08F49F4800FC65FE /* cPhenotype.cc */,
 				70B0869B08F49F3900FC65FE /* cPhenotype.h */,
 				70B0868908F49EA800FC65FE /* cPopulation.cc */,

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/cpu/cHardwareCPU.cc	2007-08-24 19:37:40 UTC (rev 2004)
@@ -38,6 +38,7 @@
 #include "cMutationLib.h"
 #include "nMutation.h"
 #include "cOrganism.h"
+#include "cOrgMessage.h"
 #include "cPhenotype.h"
 #include "cPopulation.h"
 #include "cPopulationCell.h"
@@ -350,7 +351,6 @@
     tInstLibEntry<tMethod>("sleep4", &cHardwareCPU::Inst_Sleep),
     tInstLibEntry<tMethod>("time", &cHardwareCPU::Inst_GetUpdate),
     
-
     // Promoter Model
     tInstLibEntry<tMethod>("terminate", &cHardwareCPU::Inst_Terminate),
     tInstLibEntry<tMethod>("promoter", &cHardwareCPU::Inst_Promoter),
@@ -359,6 +359,10 @@
     // Energy usage
     tInstLibEntry<tMethod>("double-energy-usage", &cHardwareCPU::Inst_DoubleEnergyUsage),
     tInstLibEntry<tMethod>("half-energy-usage", &cHardwareCPU::Inst_HalfEnergyUsage),
+
+    // Messaging
+    tInstLibEntry<tMethod>("send-msg", &cHardwareCPU::Inst_SendMessage),
+    tInstLibEntry<tMethod>("retrieve-msg", &cHardwareCPU::Inst_RetrieveMessage),
     
     // Placebo instructions
     tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
@@ -4287,10 +4291,47 @@
   return true;
 }
 
+
+/*! Send a message to the organism that is currently faced by this cell,
+where the label field of sent message is from register ?BX?, and the data field
+is from register ~?BX?.
+*/
+bool cHardwareCPU::Inst_SendMessage(cAvidaContext& ctx)
+{
+  const int label_reg = FindModifiedRegister(REG_BX);
+  const int data_reg = FindNextRegister(label_reg);
+  
+  cOrgMessage msg = cOrgMessage(organism);
+  msg.SetLabel(GetRegister(label_reg));
+  msg.SetData(GetRegister(data_reg));
+  return organism->SendMessage(ctx, msg);
+}
+
+
+/*! This method /attempts/ to retrieve a message -- It may not be possible, as in
+the case of an empty receive buffer.
+
+If a message is available, ?BX? is set to the message's label, and ~?BX? is set
+to its data.
+*/
+bool cHardwareCPU::Inst_RetrieveMessage(cAvidaContext& ctx) 
+{
+  const cOrgMessage* msg = organism->RetrieveMessage();
+  if(msg == 0)
+    return false;
+  
+  const int label_reg = FindModifiedRegister(REG_BX);
+  const int data_reg = FindNextRegister(label_reg);
+  
+  GetRegister(label_reg) = msg->GetLabel();
+  GetRegister(data_reg) = msg->GetData();
+  return true;
+}
+
+
 //// Placebo insts ////
 bool cHardwareCPU::Inst_Skip(cAvidaContext& ctx)
 {
   IP().Advance();
   return true;
 }
-

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/cpu/cHardwareCPU.h	2007-08-24 19:37:40 UTC (rev 2004)
@@ -533,6 +533,10 @@
   bool Inst_Promoter(cAvidaContext& ctx);
   bool Inst_Terminate(cAvidaContext& ctx);
   bool Inst_Regulate(cAvidaContext& ctx);
+
+  //// Messaging ////
+  bool Inst_SendMessage(cAvidaContext& ctx);
+  bool Inst_RetrieveMessage(cAvidaContext& ctx);
   
   //// Placebo ////
   bool Inst_Skip(cAvidaContext& ctx);

Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/cpu/cTestCPUInterface.h	2007-08-24 19:37:40 UTC (rev 2004)
@@ -74,6 +74,7 @@
   bool UpdateMerit(double new_merit);
   bool TestOnDivide() { return false; }
   int GetFacing() { return 0; }
+  bool SendMessage(cOrgMessage& msg) { return false; }
 };
 
 

Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/main/cOrgInterface.h	2007-08-24 19:37:40 UTC (rev 2004)
@@ -38,6 +38,7 @@
 class cCodeLabel;
 class cGenome;
 class cOrganism;
+class cOrgMessage;
 class cOrgSinkMessage;
 template <class T> class tArray;
 
@@ -82,6 +83,7 @@
   virtual bool InjectParasite(cOrganism* parent, const cCodeLabel& label, const cGenome& injected_code) = 0;
   virtual bool UpdateMerit(double new_merit) = 0;
   virtual bool TestOnDivide() = 0;
+  virtual bool SendMessage(cOrgMessage& msg) = 0;
 };
 
 #endif

Added: development/source/main/cOrgMessage.h
===================================================================
--- development/source/main/cOrgMessage.h	                        (rev 0)
+++ development/source/main/cOrgMessage.h	2007-08-24 19:37:40 UTC (rev 2004)
@@ -0,0 +1,116 @@
+/*
+ *  cOrgMessage.h
+ *  Avida
+ *
+ *  Called "org_message.hh" prior to 12/5/05.
+ *  Copyright 2005-2006 Michigan State University. All rights reserved.
+ *  Copyright 1993-2003 California Institute of Technology.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+#ifndef cOrgMessage_h
+#define cOrgMessage_h
+
+#include <iostream>
+#include <functional>
+#include <set>
+
+class cOrganism;
+
+
+/*!
+*/
+class cOrgMessage
+{
+private:
+  cOrganism* m_pSender;
+  cOrganism* m_pReceiver;
+  unsigned int m_data;
+  unsigned int m_label;
+  
+  cOrgMessage() 
+    : m_pSender(NULL), m_pReceiver(NULL), m_data(0), m_label(0) {
+    }
+  
+public:
+    cOrgMessage(cOrganism* sender)
+    : m_pSender(sender), m_pReceiver(NULL), m_data(0), m_label(0) {
+    }
+  
+  explicit cOrgMessage(int data, int label)
+    : m_pSender(NULL), m_pReceiver(NULL), m_data(data), m_label(label) {
+    }
+  
+  static cOrgMessage EmptyMessage() { return cOrgMessage(); }
+  
+  cOrganism* GetSender() { return m_pSender; }
+  cOrganism* GetReceiver() { return m_pReceiver; }
+  void SetReceiver(cOrganism* recvr) { m_pReceiver = recvr; }
+  
+  unsigned int GetData() const { return m_data; }
+  unsigned int GetLabel() const { return m_label; }
+  
+  void SetData(unsigned int data) { m_data = data; }
+  void SetLabel(unsigned int label) { m_label = label; }
+};
+
+
+///*! \brief An STL-compatible predicate on cOrgMessages.  The intent here is to
+//provide a straightforward way to track arbitrary messages *wherever* they appear
+//in the population.  The most utility can be had from message predicates if they're
+//installed into cStats (since every message goes through cStats). */
+//struct cOrgMessage_Predicate : public std::unary_function<cOrgMessage, bool> 
+//{
+//  virtual ~cOrgMessage_Predicate() { }
+//  virtual bool operator()(cOrgMessage& msg) = 0;
+//  virtual void Print(std::ostream& out) { }
+//  virtual void Reset() { }
+//};
+//
+//
+///*! A predicate that returns true and tracks the sending cell_id for messages
+//that contain the same data field as this predicate was constructed with.
+//*/
+//struct cOrgMessage_PredDataEQU : public cOrgMessage_Predicate 
+//{
+//  cOrgMessage_PredDataEQU(unsigned int data) : m_data(data) { }
+//  
+//  virtual bool operator()(cOrgMessage& msg) {
+//    if(m_data==msg.GetData()) {
+//      m_cell_ids.insert(msg.GetSender()->GetCellID());
+//    }
+//    return true;
+//  }
+//  
+//  virtual void Print(std::ostream& out) { 
+//    out << "data==" << m_data << ":{";
+//    for(std::set<int>::iterator i=m_cell_ids.begin(); i!=m_cell_ids.end(); ++i) {
+//      out << *i << ",";
+//    }
+//    out << "}";
+//  }
+//  
+//  virtual void Reset() { 
+//    m_cell_ids.clear();
+//  }
+//  
+//  unsigned int m_data;
+//  std::set<int> m_cell_ids;
+//};
+
+
+#endif

Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/main/cOrganism.cc	2007-08-24 19:37:40 UTC (rev 2004)
@@ -70,6 +70,7 @@
   , m_is_running(false)
   , m_is_sleeping(false)
   , m_net(NULL)
+  , m_msg(0)
 {
   // Initialization of structures...
   m_hardware = m_world->GetHardwareManager().Create(this);
@@ -99,6 +100,7 @@
   delete m_hardware;
   delete m_interface;
   if (m_net != NULL) delete m_net;
+  if(!m_msg) delete m_msg;
 }
 
 cOrganism::cNetSupport::~cNetSupport()
@@ -168,18 +170,31 @@
 }
 
 
+void cOrganism::DoOutput(cAvidaContext& ctx, const bool on_divide)
+{
+  DoOutput(ctx, m_input_buf, m_output_buf, on_divide, false);
+}
 
-void cOrganism::DoOutput(cAvidaContext& ctx, const int value, const bool on_divide)
+
+void cOrganism::DoOutput(cAvidaContext& ctx, const int value)
 {
-  DoOutput(ctx, m_input_buf, m_output_buf, value, on_divide);
+  m_output_buf.Add(value);
+  DoOutput(ctx, m_input_buf, m_output_buf, false, NetValidate(ctx, value));
 }
 
 
+void cOrganism::DoOutput(cAvidaContext& ctx, tBuffer<int>& input_buffer, tBuffer<int>& output_buffer, const int value)
+{
+  output_buffer.Add(value);
+  DoOutput(ctx, input_buffer, output_buffer, false, NetValidate(ctx, value));
+}
+
+
 void cOrganism::DoOutput(cAvidaContext& ctx, 
                          tBuffer<int>& input_buffer, 
                          tBuffer<int>& output_buffer,
-                         const int value,
-                         const bool on_divide)
+                         const bool on_divide,
+                         const bool net_valid)
 {
   const int deme_id = m_interface->GetDemeID();
   const tArray<double> & global_resource_count = m_interface->GetResources();
@@ -212,14 +227,8 @@
     }
   }
   
-  bool net_valid = false;
-  if (m_net) net_valid = NetValidate(ctx, value);
-  
   // Do the testing of tasks performed...
   
-  // if on IO add value to m_output_buf, if on divide don't need to
-  if(!on_divide) output_buffer.Add(value);
-  
   tArray<double> global_res_change(global_resource_count.GetSize());
   tArray<double> deme_res_change(deme_resource_count.GetSize());
   tArray<int> insts_triggered;
@@ -228,7 +237,7 @@
   if (!m_world->GetConfig().SAVE_RECEIVED.Get()) received_messages_point = NULL;
   
   cTaskContext taskctx(m_interface, input_buffer, output_buffer, other_input_list, 
-                       other_output_list, net_valid, 0, on_divide, received_messages_point);
+                       other_output_list, net_valid, 0, on_divide, received_messages_point, this);
                        
   //combine global and deme resource counts
   const tArray<double> globalAndDeme_resource_count = global_resource_count + deme_resource_count;
@@ -340,6 +349,8 @@
 
 bool cOrganism::NetValidate(cAvidaContext& ctx, int value)
 {
+  if(!m_net) return false;
+
   assert(m_net);
   
   if (0xFFFF0000 & value) return false;
@@ -569,7 +580,7 @@
   assert(m_interface);
   // Test tasks one last time before actually dividing, pass true so 
   // know that should only test "divide" tasks here
-  DoOutput(ctx, 0, true);
+  DoOutput(ctx, true);
 
   // Activate the child!  (Keep Last: may kill this organism!)
   return m_interface->Divide(ctx, this, m_child_genome);
@@ -609,3 +620,46 @@
   m_input_buf.Clear();
   m_output_buf.Clear();
 }
+
+
+bool cOrganism::SendMessage(cAvidaContext& ctx, cOrgMessage& msg)
+{
+  assert(m_interface);
+  InitMessaging();
+
+  // If we're able to succesfully send the message...
+  if(m_interface->SendMessage(msg)) {
+    // save it...
+    m_msg->sent.push_back(msg);
+    // stat-tracking...
+    m_world->GetStats().SentMessage(msg);
+    // check to see if we've performed any tasks...
+    DoOutput(ctx);
+    // and set the receiver-pointer of this message to NULL.  We don't want to
+    // walk this list later thinking that the receivers are still around.
+    m_msg->sent.back().SetReceiver(0);
+    return true;
+  }
+  
+  return false;
+}
+
+
+void cOrganism::ReceiveMessage(cOrgMessage& msg)
+{
+  InitMessaging();
+  msg.SetReceiver(this);    
+  m_msg->received.push_back(msg);
+}
+
+
+const cOrgMessage* cOrganism::RetrieveMessage()
+{
+  InitMessaging();
+
+  if(m_msg->retrieve_index < m_msg->received.size()) {
+    return &m_msg->received.at(m_msg->retrieve_index++);
+  }
+  
+  return 0;
+}

Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/main/cOrganism.h	2007-08-24 19:37:40 UTC (rev 2004)
@@ -27,6 +27,7 @@
 #define cOrganism_h
 
 #include <iostream>
+#include <vector>
 
 #ifndef cCPUMemory_h
 #include "cCPUMemory.h"
@@ -55,6 +56,9 @@
 #ifndef cOrgSourceMessage_h
 #include "cOrgSourceMessage.h"
 #endif
+#ifndef cOrgMessage_h
+#include "cOrgMessage.h"
+#endif
 #ifndef tArray_h
 #include "tArray.h"
 #endif
@@ -80,6 +84,7 @@
 class cSaleItem;
 
 
+
 class cOrganism
 {
 protected:
@@ -130,8 +135,7 @@
     ~cNetSupport();
   };
   cNetSupport* m_net;
-
-
+  
   cOrganism(); // @not_implemented
   cOrganism(const cOrganism&); // @not_implemented
   cOrganism& operator=(const cOrganism&); // @not_implemented
@@ -209,9 +213,22 @@
   // --------  Input and Output Methods  --------
   void DoInput(const int value);
   void DoInput(tBuffer<int>& input_buffer, tBuffer<int>& output_buffer, const int value);
-  void DoOutput(cAvidaContext& ctx, const int value, const bool on_divide = false);
+
+  /* These different flavors of DoOutput are "frontends" to the main DoOutput
+  that follows - One DoOutput to rule them all, etc., etc. */
+  //! Check tasks based on the current state of this organism's IO & message buffers.
+  void DoOutput(cAvidaContext& ctx, const bool on_divide=false);
+  //! Add the passed-in value to this organism's output buffer, and check tasks (on_divide=false).
+  void DoOutput(cAvidaContext& ctx, const int value);
+  //! Check tasks based on the passed-in IO buffers and value (on_divide=false).
+  void DoOutput(cAvidaContext& ctx, tBuffer<int>& input_buffer, tBuffer<int>& output_buffer, const int value);  
+
+protected:
+  /*! The main DoOutput function.  The DoOutputs above all forward to this function. */
   void DoOutput(cAvidaContext& ctx, tBuffer<int>& input_buffer, 
-                tBuffer<int>& output_buffer, const int value, const bool on_divide=false);
+                tBuffer<int>& output_buffer, const bool on_divide, const bool net_valid);
+
+public:
   void ClearInput() { m_input_buf.Clear(); }
   void AddOutput(int val) { m_output_buf.Add(val); }
 
@@ -238,7 +255,7 @@
   cInjectGenotype& GetParasite(int x) { return *m_parasites[x]; }
   int GetNumParasites() const { return m_parasites.GetSize(); }
   void ClearParasites();
-		      
+  
 
   // --------  Support Methods  --------
   double GetTestFitness(cAvidaContext& ctx);
@@ -291,6 +308,41 @@
   bool GetSterilizePos() const;
   double GetNeutralMin() const;
   double GetNeutralMax() const;
+
+  // -------- Messaging support --------
+public:
+  typedef std::vector<cOrgMessage> message_list_type; //!< Container-type for cOrgMessages.
+  
+  //! Called when this organism attempts to send a message.
+  bool SendMessage(cAvidaContext& ctx, cOrgMessage& msg);
+  //! Called when this organism has been sent a message.
+  void ReceiveMessage(cOrgMessage& msg);
+  //! Called when this organism attempts to move a received message into its CPU.
+  const cOrgMessage* RetrieveMessage();
+  //! Returns the list of all messsages received by this organism.
+  const message_list_type& GetReceivedMessages() { InitMessaging(); return m_msg->received; }
+  //! Returns the list of all messages sent by this organism.
+  const message_list_type& GetSentMessages() { InitMessaging(); return m_msg->sent; }
+  
+protected:
+  /*! Contains all the different data structures needed to support messaging within
+  cOrganism.  Inspired by cNetSupport (above), the idea is to minimize impact on
+  organisms that DON'T use messaging. */
+  struct cMessagingSupport
+  {
+    cMessagingSupport() : retrieve_index(0) { }
+    message_list_type sent; //!< List of all messages sent by this organism.
+    message_list_type received; //!< List of all messages received by this organism.
+    message_list_type::size_type retrieve_index; //!< Index of next message that can be retrieved.
+  };
+  
+  /*! This member variable is lazily initialized whenever any of the messaging
+  methods are used.  (My kingdom for boost::shared_ptr.) */
+  cMessagingSupport* m_msg;
+  
+  //! Called to check for (and initialize) messaging support within this organism.
+  inline void InitMessaging() { if(!m_msg) m_msg = new cMessagingSupport(); }
+  // -------- End of messaging support --------
 };
 
 

Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/main/cPopulationInterface.cc	2007-08-24 19:37:40 UTC (rev 2004)
@@ -29,6 +29,7 @@
 #include "cHardwareManager.h"
 #include "cOrganism.h"
 #include "cOrgSinkMessage.h"
+#include "cOrgMessage.h"
 #include "cPopulation.h"
 #include "cPopulationCell.h"
 #include "cStats.h"
@@ -233,3 +234,21 @@
 {
   return m_world->GetTestOnDivide();
 }
+
+
+/*! Send a message to the faced organism, failing if this cell does not have 
+neighbors or if the cell currently faced is not occupied. */
+bool cPopulationInterface::SendMessage(cOrgMessage& msg) {
+  cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
+  assert(cell.IsOccupied()); // This organism; sanity.
+  cPopulationCell* rcell = cell.ConnectionList().GetFirst();
+  assert(rcell != NULL); // Cells should never be null.
+
+  // Fail if the cell we're facing is not occupied.
+  if(!rcell->IsOccupied())
+    return false;
+  cOrganism* recvr = rcell->GetOrganism();
+  assert(recvr != NULL);
+  recvr->ReceiveMessage(msg);
+  return true;
+}

Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/main/cPopulationInterface.h	2007-08-24 19:37:40 UTC (rev 2004)
@@ -37,6 +37,7 @@
 #endif
 
 class cPopulation;
+class cOrgMessage;
 
 
 class cPopulationInterface : public cOrgInterface
@@ -84,6 +85,8 @@
   bool InjectParasite(cOrganism* parent, const cCodeLabel& label, const cGenome& injected_code);
   bool UpdateMerit(double new_merit);
   bool TestOnDivide();
+  //! Send a message to the faced organism.
+  bool SendMessage(cOrgMessage& msg);
 };
 
 

Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/main/cStats.cc	2007-08-24 19:37:40 UTC (rev 2004)
@@ -34,6 +34,7 @@
 #include "cWorld.h"
 #include "cWorldDriver.h"
 #include "tDataEntry.h"
+#include "cOrgMessage.h"
 
 #include "functions.h"
 
@@ -1026,3 +1027,11 @@
   }
   df.Endl();
 }
+
+
+/*! This method is called whenever an organism successfully sends a message.  Success,
+in this case, means that the message has been delivered to the receive buffer of
+the organism that this message was sent to. */
+void cStats::SentMessage(const cOrgMessage& msg)
+{
+}

Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/main/cStats.h	2007-08-24 19:37:40 UTC (rev 2004)
@@ -65,6 +65,7 @@
 class cGenotype;
 class cInjectGenotype;
 class cWorld;
+class cOrgMessage;
 
 class cStats
 {
@@ -612,6 +613,15 @@
   void PrintSenseData(const cString& filename);
   void PrintSenseExeData(const cString& filename);
   void PrintSleepData(const cString& filename);
+  
+  // -------- Messaging support --------
+protected:
+  
+    
+public:
+  //! Called for every message successfully sent anywhere in the population.
+  void SentMessage(const cOrgMessage& msg);
+  // -------- End messaging support --------
 };
 
 

Modified: development/source/main/cTaskContext.h
===================================================================
--- development/source/main/cTaskContext.h	2007-08-24 19:19:22 UTC (rev 2003)
+++ development/source/main/cTaskContext.h	2007-08-24 19:37:40 UTC (rev 2004)
@@ -37,6 +37,9 @@
 #ifndef tHashTable_h
 #include "tHashTable.h"
 #endif
+#ifndef cOrganism_h
+#include "cOrganism.h"
+#endif
 
 class cTaskEntry;
 class cTaskState;
@@ -63,11 +66,13 @@
   cTaskEntry* m_task_entry;
   tHashTable<void*, cTaskState*>* m_task_states;
 
+  cOrganism* m_organism;
+  
 public:
   cTaskContext(cOrgInterface* interface, const tBuffer<int>& inputs, const tBuffer<int>& outputs,
                const tList<tBuffer<int> >& other_inputs, const tList<tBuffer<int> >& other_outputs,
                bool in_net_valid, int in_net_completed, bool in_on_divide = false,
-               tBuffer<int>* in_received_messages = NULL)
+               tBuffer<int>* in_received_messages = NULL, cOrganism* org=0)
     : m_interface(interface)
     , m_input_buffer(inputs)
     , m_output_buffer(outputs)
@@ -80,6 +85,7 @@
     , m_on_divide(in_on_divide)
     , m_task_entry(NULL)
     , m_task_states(NULL)
+    , m_organism(org)
   {
 	  m_task_value = 0;
   }
@@ -102,6 +108,8 @@
   inline cTaskEntry* GetTaskEntry() { return m_task_entry; }
   
   inline void SetTaskStates(tHashTable<void*, cTaskState*>* states) { m_task_states = states; }
+
+  inline cOrganism* GetOrganism() { return m_organism; }
   
   inline cTaskState* GetTaskState()
   {




More information about the Avida-cvs mailing list