Example #1
0
void river_animation_generate(int seed)
{
    /** VARIÁVEIS *****************************************************/
    int i = 0;                       /* Contador                 */
    TStrip new_line;                 /* Linha gerada             */
    TStrip first_line;               /* 1ª linha gedara          */
    int zone = Config.zone;          /* 'Zona de conforto'       */
    float flux = Config.flux;        /* Fluxo total do rio       */
    int height = Config.height;      /* Altura total do grid     */
    int length = Config.length;      /* Largura total do rio     */
    int freq = Config.freq_island;   /* Distância entre ilhas    */
    float prob = Config.prob_island; /* Probabilidade de ilhas   */
    Link new_node;

    frame_length = length*5;
    frame_height = 0; /* Zera altura do frame de impressão do rio */

    /* Inicializa semente geradora de faixas de terreno
     * e cria lista para colocá-las: nosso cenário */
    tstrip_seed(seed);
    tstrip_island(prob, freq);
    river = list_init(height);

    /** INICIALIZA RIO ************************************************/
    /* Primeira linha, que servirá de base para todo o rio */
    first_line = tstrip_generate(length, zone, flux, NO_BASE, NULL);
    new_node = list_new_node(first_line);

    /* Preenche 'altura' faixas de terreno na lista: */
    list_insert(river, new_node);

    for(i = 1, base = first_line; i < height; i++, base = new_line)
    {
        new_line = tstrip_generate(length, zone, flux, base, NULL);
        new_node = list_new_node(new_line);
        list_insert(river, new_node);
    }

    /** IMPRIME RIO ***************************************************/
    gui_window_clear();
    list_select(river, HEAD, strip_print);

    boat_hpos = (int) (Config.length/2.0);
    boat_vpos = frame_height/5;
    gui_boat_draw(&boat_hpos, &boat_vpos, 5);


    gui_window_update(P1.lifes);
}
Example #2
0
ListNode *list_insert(LinkedList *list, ListNode *node, void *e) {
  ListNode *new_node;

  if (list == NULL)
    return NULL;

  new_node = list_new_node(e);

  // Check whether malloc succeeded.
  // Return NULL in case of failure.
  if (new_node == NULL)
    return NULL;

  // Update tail when inserting after the last element the list
  if (node == list->tail)
    list->tail = new_node;

  if (list->head == NULL)
    list->head = new_node;

  // Update pointers to adjacent nodes
  new_node->prev = node;

  if (node != NULL) {
    new_node->next = node->next;

    if (node->next != NULL)
      node->next->prev = new_node;

    // Insert node into existent list.
    node->next = new_node;
  }

  return new_node;
}
Example #3
0
void list_insert_after(List* self, ADT p_data)
{
	RealList* l_reallist = (RealList*)self;
	ListNode* l_node;

	l_node = list_new_node();
	l_node->data = addref(ADT, p_data);

	if ( l_reallist->current )
	{
		if ( l_reallist->current->next )
		{
			l_node->prev = l_reallist->current->next;
			l_reallist->current->next->prev = l_node;
		}
		else
		{/*if the current node is tail*/
			l_reallist->tail = l_node;
		}

		l_node->prev = l_reallist->current;
		l_reallist->current->next = l_node;
	}
	else
	{/*if the self is empty.*/
		l_reallist->head = l_node;
		l_reallist->tail = l_node;
	}

	l_reallist->current = l_node;
	l_reallist->length++;
}
Example #4
0
void list_insert_front(list *l, struct token *tk)
{
	struct lnode *n = list_new_node(tk);

	n->next = l->front;
	if (l->front == NULL)
		l->last = n;
	l->front = n;
}
Example #5
0
static struct lnode *list_insert_after_node(struct lnode *node, struct token *t)
{
	struct lnode *n = list_new_node(t);

	if (node != NULL) {
		n->next = node->next;
		node->next = n;
	}
	return n;
}
Example #6
0
list_node_t* bnf_new_rule(char* name, bnf_node_t* root)
{
  bnf_rule_t* node = (bnf_rule_t*) list_new_node(sizeof(*node), 0);
  if (node)
    {
      node->name = name;
      node->root = root;
    }
  return (list_node_t*) node;
}
Example #7
0
list_node_t* bnf_new_state(bnf_node_t* state, char* text, list_t mem)
{
  bnf_state_t* node = (bnf_state_t*) list_new_node(sizeof(*node), 0);
  if (node)
    {
      node->state = state;
      node->text = text;
      node->mem = mem;
    }
  return (list_node_t*) node;
}
Example #8
0
static int bnf_call_visit(bnf_state_t* state, bnf_visitor_t* visitor)
{
  bnf_call_t* call = (bnf_call_t*) state->state;
  bnf_rule_t* rule = bnf_visitor_find_rule(visitor, call->rule);
  bnf_rule_exit_t* rule_exit;
  if (rule)
    {
      rule_exit = (bnf_rule_exit_t*) list_new_node(sizeof(*rule_exit), state->mem);
      rule_exit->caller = state->state;
      bnf_visitor_visit(visitor, rule->root, state->text, (list_node_t*) rule_exit);
    }
  return 0;
}
Example #9
0
File: list.c Project: ASMlover/libc
int 
list_insert(list_t L, list_iter_t pos, element_t x)
{
  list_node_t node = list_new_node(x);

  if (NULL == L || NULL == pos || NULL == node)
    return RESULT_FAIL;
  node->prev = ((list_node_t)pos)->prev;
  node->next = ((list_node_t)pos);
  ((list_node_t)pos)->prev->next = node;
  ((list_node_t)pos)->prev = node;
  ++L->size;

  return RESULT_OK;
}
Example #10
0
void list_append(list_t* lst, void* data)
{
	list_node_t *node = list_new_node();
	node->data = data;

	if (lst->last) {
		/* we have last item, just append the new one */
		lst->last->next = node;
		node->prev = lst->last;
		lst->last = node;

	} else {
		/* no items in the list */
		lst->last = node;
		lst->head = node;
	}
	lst->size++;
}
Example #11
0
/// create a new map iterator positioned on the mininum node.
MapIter map_iter_new (Map *m, void *pkey, void *pvalue) {
    if (root(m) == NULL) // empty map
        return NULL;
    MapIter iter = obj_new(MapIterStruct,map_iter_free);
    iter->map = m;
    iter->node = (PEntry)root(m);
    iter->vstack = list_new_node(false);
    iter->pkey = (void**)pkey;
    iter->pvalue = (void**)pvalue;
    go_down_left(iter);
    iter->key = iter->node->key;
    iter->value = map_value_data(m,iter->node);
    if (iter->pkey) {
        *iter->pkey = iter->key;
        *iter->pvalue = iter->value;
    }
    return iter;
}
Example #12
0
ListNode *list_unshift(LinkedList *list, void *e) {
  ListNode *node;

  if (list == NULL)
    return NULL;

  node = list_new_node(e);

  if (node == NULL)
    return NULL;

  node->next = list->head;

  if (list->head)
    list->head->prev = node;

  list->head = node;

  if (list->tail == NULL)
    list->tail = node;

  return node;
}