void collision(SDL_Rect *rect, node * root, thread_data *thread_info,
		bool *alive, int *slot, int *allow_movement, int *invincible_bool,
		Mix_Music *music) {
	int i = 0;
	node * tmp = root;
	for (i = 0; i < 11; i++) {
		if (tmp != NULL) {
			if (i != 0) {
				if (tmp->astroid.velocity != 0) {
					if (hit_test(*rect, tmp->astroid.rect) != -1) {
						if (thread_info != NULL && slot != NULL) {
							// Used to check if a bullet has hit a asteroid.
							printf("%d\n", tmp->astroid.id);
							trans_astroid_destroy(tmp, thread_info, slot);
							remove_id(&root, tmp->astroid.id);
							printf("HÄR!\n");
							*alive = FALSE;
							players[thread_info->id].score += 1;
							return;
						} else if (allow_movement != NULL) {
							// Used to check if a player has hit a asteroid.
							*invincible_bool = TRUE;
							players[thread_info->id].lives -= 1;
							Mix_PlayMusic(music, 1);
							return;
						}
					}
				}
				tmp = tmp->next;
			} else {
				tmp = tmp->next;
			}
		}
	}
}
Esempio n. 2
0
int read_astroid_data(char msg[], char format_string[], node * root) {
	int id, slot, asteroid;
	if (sscanf(msg, format_string, &id, &asteroid, &slot) == 3) {
		remove_id(&root, asteroid);
		return -1;
	}
	return 0;
}
Esempio n. 3
0
void destroy_list(list l){
	if(l == NULL){
	RAISE_ERROR("Attempted to destroy empty list");
		return;
	}

	while(l->head !=NULL){
		remove_id(l,l->head);
	}
	free(l);


}
Esempio n. 4
0
void remove_all(void) {

	while (n_vars)
		remove_id(0); /* hard way */
	/* for (i = n_vars-1; i >= 0; i--)
		remove_id(i);
	*/
	/* remove_id(n_vars - 1);  */
	/* the hard way; remove_id(n_vars-1) would be the ``easy'' alternative */
	gls(NULL, 0, GLS_INIT, NULL, NULL); /* cleans up static arrays */
	reset_block_discr(); /* resets block settings */
	max_block_dimension(1); /* reset */
	if (gl_bounds != NULL) {
		efree(gl_bounds);
		gl_bounds = NULL;
	}
	if (valdata != NULL)
		free_data(valdata);
	valdata = NULL;
}
Esempio n. 5
0
int main()
{
    COMMAND cmd;
    ARG args = { 0, 0 };
    void *res, *addr;
    ID id;
    size_t size;

    init();                     /* initialisation de l'interpreteur */

    while (1) {
#ifdef DEBUG
        printf("memshell-main: debut de la boucle de l'interpreteur\n");
#endif

        printf(PROMPT);

        cmd = read_command(&args);
        switch (cmd) {

        case INIT:

            printf("Réinitialisation de la mémoire (%d octets)...",
                   HEAP_SIZE);
            mem_init();
            printf("OK\n");
            break;

        case SHOW:
            printf
                ("Mémoire initialement disponible : %d octets débutant en %p\n",
                 HEAP_SIZE, zone_memoire);
            break;

        case USED:
            used();
            break;

        case ALLOC:

            res = mem_alloc(args.size);
            /* si une erreur a lieu, on affiche 0 */
            if (res == NULL) {
                printf
                    ("Erreur : échec de l'allocation (fonction mem_alloc, retour=NULL)\n");
            } else {
                id = get_id(res, args.size);
                if (id == 0) {
                    /* s'il ne reste pas d'id libre
                       on affiche 0 et on libere le bloc */
                    printf
                        ("Erreur : nombre maximum d'allocations atteint/n");
                    mem_free(res, args.size);
                } else {        /* pas de probleme, affichage de la zone allouée */
                    printf("%ld 0x%lX\n", id,
                           (unsigned long) (res - (void *) zone_memoire));
                }
            }
            break;

        case DESTROY:
            mem_destroy();
            break;

        case FREE:

            if (get_info_from_id(args.id, &addr, &size) == -1)
                /* erreur dans la valeur de l'id */
                printf("Erreur : identificateur de bloc incorrect\n");
            else {

                /* liberation du bloc concerne */
                mem_free(addr, size);

                /* liberation de l'id */
                remove_id(args.id);

                /* NB : dans le cas normal, on n'affiche rien */
            }
            break;

        case HELP:
            help();
            break;

        case EXIT:
            mem_destroy();
            goto end;

        case ERROR:

            printf("Commande incorrecte\n");
            break;
        }
    }
end:
    return 0;
}
Esempio n. 6
0
//:FUNCTION set_drink_action
//void set_drink_action( mixed x )
//x is a simple_action string or
//a function that is evaluated whenever
//this source of fluid is drunk from.
//x can contain $o to represent the fluid.
//$o1 can represent the drink source.
void set_drink_action( mixed x ){
  if (!x) remove_id( "drink_source" );
  drink_action = x;
}
Esempio n. 7
0
File: main.c Progetto: brutti/Bplus
	int main(int argc, char **argv) {
	vetor = NULL;	
    FILE *fp = fopen("tt.csv", "r");
    char linha[MAX], *tmp = NULL;
    int na = 0, nc = 0;
    int i =0;
	int c = 0;
    if(!fp) {
        printf("Arquivo não encontrado.\n");
        return 0;
    }

    na = atoi(argv[1]); //Número da coluna
    nc = atoi(argv[2]); //Número de caracteres
    ordem = atoi(argv[3]);
   
    
    //Lê o atributo definido pelo usuário
    while(fgets(linha, MAX, fp)) {
		if(c>0){
			I[i]=i;
			tmp = strdup(linha); /* Aloca o tamanho correto para a String */
			split(tmp, na, nc,i+1); //Split na coluna definida pelo usuário;
			free(tmp);
			i++;
		}
		c++;
    }
    i = 0;
    c = 0;
    rewind(fp);
    while(fgets(linha, MAX, fp)) {
		if(c>0){
			tmp = strdup(linha);
			splitid(tmp,i);
			free(tmp);
			i++;
		}
		c++;
	}
    fclose(fp);
	nodo* arv = NULL;
	insertion_sort(vetor,i);
	arv = insere(arv,I,i);
	int n = 0;
	printf("Elementos do documento csv inseridos\n\n");
	while(n != 4){
		printf("               Menu\n\n");
		printf("Para remover os arquivos do citados no documento de entrada digite 1!\n");
		printf("Para visualizar a arvore digite 2!\n");
		printf("Para gerar o rank digite 3!\n");
		printf("Para sair digite 4!\n");
		
		scanf("%d",&n);
		if(n == 1){
			FILE *ids = NULL;
			int ii=0;
			ids = fopen("entrada.txt","r");
	
			if(!ids){
				printf("\nArquivo de entrada não encontrado no diretório atual !!! \n\n");
				return 0;
			}
			
			while(fscanf(ids, "%d\n", &ii) != EOF){
				remove_id(arv,ii);
			}
	
		}
		else if(n == 2){
			print(arv);
		}
		else if(n == 3){
			rank(arv);
		}
		else if(n == 4){
			limpa_arvore(arv);
			printf("Saiu\n\n");
		}
		else{
			printf("Valor digitado está incorreto!");
		}
			
	}
	return 0;
}
Esempio n. 8
0
bool CryptoHash::test() {
    const QString file_path = TEST_VEC_FILEPATH.arg(name());
    QString line, result;
    size_t qw_message_length = 0;
    uint64_t* qw_message = NULL;
    size_t qw_result_length = hash_length();
    uint64_t qw_result[qw_result_length];

    //Open test file
    QFile test_file(file_path);
    if(test_file.exists() == false) {
        log_error(CRYPTO_HASH_NAME, ERR_FILE_NOT_FOUND.arg(file_path));
        return false;
    }
    if(test_file.open(QIODevice::ReadOnly) == false) {
        log_error(CRYPTO_HASH_NAME, ERR_FILE_OPEN_FAILURE.arg(file_path));
        return false;
    }
    QTextStream test_istream(&test_file);
    if(test_istream.readLine() != TEST_FILE_HEADER) {
        log_error(CRYPTO_HASH_NAME, ERR_FILE_HEADER_INCORRECT.arg(file_path));
        return false;
    }

    //Perform tests
    while(test_istream.atEnd() == false) {
        //Read and clean up a line of text, ignoring comments and spacing
        line = test_istream.readLine();
        isolate_content(line);
        if(line.isEmpty()) continue;

        if(has_id(line, ID_MESSAGE)) {
            //Convert message to qwords
            remove_id(line, ID_MESSAGE);
            qw_message_length = qword_length_hex(line);
            if(qw_message_length == 0) {
                log_error(CRYPTO_HASH_NAME, ERR_BAD_HEX_DATA.arg(line));
                return false;
            }
            qw_message = new uint64_t[qw_message_length];
            if(!qw_message) {
                log_error(CRYPTO_HASH_NAME, ERR_BAD_ALLOC.arg(QString("qw_message")));
                return false;
            }
            if(qwords_from_hex_str(line, qw_message) == false) {
                log_error(CRYPTO_HASH_NAME, ERR_BAD_HEX_DATA.arg(line));
                return false;
            }
            continue;
        }

        if(has_id(line, ID_RESULT)) {
            //Hash message, check result
            remove_id(line, ID_RESULT);
            hash(qw_message_length, qw_message, qw_result);
            qwords_to_hex_str(qw_result_length, qw_result, result);
            delete[] qw_message;

            if(result!=line) {
                log_error(CRYPTO_HASH_NAME, ERR_WRONG_RESULT.arg(result).arg(line));
                return false;
            }
            continue;
        }
    }

    return true;
}