예제 #1
0
static
void handle_nextstate(state_t *next) {
    /* interpolate to a new an eggciting z coordinate */
    state_t *cur = copy_state(next);
    vec3 origo = state_to_vec(prev);
    vec3 pt = state_to_vec(cur);
    vec3 dir = normalize(sub(pt, origo));
    vec3 offset = scale(dir, max_dist);

    while (dist(prev, cur) >  max_dist) {
        /* printf("split because %f\n", dist(prev, cur)); */
        /* print_vec3(offset); */
        /* printf("\n"); */
        cur->x = prev->x + offset.x;
        cur->y = prev->y + offset.y;
        cur->z = prev->z + offset.z;
        write_statement(prev, cur, output);
        free(prev);
        prev = cur;
        cur = copy_state(next);
    }
    write_statement(prev, next, output);
    free(prev);
    free(cur);
    prev = next;
}
예제 #2
0
/************************************************************************
 * See .h file for description.
 ************************************************************************/
void copy_mhmm
  (MHMM_T*        an_mhmm,
   MHMM_T*        new_mhmm)
{
  int i_state;

  /* Copy the top-level data. */
  new_mhmm->type = an_mhmm->type;
  new_mhmm->log_odds = an_mhmm->log_odds;
  new_mhmm->num_motifs = an_mhmm->num_motifs;
  new_mhmm->num_states = an_mhmm->num_states;
  new_mhmm->num_spacers = an_mhmm->num_spacers;
  new_mhmm->spacer_states = an_mhmm->spacer_states;
  new_mhmm->alph = alph_hold(an_mhmm->alph);
  new_mhmm->background = allocate_array(alph_size_full(an_mhmm->alph));
  copy_array(an_mhmm->background, new_mhmm->background);
  copy_string(&(new_mhmm->description), an_mhmm->description);
  copy_string(&(new_mhmm->motif_file), an_mhmm->motif_file);
  copy_string(&(new_mhmm->sequence_file), an_mhmm->sequence_file);
  // FIXME: Copy hot states array.
  new_mhmm->num_hot_states = an_mhmm->num_hot_states;

  /* Copy each state. */
  for (i_state = 0; i_state < an_mhmm->num_states; i_state++) {
    copy_state(&(an_mhmm->states[i_state]),
               &(new_mhmm->states[i_state]));
  }

  /* Copy the transition matrix. */
  copy_matrix(an_mhmm->trans, new_mhmm->trans);
}
예제 #3
0
파일: opengl.cpp 프로젝트: ammen99/wayfire
wf_framebuffer_base& wf_framebuffer_base::operator = (wf_framebuffer_base&& other)
{
    if (this == &other)
        return *this;

    release();
    copy_state(std::move(other));

    return *this;
}
예제 #4
0
/* In reality no need to return nothing, the move was already checked  */
int game_state_transition(const struct state *s0, struct move *currMove, struct state *s1, struct game *myGame){
    /* store the player */
    store_curr_player(myGame, currMove);
    /* create s1 */
    create_table(myGame,s1);
    /* copy s0 into s1*/
    copy_state(s1,s0,myGame);
    /* free old state */
    free(s0->table);
    /* update the new state */
    myGame->state = *s1;
    myGame->state.table[currMove->row - 1][currMove->column - 1] = currMove->player;
    return 0;
    
}
예제 #5
0
int		op_lfork(t_vm *vm, t_process *process, int *params, int len)
{
	t_process		*fork;
	unsigned char	*addr;

	addr = vm->memory + ((((short)params[0]) +
								(process->next_instr - vm->memory)) % MEM_SIZE);
	if (!(fork = new_process(addr, vm->current_cycle -
								get_cycles_for_opcode(*process->next_instr))))
		return (len);
	if (!(fork->registres = copy_regs(process->registres)))
		exit(1);
	copy_state(fork, process);
	ft_lstadd(&vm->processes, ft_lstnew(fork, sizeof(t_process)));
	return (len);
}
예제 #6
0
//gestore degli interrupt
void int_handler(){	
	interruptStart = getTODLO();	//tempo in cui comincia la gestione dell'interrupt, da
					//assegnare poi ad un eventuale processo svegliato dall'interrupt
	state_t *returnState = (state_t*) INT_OLDAREA;
	returnState->pc -= 4;
	if( current_process != NULL){
		copy_state( returnState, &current_process->p_s );
		current_process->userTime += interruptStart - userTimeStart;//se c'è un processo aggiorno il suo userTime
		current_process->CPUTime += interruptStart - CPUTimeStart;
	}
	int cause = getCAUSE();
	if(CAUSE_IP_GET(cause, IL_TIMER)){
		if( current_timer == PSEUDO_CLOCK ){
			while( devSem[CLOCK_SEM] < 0 ){	//Ad ogni pseudo clock tick mi assicuro che il semaforo sia sempre a zero
				verhogen( &devSem[CLOCK_SEM], 1, 0, getTODLO() - interruptStart);
			}
		}
		else if(current_timer == TIME_SLICE ){
			if( current_process != NULL ){
				insertProcQ( priority_queue(current_process->priority), current_process);
				current_process->CPUTime += getTODLO() - interruptStart;	//se metto in pausa il processo aggiorno anche il suo CPUTime
				current_process = NULL;
			}
		}
	}
	else if(CAUSE_IP_GET(cause, IL_DISK)){
		dtnp_interrupt(IL_DISK);
	}
	else if(CAUSE_IP_GET(cause, IL_TAPE)){
		dtnp_interrupt(IL_TAPE);
	}
	else if(CAUSE_IP_GET(cause, IL_ETHERNET)){
		dtnp_interrupt(IL_ETHERNET);
	}
	else if(CAUSE_IP_GET(cause, IL_PRINTER)){
		dtnp_interrupt(IL_PRINTER);
	}
	else if(CAUSE_IP_GET(cause, IL_TERMINAL)){
		terminal_interrupt();
	}
	scheduler();
}
예제 #7
0
/** 
 * @brief Lookups state and hash table, adding new if none was found.
 *
 * New state is immediately pushed to BFS.
 * 
 * @param state state structure
 * @param add_action Action to perform when adding state to hash
 * 
 * @return 1 if new state was added, 0 if it was present.
 */
int state_hash_add(struct State *state, enum HashAddAction add_action)
{
	state_hash_t hash0 = STATE_TABLE_HASH(state, 0);
	state_hash_t hash = hash0;
	int found = 0;

	hash_dprintf("State hash (" HASH_FMT ")", hash0);
	dump_dprintf(" ");
	hexdump_state(state);

	/*
	 * Check each bit, setting it to 1.
	 */
	for (int i = 0; i < BITSTATE_HASH_COUNT; 
		 ++i, hash = STATE_TABLE_HASH(state, i)) {
		hash_dprintf(" (" HASH_FMT ")", hash);
		if (BIT_TEST(state_hashtable, hash))
			++found;
		else
			BIT_SET(state_hashtable, hash);
	}

	if (found < BITSTATE_HASH_COUNT) {
		/*
		 * Not all bits set -- new state 
		 */
		if (found > 0) {
			/*
			 * ... but some bits set -- possible collision 
			 */
			hash_dprintf(" {COLLISION: %d/%d bits set}", found, BITSTATE_HASH_COUNT);
			hash_collisions++;
			hash_collision_shifts += found;
		}

		switch (add_action) {
		case BfsAddCopy:
			state = copy_state(state);
		case BfsAdd:
			BFS_ADD(state);
			if (max_bfs_state_size < BFS_CUR_SIZE())
				max_bfs_state_size = BFS_CUR_SIZE();
		case BfsNoAdd:
			break;
		}

		total_state_size += BITSTATE_HASH_COUNT*STATESIZE(state);
		min_state_size = (min_state_size < STATESIZE(state)) ? min_state_size : STATESIZE(state);
		max_state_size = (max_state_size > STATESIZE(state)) ? max_state_size : STATESIZE(state);

#ifndef DEBUG
		if (dump_new_states)
			edump_state(state);
#endif

		hash_dprintf(" - ADDED");
		used_hash_entries += BITSTATE_HASH_COUNT;
	}
	else 
		/*
		 * All bits set -- old state 
		 */
		hash_dprintf(" - OLD");

	dprintf("\n");

	return (found < BITSTATE_HASH_COUNT);
}
예제 #8
0
/** 
 * @brief Lookups state and hash table, adding new if none was found.
 *
 * New state is immediately pushed to BFS.
 * 
 * @param state state structure
 * @param add_action Action to perform when adding state to hash
 * 
 * @return 1 if new state was added, 0 if it was present.
 */
int state_hash_add(struct State *state, enum HashAddAction add_action)
{
	state_hash_t hash = STATE_TABLE_HASH(state, 0);
	state_hash_t offset = 0;
	struct State *st;
	int found = 0;
	int had_collisions = 0;

	hash_dprintf("State hash (" HASH_FMT ")", hash);
	dump_dprintf(" ");
	hexdump_state(state);

	for (st = state_hashtable[hash];
		 st != NULL 
			 && (STATESIZE(state) != STATESIZE(st) || 
				 memcmp(state, st, STATESIZE(state)));
		 st = state_hashtable[hash]) {
		/*
		 * Hash slot already occupied by a state address (not NULL)
		 * which is not the same as new state
		 */
		hash_dprintf(" {COLLISION IN SLOT " HASH_FMT, SQR(offset));
		++hash_collision_shifts;
		had_collisions = 1;
		/*
		 * Open addressing with quadratic probes: slot, slot+1, slot+3, slot+6,..
		 */
		hash += ++offset;
		hash %= HASHTABLE_LENGTH;
		hash_dprintf(", NEXT " HASH_FMT "}", hash);

		dump_dprintf(" := ");
		hexdump_state(st);
	}

	if (had_collisions)
		hash_collisions++;

	/*
	 * If last slot value was NULL -- empty slot has been found,
	 * otherwise same state was found in hash.
	 */
	if (st == NULL) {
		switch (add_action) {
		case BfsAddCopy:
			state = copy_state(state);
		case BfsAdd:
			BFS_ADD(state);
		case BfsNoAdd:
			state_hashtable[hash] = state;
		}

		total_state_size += STATESIZE(state);
		min_state_size = (min_state_size < STATESIZE(state)) ? min_state_size : STATESIZE(state);
		max_state_size = (max_state_size > STATESIZE(state)) ? max_state_size : STATESIZE(state);

#ifndef DEBUG
		if (dump_new_states)
			edump_state(state);
#endif

		hash_dprintf(" - ADDED");
		++used_hash_entries;
	} else {
		found = 1;
		hash_dprintf(" - OLD");
	}

	dprintf("\n");

	return !found;
}
예제 #9
0
//----------------------------DRAW---------------------------
void draw(Display * dpy, Window win, int s_width, int s_height) {
	copy_state(state, state_buffer, 1);

	lock_state(state);

	glViewport(0, 0, s_width, s_height);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	Dimension d = get_grid_for_num_instruments(state->num_instruments, s_width, s_height);
	int i;
	for (i = 0; i < state->num_instruments; ++i) {
		float left = s_width / d.x * (i % d.x);
		float bottom = s_height / d.y * (d.y - 1 - i / d.x);
		float width = s_width / d.x;
		float height = s_height / d.y;
		glViewport(left, bottom, width, height);

		Instrument_State * is = &state->instruments[i];

		GLfloat brightness = pow(1 - pow((float)is->draw_state / MAX_DRAW_STATE * 2 - 1, 2), 0.5);
		if (is->draw_state) --is->draw_state;

		GLfloat up[] = {
			-T_BOUND, -T_BOUND, 0.0, T_BOTTOM_BRIGHTNESS, 0.0, brightness,
			0.0, T_BOUND, 0.0, 1.0, 0.0, brightness,
			T_BOUND, -T_BOUND, 0.0, T_BOTTOM_BRIGHTNESS, 0.0, brightness
		};
		GLfloat down[] = {
			-T_BOUND, T_BOUND, T_BOTTOM_BRIGHTNESS, 0.0, 0.0, brightness,
			0.0, -T_BOUND, 1.0, 0.0, 0.0, brightness,
			T_BOUND, T_BOUND, T_BOTTOM_BRIGHTNESS, 0.0, 0.0, brightness
		};

		glBindBuffer(GL_ARRAY_BUFFER, gla.array_buffer);
		if (is->direction == 'u') {
			glBufferData(GL_ARRAY_BUFFER, sizeof(up), up, GL_STATIC_DRAW);
		} else {
			glBufferData(GL_ARRAY_BUFFER, sizeof(down), down, GL_STATIC_DRAW);
		}

		glEnableVertexAttribArray(gla.position);
		glVertexAttribPointer(gla.position, 2, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);

		glEnableVertexAttribArray(gla.color);
		glVertexAttribPointer(gla.color, 4, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (void *)(2 * sizeof(GLfloat)));

		glDrawArrays(GL_TRIANGLES, 0, 3);

#ifdef SHOW_TEXT
		glListBase(gla.font_base);
		glColor4f(1.0, 1.0, 1.0, brightness / 2 + 0.5);
		float i_length = strlen(is->instrument);
		GLfloat i_left = -i_length * gla.font_width / width;
		GLfloat i_bottom = 0.9 - gla.font_height / height * 2;
		glRasterPos2f(i_left, i_bottom);
		glCallLists(i_length, GL_UNSIGNED_BYTE, (unsigned char *)is->instrument);

		char price[16] = {0};
		sprintf(price, "%f", is->price);
		float p_length = strlen(price);
		GLfloat p_left = -p_length * gla.font_width / width;
		GLfloat p_bottom = -0.9;
		glRasterPos2f(p_left, p_bottom);
		glCallLists(p_length, GL_UNSIGNED_BYTE, (unsigned char *)price);
#endif
	}

	unlock_state(state);

	glXSwapBuffers(dpy, win);
}
예제 #10
0
파일: zebra_rnh.c 프로젝트: Quagga/quagga
int
zebra_evaluate_rnh_table (vrf_id_t vrfid, int family)
{
  struct route_table *ptable;
  struct route_table *ntable;
  struct route_node *prn;
  struct route_node *nrn;
  struct rnh *rnh;
  struct zserv *client;
  struct listnode *node;
  struct rib *rib;

  ntable = lookup_rnh_table(vrfid, family);
  if (!ntable)
    {
      zlog_debug("evaluate_rnh_table: rnh table not found\n");
      return -1;
    }

  ptable = zebra_vrf_table(family2afi(family), SAFI_UNICAST, vrfid);
  if (!ptable)
    {
      zlog_debug("evaluate_rnh_table: prefix table not found\n");
      return -1;
    }

  for (nrn = route_top (ntable); nrn; nrn = route_next (nrn))
    {
      if (!nrn->info)
	  continue;
      
      rnh = nrn->info;
      prn = route_node_match(ptable, &nrn->p);
      if (!prn)
	rib = NULL;
      else
	{
	  RNODE_FOREACH_RIB(prn, rib)
	    {
	      if (CHECK_FLAG (rib->status, RIB_ENTRY_REMOVED))
		continue;
	      if (! CHECK_FLAG (rib->status, RIB_ENTRY_SELECTED_FIB))
		continue;

	      if (CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED))
		{
		  if (rib->type == ZEBRA_ROUTE_CONNECT)
		    break;

		  if (rib->type == ZEBRA_ROUTE_NHRP)
		    {
		      struct nexthop *nexthop;
		      for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
			if (nexthop->type == NEXTHOP_TYPE_IFINDEX ||
			    nexthop->type == NEXTHOP_TYPE_IFNAME)
			  break;
		      if (nexthop)
			break;
		    }
		}
	      else
		break;
	    }
	}

      if (compare_state(rib, rnh->state))
	{
	  if (IS_ZEBRA_DEBUG_NHT)
	    {
	      char bufn[INET6_ADDRSTRLEN];
	      char bufp[INET6_ADDRSTRLEN];
	      prefix2str(&nrn->p, bufn, INET6_ADDRSTRLEN);
	      if (prn)
		prefix2str(&prn->p, bufp, INET6_ADDRSTRLEN);
	      else
		strcpy(bufp, "null");
	      zlog_debug("rnh %s resolved through route %s - sending "
			 "nexthop %s event to clients", bufn, bufp,
			 rib ? "reachable" : "unreachable");
	    }
	  copy_state(rnh, rib);
	  for (ALL_LIST_ELEMENTS_RO(rnh->client_list, node, client))
	    send_client(rnh, client, vrfid);
	}
    }
  return 1;
}
예제 #11
0
파일: opengl.cpp 프로젝트: ammen99/wayfire
wf_framebuffer_base::wf_framebuffer_base(wf_framebuffer_base&& other)
{
    copy_state(std::move(other));
}