// Write out conversations to entity keyvals
void ConversationEntity::writeToEntity() {
	// Try to convert the weak_ptr reference to a shared_ptr
	Entity* entity = Node_getEntity(_entityNode.lock());
	assert(entity != NULL);

	// greebo: Remove all conversation-related spawnargs first
	clearEntity(entity);

	for (ConversationMap::const_iterator i = _conversations.begin();
		 i != _conversations.end();
		 ++i)
	{
		// Obtain the conversation and construct the key prefix from the index
		const Conversation& conv = i->second;
		std::string prefix = "conv_" + string::to_string(i->first) + "_";

		// Set the entity keyvalues
		entity->setKeyValue(prefix + "name", conv.name);
		entity->setKeyValue(prefix + "actors_must_be_within_talkdistance",
			conv.actorsMustBeWithinTalkdistance ? "1" : "0");
		entity->setKeyValue(prefix + "talk_distance", string::to_string(conv.talkDistance));
		entity->setKeyValue(prefix + "actors_always_face_each_other_while_talking",
			conv.actorsAlwaysFaceEachOther ? "1" : "0");
		entity->setKeyValue(prefix + "max_play_count", string::to_string(conv.maxPlayCount));

		// Write the actor list
		for (Conversation::ActorMap::const_iterator a = conv.actors.begin();
			 a != conv.actors.end(); ++a)
		{
			std::string actorKey = prefix + "actor_" + string::to_string(a->first);
			entity->setKeyValue(actorKey, a->second);
		}

		// Write all the commands
		for (Conversation::CommandMap::const_iterator c = conv.commands.begin();
			 c != conv.commands.end(); ++c)
		{
			std::string cmdPrefix = prefix + "cmd_" + string::to_string(c->first) + "_";

			try {
				const ConversationCommandInfo& cmdInfo =
					ConversationCommandLibrary::Instance().findCommandInfo(c->second->type);

				entity->setKeyValue(cmdPrefix + "type", cmdInfo.name);
				entity->setKeyValue(cmdPrefix + "actor", string::to_string(c->second->actor));
				entity->setKeyValue(cmdPrefix + "wait_until_finished", c->second->waitUntilFinished ? "1" : "0");

				for (ConversationCommand::ArgumentMap::const_iterator a = c->second->arguments.begin();
					a != c->second->arguments.end(); ++a)
				{
					entity->setKeyValue(cmdPrefix + "arg_" + string::to_string(a->first), a->second);
				}
			}
			catch (std::runtime_error e) {
				rError() << "Unrecognised conversation command ID: " << c->second->type << std::endl;
			}
		}
	}
}
Example #2
0
File: zombie.c Project: xhkz/zombie
void setGhost(Entity ** matrix, Entity * buffer, int y)
{
    #pragma omp parallel for
    for (int i = 0; i < SIZEX + 2; i++)
    {
        copyEntity(&matrix[i][y], &buffer[i]);
        clearEntity(&matrix[i][y]);
    }
}
// Write out Objectives to entity keyvals
void ObjectiveEntity::writeToEntity()
{
	UndoableCommand cmd("saveObjectives");

	// Try to convert the weak_ptr reference to a shared_ptr
	Entity* entity = Node_getEntity(_entityNode.lock());
	assert(entity != NULL);

	// greebo: Remove all objective-related spawnargs first
	clearEntity(entity);

	for (ObjectiveMap::const_iterator i = _objectives.begin();
		 i != _objectives.end();
		 ++i)
	{
		// Obtain the Objective and construct the key prefix from the index
		const Objective& o = i->second;
		std::string prefix = "obj" + string::to_string(i->first) + "_";

		// Set the entity keyvalues
		entity->setKeyValue(prefix + "desc", o.description);
		entity->setKeyValue(prefix + "ongoing", o.ongoing ? "1" : "0");
		entity->setKeyValue(prefix + "visible", o.visible ? "1" : "0");
		entity->setKeyValue(prefix + "mandatory", o.mandatory ? "1" : "0");
		entity->setKeyValue(prefix + "irreversible",
							 o.irreversible ? "1" : "0");
		entity->setKeyValue(prefix + "state", string::to_string(o.state));

		// Write an empty "objN_difficulty" value when this objective applies to all levels
		entity->setKeyValue(prefix + "difficulty", o.difficultyLevels);

		entity->setKeyValue(prefix + "enabling_objs", o.enablingObjs);

		entity->setKeyValue(prefix + "script_complete", o.completionScript);
		entity->setKeyValue(prefix + "script_failed", o.failureScript);

		entity->setKeyValue(prefix + "target_complete", o.completionTarget);
		entity->setKeyValue(prefix + "target_failed", o.failureTarget);

		entity->setKeyValue(prefix + "logic_success", o.logic.successLogic);
		entity->setKeyValue(prefix + "logic_failure", o.logic.failureLogic);

        // Write the Components for this Objective
        writeComponents(entity, prefix, o);
	}

	// Export the mission success/failure logic
	writeMissionLogic(*entity);

	// Export objective conditions
	writeObjectiveConditions(*entity);
}
Example #4
0
/**
 * Envoie une entité tant que sont état n'est pas final.
 * @param game L'état du jeu
 * @param hero Le héros
 * @param entity L'entité à envoyer
 * @param board Le plateau de jeu
 */
void throwEntity(GameState* game, Eceman* hero, Entity* entity, char board[ROWS][COLS]) {
    unsigned int i;

    i = 0;

    while (entity->state != FINAL) {
        i++;

        if (i % 20000000 != 0)
            continue;

        clearEntity(board, entity);
        moveEntity(game, hero, entity, board);
        drawEntity(board, entity);
    }
}
Example #5
0
void GameBoard::handleBulletCollision( int x, int y, int x_step, int y_step, bool playerType )
{
  ZZTEntity ent = entity( x, y );
  if ( playerType )
  {
    switch( ent.id() ) {
      case ZZTEntity::Object:
        // send :shot message
        break;
      case ZZTEntity::Breakable:
      case ZZTEntity::Gem:
        clearEntity( x, y );
        musicStream()->playEvent( AbstractMusicStream::Breakable );
        break;

      case ZZTEntity::Bear:
      case ZZTEntity::Ruffian:
      case ZZTEntity::Slime:
      case ZZTEntity::Shark:
      case ZZTEntity::Lion:
      case ZZTEntity::Tiger:
      case ZZTEntity::CentipedeHead:
      case ZZTEntity::CentipedeSegment:
        deleteThing( ent.thing() );
        musicStream()->playEvent( AbstractMusicStream::KillEnemy );
        break;

      default: break;
    }
  }
  else
  {
    switch( ent.id() ) {
      case ZZTEntity::Player:
        // hurt player
        break;
      default: break;
    }
  }
}
Example #6
0
File: zombie.c Project: xhkz/zombie
int main(int argc, char **argv)
{

    int threadsLimit = 0;

    int c;
    while ((c = getopt (argc, argv, "n:t")) != -1)
    {
        switch (c)
        {
        case 'n':
            threadsLimit = atoi(optarg);
            break;
        case 't':
            benchmark = true;
            break;
        default:
            ;
        }
    }
    
    if (threadsLimit) {
        omp_set_dynamic(0);
        omp_set_num_threads(threadsLimit);
    }
    
    clock_t start;
    start = clock();

    bool *locks = (bool *)malloc((SIZEX + 2) * sizeof(bool));
    for (int i = 0; i < SIZEX + 2; i++)
        locks[i] = false;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);

    initRandom(0, rank);
    Entity **matrix_a = createMatrix(SIZEX + 2, SIZEY + 2);
    Entity **matrix_b = createMatrix(SIZEX + 2, SIZEY + 2);
    initMatrix(matrix_a, SIZEX, SIZEY);

    MPI_Type_contiguous(sizeof(Entity), MPI_BYTE, &cell_t);
    MPI_Type_commit(&cell_t);
    MPI_Type_vector(SIZEX + 2, 1, 1, cell_t, &row_t);
    MPI_Type_commit(&row_t);
    MPI_Type_contiguous(sizeof(Counter), MPI_BYTE, &counter_t);
    MPI_Type_commit(&counter_t);

    Entity * northBuffer = (Entity *) malloc((SIZEX + 2) * sizeof(Entity));
    Entity * southBuffer = (Entity *) malloc((SIZEX + 2) * sizeof(Entity));

    if (!benchmark) {
        // update local counter and sync
        updateCounter(matrix_a);
        syncCounter();
        printHeader(rank);
        printCSV(0, rank);
    }

    for (int n = 0; n < STEPS; n++)
    {
        // set adjacent borders
        if (rank == NORTH)
        {
            MPI_Recv(northBuffer, 1, row_t, SOUTH, TAG, MPI_COMM_WORLD, &status);
            setBorder(northBuffer, matrix_a, SIZEY+1);

            setBuffer(matrix_a, northBuffer, SIZEY);
            MPI_Send(northBuffer, 1, row_t, SOUTH, TAG, MPI_COMM_WORLD);
        }

        if (rank == SOUTH)
        {
            setBuffer(matrix_a, southBuffer, 1);
            MPI_Send(southBuffer, 1, row_t, NORTH, TAG, MPI_COMM_WORLD);

            MPI_Recv(southBuffer, 1, row_t, NORTH, TAG, MPI_COMM_WORLD, &status);
            setBorder(southBuffer, matrix_a, 0);
        }

        #pragma omp parallel for default(none) shared(matrix_a, matrix_b, n, locks) schedule(static, SIZEX/omp_get_max_threads())
        for (int i = 1; i <= SIZEX; i++)
        {
            lock(i, locks);
            #pragma omp parallel for
            for (int j = 1; j <= SIZEY; j++)
                process(matrix_a, matrix_b, i, j);

            unlock(i, locks);
        }

        // merge adjacent border
        if (rank == NORTH)
        {
            MPI_Recv(northBuffer, 1, row_t, SOUTH, TAG, MPI_COMM_WORLD, &status);
            mergeGhost(northBuffer, matrix_b, SIZEY);

            setGhost(matrix_b, northBuffer, SIZEY+1);
            MPI_Send(northBuffer, 1, row_t, SOUTH, TAG, MPI_COMM_WORLD);
        }

        if (rank == SOUTH)
        {
            setGhost(matrix_b, southBuffer, 0);
            MPI_Send(southBuffer, 1, row_t, NORTH, TAG, MPI_COMM_WORLD);

            MPI_Recv(southBuffer, 1, row_t, NORTH, TAG, MPI_COMM_WORLD, &status);
            mergeGhost(southBuffer, matrix_b, 1);
        }

        // clear original adjacent border in matrix_a
        for (int i = 0; i < SIZEX + 2; i++)
            clearEntity(&matrix_a[i][rank == NORTH ? SIZEY + 1 : 0]);

        //some times it can not move back, then stay in the border
        transferInBorder(matrix_a, matrix_b);
        moveBackInBorder(matrix_b);

        // swap matrixes
        Entity **matrix_t = matrix_a;
        matrix_a = matrix_b;
        matrix_b = matrix_t;

        if (!benchmark)
        {
            updateCounter(matrix_a);
            syncCounter();
            printCSV(n+1, rank);
        }
    }
    
    if (benchmark)
        printf("Thread: %d, Time: %f sec\n", omp_get_max_threads(), (double)(clock() - start) / CLOCKS_PER_SEC);

    destroyMatrix(matrix_a);
    destroyMatrix(matrix_b);
    
    free(northBuffer);
    free(southBuffer);

    MPI_Finalize();

    return 0;
}
 void ComponentLibrary::clearEntity(ex::Entity e, T first, Args... args) {
     if (e.has_component<T>()) {
         e.remove<T>();
     }
     clearEntity(e, args...);
 }