Ejemplo n.º 1
0
void topdowngeneraldadd(short m,short length,signed char *data)
{
    long lowbase,highbase;
    short i,ibitrev1,ibitrev2,mover2,mstar;

    if(m == 1) return;
    else
    {   mover2 = m/2;
        mstar = m - mover2; //if blocks are unequal, upper one is bigger

        //run dadd on the two subblocks
        topdowngeneraldadd(mover2,length,data);
        topdowngeneraldadd(mstar,length,&data[mover2*length]);
    }
    //now combine the paths from the subblocks

    if(mstar > mover2) //if the subblocks are unequal,do leftover case first
    {   lowbase = (mover2-1)*length;
        highbase = (mover2+mover2)*length;
        topdownsinglesum(length,mstar,&data[lowbase],&data[highbase]);
    }

    for(i=0; i<mover2; i++) //add the matched pairs of drifts from subblocks
    {   ibitrev1 = getposition(i,mover2);  //index of drift i row in lower blk
        ibitrev2 = getposition(i,mstar);   // ditto for upper block
        lowbase = ibitrev1*length;  //set pointer to drift i vector in lower blk
        highbase = (ibitrev2 + mover2)*length;  // ditto for upper block
        topdowndaddpair(length,i,&data[lowbase],&data[highbase]);
    }

}
Ejemplo n.º 2
0
void geninvdadd(short rowcount,short length,signed char *data)
{   short i,lowercount,uppercount;
    signed char *x2d,*x2dp1;
    if(rowcount == 1) return;
    lowercount = rowcount/2;
    uppercount = rowcount - lowercount;

    for(i=0; i<lowercount; i++) //set pointers to rows of drift 2 i and 2 i + 1
    {   x2d = data + length*getposition(i,lowercount);
        x2dp1 = data +length*(lowercount + getposition(i,uppercount));

        splitpath(length,i,x2d,x2dp1); //solve for the drift i rows in
        // the lower and upper blocks
    }

    if(lowercount != uppercount)  //if blocks are different sizes, solve for
        //top row of upper block
    {   x2dp1 = data + (rowcount-1)*length;
        topsolve(length,lowercount,x2d,x2dp1);
    }

    geninvdadd(lowercount,length,data);  //invert lower block sums
    geninvdadd(uppercount,length,data+length*lowercount);//invert upper block sums

}
Ejemplo n.º 3
0
Archivo: eeprom.c Proyecto: mcu786/24aa
/**
 * @brief   Determines and returns size of data that can be processed
 */
static size_t __clamp_size(void *ip, size_t n) {
    if (n > getsize(ip))
        return 0;
    else if ((getposition(ip) + n) > getsize(ip))
        return getsize(ip) - getposition(ip);
    else
        return n;
}
Ejemplo n.º 4
0
/**
 * @brief     Write data to EEPROM.
 * @details   Only one EEPROM page can be written at once. So fucntion
 *            splits large data chunks in small EEPROM transactions if needed.
 * @note      To achieve the maximum effectivity use write operations
 *            aligned to EEPROM page boundaries.
 */
static size_t write(void *ip, const uint8_t *bp, size_t n) {

    size_t   len = 0;     /* bytes to be written at one trasaction */
    uint32_t written; /* total bytes successfully written */
    uint16_t pagesize;
    uint32_t firstpage;
    uint32_t lastpage;

    chDbgCheck((ip != NULL) && (((EepromFileStream*)ip)->vmt != NULL), "");

    if (n == 0)
        return 0;

    n = __clamp_size(ip, n);
    if (n == 0)
        return 0;

    pagesize  =  ((EepromFileStream*)ip)->cfg->pagesize;
    firstpage = (((EepromFileStream*)ip)->cfg->barrier_low + getposition(ip)) / pagesize;
    lastpage  = (((EepromFileStream*)ip)->cfg->barrier_low + getposition(ip) + n - 1) / pagesize;

    written = 0;
    /* data fitted in single page */
    if (firstpage == lastpage) {
        len = n;
        __fitted_write(ip, bp, len, &written);
        bp += len;
        return written;
    }

    else {
        /* write first piece of data to first page boundary */
        len =  ((firstpage + 1) * pagesize) - getposition(ip);
        len -= ((EepromFileStream*)ip)->cfg->barrier_low;
        __fitted_write(ip, bp, len, &written);
        bp += len;

        /* now writes blocks at a size of pages (may be no one) */
        while ((n - written) > pagesize) {
            len = pagesize;
            __fitted_write(ip, bp, len, &written);
            bp += len;
        }

        /* wrtie tail */
        len = n - written;
        if (len == 0)
            return written;
        else {
            __fitted_write(ip, bp, len, &written);
        }
    }

    return written;
}
Ejemplo n.º 5
0
int main(int argc, char **argv) {
    char o;
    int verbose = 0;
    int stones = 0;
    int bits = 0;
    position p;
    p.s = 0;

    while ((o = getopt(argc,argv,"hvt:b:")) != -1)
        switch(o) {
        case 'v':
            verbose = 1;
            break;
        case 't':
            stones = atoi(optarg);
            break;
        case 'b':
            bits = atoi(optarg);
            break;
        default:
            usage();
        }
    if (argc - optind < 1 || !argv[optind][0] || argv[optind][1])
        usage();
    if (argv[optind][0] != 'e' && (stones || bits))
        usage();

    switch (argv[optind++][0]) {
    case 'm':
        getposition(argc,argv,&p);
        if (argc - optind != 1)
            usage();
        expandmovelist(p,argv[optind],verbose);
        break;
    case 'r':
        getposition(argc,argv,&p);
        if (argc - optind)
            usage();
        trialmoves(p,verbose);
        break;
    case 'e':
        if (argc - optind != 2)
            usage();
        reduce_endgame(stones,bits,argv[optind],argv[optind+1]);
        break;
    case 'd':
        misc();
        break;
    default:
        usage();
    }

    return 0;
}
Ejemplo n.º 6
0
/**
 * @brief   Write data that can be fitted in one page boundary
 */
static void __fitted_write(void *ip, const uint8_t *data, size_t len, uint32_t *written) {
    msg_t status = RDY_RESET;

    chDbgCheck(len != 0, "something broken in hi level part");

    status  = eeprom_write(((EepromFileStream*)ip)->cfg, getposition(ip), data, len);
    if (status == RDY_OK) {
        *written += len;
        lseek(ip, getposition(ip) + len);
    }
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
    Display* display;
    Window   root;
    position clickpos, current;

    int i;
    int limit     = 0;
    int sleep_dur = 20;

    if (argc != 2 && argc != 3) {
        fprintf(stderr,
                "Usage: %s NUM [DEL]\n"
                "Clicks where the pointer is at script launch\n"
                "    Args:\n"
                "         NUM   Number of clicks, infinite if 0\n"
                "         DEL   Delay between clicks (mlls)\n",
                argv[0]);
        return 1;
    }

    myatoi(argv[1], &limit);

    if (argc == 3) {
        myatoi(argv[2], &sleep_dur);
    }
    sleep_dur *= 1000;

    if ((display = XOpenDisplay(NULL)) == NULL) {
        fprintf(stderr, "Cannot open local X-display.\n");
        exit(1);
    }

    root = DefaultRootWindow(display);

    clickpos = getposition(display, root);

    printf("Position: x=%i, y=%i\n", clickpos.x, clickpos.y);

    for(i=0 ; limit==0 || i<limit; ++i) {
        current = getposition(display, root);
        moveto(clickpos, display, root);
        click(display, root);
        moveto(current, display, root);
        usleep(sleep_dur);
    }

    return 0;
}
Ejemplo n.º 8
0
	void mesodrop::draw(vector2d viewpos)
	{
		if (state != DST_INACTIVE)
		{
			graphicobject::draw(anim, getposition() + viewpos - vector2d(16, 0), false);
		}
	}
Ejemplo n.º 9
0
static void
task_view_pert_chart_on_load	(PlannerShowView *view)
{

	GtkWidget    *layout;
	MrpTask    *root;
	GList *task_list;
	GList *l;
	MrpTaskManager *task_manager;
	//PlannerShowView     *view;
	PlannerShowViewPriv *priv;
	MrpProject *project;
	pertnodes = NULL;

	priv = view->priv;
	layout = priv->pertlayout;
	project = planner_window_get_project(PLANNER_VIEW(view)->main_window);
	task_manager = imrp_project_get_task_manager(project);
	root = mrp_task_manager_get_root (task_manager);
	task_list = mrp_task_manager_get_all_tasks(task_manager);

//	g_print("______________________22222222222222222222_______________________");
	l = planner_pertchart_nodes_creat(task_list);
	task_manager_build_dependency_graph_for_node (task_manager);
	l = setPertNodesPosition();
	avoidCrossingNode();
	avoidCrossingLine();
	removeEmptyColumn();
	getposition(l);
	getArrowPosition(pertnodes);

	drawtask(layout,project);


}
Ejemplo n.º 10
0
void itemdrop::draw(vector2d viewpos)
{
    if (state != DST_INACTIVE)
    {
        ico.draw(viewpos + getposition() - vector2d(16, 0), dalpha);
    }
}
Ejemplo n.º 11
0
void ParticleSet3D::Update(const StableFluid3D& g0, const StableFluid3D& g1, const StableFluid3D& g2, double timestep)
{
	for (int i = 0; i < gridLength; i++)
	{
		int xi, yi, zi;
		getposition(i, xi, yi, zi);
		for (Iterator it = grid1[i].begin(); it != grid1[i].end();)
		{
			Particle3D* p = *it;
			grid1[i].erase(it++);

			double x, y, z;
			p->GetPosition(x, y, z);

			//get from velocity grid
			double ux0, uy0, uz0, ux1, uy1, uz1, ux2, uy2, uz2;
			g0.getvalue(x, y, z, ux0, uy0, uz0);
			g1.getvalue(x, y, z, ux1, uy1, uz1);
			g2.getvalue(x, y, z, ux2, uy2, uz2);
			p->Update(ux0, uy0, uz0, ux1, uy1, uz1, ux2, uy2, uz2, timestep);
			p->GetPosition(x, y, z);

			if (x < 0 || x >= sizeX || y < 0 || y >= sizeY || z < 0 || z >= sizeZ)
				continue;
			grid2[getindex(int(x), int(y), int(z))].push_back(p);
		}
	}
	std::swap(grid1, grid2);
}
Ejemplo n.º 12
0
void HW3b::wave()
{
    getforce();
    getvelocity();
    getposition();
    initVertexBuffer();
    updateGL();
}
Ejemplo n.º 13
0
Archivo: eeprom.c Proyecto: mcu786/24aa
/**
 * @brief     Write data to EEPROM.
 * @details   Only one EEPROM page can be written at once. So fucntion
 *            splits large data chunks in small EEPROM transactions if needed.
 * @note      To achieve the maximum effectivity use write operations
 *            aligned to EEPROM page boundaries.
 */
static size_t write(void *ip, const uint8_t *bp, size_t n) {
    msg_t status = RDY_OK;

    size_t   len = 0;     /* bytes to be written at one trasaction */
    uint32_t written = 0; /* total bytes successfully written */
    uint32_t firstpage = getposition(ip) / EEPROM_PAGE_SIZE;
    uint32_t lastpage  = (getposition(ip) + n - 1) / EEPROM_PAGE_SIZE;

    chDbgCheck((ip != NULL) && (((EepromFileStream*)ip)->vmt != NULL), "");

    if (n == 0)
        return 0;

    n = __clamp_size(ip, n);
    if (n == 0)
        return 0;

    /* data fitted in single page */
    if (firstpage == lastpage) {
        len = n;
        __fitted_write();
        return written;
    }

    else {
        /* write first piece of data to first page boundary */
        len = ((firstpage + 1) * EEPROM_PAGE_SIZE) - getposition(ip);
        __fitted_write();

        /* now writes blocks at a size of pages (may be no one) */
        while ((n - written) > EEPROM_PAGE_SIZE) {
            len = EEPROM_PAGE_SIZE;
            __fitted_write();
        }

        /* wrtie tail */
        len = n - written;
        if (len == 0)
            return written;
        else {
            __fitted_write();
        }
    }
    return written;
}
Ejemplo n.º 14
0
	bool Mob::isinrange(const Rectangle<int16_t>& range) const
	{
		if (!active)
			return false;

		Rectangle<int16_t> bounds = animations.at(stance).getbounds();
		bounds.shift(getposition());
		return range.overlaps(bounds);
	}
Ejemplo n.º 15
0
	void Mob::updatemovement()
	{
		MoveMobPacket(
			oid, 
			1, 0, 0, 0, 0, 0, 0, 
			getposition(),
			Movement(phobj, valueof(stance, flip))
			).dispatch();
	}
Ejemplo n.º 16
0
void wave(void)
{
    if (waving)
    {
        getforce();
        getvelocity();
        getposition();
        glutPostRedisplay();
    }
}
Ejemplo n.º 17
0
/////////////////////////////////////////////////////////
// bang
//
/////////////////////////////////////////////////////////
void newWave :: bangMess(void)
{

		savepos();

		getvelocity();
		getposition();

		getFaceNorms();
        getVertNorms();

        getforce();
		getdamp();

}
Ejemplo n.º 18
0
	std::vector<DamageNumber> Mob::placenumbers(std::vector<std::pair<int32_t, bool>> damagelines) const
	{
		std::vector<DamageNumber> numbers;
		int16_t head = getheadpos(getposition()).y();
		for (size_t i = 0; i < damagelines.size(); i++)
		{
			int32_t amount = damagelines[i].first;
			bool critical = damagelines[i].second;
			auto type = critical ? DamageNumber::CRITICAL : DamageNumber::NORMAL;
			auto number = DamageNumber(type, amount, head);
			numbers.push_back(number);

			head -= DamageNumber::rowheight(critical);
		}
		return numbers;
	}
Ejemplo n.º 19
0
Archivo: eeprom.c Proyecto: mcu786/24aa
/**
 * Read some bytes from current position in file. After successful
 * read operation the position pointer will be increased by the number
 * of read bytes.
 */
static size_t read(void *ip, uint8_t *bp, size_t n) {
    msg_t status = RDY_OK;

    chDbgCheck((ip != NULL) && (((EepromFileStream*)ip)->vmt != NULL), "");

    if (n == 0)
        return 0;

    n = __clamp_size(ip, n);
    if (n == 0)
        return 0;

    /* Stupid STM32 I2C cell does not allow to read less than 2 bytes.
       So we must read 2 bytes and return needed one. */
#if (defined(STM32F4XX) || defined(STM32F2XX) || defined(STM32F1XX) || \
                                                 defined(STM32L1XX))
    if (n == 1) {
        uint8_t __buf[2];
        /* if NOT last byte of file requested */
        if ((getposition(ip) + 1) < getsize(ip)) {
            if (read(ip, __buf, 2) == 2) {
                lseek(ip, (getposition(ip) + 1));
                bp[0] = __buf[0];
                return 1;
            }
            else
                return 0;
        }
        else {
            lseek(ip, (getposition(ip) - 1));
            if (read(ip, __buf, 2) == 2) {
                lseek(ip, (getposition(ip) + 2));
                bp[0] = __buf[1];
                return 1;
            }
            else
                return 0;
        }
    }
#endif

    /* call low level function */
    status  = eeprom_read(getposition(ip), bp, n);
    if (status != RDY_OK)
        return 0;
    else {
        lseek(ip, (getposition(ip) + n));
        return n;
    }
}
Ejemplo n.º 20
0
/***
 *** The timeout function. Often in animations,
 *** timeout functions are suitable for continous
 *** frame updates.
 ***/
static gboolean
timeout (GtkWidget *widget)
{
  GtkAllocation allocation;
  GdkWindow *window;
  getforce ();
  getvelocity ();
  getposition ();

  window = gtk_widget_get_window (widget);
  gtk_widget_get_allocation (widget, &allocation);

  /* Invalidate the whole window. */
  gdk_window_invalidate_rect (window, &allocation, FALSE);

  /* Update synchronously (fast). */
  gdk_window_process_updates (window, FALSE);

  return TRUE;
}
Ejemplo n.º 21
0
void ParticleSet3D::Reseed(const LevelSet3D& levelSet)
{
	for (int i = 0; i<gridLength; i++)
	{
		for (std::list<Particle3D*>::iterator it = grid1[i].begin(); it != grid1[i].end(); it++)
		{
			delete *it;
		}
		grid1[i].clear();
		int x, y, z;
		getposition(i, x, y, z);

		bool reseed = false;
		for (int dx = 0; dx<2; dx++)
		{
			for (int dy = 0; dy<2; dy++)
			{
				for (int dz = 0; dz<2; dz++)
				{
					if (std::fabs(levelSet.LinearSample(x + dx, y + dy, z + dz)) < RESEED_THRESHOLD)
					{
						reseed = true;
					}
				}
			}
		}
		if (reseed)
		{
			for (int j = 0; j < PARTICLES_PER_NODE; j++)
			{
				double dx = rand() / double(RAND_MAX);
				double dy = rand() / double(RAND_MAX);
				double dz = rand() / double(RAND_MAX);
				double phi = levelSet.LinearSample(x + dx, y + dy, z + dz);

				grid2[i].push_back(new Particle3D(x + dx, y + dy, z + dz, phi));
			}
		}
	}
	std::swap(grid1, grid2);
}
Ejemplo n.º 22
0
void ParticleSet3D::UpdateWorker(WorkerData data)
{
	for (int i = data.iBegin; i < data.iEnd; i++)
	{
		int xi, yi, zi;
		getposition(i, xi, yi, zi);
		for (Iterator it = grid1[i].begin(); it != grid1[i].end(); it++)
		{
			Particle3D* p = *it;

			double x, y, z;
			p->GetPosition(x, y, z);

			//get from velocity grid
			double ux0, uy0, uz0, ux1, uy1, uz1, ux2, uy2, uz2;
			(*data.g0).getvalue(x, y, z, ux0, uy0, uz0);
			(*data.g1).getvalue(x, y, z, ux1, uy1, uz1);
			(*data.g2).getvalue(x, y, z, ux2, uy2, uz2);
			p->Update(ux0, uy0, uz0, ux1, uy1, uz1, ux2, uy2, uz2, data.timestep);
		}
	}
}
Ejemplo n.º 23
0
/**
 * Prints the character to the console and moves cursor. Also accepts control characters!
 * TODO comment
 *
 * @param c character to print
 * @return the character printed
 */
int putchar(int c)
{
	int position=getposition();

	unsigned char ch=(unsigned char)c;

	if(position>=BUFFER_TEXT_WIDTH*BUFFER_TEXT_HEIGHT)
	{
		position=BUFFER_TEXT_WIDTH*(BUFFER_TEXT_HEIGHT-1);
		setposition(position);
		movelinesup();
	}

	switch(ch)
	{
		case '\n':
			position+=BUFFER_TEXT_WIDTH-position%BUFFER_TEXT_WIDTH;
			break;
		case '\t':
			position+=5-position%5;
			break;
		case '\r':
			position-=position%BUFFER_TEXT_WIDTH;
			break;
		case '\b':
			position--;
			break;
		default:
			*(BUFFER_TEXT+position*2)=ch;
			*(BUFFER_TEXT+position*2+1)=getcolor();
			position++;
			break;
	}
	setposition(position);
	return c;
}
Ejemplo n.º 24
0
	void Player::draw(vector2d<int32_t> viewpos) const
	{
		vector2d<int32_t> absp = getposition() + viewpos;
		look.draw(absp);
		name.gettext().draw(absp);
	}
Ejemplo n.º 25
0
	rectangle2d<int32_t> Player::bounds() const
	{
		return rectangle2d<int32_t>(getposition() - vector2d<int32_t>(30, 70), getposition() + vector2d<int32_t>(30, 10));
	}
Ejemplo n.º 26
0
/*Function to delete file and restore it with original contents.
Input:char* path
Output:int
*/
int
restorefile(char* path)
{
        
        int status              =       0;
        int ret                 =      -1;
        char temp_name[NAME_SIZE]    =               "";
        int l                   =       0;
        char *ssc               =       NULL;
        int size                =       0;
        int size1               =       0;
        int     pos             =       0;
        char* buffer            =       NULL;
        char* buffer2           =       NULL;
        char* ptr               =       NULL;
        int length              =       0;
        int sd1	                =       -1;
        int    fd_block         =       -1;
        struct stat             st;
        int bset                =       0;
        int eset                =       0;
        int fd2	                =       -1;
        char actualpath [PATH_MAX+1];
        char* ts1               =       NULL;
        char* ts2               =       NULL;
        char* dir               =       NULL;
        char* filename1         =       NULL;
        
        ts1 = strdup(path);
        ts2 = strdup(path);
        dir = dirname(ts1);
        filename1 = basename(ts2);
        sprintf(dir,"%s/",dir);
        sprintf(temp_name,"%sDedup_%s",dir,filename1);
        printf("%s\n",dir);
        printf("\npath%s",path);
        printf("%s\n",filename1);
        printf("\n%s\n",temp_name);
        sd1 = open(temp_name,O_RDONLY);
        if (sd1< 1)
        {
                fprintf(stderr,"%s\n",strerror(errno));
                goto out;
        }
        else
        {
                printf("\nStub file opened\n");
        }

        fstat(sd1, &st);
        size = st.st_size;
        fd2 = open(path,O_CREAT|O_RDWR);
        if (fd2< 1)
        {
                fprintf(stderr,"%s\n",strerror(errno));
                goto out;
        }
        else
        {
                printf("\nRestore file created\n");
        }
        if (size> 0)
        {
                if (-1 == lseek(sd1,0,SEEK_SET))
                {
                        fprintf(stderr,"%s\n",strerror(errno));
                        goto out;
                }
        }
        if(size==0)
        {
                printf("\nNo contents\n");
                ret=-1;
                goto out;
        }
        while(size>0)
        {
                ret=read(sd1,&length,int_size);
                if (ret== -1)
                {
                        fprintf(stderr,"%s\n",strerror(errno));
                        goto out;
                }
                buffer=(char*)calloc(1,length+1);
                ret=read(sd1,buffer,length);
                if (ret== -1)
                {
                        fprintf(stderr,"%s\n",strerror(errno));
                        goto out;
                }
                ret=read(sd1,&bset,int_size);
                if (ret== -1)
                {
                        fprintf(stderr,"%s\n",strerror(errno));
                        goto out;
                }
                ret=read(sd1,&eset,int_size);
                if (ret== -1)
                {
                        fprintf(stderr,"%s\n",strerror(errno));
                        goto out;
                }
                buffer[length]='\0';
                pos=getposition(buffer);
                if (pos== -1)
                        goto out;
                printf("\nPosition is %d\n",pos);
                buffer2=get_block(pos);
                if (strcmp(buffer2,"")== 0)
                {
                        goto out;
                }
                printf("block  is %s\n",buffer2);
                ret= write(fd2,buffer2,strlen(buffer2));
                if (ret< 0)
                {
                        fprintf(stderr,"%s\n",strerror(errno));
                        goto out;
                }
                size1-=(length+int_size+int_size+int_size);
                clean_buff(&buffer);
                clean_buff(&buffer2);
        }
        ret=0;
out:
return ret;

}
Ejemplo n.º 27
0
	rectangle2d<int16_t> Drop::bounds() const
	{ 
		auto lt = getposition();
		auto rb = lt + Point<int16_t>(32, 32);
		return rectangle2d<int16_t>(lt, rb); 
	}
Ejemplo n.º 28
0
	Point<int16_t> Mob::getheadpos() const
	{
		Point<int16_t> position = getposition();
		return getheadpos(position);
	}