Esempio n. 1
0
/* Trim zero blocks of the beginning and end of the object. */
static int default_trim(int fd, uint64_t oid, const struct siocb *iocb,
			uint64_t *poffset, uint32_t *plen)
{
	trim_zero_blocks(iocb->buf, poffset, plen);

	if (iocb->offset < *poffset) {
		sd_debug("discard between %d, %ld, %" PRIx64, iocb->offset,
			 *poffset, oid);

		if (discard(fd, iocb->offset, *poffset) < 0)
			return -1;
	}

	if (*poffset + *plen < iocb->offset + iocb->length) {
		uint64_t end = iocb->offset + iocb->length;
		if (end == get_objsize(oid))
			/* This is necessary to punch the last block */
			end = round_up(end, BLOCK_SIZE);
		sd_debug("discard between %ld, %ld, %" PRIx64, *poffset + *plen,
			 end, oid);

		if (discard(fd, *poffset + *plen, end) < 0)
			return -1;
	}

	return 0;
}
Esempio n. 2
0
const char * configstring (const char * file, const char * part, const char * item, const char * text) 

{
    FILE *fp;
    if (file && part && item) {
        if ((fp = fopen (file, "rb"))) {
            for (c = getc (fp); c != EOF; discard (fp)) {
                while (isblank (c)) {                
                    c = getc (fp);
                }
                if (c != '[') {
                    continue;
                }
                do {
                    c = getc (fp);
                }
                while (isblank (c));
                if (!compare (fp, part)) {
                    continue;
                }
                if (c != ']') {
                    continue;
                }
                for (discard (fp); (c != '[') && (c != EOF); discard (fp)) {
                    while (isblank (c)) {
                        c = getc (fp);
                    }
                    if (c == ';') {
                        continue;
                    }
                    if (!compare (fp, item)) {
                        continue;
                    }
                    if (c != '=') {
                        continue;
                    }
                    do {
                        c = getc (fp);
                    }
                    while (isblank (c));
                    collect (fp);
                    text = buffer;
                    break;
                }
                break;
            }
            fclose (fp);
        }
    }

    if (text) {
        text = strdup(text);
    }

    return text;
}
Esempio n. 3
0
File: sl_list.c Progetto: Rubusch/c
/*
  removes an element within the list
    
    data       data of the element to find
    data_size  size of data
//*/
int removeelement(const char* data, const unsigned int data_size)
{
  // checks
  if(NULL == data) return -1;

  // find and delete
  element_t* tmp = find(data, data_size);
  if(NULL == tmp){
    fprintf(stderr, "element \"%s\" not found in list\n", data);
    return -1;
  }

  // element was first
  if(tmp == first){

    // list only has one element
    if(first == last){
      // TODO use discard first.. reset elements
      return 0;
    }

    first = first->next;
    if(0 != discard(&tmp)){
      return -1;
    }
    tmp = NULL;
    return 0;
  }

  // get prev element
  element_t* prev = first;
  while(prev->next){
    if(prev->next == tmp){
      break;
    }
  }
  
  // next element
  element_t* next = prev->next;
  if(NULL == next){
    return removelastelement();
  }

  // unlink
  prev->next = next;

  // delete
  if(0 != discard(&tmp)){
    return -1;
  }

  return 0;
}
Esempio n. 4
0
inline Checkpoint mpi_plain(
    MPI_Comm communicator,
    I&& integrand,
    std::vector<std::size_t> const& iteration_calls,
    Checkpoint chkpt = make_plain_chkpt<numeric_type_of<I>>(),
    Callback callback = mpi_callback<Checkpoint>()
) {
    using T = numeric_type_of<I>;

    int rank = 0;
    MPI_Comm_rank(communicator, &rank);
    int world = 0;
    MPI_Comm_size(communicator, &world);

    auto generator = chkpt.generator();

    std::vector<T> buffer;

    std::size_t const usage = integrand.dimensions() *
        random_number_usage<T, decltype (generator)>();

    // perform iterations
    for (auto calls : iteration_calls)
    {
        generator.discard(usage * discard_before(calls, rank, world));

        // the number of function calls for each MPI process
        std::size_t const sub_calls = (calls / world) +
            (static_cast <std::size_t> (rank) < (calls % world) ? 1 : 0);
        auto const result = plain_iteration(integrand, sub_calls, generator);

        generator.discard(usage * discard_after(calls, sub_calls, rank, world));

        auto const& new_result = allreduce_result(
            communicator,
            result,
            buffer,
            std::vector<T>(),
            calls
        );

        chkpt.add(new_result, generator);

        if (!callback(communicator, chkpt))
        {
            break;
        }
    }

    return chkpt;
}
/*
 * fall:
 *	Drop an item someplace around here.
 */
int
fall(struct linked_list *item, int pr)
{
	register struct object *obj ;
	register struct room *rp ;
	static coord fpos ;
	int ret;

	obj = (struct object *) ldata(item) ;
	rp = roomin(&hero);
	if (obj->o_flags & CANRETURN) {
	    add_pack(item, TRUE);
	    return TRUE;
	}
	else if (fallpos(&obj->o_pos, &fpos, TRUE)) {
		if (obj->o_flags & CANBURN && ntraps + 1 < MAXTRAPS + MAXTRAPS) {
		    mvaddch(fpos.y, fpos.x, FIRETRAP);
		    traps[ntraps].tr_type = FIRETRAP;
		    traps[ntraps].tr_flags = ISFOUND;
		    traps[ntraps].tr_show = FIRETRAP;
		    traps[ntraps].tr_pos.y = fpos.y;
		    traps[ntraps++].tr_pos.x = fpos.x;
		    if (rp != NULL)
			rp->r_flags &= ~ISDARK;
			discard(item);
			ret = FALSE;
		}
		else {
		    mvaddch(fpos.y, fpos.x, obj->o_type) ;
		    obj->o_pos = fpos ;
		    attach(lvl_obj, item) ;
			ret = TRUE;
		}
		if (rp != NULL &&
		    (!(rp->r_flags & ISDARK) ||
		    (rp->r_flags & HASFIRE))) {
			light(&hero) ;
			mvwaddch(cw, hero.y, hero.x, PLAYER) ;
		}
		return ret;
	}
	if (pr) {
		if (obj->o_type == WEAPON)
			addmsg("The %s", weaps[obj->o_which]);
		else
			addmsg(inv_name(obj, TRUE));
		msg(" vanishes as it hits the ground.");
	}
	discard(item) ;
	return FALSE;
}
Esempio n. 6
0
int toplevel(pstate *state) {
    UNPACK_STATE();
    int found = 0;
    while(curr <= eof) {
        qscan3('{','[','#');
        switch(*curr) {
            case '{': discard(); found += new_dict(state); break;
            case '[': discard(); found += new_list(state); break;
            case '#': discard(); found ++; break;
            default:  discard(); // EOF
        }
    }
    return found;
}
Esempio n. 7
0
void WriteMail::init()
{
    m_toolbar = new QToolBar(this);
    addToolBar(m_toolbar);
    m_widgetStack = new QStackedWidget(this);

    m_cancelAction = new QAction(Qtmail::icon("cancel"),tr("Close"),this);
    connect( m_cancelAction, SIGNAL(triggered()), this, SLOT(discard()) );
    addAction(m_cancelAction);

    m_draftAction = new QAction(Qtmail::icon("saveToDraft"),tr("Save in drafts"),this);
    connect( m_draftAction, SIGNAL(triggered()), this, SLOT(draft()) );
    m_draftAction->setWhatsThis( tr("Save this message as a draft.") );
    addAction(m_draftAction);

    m_sendAction = new QAction(Qtmail::icon("sendmail"),tr("Send"),this);
    connect( m_sendAction, SIGNAL(triggered()), this, SLOT(sendStage()) );
    m_sendAction->setWhatsThis( tr("Send the message.") );
    addAction(m_sendAction);

    m_accountSelection = new QComboBox(m_toolbar);
    connect( m_accountSelection, SIGNAL(currentIndexChanged(int)), this, SLOT(accountSelectionChanged(int)) );

    m_selectComposerWidget = new SelectComposerWidget(this);
    m_selectComposerWidget->setObjectName("selectComposer");
    connect(m_selectComposerWidget, SIGNAL(selected(QPair<QString,QMailMessage::MessageType>)),
            this, SLOT(composerSelected(QPair<QString,QMailMessage::MessageType>)));
    connect(m_selectComposerWidget, SIGNAL(cancel()), this, SLOT(discard()));
    m_widgetStack->addWidget(m_selectComposerWidget);

    setCentralWidget(m_widgetStack);

    QMenuBar* mainMenuBar = new QMenuBar();
    setMenuBar(mainMenuBar);

    QMenu* file = mainMenuBar->addMenu("File");
    file->addAction(m_sendAction);
    file->addAction(m_draftAction);
    file->addSeparator();
    file->addAction(m_cancelAction);

    m_toolbar->addAction(m_sendAction);
    m_toolbar->addAction(m_draftAction);
    m_toolbar->addWidget(m_accountSelection);
    m_toolbar->addSeparator();

    setWindowTitle(tr("Compose"));

    setGeometry(0,0,defaultWidth,defaultHeight);
}
void QQuickDialog::click(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role)
{
    setVisible(false);
    m_clickedButton = static_cast<StandardButton>(button);
    emit buttonClicked();
    switch (role) {
    case QPlatformDialogHelper::AcceptRole:
        emit accept();
        break;
    case QPlatformDialogHelper::RejectRole:
        emit reject();
        break;
    case QPlatformDialogHelper::DestructiveRole:
        emit discard();
        break;
    case QPlatformDialogHelper::HelpRole:
        emit help();
        break;
    case QPlatformDialogHelper::YesRole:
        emit yes();
        break;
    case QPlatformDialogHelper::NoRole:
        emit no();
        break;
    case QPlatformDialogHelper::ApplyRole:
        emit apply();
        break;
    case QPlatformDialogHelper::ResetRole:
        emit reset();
        break;
    default:
        qWarning("unhandled Dialog button %d with role %d", (int)button, (int)role);
    }
}
Esempio n. 9
0
// This one puts some data inside the ring buffer.
void RingBuffer::put(AudioBuffer& buf)
{
    std::lock_guard<std::mutex> l(lock_);
    const size_t sample_num = buf.frames();
    const size_t buffer_size = buffer_.frames();
    if (buffer_size == 0)
        return;

    size_t len = putLength();
    if (buffer_size - len < sample_num)
        discard(sample_num);
    size_t toCopy = sample_num;

    // Add more channels if the input buffer holds more channels than the ring.
    if (buffer_.channels() < buf.channels())
        buffer_.setChannelNum(buf.channels());

    size_t in_pos = 0;
    size_t pos = endPos_;

    while (toCopy) {
        size_t block = toCopy;

        if (block > buffer_size - pos) // Wrap block around ring ?
            block = buffer_size - pos; // Fill in to the end of the buffer

        buffer_.copy(buf, block, in_pos, pos);
        in_pos += block;
        pos = (pos + block) % buffer_size;
        toCopy -= block;
    }

    endPos_ = pos;
    not_empty_.notify_all();
}
Esempio n. 10
0
void
fall(struct linked_list *item, int pr)
{
    struct object *obj;
    struct room *rp;
    static coord fpos;

    obj = (struct object *) ldata(item);
    if (fallpos(&obj->o_pos, &fpos, TRUE))
    {
	mvaddrawch(fpos.y, fpos.x, obj->o_type);
	obj->o_pos = fpos;
	if ((rp = roomin(&hero)) != NULL && !(rp->r_flags & ISDARK))
	{
	    light(&hero);
	    mvwaddrawch(cw, hero.y, hero.x, PLAYER);
	}
	attach(lvl_obj, item);
	return;
    }
    if (pr)
        if (obj->o_type == WEAPON) /* BUGFUX: Identification trick */
            msg("Your %s vanishes as it hits the ground.", w_names[obj->o_which]);
        else
            msg("%s vanishes as it hits the ground.", inv_name(obj,TRUE));
    discard(item);
}
Esempio n. 11
0
static int
type1crypt(i_ctx_t *i_ctx_p,
           int (*proc)(byte *, const byte *, uint, ushort *))
{
    os_ptr op = osp;
    crypt_state state;
    uint ssize;

    check_type(op[-2], t_integer);
    state = op[-2].value.intval;
    if (op[-2].value.intval != state)
        return_error(e_rangecheck);	/* state value was truncated */
    check_read_type(op[-1], t_string);
    check_write_type(*op, t_string);
    ssize = r_size(op - 1);
    if (r_size(op) < ssize)
        return_error(e_rangecheck);
    discard((*proc)(op->value.bytes, op[-1].value.const_bytes, ssize,
                    &state));	/* can't fail */
    op[-2].value.intval = state;
    op[-1] = *op;
    r_set_size(op - 1, ssize);
    pop(1);
    return 0;
}
void EditEnumerationDialog::updateCurrentItem()
{
    discard();
    auto const item = m_dialog->itemList->currentItem();
    if (item != nullptr)
        item->setText(m_dialog->currentItem->text());
}
Esempio n. 13
0
/*
 * playhand:
 *	Do up one hand of the game
 */
int
playhand(bool mycrib)
{
	int deckpos;

	werase(Compwin);
	wrefresh(Compwin);
	werase(Tablewin);
	wrefresh(Tablewin);

	knownum = 0;
	deckpos = deal(mycrib);
	sorthand(chand, FULLHAND);
	sorthand(phand, FULLHAND);
	makeknown(chand, FULLHAND);
	prhand(phand, FULLHAND, Playwin, FALSE);
	discard(mycrib);
	if (cut(mycrib, deckpos))
		return TRUE;
	if (peg(mycrib))
		return TRUE;
	werase(Tablewin);
	wrefresh(Tablewin);
	if (score(mycrib))
		return TRUE;
	return FALSE;
}
Esempio n. 14
0
/**
 * Destroy descriptor ring
 *
 * @v netfront		Netfront device
 * @v ring		Descriptor ring
 * @v discard		Method used to discard outstanding buffer, or NULL
 */
static void netfront_destroy_ring ( struct netfront_nic *netfront,
				    struct netfront_ring *ring,
				    void ( * discard ) ( struct io_buffer * ) ){
	struct xen_device *xendev = netfront->xendev;
	struct xen_hypervisor *xen = xendev->xen;
	struct io_buffer *iobuf;
	unsigned int id;

	/* Flush any outstanding buffers */
	while ( ! netfront_ring_is_empty ( ring ) ) {
		id = ring->ids[ ring->id_cons & ( ring->count - 1 ) ];
		iobuf = netfront_pull ( netfront, ring, id );
		if ( discard )
			discard ( iobuf );
	}

	/* Unpublish shared ring reference */
	netfront_rm ( netfront, ring->ref_key );

	/* Revoke access from shared ring */
	xengrant_invalidate ( xen, ring->ref );

	/* Free page */
	free_dma ( ring->sring.raw, PAGE_SIZE );
	ring->sring.raw = NULL;
}
Esempio n. 15
0
void qore_program_private::del(ExceptionSink* xsink) {
   printd(5, "QoreProgram::del() pgm: %p (base_object: %d)\n", pgm, base_object);

   if (thr_init)
      thr_init->deref(xsink);

   if (base_object) {
      deleteThreadData(xsink);

      // delete thread local storage key
      delete thread_local_storage;
      base_object = false;
   }

   // have to delete global variables first because of destructors.
   // method call can be repeated
   qore_root_ns_private::clearData(*RootNS, xsink);

   // delete all global variables, class static vars and constants
   RootNS->deleteData(xsink);

   // delete defines
   for (dmap_t::iterator i = dmap.begin(), e = dmap.end(); i != e; ++i)
      discard(i->second, xsink);
   dmap.clear();

   // method call can be repeated
   sb.del();
   //printd(5, "QoreProgram::~QoreProgram() this: %p deleting root ns %p\n", this, RootNS);

   delete RootNS;
   RootNS = 0;
}
void
fall(THING *obj, int pr)
{
    PLACE *pp;
    coord fpos;

    if (fallpos(&obj->o_pos, &fpos))
    {
	pp = INDEX(fpos.y, fpos.x);
	pp->p_ch = obj->o_type;
	obj->o_pos = fpos;
	if (cansee(fpos.y, fpos.x))
	{
	    if (pp->p_monst != NULL)
		pp->p_monst->t_oldch = obj->o_type;
	    else
		mvaddch(fpos.y, fpos.x, obj->o_type);
	}
	attach(lvl_obj, obj);
	return;
    }
    if (pr)
    {
	if (has_hit)
	{
	    endmsg();
	    has_hit = FALSE;
	}
	msg("the %s vanishes as it hits the ground",
	    weap_info[obj->o_which].oi_name);
    }
    discard(obj);
}
Esempio n. 17
0
void HttpClient::reset(FXbool forceclose){
  if (forceclose)
    close();
  else
    discard();
  clear();
  }
Esempio n. 18
0
void Sprite::copyFrom(const Sprite &sprite) {
	discard();

	if (sprite._surfacePaletted.pixels) {
		_surfacePaletted.copyFrom(sprite._surfacePaletted);

		_transparencyMap = new uint8[_surfacePaletted.w * _surfacePaletted.h];
		memcpy(_transparencyMap, sprite._transparencyMap, _surfacePaletted.w * _surfacePaletted.h);
	}

	if (sprite._surfaceTrueColor.pixels)
		_surfaceTrueColor.copyFrom(sprite._surfaceTrueColor);

	_palette = sprite._palette;

	_fileName = sprite._fileName;
	_fromCursor = sprite._fromCursor;

	_defaultX = sprite._defaultX;
	_defaultY = sprite._defaultY;

	_feetX = sprite._feetX;
	_feetY = sprite._feetY;

	_flippedHorizontally = sprite._flippedHorizontally;
	_flippedVertically   = sprite._flippedVertically;

	_scale        = sprite._scale;
	_scaleInverse = sprite._scaleInverse;
}
Esempio n. 19
0
int checkGreatHall(int player, struct gameState *post)
{
	int old_numActions = post->numActions;
	struct gameState pre;
	memcpy(&pre, post, sizeof(struct gameState));

	int r = great_hall(player, post, 0);
	//what great_hall is supposed to do
	if(pre.deckCount[player] < 1)
	{
		shuffle( player, &pre);
	}
	pre.hand[player][pre.handCount[player]] = pre.deck[player][pre.deckCount[player]-1];
	pre.handCount[player]++;
	pre.deckCount[player]--;
	pre.numActions++:
	discard(0, player, &pre, 0);

	// check if post and pre are the same
	if( pre.deckCount[player] == post->deckCount[player])
	{
		if (pre.handCount[player] == post->handCount[player])
		{
			if(pre.dicardCount[player] == post->discardCount[player])
			{	if(pre.numActions == post->numActions)
				{
					return 0;
				}
			}
		}
	}
	return -1;
}
Esempio n. 20
0
gl::Error StreamingIndexBufferInterface::reserveBufferSpace(unsigned int size, GLenum indexType)
{
    unsigned int curBufferSize = getBufferSize();
    unsigned int writePos = getWritePosition();
    if (size > curBufferSize)
    {
        gl::Error error = setBufferSize(std::max(size, 2 * curBufferSize), indexType);
        if (error.isError())
        {
            return error;
        }
        setWritePosition(0);
    }
    else if (writePos + size > curBufferSize || writePos + size < writePos)
    {
        gl::Error error = discard();
        if (error.isError())
        {
            return error;
        }
        setWritePosition(0);
    }

    return gl::Error(GL_NO_ERROR);
}
Esempio n. 21
0
int main(){
	//initialize loop variables and value return variables
	int i, j, k, p, r;
	//seed our RNG for different combos of 3 empty piles
	srand(time(NULL));
	//declare seed for RNG as initialize argument
	int seed = 19191;
	int numPlayers = 2;
	//declare player 1 (all tests are symmetric across players here)
	int player = 0;
	//set supply pile contents to anything, all that matters for this test
	//is their respective counts.
	int kingdom[10] = {adventurer, council_room, feast, gardens, mine
        , remodel, smithy, village, baron, great_hall};
    struct gameState state;
    printf("Test for great hall card effect\n===================\n");
    //initialize gamestate
    memset(&state, 0, sizeof(struct gameState));
    r = initializeGame(numPlayers,kingdom,seed,&state);
    state.whoseTurn = player;
    assert(handActionIncrease(&state)==1);
    memset(&state, 0, sizeof(struct gameState));
    r = initializeGame(numPlayers,kingdom,seed,&state);
    state.whoseTurn = player;
    assert(emptyDeck(&state)==1);
    memset(&state, 0, sizeof(struct gameState));
    r = initializeGame(numPlayers,kingdom,seed,&state);
    state.whoseTurn = player;
    assert(discard(&state)==1);
    printf("All tests successful!\n\n");
    return 0;
}
Esempio n. 22
0
void SchematicSceneBuilder::add_wire_component(
    std::map<std::string, std::string> props
  )
{
  if(!discard(props)) {
    Wire* item = static_cast<Wire*>(
      SchematicScene::itemByType(SchematicScene::WireItemType));

    bool ok;

    double to_x = QString::fromStdString(props["to_x"]).toDouble(&ok);
    if(!ok)
      to_x = SchematicScene::GridStep;

    double to_y = QString::fromStdString(props["to_y"]).toDouble(&ok);
    if(!ok)
      to_y = SchematicScene::GridStep;

    bool conn = QString::fromStdString(props["conn"]).toInt(&ok);
    if(!ok)
      conn = false;

    item->setWire(QLineF(QPointF(0, 0), QPointF(to_x, to_y)));
    item->setConnectedJunctions(conn);

    scene_->addSupportedItem(item, false);
    grid_coordinate(item, props);
    items_.push_back(item);
  }
}
Esempio n. 23
0
void LineBehavior::circle(vector<RobotState>* robots) {
    

    // update diameter extremities
    if (robots->at(1).getTouch()) {
        ofVec2f pos = robots->at(1).getPosition();
        robots->at(1).setGoal(pos);
    }
    if (robots->at(2).getTouch()) {
        ofVec2f pos = robots->at(2).getPosition();
        robots->at(2).setGoal(pos);
    }
    
    // get diameter extremities
    ofVec2f p1 = robots->at(1).getGoal();
    ofVec2f p2 = robots->at(2).getGoal();

    // count number of needed robots
    float d = PI * p1.distance(p2);
    float current_spacing = d / (nmid+3);
    if (current_spacing < minspacing || current_spacing > maxspacing) {
        nmid = max(0, min(nbRobots-3, (int)(d / spacing) - 3));
        nmid = 2 * (int)(nmid/2); // has to be even
    }

    // update interpolating robots
    ofVec2f o = (p1+p2)/2;
    for (int i=0; i<nmid/2; i++) {
        
        //
        int k = i;
        
        float a = 180 * (k+1) / (float)(nmid/2 + 1);
        ofVec2f p = o + (p2 - o).rotate(a);
        robots->at(3 + i*2).setGoal(p);
        robots->at(3 + i*2).setColor(ofColor(0, 0, 255));
        ofVec2f p_ = o + (p1 - o).rotate(a);
        robots->at(3 + i*2 + 1).setGoal(p_);
        robots->at(3 + i*2 + 1).setColor(ofColor(0, 0, 255));
    }
    // put remaining robots aside
    discard(robots, nmid + 3, robots->size()-1);
    
    // translate
    int translating = 0;
    for (int i=3; i < 3+nmid; i++)
        if (robots->at(i).getTouch())
            translating = i;
    if (translating > 0) {
        ofVec2f goal = robots->at(translating).getGoal();
        ofVec2f pos = robots->at(translating).getPosition();
        ofVec2f delta = pos - goal;
        for (int i=1; i < 3+nmid; i++) {
            ofVec2f goali = robots->at(i).getGoal();
            robots->at(i).setGoal(goali + delta);
        }
    }
    
}
Esempio n. 24
0
void MinionEquipment::updateOwners(const vector<Item*> items) {
  for (const Item* item : items)
    if (owners.count(item->getUniqueId())) {
      const Creature* c = owners.at(item->getUniqueId());
      if (c->isDead() || !needs(c, item, true, true))
        discard(item);
    }
}
Esempio n. 25
0
void MinionEquipment::updateOwners(const vector<Item*> items) {
  for (const Item* item : items)
    if (auto owner = owners.getMaybe(item)) {
      const Creature* c = *owner;
      if (c->isDead() || !needs(c, item, true, true))
        discard(item);
    }
}
Esempio n. 26
0
static int
s_fileno_write_flush(register stream * s)
{
    int result = s_process_write_buf(s, false);

    discard(fsync(sfileno(s)));
    return result;
}
Esempio n. 27
0
void LineBehavior::line(vector<RobotState>* robots) {


    // update line extremities
    if (robots->at(1).getTouch()) {
        ofVec2f pos = robots->at(1).getPosition();
        robots->at(1).setGoal(pos);
    }
    if (robots->at(2).getTouch()) {
        ofVec2f pos = robots->at(2).getPosition();
        robots->at(2).setGoal(pos);
    }

    // get line extremities
    ofVec2f p1 = robots->at(1).getGoal();
    ofVec2f p2 = robots->at(2).getGoal();

    // count number of needed robots
    float d = p1.distance(p2);
    float current_spacing = d / (nmid+1);
    if (current_spacing < minspacing || current_spacing > maxspacing)
        nmid = max(0, min(nbRobots-3, (int)(d / spacing) - 1));

    // update interpolating robots
    for (int i=0; i<nmid; i++) {
        
        // insert/remove in the middle
        int k;
        if (i%2 == 0)
            k = i/2;
        else
            k = (nmid-1) - (i-1)/2;
        
        float t = (k+1) / (float)(nmid + 1);
        ofVec2f p = p1 + t * (p2 - p1);
        robots->at(3+i).setGoal(p);
        robots->at(3+i).setColor(ofColor(0, 0, 255));
    }
    // put remaining robots aside
    discard(robots, nmid + 3, robots->size()-1);

    // translate
    int translating = 0;
    for (int i=3; i < 3+nmid; i++)
        if (robots->at(i).getTouch())
            translating = i;
    if (translating > 0) {
        ofVec2f goal = robots->at(translating).getGoal();
        ofVec2f pos = robots->at(translating).getPosition();
        ofVec2f delta = pos - goal;
        for (int i=1; i < 3+nmid; i++) {
            ofVec2f goali = robots->at(i).getGoal();
            robots->at(i).setGoal(goali + delta);
        }
    }

    
}
Esempio n. 28
0
bool MinionEquipment::canTakeItem(const Creature* c, const Item* it) {
  if (const Creature* owner = getOwner(it)) {
    if (c == owner) {
      if (!needs(c, it)) {
        discard(it);
        return false;
      }
      return true;
    }
    if (owner->isDead())
      discard(it);
    else
      return false;
  }
  if (!getEquipmentType(it) || !c->isHumanoid())
    return false;
  return needs(c, it);
}
Esempio n. 29
0
JASEL_NODISCARD JASEL_ATTR_ASSUME_ALIGNED(align) JASEL_CXX14_CONSTEXPR T *assume_aligned(T *u)
{
#if 1
	discard(JASEL_ASSUME_ALIGNED(u, align));
#else
	JASEL_ASSUME(check_aligned<align>(u));
#endif
	return u;
}
        void  free (BufferHeader* bh)
        {
            assert(bh->size > 0);
            assert(bh->size <= size_);
            assert(bh->store == BUFFER_IN_MEM);
            assert(bh->ctx == this);

            if (SEQNO_NONE == bh->seqno_g) discard (bh);
        }