[Avida-SVN] r2978 - development/source/main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Wed Nov 26 13:06:15 PST 2008


Author: brysonda
Date: 2008-11-26 16:06:15 -0500 (Wed, 26 Nov 2008)
New Revision: 2978

Modified:
   development/source/main/cOrganism.cc
   development/source/main/cOrganism.h
   development/source/main/cTaskContext.h
   development/source/main/cTaskLib.cc
Log:
Refactor the communication of my ye ol' network support to the task lib to further clean up cTaskContext.

Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc	2008-11-26 20:47:23 UTC (rev 2977)
+++ development/source/main/cOrganism.cc	2008-11-26 21:06:15 UTC (rev 2978)
@@ -258,29 +258,31 @@
 
 void cOrganism::DoOutput(cAvidaContext& ctx, const bool on_divide)
 {
-  doOutput(ctx, m_input_buf, m_output_buf, on_divide, false);
+  if (m_net) m_net->valid = false;
+  doOutput(ctx, m_input_buf, m_output_buf, on_divide);
 }
 
 
 void cOrganism::DoOutput(cAvidaContext& ctx, const int value)
 {
   m_output_buf.Add(value);
-  doOutput(ctx, m_input_buf, m_output_buf, false, NetValidate(ctx, value));
+  NetValidate(ctx, value);
+  doOutput(ctx, m_input_buf, m_output_buf, false);
 }
 
 
 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));
+  NetValidate(ctx, value);
+  doOutput(ctx, input_buffer, output_buffer, false);
 }
 
 
 void cOrganism::doOutput(cAvidaContext& ctx, 
                          tBuffer<int>& input_buffer, 
                          tBuffer<int>& output_buffer,
-                         const bool on_divide,
-                         const bool net_valid)
+                         const bool on_divide)
 {
   const int deme_id = m_interface->GetDemeID();
   const tArray<double> & global_resource_count = m_interface->GetResources();
@@ -325,7 +327,7 @@
   if (!m_world->GetConfig().SAVE_RECEIVED.Get()) received_messages_point = NULL;
   
   cTaskContext taskctx(this, input_buffer, output_buffer, other_input_list, other_output_list,
-                       m_hardware->GetExtendedMemory(), net_valid, 0, on_divide, received_messages_point);
+                       m_hardware->GetExtendedMemory(), on_divide, received_messages_point);
                        
   //combine global and deme resource counts
   const tArray<double> globalAndDeme_resource_count = global_resource_count + deme_resource_count;
@@ -434,24 +436,23 @@
   return true;
 }
 
-bool cOrganism::NetValidate(cAvidaContext& ctx, int value)
+void cOrganism::NetValidate(cAvidaContext& ctx, int value)
 {
-  if(!m_net) return false;
+  if (!m_net) return;
 
-  assert(m_net);
+  m_net->valid = false;
   
-  if (0xFFFF0000 & value) return false;
+  if (0xFFFF0000 & value) return;
   
   for (int i = 0; i < m_net->received.GetSize(); i++) {
     cOrgSinkMessage* msg = m_net->received[i];
     if (!msg->GetValidated() && (msg->GetOriginalValue() & 0xFFFF) == value) {
       msg->SetValidated();
       assert(m_interface);
-      return m_interface->NetRemoteValidate(ctx, msg);
+      m_net->valid = m_interface->NetRemoteValidate(ctx, msg);
+      break;
     }
   }
-    
-  return false;
 }
 
 bool cOrganism::NetRemoteValidate(cAvidaContext& ctx, int value)
@@ -469,7 +470,9 @@
   }
   if (!found) return false;
 
-  int completed = 0;
+  m_net->valid = false;
+  int& completed = m_net->completed;
+  completed = 0;
   while (m_net->last_seq < m_net->seq.GetSize() && m_net->seq[m_net->last_seq].GetReceived()) {
     completed++;
     m_net->last_seq++;
@@ -512,7 +515,7 @@
     tArray<int> insts_triggered;
 
     cTaskContext taskctx(this, m_input_buf, m_output_buf, other_input_list, other_output_list,
-                         m_hardware->GetExtendedMemory(), false, completed);
+                         m_hardware->GetExtendedMemory());
     m_phenotype.TestOutput(ctx, taskctx, resource_count, m_rbins, res_change, insts_triggered);
     m_interface->UpdateResources(res_change);
     

Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h	2008-11-26 20:47:23 UTC (rev 2977)
+++ development/source/main/cOrganism.h	2008-11-26 21:06:15 UTC (rev 2978)
@@ -143,8 +143,10 @@
     tSmartArray<cOrgSourceMessage> sent;
     tSmartArray<cOrgSeqMessage> seq; 
     int last_seq;
+    bool valid;
+    int completed;
     
-    cNetSupport() : last_seq(0) { ; }
+    cNetSupport() : last_seq(0), valid(false), completed(0) { ; }
     ~cNetSupport();
   };
   cNetSupport* m_net;
@@ -302,9 +304,11 @@
   void NetSend(cAvidaContext& ctx, int value);
   cOrgSinkMessage* NetPop() { return m_net->pending.PopRear(); }
   bool NetReceive(int& value);
-  bool NetValidate(cAvidaContext& ctx, int value);
+  void NetValidate(cAvidaContext& ctx, int value);
   bool NetRemoteValidate(cAvidaContext& ctx, int value);
   int NetLast() { return m_net->last_seq; }
+  bool NetIsValid() { if (m_net) return m_net->valid; else return false; }
+  int NetCompleted() { if (m_net) return m_net->completed; else return 0; }
 
   
   // --------  Parasite Interactions  --------
@@ -478,8 +482,7 @@
   void initialize(cAvidaContext& ctx);
   
   /*! 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 bool on_divide, const bool net_valid);
+  void doOutput(cAvidaContext& ctx, tBuffer<int>& input_buffer, tBuffer<int>& output_buffer, const bool on_divide);
 };
 
 

Modified: development/source/main/cTaskContext.h
===================================================================
--- development/source/main/cTaskContext.h	2008-11-26 20:47:23 UTC (rev 2977)
+++ development/source/main/cTaskContext.h	2008-11-26 21:06:15 UTC (rev 2978)
@@ -51,8 +51,6 @@
   const tList<tBuffer<int> >& m_other_input_buffers;
   const tList<tBuffer<int> >& m_other_output_buffers;
   const tArray<int>& m_ext_mem;
-  bool m_net_valid;
-  int m_net_completed;
   tBuffer<int>* m_received_messages;
   int m_logic_id;
   bool m_on_divide;
@@ -68,7 +66,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_net_valid, int in_net_completed, bool in_on_divide = false,
+               const tArray<int>& ext_mem, bool in_on_divide = false,
                tBuffer<int>* in_received_messages = NULL)
     : m_organism(organism)
     , m_input_buffer(inputs)
@@ -76,8 +74,6 @@
     , m_other_input_buffers(other_inputs)
     , m_other_output_buffers(other_outputs)
     , m_ext_mem(ext_mem)
-    , m_net_valid(in_net_valid)
-    , m_net_completed(in_net_completed)
     , m_received_messages(in_received_messages)
     , m_logic_id(0)
     , m_on_divide(in_on_divide)
@@ -93,8 +89,6 @@
   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 bool NetIsValid() const { return m_net_valid; }
-  inline int GetNetCompleted() const { return m_net_completed; }
   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; }

Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc	2008-11-26 20:47:23 UTC (rev 2977)
+++ development/source/main/cTaskLib.cc	2008-11-26 21:06:15 UTC (rev 2978)
@@ -2862,13 +2862,13 @@
 
 double cTaskLib::Task_NetSend(cTaskContext& ctx) const
 {
-  return 1.0 * ctx.GetNetCompleted();
+  return 1.0 * ctx.GetOrganism()->NetCompleted();
 }
 
 
 double cTaskLib::Task_NetReceive(cTaskContext& ctx) const
 {
-  if (ctx.NetIsValid()) return 1.0;
+  if (ctx.GetOrganism()->NetIsValid()) return 1.0;
   return 0.0;
 }
 




More information about the Avida-cvs mailing list