DistribucionCondicionalCBI::~DistribucionCondicionalCBI() {
  int i, j;
  
  delete [] nombreImagen;
  for (i = 0; i < nVis; i++){
    delete [] nombresVis[i]; 
    free (samples_obs[i]);
    free (header_obs[i]);
    free (samples_mod[i]);
  }
  delete [] nombresVis;

  free (header_obs);
  free (samples_obs);
  free (samples_mod);

  for (i = 0; i < nVis; i++) {
    for (j = 0; j < fg_image->npixels; j++) {
      free (atten[i][j + 1]);
    }
    free (atten[i]);
  }
  free (atten);

  delete_map (cmb_image);
  delete_map (fg_image);
}
Exemple #2
0
void correct(map_t* known_words, char *word) {
   map_t *edits, *edits2;

   if (find_map(known_words, word)) {
       printf("%s\n", word);
       return;
   } 

   edits = create_map();
   calc_edits1(word, edits, load_map);

   int max = 0;
   char max_word[WORD_LEN_MAX];
  
   traverse_map(edits, 0, "", find_max, known_words, &max, max_word);

   if (!max) {
       edits2 = create_map();
       traverse_map(edits, 0, "", calc_edits2, edits2, NULL, NULL);
       traverse_map(edits2, 0, "", find_max, known_words, &max, max_word);
       delete_map(edits2);
   }
   delete_map(edits);

   printf("%s %d\n", max_word, max);   
}
Exemple #3
0
// revoke access to GPIO and PWM
bool GPIO_teardown() {
//	delete_map(timer_map);
	delete_map(clock_map);
	delete_map(pwm_map);
	delete_map(gpio_map);
	return true;
}
Exemple #4
0
// set up access to the GPIO and PWM
bool GPIO_setup() {

	uint32_t base_address = 0;

	if (!get_cpu_io_base_address(&base_address)) {
		warn("cannot get the GPIO base address");
		return false;
	}

	const char *memory_device = "/dev/mem";

	int mem_fd = open(memory_device, O_RDWR | O_SYNC | O_CLOEXEC);

	if (mem_fd < 0) {
		warn("cannot open: %s", memory_device);
		return false;
	}

	// memory map entry to access the various peripheral registers

	if (!create_rw_map(&gpio_map, mem_fd, base_address, GPIO_REGISTERS)) {
		warn("failed to mmap gpio");
		goto close_mem;
	}
	if (!create_rw_map(&pwm_map, mem_fd, base_address, PWM_REGISTERS)) {
		warn("failed to mmap pwm");
		goto unmap_gpio;
	}
	if (!create_rw_map(&clock_map, mem_fd, base_address, CLOCK_REGISTERS)) {
		warn("failed to mmap clock");
		goto unmap_pwm;
	}
	/* if (!create_rw_map(&timer_map, mem_fd, base_address, TIMER_REGISTERS)) { */
	/* 	warn("failed to mmap timer"); */
	/* 	goto unmap_clock; */
	/* } */

	// close memory device and return success
	close(mem_fd);
	return true;

	// failure case delete items already created
/* unmap_clock: */
/*         delete_map(clock_map); */
unmap_pwm:
	delete_map(pwm_map);
unmap_gpio:
	delete_map(gpio_map);
close_mem:
	close(mem_fd);
	return false;
}
Exemple #5
0
// revoke access to GPIO and PWM
bool GPIO_teardown() {
	for (size_t i = 0; i < SIZE_OF_ARRAY(gpio_map); ++i) {
		delete_map(gpio_map[i]);
	}

	for (size_t i = 0; i < SIZE_OF_ARRAY(pwm); ++i) {
		if (NULL != pwm[i].name) {
			close(pwm[i].fd);
			free(pwm[i].name);
		}
	}

	if (NULL != slots) {
		// should unload the loaded firmware here,
		// but any attempt to do this crashes the process
		// probably a kernel bug, which may cause system instablility
		free(slots);
	}

	if (NULL != ocp) {
		free(ocp);
	}

	// clear all pointers so calling setup again will work
	memset(gpio_map, 0, sizeof(gpio_map));
	memset(pwm, 0, sizeof(pwm));
	slots = NULL;
	ocp = NULL;

	return true;
}
FuncionChi2VoronoiImagen::~FuncionChi2VoronoiImagen () {
  delete_map (im);
  if (malla != NULL) {
    eliminarMallaVoronoi (malla);
    malla = NULL;
  }
  delete [] nombreImagen;
}
Exemple #7
0
int main(int argc, char **argv) {
   map_t *known_words = create_map();
   train(known_words);
   s_known_words = known_words;

   char *word = argv[1];
   correct(known_words, word);

   delete_map(known_words);
}
Exemple #8
0
void SceneStart::handle_signal(Input::Signal* sig){
	std::cout<<"SceneStart got signal:"<<sig->get_data()<<std::endl;
	if(sig->get_data()=="CreateNewMap"){
		create_new_map();
	}else if(sig->get_data()=="CreateMap"){
		create_map();
	}else if(sig->get_data()=="edit_map"){
		load_map("edit");
	}else if(sig->get_data()=="delete_map"){
		delete_map();
	}else if(sig->get_data()=="play"){
		load_map("play");
	}
}
Exemple #9
0
void global_term(void){
	self.exit = 1;
	emc_thread_join(self.treconnect);
#if defined (EMC_WINDOWS)
	WSACleanup();
#endif
	hashmap_delete(self.devices);
	self.devices = NULL;
	hashmap_delete(self.plugs);
	self.plugs = NULL;
	unpack_delete(self.upk);
	self.upk = NULL;
	delete_nqueue(self.id_allocator);
	self.id_allocator = NULL;
	delete_sendqueue(self.sq);
	self.sq = NULL;
	delete_map(self.rcmq);
	self.rcmq = NULL;
}
void FuncionChi2VoronoiImagen::guardarInfo (string info) {
  // Para este caso usaremos info como el sufijo de los archivos a
  // guargar.
  string nombre_archivo;
  struct image *im_aux = do_read (this->nombreImagen);
  int nx = im_aux->size[0], ny = im_aux->size[1];

  for (int i = 0; i < nx; i++) {
    for (int j = 0; j < ny; j++) {
      double x = i / (nx - 1.0);
      double y = j / (ny - 1.0);
      im_aux->pixels[i + j * nx] = (encontrarPoligono (malla, x, y)->valor);
      //cout << im_aux->pixels[i + j * nx] << " ";
    }
  }
  cout << "\n";
  
  nombre_archivo = "!FuncionChi2VorIm" + info + ".fits";

  char *nombreC = new char [nombre_archivo.length() + 1];
  nombre_archivo.copy(nombreC, string::npos);
  nombreC [nombre_archivo.length()] = 0;
  

  cout << "guardando " << nombreC << "\n";
  do_write_fits (im_aux, nombreC);

  nombre_archivo = "MallaChi2VorIm" + info + ".dat";
  delete [] nombreC;
  nombreC = new char [nombre_archivo.length() + 1];
  nombre_archivo.copy(nombreC, string::npos);
  nombreC [nombre_archivo.length()] = 0;

  if (malla != NULL) {
    imprimirMallaArchivo (malla, nombreC);
  }

  delete [] nombreC;
  delete_map (im_aux);
}
Exemple #11
0
void dispose_session(struct session *ses)
{
	int index;

	push_call("dispose_session(%p)", ses);

	UNLINK(ses, gtd->dispose_next, gtd->dispose_prev);

	for (index = 0 ; index < LIST_MAX ; index++)
	{
		free_list(ses->list[index]);
	}

	if (ses->map)
	{
		delete_map(ses);
	}

	if (ses->mccp)
	{
		inflateEnd(ses->mccp);
		free(ses->mccp);
	}

	init_buffer(ses, 0);

	free(ses->name);
	free(ses->host);
	free(ses->ip);
	free(ses->port);
	free(ses->group);
	free(ses->read_buf);
	free(ses->cmd_color);

	free(ses);

	pop_call();
	return;
}
Exemple #12
0
double quantaOptimo (struct image *fg_image,
		     struct uvf_header **header, 
		     struct uvf_sample **samples_obs,
		     int n_vis,
		     double quanta) {
  double c1 = 0, c2 = 0;
  struct image *cmb_image, *fg_image_aux;
  struct uvf_sample *samples_mod;
  struct pbeam beam;
  
  init_beam (&beam);
  beam.type = CBI;

  cmb_image = new_map();
  fg_image_aux = new_map();
  copy_empty_map (cmb_image, fg_image);
  copy_empty_map (fg_image_aux, fg_image);
  for (int i = 0; i < fg_image->npixels; i++){
    fg_image_aux->pixels[i] = fg_image->pixels[i] / quanta;
  }
  
  for (int arch = 0; arch < n_vis; arch++) {
    samples_mod = (struct uvf_sample*) malloc((header[arch]->nsamp) * 
					      sizeof(struct uvf_sample));
    if (samples_mod == NULL) {
      fprintf (stderr, "ERROR en quantaOptimo, fL->samples_mod[%d] = NULL.\n", arch);
      exit (1);
    }
    
    mockcbi_sub (cmb_image, fg_image_aux,
		 header[arch], samples_obs[arch], 
		 samples_mod, beam);
    for (int iff = 0; iff < header[arch]->nif; iff++) {
      for (int samp = 0; samp < header[arch]->nsamp; samp++) {
	c1 += ((samples_mod[samp].rdata[iff * 3] * 
		samples_obs[arch][samp].rdata[iff * 3] + 
		samples_mod[samp].rdata[iff * 3 + 1] * 
		samples_obs[arch][samp].rdata[iff * 3 + 1]) *
	       samples_obs[arch][samp].rdata[iff * 3 + 2]);
	       
	c2 += ((POW(samples_mod[samp].rdata[iff * 3]) +
		POW(samples_mod[samp].rdata[iff * 3 + 1])) *
	       samples_obs[arch][samp].rdata[iff * 3 + 2]);
//	ret += ((SQR(fL->samples_mod[arch][samp].rdata[iff * 3] 
//		     - fL->samples_obs[arch][samp].rdata[iff * 3])
//		 + SQR(fL->samples_mod[arch][samp].rdata[iff * 3 + 1] 
//		       - fL->samples_obs[arch][samp].rdata[iff * 3 + 1]))
//		* fL->samples_mod[arch][samp].rdata[iff * 3 + 2]);
      }
    }
    free (samples_mod);
  }


  delete_map (cmb_image);
  delete_map (fg_image_aux);

  //cout << "c1 = " << c1 << ", c2 = " << c2 << "\n";

  return c1 / c2;
}
Exemple #13
0
/*
 * FUNCTION:	update_map_from_dit()
 *
 * DESCRIPTION:	Core code called to update an entire map.
 *		Information is recovered from LDAP and used to build a duplicate
 *		copy of the live maps. When this is complete the maps are
 *		locked and then overwritten by the new copy.
 *
 * INPUTS:	map_ctrl containing lots of information about the map and a
 *		pointer to it's lock which will be required.
 *		Flag indicating if progress logging is required.
 *
 * OUTPUTS:	SUCCESS = Map updated
 *		FAILURE = Map not updated
 */
suc_code
update_map_from_dit(map_ctrl *map, bool_t log_flag) {
	__nis_table_mapping_t	*t;
	__nis_rule_value_t	*rv;
	__nis_ldap_search_t	*ls;
	__nis_object_dn_t	*objectDN = NULL;
	datum			*datval, *datkey;
	int			nr = 0, i, j, nv, numDNs;
	int			statP = SUCCESS, flag;
	char			*objname, **dn;
	/* Name of temporary entries DBM file */
	char			*temp_entries;
	/* Name of temporary TTL DBM file */
	char			*temp_ttl;
	/* Temporary DBM handles */
	DBM			*temp_entries_db;
	DBM			*temp_ttl_db;
	map_ctrl		temp_map;
	datum			key;
	char			*myself = "update_map_from_dit";
	bool_t			secure_flag;
	int			entry_count = 1;
	int			next_print = PRINT_FREQ;
	int			search_flag = SUCCESS;

	int			m;

	/* list of maps whose keys will be transliterated to lowercase */
	char			*xlate_to_lcase_maps[] = {
		"hosts.byname",
		"ipnodes.byname",
		NULL
	};
	bool_t			xlate_to_lcase = FALSE;

	if (!map || !map->map_name || !map->domain) {
		return (FAILURE);
	}

	__nisdb_get_tsd()->escapeFlag = '\0';

	/*
	 * netgroup.byxxx maps are a special case. They are regenerated from
	 * the netgroup map, not the DIT, so handle special case.
	 */
	if ((0 == strcmp(map->map_name, NETGROUP_BYHOST)) ||
		0 == (strcmp(map->map_name,  NETGROUP_BYUSER))) {
		return (update_netgroup_byxxx(map));
	}

	/* Get the mapping information for the map */
	if ((t = mappingFromMap(map->map_name, map->domain, &statP)) == 0) {
		if (statP == MAP_NO_MAPPING_EXISTS)
			logmsg(MSG_NOTIMECHECK, LOG_WARNING,
			"%s: No mapping information available for %s,%s",
				myself, map->map_name, map->domain);
		return (FAILURE);
	}

	/* Allocate and set up names */
	if (SUCCESS != alloc_temp_names(map->map_path,
				&temp_entries, &temp_ttl)) {
		logmsg(MSG_NOTIMECHECK, LOG_ERR,
			"%s: Unable to create map names for %s",
			myself, map->map_path);
		return (FAILURE);
	}

	/* Create temp entry and TTL file */
	if ((temp_entries_db = dbm_open(temp_entries, O_RDWR | O_CREAT, 0644))
						== NULL) {
		logmsg(MSG_NOTIMECHECK, LOG_ERR, "%s: Could not open %s",
						myself, temp_entries);
		sfree(temp_entries);
		sfree(temp_ttl);
		return (FAILURE);
	}

	if ((temp_ttl_db = dbm_open(temp_ttl, O_RDWR | O_CREAT, 0644))
						== NULL) {
		logmsg(MSG_NOTIMECHECK, LOG_ERR, "%s: Could not open %s",
						myself, temp_ttl);
		dbm_close(temp_entries_db);
		delete_map(temp_entries);
		sfree(temp_entries);
		sfree(temp_ttl);
		return (FAILURE);
	}

	/* Initialize domainContext tsd */
	__nisdb_get_tsd()->domainContext = 0;
	for (i = 0; i < ypDomains.numDomains; i++) {
		if (0 == ypDomains.domainLabels[i])
			continue;
		if (0 == strcasecmp(map->domain, ypDomains.domainLabels[i])) {
			__nisdb_get_tsd()->domainContext = ypDomains.domains[i];
			break;
		}
	}

	if (!(objname = getFullMapName(map->map_name, map->domain))) {
		if (temp_entries_db)
			dbm_close(temp_entries_db);
		if (temp_ttl_db)
			dbm_close(temp_ttl_db);
		delete_map(temp_entries);
		sfree(temp_entries);
		delete_map(temp_ttl);
		sfree(temp_ttl);
		return (FAILURE);
	}

	/*
	 * set xlate_to_lcase to TRUE if map_name is found in
	 * xlate_to_lcase_maps[]
	 */
	m = 0;
	while (xlate_to_lcase_maps[m] != NULL) {
		if (strncmp(map->map_name, xlate_to_lcase_maps[m],
			strlen(xlate_to_lcase_maps[m])) == 0) {
			xlate_to_lcase = TRUE;
			break;
		}
		++m;
	}

	/* Try each mapping for the map */
	for (flag = 0; t != 0 && search_flag != FAILURE; t = t->next) {

		/* Check if the mapping is the correct one */
		if (strcmp(objname, t->objName) != 0) {
			continue;
		}

		/* Check if rulesFromLDAP are provided */
		if (t->numRulesFromLDAP == 0) {
			logmsg(MSG_NOTIMECHECK, LOG_ERR,
				"%s: No rulesFromLDAP available for %s (%s)",
				myself, t->dbId, map->map_name);
			continue;
		}

		/* Set flag to indicate update is enabled */
		flag = 1;
		/* Create ldap request for enumeration */
		for (objectDN = t->objectDN;
				objectDN && objectDN->read.base;
				objectDN = objectDN->next) {
			if ((ls = createLdapRequest(t, 0, 0, 1, NULL,
						objectDN)) == 0) {
				logmsg(MSG_NOTIMECHECK, LOG_ERR,
					"%s: Failed to create "
					"ldapSearch request for "
					"%s (%s) for base %s",
					myself, t->dbId,
					map->map_name,
					objectDN->read.base);
				statP = FAILURE;
				search_flag = FAILURE;
				break;
			}

			if (log_flag) {
				printf("Waiting for LDAP search results.\n");
			}

			/* Query LDAP */
			nr = (ls->isDN)?0:-1;
			rv = ldapSearch(ls, &nr, 0, &statP);
			freeLdapSearch(ls);
			if (rv == 0) {
				if (statP == LDAP_NO_SUCH_OBJECT) {
				/*
				 * No Entry exists in the ldap server. Not
				 * a problem. Maybe there are just no entries
				 * in this map.
				 */
					continue;
				}
				logmsg(MSG_NOTIMECHECK, LOG_ERR,
					"%s: ldapSearch error %d "
					"(%s) for %s (%s) for base %s",
					myself, statP, ldap_err2string(statP),
					t->dbId, map->map_name,
					objectDN->read.base);
				statP = FAILURE;
				search_flag = FAILURE;
				break;
			}

			if (log_flag) {
				printf("Processing search results.\n");
			}

			/* Obtain list of DNs for logging */
			if ((dn = findDNs(myself, rv, nr, 0, &numDNs)) == 0) {
				statP = FAILURE;
				search_flag = FAILURE;
				break;
			}

			/* For each entry in the result  do the following */
			for (i = 0; i < nr; i++) {
			/* Convert LDAP data to NIS equivalents */
				statP = buildNISRuleValue(t, &rv[i],
						map->domain);
				if (statP == MAP_INDEXLIST_ERROR)
					continue;
				if (statP != SUCCESS) {
					logmsg(MSG_NOTIMECHECK, LOG_WARNING,
					    "%s: Conversion error %d (LDAP to "
					    "name=value pairs) "
					    "for (dn: %s) for "
					    "%s (%s) for base %s",
					    myself, statP, NIL(dn[i]),
					    t->dbId, map->map_name,
					    objectDN->read.base);
					continue;
				}

				/* Obtain the datum for value */
				datval = ruleValueToDatum(t, &rv[i], &statP);
				if (datval == 0) {
					logmsg(MSG_NOTIMECHECK, LOG_WARNING,
						"%s: Conversion error %d "
						"(name=value pairs to NIS)"
						" for (dn: %s) for "
						"%s (%s) for base %s",
						myself, statP, NIL(dn[i]),
						t->dbId, map->map_name,
						objectDN->read.base);
					continue;
				}

				/* Obtain the datum for key */
				datkey = getKeyFromRuleValue(t, &rv[i],
				    &nv, &statP, xlate_to_lcase);
				if (datkey == 0) {
					logmsg(MSG_NOTIMECHECK, LOG_WARNING,
						"%s: Unable to obtain NIS "
						"key from LDAP data (dn:%s) "
						"for %s (%s) for base %s",
						myself, NIL(dn[i]), t->dbId,
						map->map_name,
						objectDN->read.base);
					sfree(datval->dptr);
					sfree(datval);
					continue;
				}

				/* Write to the temporary map */
				for (j = 0; j < nv; j++, entry_count ++) {
					if (datkey[j].dsize == 0)
						continue;
					errno = 0;
					/* DBM_INSERT to match */
					/* singleReadFromDIT */
					if (dbm_store(temp_entries_db,
						datkey[j],
						*datval,
						DBM_INSERT) < 0) {
						/*
						 * For some cases errno may
						 * still be 0 but dbm_error
						 * isn't informative at all.
						 */
						logmsg(MSG_NOTIMECHECK,
						    LOG_WARNING,
						    "%s: dbm store error "
						    "(errno=%d) "
						    "for (key=%s, value=%s) "
						    "for %s (%s) for base %s",
						    myself,
						    errno,
						    datkey[j].dptr,
						    datval->dptr, t->dbId,
						    map->map_name,
						    objectDN->read.base);
						/* clear the error */
						dbm_clearerr(temp_entries_db);
					}
					sfree(datkey[j].dptr);

					if (log_flag && (entry_count >=
							next_print)) {
						printf("%d entries processed\n",
							entry_count);
						next_print *= 2;
					}

				}
				sfree(datkey);
				sfree(datval->dptr);
				sfree(datval);
			}

			freeRuleValue(rv, nr);
			freeDNs(dn, numDNs);
		} /* End of for over objectDN */
	}
	sfree(objname);

	if (t != 0 || flag == 0 || search_flag == FAILURE) {
		if (temp_entries_db)
			dbm_close(temp_entries_db);
		if (temp_ttl_db)
			dbm_close(temp_ttl_db);
		delete_map(temp_entries);
		sfree(temp_entries);
		delete_map(temp_ttl);
		sfree(temp_ttl);
		return (statP);
	}
	/* Set up enough of map_ctrl to call update_entry_ttl */
	temp_map.map_name = map->map_name;
	temp_map.domain = map->domain;
	temp_map.ttl = temp_ttl_db;

	/* Generate new TTL file */
	key = dbm_firstkey(temp_entries_db);
	while (key.dptr != 0) {
		if (!is_special_key(&key))
			/*
			 * We don't want all the entries to time out at the
			 * same time so create random TTLs.
			 */
			if (FAILURE == update_entry_ttl(&temp_map, &key,
								TTL_RAND))
				logmsg(MSG_NOTIMECHECK, LOG_ERR,
					"%s: Could not update TTL for "
					"(key=%s) for map %s,%s",
					myself, NIL(key.dptr), map->map_name,
					map->domain);
		key = dbm_nextkey(temp_entries_db);
	}

	/* Update map TTL */
	if (SUCCESS != update_map_ttl(&temp_map)) {
		logmsg(MSG_NOTIMECHECK, LOG_ERR, "%s: Could not update map TTL "
			"for %s,%s", myself, map->map_name, map->domain);
	}

	/* Set up 'special' nis entries */
	add_special_entries(temp_entries_db, map, &secure_flag);

	/* Close temp DBM files */
	dbm_close(temp_entries_db);
	dbm_close(temp_ttl_db);

	/* Lock access to the map for copy */
	lock_map_ctrl(map);

	/* Move temp maps to real ones */
	rename_map(temp_entries, map->map_path, secure_flag);
	rename_map(temp_ttl, map->ttl_path, secure_flag);

	/* Free file names */
	sfree(temp_entries);
	sfree(temp_ttl);

	/* Unlock map */
	unlock_map_ctrl(map);

	return (SUCCESS);
}
Exemple #14
0
int main()
{
    // Ressources
    unsigned long t_debut, t_fin;
    float dt, waitShoot = 0;
    BITMAP *buffer;
    int fin = 0, v = 200;
    Map *map;
    DepthList *depthList;
    Rect screen_pos, map_pos;
    Actor *joueur;

    // Initialisation
    fprintf(stderr,"Initialisation ...\n");
    timeBeginPeriod(1);
    set_uformat(U_ASCII);
    set_color_depth(32);
    allegro_init();
    install_keyboard();
    install_mouse();
    srand(time(NULL));

    if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768, 0, 0))
        ERREUR("Echec du lancement du mode graphique.");
    buffer = create_bitmap(SCREEN_W, SCREEN_H);
    resman_loadSprites();

    fprintf(stderr,"Chargement des ressources ...\n");
    map = new_map("media/map/test1");
    map_pos.x = map_pos.y = 0;
    map_pos.w = map->w;
    map_pos.h = map->h;
    actList = new_glist();
    root = new_tree(map_pos);
    map_addEntities(map, actList, root);
    depthList = new_dlist();
    screen_pos.w = SCREEN_W;
    screen_pos.h = SCREEN_H;

    // Ajout du joueur
    joueur = actor_addJoueur(actList, root, 500, 500);

    // Intro
    debut();

    // Boucle principale
    fprintf(stderr,"Debut !\n");
    t_debut = timeGetTime();
    while(!fin)
    {
        // Gestion clavier
        if(key[KEY_ESC])
        {
            fin = 1;
        }
        if(key[KEY_W])
        {
            joueur->vit_y = -v;
            joueur->direction_regard = HAUT;
            joueur->etat = ETAT_MARCHE;
        }
        else if(key[KEY_S])
        {
            joueur->vit_y = v;
            joueur->direction_regard = BAS;
            joueur->etat = ETAT_MARCHE;
        }
        else
            joueur->vit_y = 0;
        if(key[KEY_A])
        {
            joueur->vit_x = -v;
            joueur->direction_regard = GAUCHE;
            joueur->etat = ETAT_MARCHE;
        }
        else if(key[KEY_D])
        {
            joueur->vit_x = v;
            joueur->direction_regard = DROITE;
            joueur->etat = ETAT_MARCHE;
        }
        else
            joueur->vit_x = 0;
        if(joueur->vit_x != 0 && joueur->vit_y != 0)
        {
            joueur->vit_x /= sqrt(2);
            joueur->vit_y /= sqrt(2);
        }
        if(!key[KEY_W] && !key[KEY_D] && !key[KEY_S] && !key[KEY_A])
            joueur->etat = ETAT_REPOS;
        if(key[KEY_Q])
        {
            if(waitShoot <= 0)
            {
                waitShoot = .1;
                actor_addTree(actList, root, mouse_x + screen_pos.x, mouse_y + screen_pos.y);
            }
        }
        waitShoot -= dt;
        if(mouse_b&1)
        {
            float vx, vy, v;
            if(waitShoot <= 0)
            {
                waitShoot = .3;
                vx = mouse_x - (joueur->pos_x - screen_pos.x);
                vy = mouse_y - (joueur->pos_y - screen_pos.y);
                v = sqrt(vx*vx + vy*vy);
                vx = vx/v;
                vy = vy/v;
                actor_addMissile(actList, root, joueur->pos_x + vx*joueur->w*1.5, joueur->pos_y + vy*joueur->h*1.5, vx*300, vy*300);
            }
        }
        if(key[KEY_P])
        {
            FILE *fd = fopen("arbres.txt", "w+");
            Actor *act;
            glist_startIter(actList);
            while(!glist_endIter(actList))
            {
                act = glist_getCurrentData(actList);
                if(act->type == ACT_TREE)
                    fprintf(fd, "%d\n%d\n", (int) act->pos_x, (int) act->pos_y);
                glist_iter(actList);
            }
            fclose(fd);
        }


        // Double buffer
        clear_bitmap(buffer);
        render_map(buffer, map, screen_pos.x, screen_pos.y);


        // Mises à jour
        resman_updateSprites(&dt);
        actor_spawnMonster(actList, root);
        actor_ia(actList, joueur);
        // Deplacement
        glist_startIter(actList);
        while(!glist_endIter(actList))
        {
            actor_update(glist_getCurrentData(actList), map_pos, map, dt);
            if( ((Actor*) glist_getCurrentData(actList))->deleting)
            {
                glist_remCell(actList, glist_getCurrentId(actList));
            }
            else
                glist_iter(actList);
        }
        // Cadrage ecran
        screen_pos.x = joueur->pos_x - SCREEN_W/2;
        screen_pos.y = joueur->pos_y - SCREEN_H/2;

        // Collision
        tree_collisionDetection(root);

        // Affichage
        tree_update(root);
        dlist_getActorsFromTree(depthList, root, screen_pos);
        dlist_update(depthList, screen_pos);
        dlist_blit(depthList, buffer, screen_pos);
        draw_cursor(buffer);
        textprintf_centre_ex(buffer, font, SCREEN_W/2, 5, makecol(0, 0, 0), makecol(255, 0, 0), "   Vies restantes : %d   |   Score : %d   ", joueur->vie, score);

        // Rafraichissement écran
        vsync();
        blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

        // Gestion du temps
        t_fin = timeGetTime();
        dt = ((float)t_fin - t_debut)/1000;
        t_debut = t_fin;

        // Test fin de jeu
        if(joueur->deleting)
            fin = 1;
        resman_freeList();
    }
    // Game over
    gameover();

    // Fin
    timeEndPeriod(1);
    delete_map(map);
    del_tree(root);
    del_dlist(depthList);
    del_glist(actList);
    destroy_bitmap(buffer);
    resman_freeSprites();
    allegro_exit();
    return 0;
}