void GroupObjectImplementation::calcGroupLevel() {
	int highestPlayer = 0;
	groupLevel = 0;

	for (int i = 0; i < getGroupSize(); i++) {
		Reference<SceneObject*> member = getGroupMember(i);

		if (member->isPet()) {
			CreatureObject* creature = cast<CreatureObject*>(member.get());

			groupLevel += creature->getLevel() / 5;

		} else if (member->isPlayerCreature()) {
			CreatureObject* creature = cast<CreatureObject*>(member.get());

			int memberLevel = creature->getLevel();

			if (memberLevel > highestPlayer) {
				groupLevel += (memberLevel - highestPlayer + (highestPlayer / 5));
				highestPlayer = memberLevel;
			} else {
				groupLevel += memberLevel / 5;
			}
		}
	}

	GroupObjectDeltaMessage6* msg = new GroupObjectDeltaMessage6(_this.getReferenceUnsafeStaticCast());

	msg->updateLevel(this->groupLevel);
	msg->close();

	broadcastMessage(msg);
}
int GroupObjectImplementation::getNumberOfPlayerMembers() {
	int playerCount = 0;

	for (int i = 0; i < getGroupSize(); i++) {
		Reference<SceneObject*> member = getGroupMember(i);

		if (member->isPlayerCreature()) {
			playerCount++;
		}
	}

	return playerCount;
}
bool GroupObjectImplementation::isOtherMemberPlayingMusic(CreatureObject* player) {
	for (int i = 0; i < getGroupSize(); ++i) {
		Reference<CreatureObject*> groupMember = (getGroupMember(i)).castTo<CreatureObject*>();

		if (groupMember == NULL || groupMember == player || !groupMember->isPlayerCreature())
			continue;

		if (groupMember->isPlayingMusic()) {
			return true;
		}
	}

	return false;
}
void GroupObjectImplementation::calcGroupLevel() {
	groupLevel = 0;

	for (int i = 0; i < getGroupSize(); i++) {
		SceneObject* member = getGroupMember(i);

		if (member->isCreatureObject()) {
			CreatureObject* creature = cast<CreatureObject*>(member);

			int currentlevel = groupLevel - getGroupSize();
			int memberlevel = creature->getLevel();

			if (memberlevel > currentlevel)
				groupLevel = memberlevel + getGroupSize();
		}
	}

	GroupObjectDeltaMessage6* msg = new GroupObjectDeltaMessage6(_this.get());

	msg->updateLevel(this->groupLevel);
	msg->close();

	broadcastMessage(msg);
}
示例#5
0
static int renderGroup(Group* group, Track* startTrack, int posX, int* trackOffset, struct TrackInfo info, TrackData* trackData)
{
    int i, startTrackIndex = 0, size, track_count = group->trackCount;
    const int oldY = info.startY;
    const int windowSizeX = info.viewInfo->windowSizeX;

    drawFoldButton(posX + 6, oldY - (font_size + 5), &group->folded, true);

    Emgui_setFont(info.viewInfo->smallFontId);

    startTrackIndex = findStartTrack(group, startTrack);

    size = getGroupSize(info.viewInfo, group, startTrackIndex);

    renderGroupHeader(group, posX, oldY, size, info.viewInfo->windowSizeX);

    info.startPos += 5;
    info.startY += 40;

    *trackOffset += (track_count - startTrackIndex);

    if (!group->folded)
    {
        for (i = startTrackIndex; i < track_count; ++i)
        {
            Track* t = group->t.tracks[i];
            posX += renderChannel(&info, posX, t, false);

            if (posX >= windowSizeX)
            {
                if (trackData->activeTrack >= i)
                    info.viewInfo->startTrack++;

                return size;
            }
        }
    }
    else
    {
        renderChannel(&info, posX, group->t.tracks[0], true);
    }

    Emgui_setDefaultFont();

    return size;
}
示例#6
0
int TrackView_getWidth(TrackViewInfo* viewInfo, struct TrackData* trackData)
{
    int i, size = 0, group_count = trackData->groupCount;

    if (trackData->groupCount == 0)
        return 0;

    for (i = 0; i < group_count; ++i)
    {
        Group* group = &trackData->groups[i];

        if (group->trackCount == 1)
            size += getTrackSize(viewInfo, group->t.track);
        else
            size += getGroupSize(viewInfo, group, 0);
    }

    return size;
}
示例#7
0
TA_RetCode TA_FuncTableAlloc( const char *group, TA_StringTable **table )
{
   TA_RetCode retCode;
   unsigned int i;
   TA_StringTable *stringTable;
   unsigned int groupId; /* TA_GroupId */
   unsigned int groupSize;
   const char *stringPtr;
   TA_StringTablePriv *stringTablePriv;

   if( (group == NULL) || (table == NULL ) )
   {
      return TA_BAD_PARAM;
   }

   *table = NULL;
   stringPtr = NULL;

   /* Get information on the group. */
   retCode = getGroupId( group, &groupId );
   if( retCode != TA_SUCCESS )
   {
      return retCode;
   }

   retCode = getGroupSize( (TA_GroupId)groupId, &groupSize );
   if( retCode != TA_SUCCESS )
   {
      return retCode;
   }

   /* Allocate the table. */

   stringTable = (TA_StringTable *)TA_Malloc( sizeof(TA_StringTable) + sizeof(TA_StringTablePriv) );
   if( !stringTable )
   {
      *table = NULL;
      return TA_ALLOC_ERR;
   }

   memset( stringTable, 0, sizeof(TA_StringTable) + sizeof(TA_StringTablePriv) );
   stringTablePriv = (TA_StringTablePriv *)(((char *)stringTable)+sizeof(TA_StringTable));
   stringTablePriv->magicNumber = TA_STRING_TABLE_FUNC_MAGIC_NB;
   stringTable->hiddenData = stringTablePriv;

   /* From this point, TA_FuncTableFree can be safely called. */
   stringTable->size = groupSize;
   if( groupSize != 0 )
   {
      stringTable->string = (const char **)TA_Malloc( (stringTable->size) *
                                                      sizeof(const char *) );

      if( stringTable->string == NULL )
      {
         *table = NULL;
         TA_FuncTableFree( stringTable );
         return TA_ALLOC_ERR;
      }

      memset( (void *)stringTable->string, 0,
              (stringTable->size) * sizeof(const char *) );

      for( i=0; i < stringTable->size; i++ )
      {
         retCode = getFuncNameByIdx( (TA_GroupId)groupId, i, &stringPtr );

         if( retCode != TA_SUCCESS )
         {
            *table = NULL;
            TA_FuncTableFree( stringTable );
            return TA_ALLOC_ERR;
         }

         (stringTable->string)[i] = stringPtr;
      }
   }

   /* Return the table to the caller. */
   *table = stringTable;

   return TA_SUCCESS;
}
  void ModNeatExperiment7::processGroup(shared_ptr<NEAT::GeneticGeneration> generation) {
    
    // FORK a number of processes equal to the number of individuals we are going to process
    // getGroupSize is the size of ::getGroupCapacity
    const int groupSize = getGroupSize();
    pid_t* pids = new pid_t[groupSize];

    for (int i = 0; i < groupSize; ++i) {
      // increment individual count if the current individual number is smaller than the population size.
      // if it is not, then it is the first individual of the next population.
      // this is an ugly workaround since it is not easily possible to get the current individual or generation
      // from HyperNEAT itself, thus it needs to be managed by ourselves.
      if(currIndividual == popSize) {
        // reset individual and increase generation number
        currIndividual = 1;
        currGeneration++;
      } else {
        // this is just a next individual in the current generation
        currIndividual++;
      }

      screen << "processing generation: " << currGeneration << ", individual: " << currIndividual << ", on thread: " << i << endl;
      shared_ptr<NEAT::GeneticIndividual> individual = group[i];
      // avoid 0 fitness
      if (individual->getFitness() <= 0) individual->setFitness(0.000001);

      // spawn child process after 1 sec (webotsrc test)
      usleep(1000 * 1000);
      pids[i] = fork();
      
      // child code
      if (pids[i] == 0) {
        // code only executed by child process
        // evaluate individual and get fitness
        double fitness = processEvaluation(individual, NULL, i);
        
        // write fitness to a named textfile
        stringstream ss;
        ss << i;
        string temp_str = "simulation" + ss.str() + ".txt";

        // write fitness to textfile
        ofstream a_file (temp_str.c_str());
        a_file << fitness;
        a_file.close();

        exit(0); // exit child process successfully
      }

    }

    // WAIT for each individual process and only when all have exited, continue main process
    for (int i = 0; i < groupSize; ++i) {
      int status;
      while (-1 == waitpid(pids[i], &status, 0)) {
        if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
          screen << "Process " << i << " (pid " << pids[i] << ") failed" << endl;
          exit(1);
        }
      }
    }

    // READ back the fitness values and 
    for (int i = 0; i < groupSize; ++i) {
      // get individual to reward fitness too
      shared_ptr<NEAT::GeneticIndividual> individual = group[i];

      // Opens for reading the file
      stringstream ss;
      ss << i;
      string temp_str = "simulation" + ss.str() + ".txt";
      ifstream b_file (temp_str.c_str());
      // Reads one string from the file
      string fitness;
      b_file >> fitness;
      b_file.close();

      // reward this individual its fitness
      individual->reward(abs(::atof(fitness.c_str())) + 0.000001);
    }

  }
示例#9
0
TA_RetCode TA_FuncTableAlloc( TA_Libc *libHandle, const char *group, TA_StringTable **table )
{
   TA_PROLOG;
   TA_RetCode retCode;
   unsigned int i;
   TA_StringTable *stringTable;
   unsigned int groupId; /* TA_GroupId */
   unsigned int groupSize;
   const char *stringPtr;
   TA_StringTableFuncHidden *stringTableHidden;
   TA_TRACE_BEGIN( libHandle, TA_FuncTableAlloc );

   if( (group == NULL) || (table == NULL ) )
   {
      TA_TRACE_RETURN( TA_BAD_PARAM );
   }

   *table = NULL;

   /* Get information on the group. */
   #ifdef TA_GEN_CODE
      retCode = getGroupId( libHandle, group, &groupId );
   #else
      retCode = getGroupId( group, &groupId );
   #endif
   if( retCode != TA_SUCCESS )
   {
      TA_TRACE_RETURN( retCode );
   }

   #ifdef TA_GEN_CODE
      retCode = getGroupSize( libHandle, (TA_GroupId)groupId, &groupSize );
   #else
      retCode = getGroupSize( (TA_GroupId)groupId, &groupSize );
   #endif
   if( retCode != TA_SUCCESS )
   {
      TA_TRACE_RETURN( retCode );
   }

   /* Allocate the table. */
   stringTable = (TA_StringTable *)TA_Malloc( libHandle, sizeof(TA_StringTable) );
   if( !stringTable )
   {
      TA_TRACE_RETURN( TA_ALLOC_ERR );
   }

   stringTableHidden = (TA_StringTableFuncHidden *)TA_Malloc( libHandle, sizeof(TA_StringTableFuncHidden) );
   if( !stringTable )
   {
      TA_Free( libHandle, stringTable );
      TA_TRACE_RETURN( TA_ALLOC_ERR );
   }

   stringTable->hiddenData = stringTableHidden;
   stringTableHidden->libHandle = libHandle;
   stringTableHidden->magicNb = TA_STRING_TABLE_FUNC_MAGIC_NB;

   /* From this point, TA_FuncTableFree can be safely called. */
   stringTable->size = groupSize;
   if( groupSize == 0 )
      stringTable->string = NULL;
   else
   {
      stringTable->string = (const char **)TA_Malloc( libHandle, (stringTable->size) *
                                                      sizeof(const char *) );

      if( stringTable->string == NULL )
      {
         TA_FuncTableFree( stringTable );
         TA_TRACE_RETURN( TA_ALLOC_ERR );
      }

      memset( (void *)stringTable->string, 0,
              (stringTable->size) * sizeof(const char *) );

      for( i=0; i < stringTable->size; i++ )
      {
         #ifdef TA_GEN_CODE
            retCode = getFuncNameByIdx( libHandle, (TA_GroupId)groupId, i, &stringPtr );
         #else
            retCode = getFuncNameByIdx( (TA_GroupId)groupId, i, &stringPtr );
         #endif

         if( retCode != TA_SUCCESS )
         {
            TA_FuncTableFree( stringTable );
            TA_TRACE_RETURN( TA_ALLOC_ERR );
         }

         (stringTable->string)[i] = stringPtr;
      }
   }

   /* Return the table to the caller. */
   *table = stringTable;

   TA_TRACE_RETURN( TA_SUCCESS );
}