MCPcopy Create free account
hub / github.com/devosoft/avida / SendMessage

Method SendMessage

avida-core/source/main/cPopulationInterface.cc:523–581  ·  view source on GitHub ↗

! Internal-use method to consolidate message-sending code. */

Source from the content-addressed store, hash-verified

521/*! Internal-use method to consolidate message-sending code.
522 */
523bool cPopulationInterface::SendMessage(cOrgMessage& msg, cPopulationCell& rcell) //**
524{
525 bool dropped = false;
526 bool lost = false;
527
528 static const double drop_prob = m_world->GetConfig().NET_DROP_PROB.Get();
529 if ((drop_prob > 0.0) && m_world->GetRandom().P(drop_prob)) {
530 // message dropped
531 GetDeme()->messageDropped();
532 GetDeme()->messageSendFailed();
533 dropped = true;
534 }
535
536 if (!m_world->GetConfig().NEURAL_NETWORKING.Get() || m_world->GetConfig().USE_AVATARS.Get() != 2) {
537 // Not using neural networking avatars..
538 // Fail if the cell we're facing is not occupied.
539 if(!rcell.IsOccupied()) lost = true;
540 } else {
541 // If neural networking with avatars check for input avatars in this cell
542 if (!rcell.GetNumAVInputs()) lost = true;
543 // If self communication is not allowed, must check for an input avatar for another organism
544 else if (!m_world->GetConfig().SELF_COMMUNICATION.Get()) {
545 lost = true;
546 cOrganism* sender = GetOrganism();
547 for (int i = 0; i < rcell.GetNumAVInputs(); i++) {
548 if (sender != rcell.GetCellInputAVs()[i]) lost = false;
549 }
550 }
551 }
552
553 if (lost) GetDeme()->messageSendFailed();
554
555 // record this message, regardless of whether it's actually received.
556 if(m_world->GetConfig().NET_LOG_MESSAGES.Get()) m_world->GetStats().LogMessage(msg, dropped, lost);
557
558 if(dropped || lost) return false;
559
560 if (!m_world->GetConfig().NEURAL_NETWORKING.Get() || m_world->GetConfig().USE_AVATARS.Get() != 2) {
561 // Not using neural networking avatars..
562 cOrganism* recvr = rcell.GetOrganism();
563 assert(recvr != 0);
564 recvr->ReceiveMessage(msg);
565 m_world->GetStats().SentMessage(msg);
566 GetDeme()->MessageSuccessfullySent();
567 } else {
568 // If using neural networking avatars, message must be sent to all orgs with input avatars in the cell. @JJB
569 cOrganism* sender = GetOrganism();
570 for (int i = 0; i < rcell.GetNumAVInputs(); i++) {
571 cOrganism* recvr = rcell.GetCellInputAVs()[i];
572 assert(recvr != 0);
573 if ((sender != recvr) || m_world->GetConfig().SELF_COMMUNICATION.Get()) {
574 recvr->ReceiveMessage(msg);
575 m_world->GetStats().SentMessage(msg);
576 GetDeme()->MessageSuccessfullySent();
577 }
578 }
579 }
580 return true;

Callers

nothing calls this directly

Calls 15

GetConfigMethod · 0.80
messageDroppedMethod · 0.80
messageSendFailedMethod · 0.80
IsOccupiedMethod · 0.80
GetNumAVInputsMethod · 0.80
GetCellInputAVsMethod · 0.80
LogMessageMethod · 0.80
ReceiveMessageMethod · 0.80
SentMessageMethod · 0.80
SetTransCellIDMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected