示例#1
0
/* attr[0] is non-hilite attr, attr[1] is highlight attr */
void printmenuitem(const char *str,char* attr)
{
    char page = getdisppage();
    char row,col;
    int hlite=NOHLITE; // Initially no highlighting

    getpos(&row,&col,page);
    while ( *str ) {
      switch (*str) 
	{
	case '\b':
	  --col;
	  break;
	case '\n':
	  ++row;
	  break;
	case '\r':
	  col=0;
	  break;
	case BELL: // No Bell Char
	  break;
	case ENABLEHLITE: // Switch on highlighting
	  hlite = HLITE;
	  break;
	case DISABLEHLITE: // Turn off highlighting
	  hlite = NOHLITE;
	  break;
	default:
	  putch(*str, attr[hlite], page);
	  ++col;
	}
      if (col > getnumcols())
	{
	  ++row;
	  col=0;
	}
      if (row > getnumrows())
	{
	  scrollup();
	  row= getnumrows();
	}
      gotoxy(row,col,page);
      str++;
    }
}
示例#2
0
bool assemblegffexolocstr(XMLFile &xml, GFFFile &gff, uint32 n)
{
	int pr, lang=0;
	std::string lbl;
	ExoLocString exo;
	uint64 tmp;

	while((pr = xml.parse()) >= 0)
	{
		switch(pr)
		{
			case 0:
				if(rsubstr(xml.section, 6) == ".label") lbl = xml.value;
				if(rsubstr(xml.section, 7) == ".strref")
				{
					sscanf(xml.value.c_str(), S_UINT64, &tmp);
					exo.stringref = (uint32) tmp;
				}
				if(rsubstr(xml.section, 16) == ".substr.language")
				{
					if((lang = getpos(langs, LANGS, xml.value)) == -1)
						return printxmlerr(xml, "Invalid language");
				}
				if(rsubstr(xml.section, 7) == ".substr")
					exo.str[lang] = unquotestr(xml.value);
				break;
			case 1:
				if(rsubstr(xml.section, 7) != ".substr")
					return printxmlerr(xml, "Invalid tag");
				break;
			case 2:
				if(rsubstr(xml.value, 10) == ".exolocstr")
				{
					if(gff.writeExoLocString(n, lbl, exo))
						return printxmlerr(xml, gff.getStrError());
					return true;
				}
				break;
		}
	}
	if(pr != -6) return printxmlerr(xml, xml.getStrError());
	printxmlerr(xml, "Unexpected end of file");
	return false;
}
示例#3
0
void tele(void)
{
	coord cc;

	/* Disable teleportation in stronghold && Vlad's Tower */
	if (level->flags.noteleport) {
		if (!wizard) {
		    pline("A mysterious force prevents you from teleporting!");
		    return;
		}
	}

	/* don't show trap if "Sorry..." */
	if (!Blinded) make_blinded(0L,FALSE);

	if ((u.uhave.amulet || On_W_tower_level(&u.uz)) && !rn2(3)) {
	    pline("You feel disoriented for a moment.");
	    return;
	}
	if ((Teleport_control && !Stunned) || wizard) {
	    if (unconscious()) {
		pline("Being unconscious, you cannot control your teleport.");
	    } else {
		    char buf[BUFSZ];
		    if (u.usteed)
			    sprintf(buf," and %s", mon_nam(u.usteed));
		    pline("To what position do you%s want to be teleported?",
				u.usteed ? buf : "");
		    cc.x = u.ux;
		    cc.y = u.uy;
		    if (getpos(&cc, TRUE, "the desired position") < 0)
			return;	/* abort */
		    /* possible extensions: introduce a small error if
		       magic power is low; allow transfer to solid rock */
		    if (teleok(cc.x, cc.y, FALSE)) {
			teleds(cc.x, cc.y, FALSE);
			return;
		    }
		    pline("Sorry...");
		}
	}

	safe_teleds(FALSE);
}
示例#4
0
bool VFSFileReal::open(const char *mode /* = NULL */)
{
    VFS_GUARD_OPT(this);

    if(isopen())
        close();

    dropBuf(true);

    _fh = real_fopen(fullname(), mode ? mode : "rb");
    if(!_fh)
        return false;

    real_fseek((FILE*)_fh, 0, SEEK_END);
    _size = getpos();
    real_fseek((FILE*)_fh, 0, SEEK_SET);

    return true;
}
示例#5
0
bool assembleerfdesc(XMLFile &xml, ERFFile &erf)
{
	int pr, lang=0;
	ExoLocString exo;
	uint64 tmp;

	while((pr = xml.parse()) >= 0)
	{
		switch(pr)
		{
			case 0:
				if(rsubstr(xml.section, 7) == ".strref")
				{
					sscanf(xml.value.c_str(), S_UINT64, &tmp);
					exo.stringref = (uint32) tmp;
				}
				if(rsubstr(xml.section, 16) == ".substr.language")
				{
					if((lang = getpos(langs, LANGS, xml.value)) == -1)
						return printxmlerr(xml, "Invalid language");
				}
				if(rsubstr(xml.section, 7) == ".substr")
					exo.str[lang] = unquotestr(xml.value);
				break;
			case 1:
				if(rsubstr(xml.section, 7) != ".substr")
					return printxmlerr(xml, "Invalid tag");
				break;
			case 2:
				if(rsubstr(xml.value, 12) == ".description")
				{
					erf.desc = exo;
					return true;
				}
				break;
		}
	}
	if(pr != -6) return printxmlerr(xml, xml.getStrError());
	printxmlerr(xml, "Unexpected end of file");
	return false;
}
示例#6
0
文件: robot.c 项目: jemeador/code
void run(int r, int c, int cc)
{
  char ** arena = malloc(sizeof(char *)*(r+2));
  char cmds[cc];
  int j, i, *pos, stickers;
  for (j=1;j<r+1;j++)
  {
    arena[j] = malloc(sizeof(char)*(c+3));
    arena[j][0] = '#';
    scanf("%s",arena[j]+1);
    arena[j][c+1] = '#';
  }
  arena[0] = malloc(sizeof(char)*(c+2)); 
  arena[r+1] = malloc(sizeof(char)*(c+2));
  for (j=0;j<c+2;j++)
  {
    arena[0][j] = '#'; 
    arena[r+1][j] = '#';
  }
  for (j=0;j<r+2;j++)
  {
    for (i=0;i<c+2;i++)
      printd("%c",arena[j][i]);
    printd("\n");
  }
  scanf(" %s", cmds);
  pos = getpos(r+2,c+2,arena);
  if (!pos)
  {
    printd("No robot?! :(");
    return;
  }
  printd("%d %d %d\n", pos[0], pos[1], pos[2]);  
  stickers = 0;
  for (j=0;j<cc;j++)
  {
    stickers += move(cmds[j], pos, arena);
    printd("%d %d %d\n", pos[0], pos[1], pos[2]);  
  }
  printf("%d\n", stickers);
}
示例#7
0
文件: cursor.c 项目: rmbking/seditor
void CursorUp(int line)
{
	int rows;
	if(file.cur_line > 1)
	{
		if(file.cur_line > file.start_line)
		{
			if(file.line[file.cur_line - 1].line_row < screen.row_offset)
			{
				rows = screen.row_rank[screen.cur_row ];
				screen.cur_col = screen.win_width;
			}
			else
			{
				rows = screen.row_rank[screen.cur_row] + file.line[file.cur_line-1].line_row - screen.row_offset;
				screen.cur_col = screen.col_offset;
			}
			while(rows--)

				screen.cur_row--;
		}	//not preread the former line,may cause bug.
		else
		{
			file.start_line--;
			display(file.start_line);
			if(file.line[file.start_line].line_row < screen.row_offset)
			{
				screen.cur_row = file.line[file.start_line].line_row;
				screen.cur_col = screen.win_width;
			}	
			else
			{
				screen.cur_row = screen.row_offset;
				screen.cur_col = screen.col_offset;	
			}
		}
		CursorMove();
		getpos();
		CheckCursor();
	}
}
示例#8
0
int iostream::getsize( void )
{
	int pos;
	int siz;
	
	if ( mode == 0 ) {
		if ( srct == 0 ) {
			pos = ftell( fptr );
			fseek( fptr, 0, SEEK_END );
			siz = ftell( fptr );
			fseek( fptr, pos, SEEK_SET );
		}
		else {
			siz = mrdr->getsize();
		}
	}
	else {
		siz = getpos();
	}

	return siz;
}
示例#9
0
const void *VFSFile::getBuf(allocator_func alloc /* = NULL */, delete_func del /* = NULL */)
{
    assert(!alloc == !del); // either both or none may be defined. Checked extra early to prevent possible errors later.

    VFS_GUARD_OPT(this);
    if(_buf)
        return _buf;

    bool op = isopen();

    if(!op && !open()) // open with default params if not open
        return NULL;

    unsigned int s = (unsigned int)size();
    _buf = allocHelper(alloc, s + 4); // a bit extra padding
    if(!_buf)
        return NULL;

    _delfunc = del;

    vfspos offs;
    if(op)
    {
        vfspos oldpos = getpos();
        seek(0);
        offs = read(_buf, s);
        seek(oldpos);
    }
    else
    {
        offs = read(_buf, s);
        close();
    }
    // Might as well be text mode reading, which means less actual bytes than size() said,
    // so this can't be done earlier.
    memset((char*)_buf + offs, 0, 4);

    return _buf;
}
示例#10
0
文件: cursor.c 项目: rmbking/seditor
void CursorDown(int line)
{
	int rows;
	int lines;
	if(file.cur_line < file.total_line)
	{
		if(screen.row_offset > file.line[file.cur_line+1].line_row)
		{
			screen.cur_col = screen.win_width;
			lines = file.line[file.cur_line].line_row - screen.row_rank[screen.cur_row] + file.line[file.cur_line + 1].line_row;
		}
		else
		{
			screen.cur_col = screen.col_offset;
			lines = file.line[file.cur_line].line_row - screen.row_rank[screen.cur_row] + screen.row_offset;
		}
		while(lines--)
		{
			if(screen.cur_row < screen.win_height - 1)
			{
				screen.cur_row++;
			}
			else
			{
				if(file.start_line  <= file.total_line)
				{
					rows = file.line[file.start_line].line_row;	//start_line.row > 1 ,so move back the cursor
					file.start_line++;
					display(file.start_line);
					screen.cur_row = screen.win_height-rows;
				}
			}
		}
		CursorMove();
		getpos();
		CheckCursor();
	 }
}
示例#11
0
/*
 * Window size.
 */
void
c_size(struct ww *w)
{
	int col, row;

	if (!terse)
		wwputs("New window size (lower right corner): ", cmdwin);
	col = MIN(w->ww_w.r, wwncol) - 1;
	row = MIN(w->ww_w.b, wwnrow) - 1;
	wwadd(boxwin, framewin->ww_back);
	for (;;) {
		wwbox(boxwin, w->ww_w.t - 1, w->ww_w.l - 1,
			row - w->ww_w.t + 3, col - w->ww_w.l + 3);
		wwsetcursor(row, col);
		while (wwpeekc() < 0)
			wwiomux();
		switch (getpos(&row, &col, w->ww_w.t, w->ww_w.l,
			wwnrow - 1, wwncol - 1)) {
		case 3:
			wwunbox(boxwin);
			wwdelete(boxwin);
			return;
		case 2:
			wwunbox(boxwin);
			break;
		case 1:
			wwunbox(boxwin);
		case 0:
			continue;
		}
		break;
	}
	wwdelete(boxwin);
	if (!terse)
		wwputc('\n', cmdwin);
	wwcurtowin(cmdwin);
	sizewin(w, row - w->ww_w.t + 1, col - w->ww_w.l + 1);
}
示例#12
0
// Mark a buffer as used extracting it from the free list
void setused(buffer *buff) {
    int used = getpos(buff);

    if (used != -1) {
        if (buff->freeprev != -1)
            bc->buffers[buff->freeprev].freenext = buff->freenext;

        if (buff->freenext != -1)
            bc->buffers[buff->freenext].freeprev = buff->freeprev;

        if (bc->header.freestart == used) {
            bc->header.freestart = buff->freenext;
            bc->buffers[buff->freenext].freeprev = -1;
        }

        if (bc->header.freeend == used) {
            bc->header.freeend = buff->freeprev;
            bc->buffers[buff->freeprev].freenext = -1;
        }

        buff->freeprev = buff->freenext = -1;
    }
}
示例#13
0
vector<double> GTPWrapper::getSensoryInput(bool first)
{
  //int * fpos = getpos(first);
  //cout << "fpos: " << fpos[0] << " , " << fpos[1] << endl;
  //get all the data..
  boost::dynamic_bitset<> * oslook = sqlook(first);
  vector<double> lrange = getLongrange(first);

  int * pos = getpos(first);
  int l = islegal(first);//(board.at(((bsize-(pos[0]+1))*bsize)+pos[1]) == 0 ) ? true : false;// islegal(first); TODO make this back ... or not?
  //cout << "pos: " << pos[0] << " , " << pos[1] << endl;
  //now convert the look to black and white bools..
  vector<double> slook;
  //int c2=0;
  vector<double> ret;
  for(unsigned int i=0;i<(*oslook).size();i++)
    ret.push_back((*oslook)[i]);
  delete oslook;
//   int c=0;
//   for(unsigned int i=0;i<slook.size();i++)
//     if(slook.at(i)!=0.0)
//       c++;
//   if(c!=0)
//     cout << c << " not null points in slook vector" << endl;
  //concat the vectors...that is for a later time
  //cause now my battery is running empty and I
  //am on a bus heading home for crhistmas! :D
  //...and also, dunno this syntax, need web :p
  //vector<double> ret(slook.begin(),slook.end());
  //  ret.insert(ret.end(),lrange.begin(),lrange.end());
  for(unsigned int i=0;i<lrange.size();i++)
    ret.push_back(ret.at(i));
  ret.push_back((double)pos[0]/(double)bsize);
  ret.push_back((double)pos[1]/(double)bsize);
  ret.push_back(l);
  return ret;
}
示例#14
0
文件: pousse.c 项目: dbkang/icfp1998
void
printboard(struct config *bp)
{
	int i, j, c;

	fprintf(stderr, "                  +");
	for (i = 0; i < bsize; i++)
		fprintf(stderr, "-");
	fprintf(stderr, "+\n");
	for (i = 0; i < bsize; i++) {
		fprintf(stderr, "%2d: %4d:%d/%4d:%d |", i+1, 
			ROW(bp,i).xscore, ROW(bp,i).xfull, 
			ROW(bp,i).oscore, ROW(bp,i).ofull);
		for (j = 0; j < bsize; j++) {
			c = getpos(bp->board, i*bsize+j);
			fprintf(stderr, "%c", TOCHAR(c));
		}
		fprintf(stderr, "|\n");
	}
	fprintf(stderr, "                  +");
	for (i = 0; i < bsize; i++)
		fprintf(stderr, "-");
	fprintf(stderr, "+\n");
	fprintf(stderr, "                   ");
	for (i = 0; i < bsize; i++)
		fprintf(stderr, "%d", (i+1)%10);
	fprintf(stderr, "\n\n");
	for (i = 0; i < bsize; i++) {
		fprintf(stderr, "%2d: %4d:%d/%4d:%d\n", i+1, 
			COL(bp, i).xscore, COL(bp, i).xfull, 
			COL(bp,i).oscore, COL(bp, i).ofull);
	}
	fprintf(stderr, "score x=%d:%d o=%d:%d\n",
		bp->xscore, bp->xfull,
		bp->oscore, bp->ofull);
}
示例#15
0
World::World():
    tickCount(milliseconds(TICKMS)), curGeneration(0),
    paused(true), started(false), lastTick(std::chrono::duration_cast<milliseconds>(
        std::chrono::system_clock::now().time_since_epoch()))
{
    srand((int)time(0));

    for (auto it = grass.begin(); it != grass.end(); ++it)
        *it = new Grass(it.getpos());

    for (auto it = creatures.begin(); it != creatures.end(); ++it)
        *it = nullptr;

    // add ids to Animal::ids
    Animal::InitIds();

    SpawnCreatures<Rabbit>(RABBIT_COUNT);
    SpawnCreatures<Wolf>(WOLF_COUNT);
    SpawnCreatures<Weasel>(WEASEL_COUNT);
    SpawnCreatures<Dino>(DINO_COUNT);

    // serialize initial state
    AddGeneration();
}
示例#16
0
//------------------------------------------------------------------------------
void istream::getStr(char *str) {
  FatPos_t pos;
  uint16_t i = 0;
  uint16_t m = width() ? width() - 1 : 0XFFFE;
  if (m != 0) {
    getpos(&pos);
    int c = readSkip();

    while (i < m) {
      if (c < 0) {
        break;
      }
      if (isspace(c)) {
        setpos(&pos);
        break;
      }
      str[i++] = c;
      c = getch(&pos);
    }
  }
  str[i] = '\0';
  if (i == 0) setstate(failbit);
  width(0);
}
示例#17
0
// Решение задачи - динамическое
void Solve(void)
{ int dx, dy, x, y, fl, xi, yi;
  LongNum min, max;
  for(dx=0; dx<N; dx++)
    for(dy=0; dy<M; dy++)
      if(dx||dy)
	for(x=0; x<N-dx; x++)
	  for(y=0; y<M-dy; y++)
	    { fl=0;
	      for(xi=0; xi<dx; xi++, fl=1)
		 check(min, max, fl, getpos(x,y,xi,dy),
				     getpos(x+xi+1,y,dx-xi-1,dy));
	      for(yi=0; yi<dy; yi++, fl=1)
		 check(min, max, fl, getpos(x,y,dx,yi),
				     getpos(x,y+yi+1,dx,dy-yi-1));
	      din[0][getpos(x,y,dx,dy)]=min;
	      din[1][getpos(x,y,dx,dy)]=max;
	    }
}
示例#18
0
文件: last.c 项目: 10crimes/code
void main() {
  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  mypalette(255,0,0,0);
  mypalette(0,0,0,0);
  mypalette(255,1,1,1);
  mypalette(128,0,0,0);
  randomise();
  for (int i=0;i<=15;i++) {
    waves+Wave();
    // waves.num(i).display();
  }
  for (int r=0;r<16;r++) {
    for (int g=0;g<16;g++) {
      int palc=r+g*16;
      mypalette(palc,(r==0?0:brightness+0.2+change*0.5*r/15.0),(g==0?0:brightness+change*0.1+0.2*g/15.0),(g==0?0:brightness+change*0.2+0.6*g/15.0));
      // Groovy colours mypalette(palc,(r==0?0:0.1+0.6*r/15.0),(g==0?0:0.1+0.2*g/15.0),(g==0?0:0.1+0.7*g/15.0));
      // Good colours: mypalette(palc,(r==0?0:0.3+0.4*r/15.0),(g==0?0:0.1+0.2*g/15.0),(g==0?0:0.3+0.5*g/15.0));
    }
  }
  V3d vel=V3d(0,0,0);
  V3d acc=V3d(0,0,0);
  Ori ori;
  float droll=0;
  float dyaw=0;
  float dpitch=0;
  int frame=0;
  List<V3d> particles=List<V3d>(gridsize*gridsize*gridsize);
  /* for (int i=1;i<gridsize*gridsize*gridsize;i++) {
       particles+gridsize*V3d(floatrnd(-1,1),floatrnd(-1,1),floatrnd(-1,1));
     }*/
  int ps=1;
  float rad=0;
  for (float thru=0;thru<1.0;thru+=0.0016) {
    V3d here=getpos(thru);
    V3d forward=getpos(thru+0.00001)-here;
    V3d up=V3d::normcross(V3d::crazy,forward);
    V3d right=V3d::normcross(forward,up);
    for (int i=0;i<ps;i++) {
      float t=2*pi*(float)i/(float)ps;
      float s=sin(t);
      float c=cos(t);
      particles+(here+rad*(s*up+c*right));
    }
    // v.print();
  }
  starttimer();
  float thru=0;
  float marker=0;
  V3d pos=getpos(marker);
  V3d *tail=new V3d[taillen];
  int tailpos=0;
  do {
    thru+=0.001;
    // V3d last=V3d(pos.x,pos.y,pos.z);
    // V3d pos=getpos(thru);
    // V3d next=getpos(thru+0.00001);
    // V3d newz=next-pos;
    // ori.forcez(newz);
    frame++;
    // float pd=1.6+1.3*sin(2*pi*frame/1000.0);
    float pd=2.0;
    PPsetup(scrwid,scrhei,pd);
    left.clear(0);
    right.clear(0);
    // b.fadeby(16);
    int ioff=-mydiv(pos.x,gjump);
    int joff=-mydiv(pos.y,gjump);
    int koff=-mydiv(pos.z,gjump);
    ori.quickorisetup();
    // Need to find largest axis, and do loops with that one outside
    int ks=mysgn(ori.qz.z);
    int js=-mysgn(ori.qz.y);
    int is=-mysgn(ori.qz.x);
    for (int i=1;i<=particles.len;i++) {
      int x,y;
      V3d p=particles.num(i);
      V3d cen=p-pos+0.0*ori.y;
      cen=V3d::disorientate(cen,ori);
      int c=15.0-chop(14.0*(cen.z+gridsize)/(float)(gridsize*2),0,14);
      // int c=7.0-chop(6.0*(i/particles.len),0,6);
      plotsphere(cen,c);
    }
    
    // Plot and move marker
    V3d m;
    for (int i=1;i<=15;i++) {
      m=V3d::disorientate(getpos(marker)-pos,ori);
      if (m.mod()<markerrange)
        marker+=0.0002;
    }
    
    float u=PPgetunitnoadd(m);
    bool plot=false;
    if (u) {
      int x,y;
      float rad=0.08*u;
      PPgetscrposnoadd(m,PPlefteye,&x,&y);
      if (left.inimage(x,y)) {
        plot=true;
        left.opencircle(x,y,rad,15);
      }
      PPgetscrposnoadd(m,PPrighteye,&x,&y);
      if (right.inimage(x,y)) {
        plot=true;
        right.opencircle(x,y,rad,15*16);
      }
    }
    if (!plot) {
      V2d v=scrwid*2*V2d(m.x,m.y).norm();
      if (abs(v.x)>scrwid/2) {
        float change=(float)scrwid/2.0/abs(v.x);
        v=change*v;
      }
      if (abs(v.y)>scrhei/2) {
        float change=(float)scrhei/2.0/abs(v.y);
        v=change*v;
      }
      v=v+V2d(scrwid/2,scrhei/2);
      left.opencircle(v,5,15);
      right.opencircle(v,5,15*16);
    }
    
    // Pull player towards marker
    // if (m.mod()>markerrange+.1) {
      V3d pulldir=getpos(marker)-pos;
      // vel=vel+pulldir*0.02;
      // float amount=(V3d::normdot(ori.z(),pulldir)+5.0)/6.0;
      float amount=chop(0.99-(m.mod()-markerrange)/5.0,0,1);
      V3d newz=ori.z()*amount+(1.0-amount)*pulldir;
      ori.forcez(newz);
      // vel=vel*amount;
      // 
    //}

    // Draw and update tail
    V3d last=(tail[tailpos]-pos).disorientate(ori);
    for (int k=1;k<taillen;k++) {
      int j=mymod(tailpos+k,taillen);
      V3d next=(tail[j]-pos).disorientate(ori);
      plotline(last,next,(float)k/(float)taillen);
      last=next;
    }

    if ((frame % 5)==0) {
    tail[tailpos]=pos-ori.qz;
    tailpos=mymod(tailpos+1,taillen);
    }
        
    // Or screens
    for (int i=0;i<scrwid;i++) {
      for (int j=0;j<scrhei;j++) {
        b.bmp[j][i]=(left.bmp[j][i] | right.bmp[j][i]);
      }
    }
    b.writetoscreen();
    // acc=hang(acc,V3d::origin,0.95,0.01);
    
    // Movement
    float angvel=turnability;
    if (key[KEY_LCONTROL])
      vel=vel+ori.z()*forcevel;
    else
      angvel=turnability*2.0;
    if (key[KEY_UP])
      dpitch=dpitch+angvel;
    if (key[KEY_DOWN])
      dpitch=dpitch-angvel;
    if (key[KEY_LEFT])
      if (key[KEY_ALT])
      droll=droll-angvel;
    else
    dyaw=dyaw-angvel;
    if (key[KEY_RIGHT])
      if (key[KEY_ALT])
      droll=droll+angvel;
    else
    dyaw=dyaw+angvel;
    vel=hang(vel,V3d::o,0.91,0);
    pos=pos+vel;
    droll=hang(droll,0,0.9,0);
    dyaw=hang(dyaw,0,0.9,0);
    dpitch=hang(dpitch,0,0.9,0);
    ori.roll(droll/5.0);
    ori.yaw(dyaw/5.0);
    ori.pitch(dpitch/5.0);
    
    framedone();
  } while (!key[KEY_SPACE] && !key[KEY_ESC]);
  savetimer();
  allegro_exit();
  displayframespersecond();
}
示例#19
0
bool DTrack::sample()
{
	bool stat;
	int i, j, id;
	int nbt, nvt;
	int num_body, num_flystick, num_meatool;

	if(!thrRunning){
		return false;
	}
	
	stat = standalone->receive();  // receive data from DTrack (blocking with timeout)

	if(!stat){
		return false;
	}

	static int known_num_body = 0;
	num_body = standalone->get_num_body();
	num_flystick = standalone->get_num_flystick();
	num_meatool = standalone->get_num_meatool();
	
	if (known_num_body != num_body) {
		vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
			<< "[DTrack] Change in the number of known bodies - "
			<< "was " << known_num_body << ", now is " << num_body
			<< std::endl << vprDEBUG_FLUSH;
		known_num_body = num_body;
	}
	
	resize_curPosition(num_flystick + num_meatool + num_body);
	resize_curDigital(num_flystick * BUTTONS_PER_FLYSTICK + num_meatool * BUTTONS_PER_MEATOOL);
	resize_curAnalog(num_flystick * VALUATORS_PER_FLYSTICK);

	// get 'Flystick' data:

	for(i=0; i<num_flystick; i++){
		dtrack_flystick_type dat = standalone->get_flystick(i);
		
		if(dat.quality >= 0){  // check if Flystick position is tracked
			curPosition[i].setValue(getpos(dat));
			curPosition[i].setTime();
		}                      // otherwise keep last valid position

		// Flystick buttons:

		nbt = dat.num_button;
		
		if(nbt > BUTTONS_PER_FLYSTICK){
			nbt = BUTTONS_PER_FLYSTICK;
		}
		
		for(j=0; j<nbt; j++){
			id = j + i * BUTTONS_PER_FLYSTICK;  // VRJuggler id number
			
			curDigital[id] =
                           static_cast<DigitalState::State>(dat.button[j]);
			curDigital[id].setTime();
		}
		
		// Flystick valuators ('HAT switch' or 'joystick'):
		
		nvt = dat.num_joystick;
		
		if(nvt > VALUATORS_PER_FLYSTICK){
			nvt = VALUATORS_PER_FLYSTICK;
		}
		
		for(j=0; j<nvt; j++){
			id = j + i * VALUATORS_PER_FLYSTICK;  // VRJuggler id number
			
			curAnalog[id] = dat.joystick[j];
			curAnalog[id].setTime();
		}
	}

	// get 'measurement tool' data:

	for(i=0; i<num_meatool; i++){
		dtrack_meatool_type dat = standalone->get_meatool(i);
		
		if(dat.quality >= 0){  // check if position is tracked
			id = i + num_flystick;  // VRJuggler id number
			
			curPosition[id].setValue(getpos(dat));
			curPosition[id].setTime();
		}                      // otherwise keep last valid position

		// measurement tool buttons:

		nbt = dat.num_button;
		
		if(nbt > BUTTONS_PER_MEATOOL){
			nbt = BUTTONS_PER_MEATOOL;
		}
		
		for(j=0; j<nbt; j++){
			id = j + i * BUTTONS_PER_MEATOOL + num_flystick * BUTTONS_PER_FLYSTICK;  // VRJuggler id number
			
			curDigital[id] =
                           static_cast<DigitalState::State>(dat.button[j]);
			curDigital[id].setTime();
		}
	}

	// get 'standard body' data:

	for(i=0; i<num_body; i++){
		dtrack_body_type dat = standalone->get_body(i);

		if(dat.quality >= 0){  // check if position is tracked
			id = i + num_flystick + num_meatool;  // VRJuggler id number

			curPosition[id].setValue(getpos(dat));
			curPosition[id].setTime();
		}                      // otherwise keep last valid position
	}

	// update buffers:

	addPositionSample(curPosition);
	addDigitalSample(curDigital);
	addAnalogSample(curAnalog);
	
	return true;
}
示例#20
0
void
c_yank(void)
{
	struct ww *w = selwin;
	int col1, row1;
	int col2, row2;
	int r, c;

	if (!terse)
		wwputs("Yank starting position: ", cmdwin);
	wwcursor(w, 0);
	row1 = w->ww_cur.r;
	col1 = w->ww_cur.c;
	for (;;) {
		wwsetcursor(row1, col1);
		while (wwpeekc() < 0)
			wwiomux();
		switch (getpos(&row1, &col1, w->ww_i.t, w->ww_i.l,
			       w->ww_i.b - 1, w->ww_i.r - 1)) {
		case 3:
			goto out;
		case 2:
			break;
		case 1:
		case 0:
			continue;
		}
		break;
	}
	if (!terse)
		wwputs("\nYank ending position: ", cmdwin);
	row2 = row1;
	col2 = col1;
	for (;;) {
		wwsetcursor(row2, col2);
		while (wwpeekc() < 0)
			wwiomux();
		r = row2;
		c = col2;
		switch (getpos(&row2, &col2, w->ww_i.t, w->ww_i.l,
			       w->ww_i.b - 1, w->ww_i.r - 1)) {
		case 3:
			yank_highlight(row1, col1, r, c);
			goto out;
		case 2:
			break;
		case 1:
			yank_highlight(row1, col1, r, c);
			yank_highlight(row1, col1, row2, col2);
		case 0:
			continue;
		}
		break;
	}
	if (row2 < row1 || (row2 == row1 && col2 < col1)) {
		r = row1;
		c = col1;
		row1 = row2;
		col1 = col2;
		row2 = r;
		col2 = c;
	}
	unyank();
	c = col1;
	for (r = row1; r < row2; r++) {
		yank_line(r, c, w->ww_b.r);
		c = w->ww_b.l;
	}
	yank_line(r, c, col2);
	yank_highlight(row1, col1, row2, col2);
	if (!terse)
		wwputc('\n', cmdwin);
out:
	wwcursor(w, 1);
}
示例#21
0
文件: pager.c 项目: DanielT/NitroHack
/* quick: use cursor && don't search for "more info" */
static int do_look(boolean quick)
{
    char out_str[BUFSZ];
    char firstmatch[BUFSZ];
    int i, ans = 0, objplur = 0;
    int found;		/* count of matching syms found */
    coord cc;		/* screen pos of unknown glyph */
    boolean save_verbose;	/* saved value of flags.verbose */
    boolean from_screen;	/* question from the screen */
    struct nh_desc_buf descbuf;
    struct obj *otmp;

    if (quick) {
	from_screen = TRUE;	/* yes, we want to use the cursor */
    } else {
	i = ynq("Specify unknown object by cursor?");
	if (i == 'q') return 0;
	from_screen = (i == 'y');
    }

    if (from_screen) {
	cc.x = u.ux;
	cc.y = u.uy;
    } else {
	getlin("Specify what? (type the word)", out_str);
	if (out_str[0] == '\0' || out_str[0] == '\033')
	    return 0;

	/* the ability to specify symbols is gone: it is simply impossible to
	 * know how the window port is displaying things (tiles?) and even if
	 * charaters are used it may not be possible to type them (utf8)
	 */
	
	checkfile(out_str, NULL, TRUE, TRUE);
	return 0;
    }
    /* Save the verbose flag, we change it later. */
    save_verbose = flags.verbose;
    flags.verbose = flags.verbose && !quick;
    
    /*
     * we're identifying from the screen.
     */
    do {
	/* Reset some variables. */
	found = 0;
	out_str[0] = '\0';
	objplur = 0;

	if (flags.verbose)
	    pline("Please move the cursor to %s.",
		    what_is_an_unknown_object);
	else
	    pline("Pick an object.");

	ans = getpos(&cc, FALSE, what_is_an_unknown_object);
	if (ans < 0 || cc.x < 0) {
	    flags.verbose = save_verbose;
	    return 0;	/* done */
	}
	flags.verbose = FALSE;	/* only print long question once */

	nh_describe_pos(cc.x, cc.y, &descbuf);
	
	otmp = vobj_at(cc.x, cc.y);
	if (otmp && is_plural(otmp))
	    objplur = 1;
	
	out_str[0] = '\0';
	if (append_str(out_str, descbuf.effectdesc, 0))
	    if (++found == 1)
		strcpy (firstmatch, descbuf.effectdesc);
	
	if (append_str(out_str, descbuf.invisdesc, 0))
	    if (++found == 1)
		strcpy (firstmatch, descbuf.invisdesc);
	
	if (append_str(out_str, descbuf.mondesc, 0))
	    if (++found == 1)
		strcpy (firstmatch, descbuf.mondesc);
	
	if (append_str(out_str, descbuf.objdesc, objplur))
	    if (++found == 1)
		strcpy (firstmatch, descbuf.objdesc);
	
	if (append_str(out_str, descbuf.trapdesc, 0))
	    if (++found == 1)
		strcpy (firstmatch, descbuf.trapdesc);
	
	if (append_str(out_str, descbuf.bgdesc, 0))
	    if (!found) {
		found++; /* only increment found if nothing else was seen,
		so that checkfile can be called below */
		strcpy (firstmatch, descbuf.bgdesc);
	    }
	

	/* Finally, print out our explanation. */
	if (found) {
	    out_str[0] = highc(out_str[0]);
	    pline("%s.", out_str);
	    /* check the data file for information about this thing */
	    if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE &&
			(ans == LOOK_VERBOSE || !quick)) {
		checkfile(firstmatch, NULL, FALSE, ans == LOOK_VERBOSE);
	    }
	} else {
	    pline("I've never heard of such things.");
	}
    } while (!quick && ans != LOOK_ONCE);

    flags.verbose = save_verbose;

    return 0;
}
示例#22
0
bool DTrack::sample()
{
	bool stat;
	int i, j, id;
	int nbt, nvt;
	int num_body, num_flystick, num_meatool;

	if(!thrRunning){
		return false;
	}
	
	stat = standalone->receive();  // receive data from DTrack (blocking with timeout)

	if(!stat){
		return false;
	}

	num_body = standalone->get_num_body();
	num_flystick = standalone->get_num_flystick();
	num_meatool = standalone->get_num_meatool();
	
	resize_curPosition(num_flystick + num_meatool + num_body);
	resize_curDigital(num_flystick * BUTTONS_PER_FLYSTICK + num_meatool * BUTTONS_PER_MEATOOL);
	resize_curAnalog(num_flystick * VALUATORS_PER_FLYSTICK);

	// get 'Flystick' data:

	for(i=0; i<num_flystick; i++){
		dtrack_flystick_type dat = standalone->get_flystick(i);
		
		if(dat.quality >= 0){  // check if Flystick position is tracked
			curPosition[i].mPosData = getpos(dat);
			curPosition[i].setTime();
		}                      // otherwise keep last valid position

		// Flystick buttons:

		nbt = dat.num_button;
		
		if(nbt > BUTTONS_PER_FLYSTICK){
			nbt = BUTTONS_PER_FLYSTICK;
		}
		
		for(j=0; j<nbt; j++){
			id = j + i * BUTTONS_PER_FLYSTICK;  // VRJuggler id number
			
			curDigital[id] = dat.button[j];
			curDigital[id].setTime();
		}
		
		// Flystick valuators ('HAT switch' or 'joystick'):
		
		nvt = dat.num_joystick;
		
		if(nvt > VALUATORS_PER_FLYSTICK){
			nvt = VALUATORS_PER_FLYSTICK;
		}
		
		for(j=0; j<nvt; j++){
			id = j + i * VALUATORS_PER_FLYSTICK;  // VRJuggler id number
			
			curAnalog[id] = dat.joystick[j] / 2.0 + 0.5;  // normalizing
			curAnalog[id].setTime();
		}
	}

	// get 'measurement tool' data:

	for(i=0; i<num_meatool; i++){
		dtrack_meatool_type dat = standalone->get_meatool(i);
		
		if(dat.quality >= 0){  // check if position is tracked
			id = i + num_flystick;  // VRJuggler id number
			
			curPosition[id].mPosData = getpos(dat);
			curPosition[id].setTime();
		}                      // otherwise keep last valid position

		// measurement tool buttons:

		nbt = dat.num_button;
		
		if(nbt > BUTTONS_PER_MEATOOL){
			nbt = BUTTONS_PER_MEATOOL;
		}
		
		for(j=0; j<nbt; j++){
			id = j + i * BUTTONS_PER_MEATOOL + num_flystick * BUTTONS_PER_FLYSTICK;  // VRJuggler id number
			
			curDigital[id] = dat.button[j];
			curDigital[id].setTime();
		}
	}

	// get 'standard body' data:

	for(i=0; i<num_body; i++){
		dtrack_body_type dat = standalone->get_body(i);

		if(dat.quality >= 0){  // check if position is tracked
			id = i + num_flystick + num_meatool;  // VRJuggler id number

			curPosition[id].mPosData = getpos(dat);
			curPosition[id].setTime();
		}                      // otherwise keep last valid position
	}

	// update buffers:

	addPositionSample(curPosition);
	addDigitalSample(curDigital);
	addAnalogSample(curAnalog);
	
	return true;
}
示例#23
0
//------------------------------------------------------------------------------
bool istream::getNumber(uint32_t posMax, uint32_t negMax, uint32_t* num) {
  int16_t c;
  int8_t any = 0;
  int8_t have_zero = 0;
  uint8_t neg;
  uint32_t val = 0;
  uint32_t cutoff;
  uint8_t cutlim;
  FatPos_t endPos;
  uint8_t f = flags() & basefield;
  uint8_t base = f == oct ? 8 : f != hex ? 10 : 16;
  getpos(&endPos);
  c = readSkip();

  neg = c == '-' ? 1 : 0;
  if (c == '-' || c == '+') {
    c = getch();
  }

  if (base == 16 && c == '0') {  // TESTSUITE
    c = getch(&endPos);
    if (c == 'X' || c == 'x') {
      c = getch();
      // remember zero in case no hex digits follow x/X
      have_zero = 1;
    } else {
      any = 1;
    }
  }
  // set values for overflow test
  cutoff = neg ? negMax : posMax;
  cutlim = cutoff % base;
  cutoff /= base;

  while (1) {
    if (isdigit(c)) {
      c -= '0';
    } else if (isalpha(c)) {
      c -= isupper(c) ? 'A' - 10 : 'a' - 10;
    } else {
      break;
    }
    if (c >= base) {
      break;
    }
    if (val > cutoff || (val == cutoff && c > cutlim)) {
      // indicate overflow error
      any = -1;
      break;
    }
    val = val * base + c;
    c = getch(&endPos);
    any = 1;
  }
  setpos(&endPos);
  if (any > 0 || (have_zero && any >= 0)) {
    *num =  neg ? -val : val;
    return true;
  }
  setstate(failbit);
  return false;
}
示例#24
0
bool istream::getDouble(double* value) {
  bool got_digit = false;
  bool got_dot = false;
  bool neg;
  int16_t c;
  bool expNeg = false;
  int16_t exp = 0;
  int16_t fracExp = 0;
  uint32_t frac = 0;
  FatPos_t endPos;
  double pow10;
  double v;

  getpos(&endPos);
  c = readSkip();
  neg = c == '-';
  if (c == '-' || c == '+') {
    c = getch();
  }
  while (1) {
    if (isdigit(c)) {
      got_digit = true;
      if (frac < uint32_max/10) {
        frac = frac * 10 + (c  - '0');
        if (got_dot) fracExp--;
      } else {
        if (!got_dot) fracExp++;
      }
    } else if (!got_dot && c == '.') {
      got_dot = true;
    } else {
      break;
    }
    if (fracExp < -EXP_LIMIT || fracExp > EXP_LIMIT) goto fail;
    c = getch(&endPos);
  }
  if (!got_digit) goto fail;
  if (c == 'e' || c == 'E') {
    c = getch();
    expNeg = c == '-';
    if (c == '-' || c == '+') {
      c = getch();
    }
    while (isdigit(c)) {
      if (exp > EXP_LIMIT) goto fail;
      exp = exp * 10 + (c - '0');
      c = getch(&endPos);
    }
  }
  v = static_cast<double>(frac);
  exp = expNeg ? fracExp - exp : fracExp + exp;
  expNeg = exp < 0;
  if (expNeg) exp = -exp;
  pow10 = 10.0;
  while (exp) {
    if (exp & 1) {
      if (expNeg) {
        // check for underflow
        if (v < FLT_MIN * pow10  && frac != 0) goto fail;
        v /= pow10;
      } else {
        // check for overflow
        if (v > FLT_MAX / pow10) goto fail;
        v *= pow10;
      }
    }
    pow10 *= pow10;
    exp >>= 1;
  }
  setpos(&endPos);
  *value = neg ? -v : v;
  return true;

 fail:
  // error restore position to last good place
  setpos(&endPos);
  setstate(failbit);
  return false;
}
示例#25
0
void main() {
  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  mypalette(255,0,0,0);
  mypalette(0,0,0,0);
  mypalette(255,1,1,1);
  mypalette(128,0,0,0);
  randomise();
  for (int i=0;i<=5;i++) {
    waves+Wave();
    //waves.num(i).display();
  }
  for (int r=0;r<8;r++) {
  for (int g=0;g<8;g++) {
    int palc=r+g*8;
    mypalette(palc,(r==0?0:0.1+0.6*r/7.0),(g==0?0:0.1+0.2*g/7.0),(g==0?0:0.1+0.7*g/7.0));
    // Good colours: mypalette(palc,(r==0?0:0.3+0.4*r/7.0),(g==0?0:0.1+0.2*g/7.0),(g==0?0:0.3+0.5*g/7.0));
  }
  }
  V3d vel=V3d(0,0,0);
  V3d acc=V3d(0,0,0);
  Ori ori;
  float droll=0;
  float dyaw=0;
  float roll=0;
  float yaw=0;
  float pitch=0;
  int frame=0;
  List<V3d> particles=List<V3d>(gridsize*gridsize*gridsize);
/*  for (int i=1;i<gridsize*gridsize*gridsize;i++) {
    particles+gridsize*V3d(floatrnd(-1,1),floatrnd(-1,1),floatrnd(-1,1));
  }*/
  for (float thru=0;thru<1.0;thru+=0.01) {
    particles+getpos(thru);
    //v.print();
  }
  starttimer();
  float thru=0;
  V3d pos=getpos(thru);
  do {
    thru+=0.001;
    V3d last=pos;
    V3d pos=getpos(thru);
    V3d newz=pos-last;
    ori.forcez(newz);
    frame++;
    float pd=1.6+1.3*sin(2*pi*frame/1000.0);
    PPsetup(scrwid,scrhei,pd);
    left.clear(0);
    right.clear(0);
//    b.fadeby(16);
    V3d off=V3d(mymod(pos.x,gridsize),mymod(pos.y,gridsize),mymod(pos.z,gridsize));
    int ioff=-mydiv(pos.x,gjump);
    int joff=-mydiv(pos.y,gjump);
    int koff=-mydiv(pos.z,gjump);
    ori.quickorisetup();
    // Need to find largest axis, and do loops with that one outside
    int ks=mysgn(ori.qz.z);
    int js=-mysgn(ori.qz.y);
    int is=-mysgn(ori.qz.x);
    for (int i=1;i<=particles.len;i++) {
          int x,y;
          V3d p=particles.num(i);
          //V3d cen=p-off;
          V3d cen=p+pos;
          cen=V3d(mymod2(cen.x,-gridsize,gridsize),mymod2(cen.y,-gridsize,gridsize),mymod2(cen.z,-gridsize,gridsize));
          cen=V3d::qorientate(cen,ori);
          int c=7.0-chop(6.0*(cen.z+gridsize)/(float)(gridsize*2),0,6);
          plotsphere(cen,c);
        }
    for (int i=0;i<scrwid;i++) {
    for (int j=0;j<scrhei;j++) {
      b.bmp[j][i]=(left.bmp[j][i] | right.bmp[j][i]);
    }
    }
    b.writetoscreen();
//    acc=hang(acc,V3d::origin,0.95,0.01);
//    vel=hang(vel,(ori.qz/5.0).neg(),0.9,0)+acc;
//    pos=pos+vel;
//    droll=hang(droll,0,0.9,0.01);
//    dyaw=hang(dyaw,0,0.95,0.01);
//    roll=hang(roll,0,0.95,0)+droll;
//    yaw=hang(yaw,0,0.92,0)+dyaw;
//    pitch=hang(pitch,0,0.999,0.01);
//    pos=pos+ori.qz*4;
//    ori.roll(roll/5.0);
//    ori.yaw(yaw/5.0);
//    pos=pos-ori.z()*4;
    framedone();
  } while (!key[KEY_SPACE] && !key[KEY_ESC]);
  savetimer();
  allegro_exit();
  displayframespersecond();
}
示例#26
0
//	CUEシート読み込み
BRESULT opencue(SXSIDEV sxsi, const OEMCHAR *fname) {

	_CDTRK		trk[99];
	OEMCHAR		path[MAX_PATH];
	UINT		index;
	UINT8		curtrk;
	UINT		curtype;
	TEXTFILEH	tfh;
	OEMCHAR		buf_mode[10];
	OEMCHAR		buf[512];
	OEMCHAR		*argv[8];
	int			argc;
//	--------
	UINT16		curssize;
	UINT32		curpos0;
	UINT32		curpregap;

	ZeroMemory(trk, sizeof(trk));
	path[0] = '\0';
	index = 0;
	curtrk = 1;
	curtype = 0x14;
//	--------
	curpos0 = 0;
	curpregap = 0;
//	--------

	tfh = textfile_open(fname, 0x800);
	if (tfh == NULL) {
		goto opencue_err2;
	}
	while (textfile_read(tfh, buf, NELEMENTS(buf)) == SUCCESS) {
		argc = milstr_getarg(buf, argv, NELEMENTS(argv));
		if ((argc >= 3) && (!milstr_cmp(argv[0], str_file))) {				//	FILE
			if (!milstr_cmp(argv[argc-1], str_binary) && path[0] == '\0') {	//		BINARY
				file_cpyname(path, fname, NELEMENTS(path));
				file_cutname(path);
				file_catname(path, argv[1], NELEMENTS(path));
			}
		}
		else if ((argc >= 3) && (!milstr_cmp(argv[0], str_track))) {		//	TRACK
			curtrk = (UINT8)milstr_solveINT(argv[1]);
			milstr_ncpy(buf_mode, argv[2], NELEMENTS(str_mode1));
			if (!milstr_cmp(buf_mode, str_mode1)) {							//		MODE1/????
				curtype = 0x14;
				curssize = (UINT16)milstr_solveINT(argv[2] + 6);
			}
			else if (!milstr_cmp(buf_mode, str_mode2)) {					//		MODE2/????
				curtype = 0x14;
				curssize = (UINT16)milstr_solveINT(argv[2] + 6);
			}
			else if (!milstr_cmp(argv[2], str_audio)) {						//		AUDIO
				curtype = 0x10;
				curssize = 2352;
			}
		}
		else if ((argc >= 2) && (!milstr_cmp(argv[0], str_pregap))) {		//	PREGAP
			curpregap = getpos(argv[1]);
		}
		else if ((argc >= 3) && (!milstr_cmp(argv[0], str_index))) {		//	INDEX ??
			if (index < NELEMENTS(trk)) {
				if ((UINT8)milstr_solveINT(argv[1]) == 0) {					//	INDEX 00
					curpos0 = getpos(argv[2]);
					continue;
				}
				if ((UINT8)milstr_solveINT(argv[1]) != 1) {					//	INDEX 01以外
					continue;
				}

				trk[index].adr_ctl			= curtype;
				trk[index].point			= curtrk;
				trk[index].pos				= getpos(argv[2]);
				trk[index].pos0				= (curpos0 == 0) ? trk[index].pos : curpos0;

				trk[index].sector_size		= curssize;

				trk[index].pregap_sectors	= curpregap + (trk[index].pos - trk[index].pos0);

				trk[index].img_pregap_sec	= (trk[index].pos0 == 0) ? trk[index].pos : trk[index].pos0;
				trk[index].img_start_sec	= trk[index].pos;

//				trk[index].pregap_sector	= trk[index].start_sector - trk[index].pregap_sectors;

				index++;
				curpregap = 0;
				curpos0 = 0;
			}
		}
	}

	if (index == 0) {
		goto opencue_err1;
	}

	set_secread(sxsi, trk, index);
	sxsi->totals = -1;

	textfile_close(tfh);

	return(setsxsidev(sxsi, path, trk, index));

opencue_err1:
	textfile_close(tfh);

opencue_err2:
	return(FAILURE);
}
示例#27
0
文件: kips.c 项目: 10crimes/code
void main() {
  setuptriglookup();

  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  mypalette(255,0,0,0);
  mypalette(0,0,0,0);
  mypalette(255,1,1,1);
  mypalette(128,0,0,0);
  for (int r=0;r<16;r++) {
    for (int g=0;g<16;g++) {
      int palc=r+g*16;
      mypalette(palc,(r==0?0:brightness+0.2+change*0.5*r/15.0),(g==0?0:brightness+change*0.1+0.2*g/15.0),(g==0?0:brightness+change*0.2+0.6*g/15.0));
      // Groovy colours mypalette(palc,(r==0?0:0.1+0.6*r/15.0),(g==0?0:0.1+0.2*g/15.0),(g==0?0:0.1+0.7*g/15.0));
      // Good colours: mypalette(palc,(r==0?0:0.3+0.4*r/15.0),(g==0?0:0.1+0.2*g/15.0),(g==0?0:0.3+0.5*g/15.0));
    }
  }

    float pd=2.5;
    PPsetup(scrwid,scrhei,pd);
  V3d vel=V3d(0,0,0);
  V3d acc=V3d(0,0,0);
  float droll=0;
  float dyaw=0;
  float dpitch=0;
  int frame=0;

  // Set up track
  randomise();
  for (int i=0;i<=15;i++) {
    waves+Wave();
    // waves.num(i).display();
  }

  for (float thru=0;thru<1.0;thru+=1.0/(float)numps) {
    V3d here=getpos(thru);
    V3d forward=getpos(thru+0.00001)-here;
    V3d up=V3d::normcross(V3d::crazy,forward);
    V3d right=V3d::normcross(forward,up);
    for (int i=0;i<tunnelps;i++) {
      float t=2*pi*(float)i/(float)tunnelps;
      float s=sin(t);
      float c=cos(t);
      V3d v=here+tunnelrad*(s*up+c*right);
      octree.add(v);
    }
  }

  for (int i=1;i<500;i++) {
    octree.add(8.0*V3d(floatrnd(-1,1),floatrnd(-1,1),floatrnd(-1,1)));
  }

  // Display track
  float t=0;
  do {
    t=t+0.03;
    V3d from=V3d::rotate(6.0*V3d::k,V3d::j,t);
    ori.forcez(from.neg());
    pos=from;
    plotscene();
    writescreen();
  } while (!key[KEY_SPACE]);
  do {
  } while (key[KEY_SPACE]);

  // Race
  starttimer();
  float thru=0;
  float marker=0;
  pos=getpos(marker);
  V3d *tail=new V3d[taillen];
  int tailpos=0;
  do {
    thru+=0.001;
    // V3d last=V3d(pos.x,pos.y,pos.z);
    // V3d pos=getpos(thru);
    // V3d next=getpos(thru+0.00001);
    // V3d newz=next-pos;
    // ori.forcez(newz);
    frame++;
    // float pd=1.6+1.3*sin(2*pi*frame/1000.0);
    
    plotscene();
    
    // Plot and move marker
    V3d m;
    for (int i=1;i<=15;i++) {
      m=V3d::disorientate(getpos(marker)-pos,ori);
      if (m.mod()<markerrange)
        marker+=0.0002;
    }
    
    float u=PPgetunitnoadd(m);
    bool plot=false;
    if (u) {
      int x,y;
      float rad=0.12*u;
      if (PPgetscrposnoadd(m,PPlefteye,&x,&y))
      if (left.inimage(x,y)) {
        plot=true;
        left.opencircle(x,y,rad,15);
        left.opencircle(x,y,rad/2,15);
      }
      if (PPgetscrposnoadd(m,PPrighteye,&x,&y))
      if (right.inimage(x,y)) {
        plot=true;
        right.opencircle(x,y,rad,15*16);
        right.opencircle(x,y,rad/2,15*16);
      }
    }
    if (!plot) {
      V2d v=scrwid*2*V2d(m.x,m.y).norm();
      if (abs(v.x)>scrwid/2) {
        float change=(float)scrwid/2.0/abs(v.x);
        v=change*v;
      }
      if (abs(v.y)>scrhei/2) {
        float change=(float)scrhei/2.0/abs(v.y);
        v=change*v;
      }
      v=v+V2d(scrwid/2,scrhei/2);
      left.opencircle(v,5,15);
      right.opencircle(v,5,15*16);
    }
    
    // Pull player towards marker
    // if (m.mod()>markerrange+.1) {
      V3d pulldir=getpos(marker)-pos;
      // vel=vel+pulldir*0.02;
      // float amount=(V3d::normdot(ori.z(),pulldir)+5.0)/6.0;
      float amount=chop(0.99-(m.mod()-markerrange)/5.0,0,1);
      V3d newz=ori.z()*amount+(1.0-amount)*pulldir;
      ori.forcez(newz);
      // vel=vel*amount;
      // 
      // 
//    }
    
    // Draw and update tail
    V3d last=(tail[tailpos]-pos).disorientate(ori);
    for (int k=1;k<taillen;k++) {
      int j=mymod(tailpos+k,taillen);
      V3d next=(tail[j]-pos).disorientate(ori);
      plotline(last,next,(float)k/(float)taillen);
      last=next;
    }
    
    if ((frame % 2)==0) {
      tail[tailpos]=pos-ori.qz;
      tailpos=mymod(tailpos+1,taillen);
    }
    
  writescreen();
    
    // acc=hang(acc,V3d::origin,0.95,0.01);
    // Movement
    float angvel=turnability;
    if (key[KEY_LCONTROL])
      vel=vel+ori.z()*forcevel;
    else
    angvel=turnability*2.0;
    if (key[KEY_DOWN])
      dpitch=dpitch+angvel;
    if (key[KEY_UP])
      dpitch=dpitch-angvel;
    if (key[KEY_LEFT])
      if (key[KEY_ALT])
      droll=droll-angvel;
    else
    dyaw=dyaw-angvel;
    if (key[KEY_RIGHT])
      if (key[KEY_ALT])
      droll=droll+angvel;
    else
    dyaw=dyaw+angvel;
    vel=hang(vel,V3d::o,0.92,0);
    pos=pos+vel;
    droll=hang(droll,0,0.9,0);
    dyaw=hang(dyaw,0,0.9,0);
    dpitch=hang(dpitch,0,0.9,0);
    ori.roll(droll/5.0);
    ori.yaw(dyaw/5.0);
    ori.pitch(dpitch/5.0);
    
    framedone();
  } while (!key[KEY_SPACE] && !key[KEY_ESC]);
  savetimer();
  allegro_exit();
  displayframespersecond();
}
示例#28
0
int main()
{
	List *ltmp   = NULL;
	Node *ntmp   = NULL;
	int   i      = 0;
	int   data[] = { 0, 1, 2, 4, 8, 16, 32, 48, 64 };
	int   num    = 0;
	int   testno = 0;

	char *output[11];
	output[i++]  = "-> NULL";
	output[i++]  = "-> NULL";
	output[i++]  = "0 -> NULL";
	output[i++]  = "1 -> 0 -> NULL";
	output[i++]  = "2 -> 1 -> 0 -> NULL";
	output[i++]  = "4 -> 2 -> 1 -> 0 -> NULL";
	output[i++]  = "4 -> 2 -> 1 -> 8 -> 0 -> NULL";
	output[i++]  = "4 -> 2 -> 1 -> 16 -> 8 -> 0 -> NULL";
	output[i++]  = "4 -> 2 -> 1 -> 32 -> 16 -> 8 -> 0 -> NULL";
	output[i++]  = "4 -> 2 -> 48 -> 1 -> 32 -> 16 -> 8 -> 0 -> NULL";
	output[i++]  = "4 -> 64 -> 2 -> 48 -> 1 -> 32 -> 16 -> 8 -> 0 -> NULL";

	fprintf(stdout, "UNIT TEST: list library insert() function\n");
	fprintf(stdout, "=========================================\n");

	// NULL list test
	fprintf(stdout, "Test %d: Inserting on NULL list ...\n", testno++);
	fprintf(stdout, " you have: "); 
	ltmp         = insert(ltmp, NULL, NULL);
	displayf(ltmp, 0);
	fprintf(stdout, "should be: %s\n\n", output[num++]); 
	fflush(stdout);

	ltmp         = mklist();

	// EMPTY list test
	fprintf(stdout, "Test %d: Inserting on empty list ...\n", testno++);
	fprintf(stdout, " you have: "); 
	ltmp         = insert(ltmp, NULL, NULL);
	displayf(ltmp, 0);
	fprintf(stdout, "should be: %s\n\n", output[num++]); 
	fflush(stdout);
	
	fprintf(stdout, "Test %d: Checking list quantity ...\n", testno++);
	fprintf(stdout, " you have: %lu\n", ltmp -> qty); 
	fprintf(stdout, "should be: %d\n\n", 0); 
	fflush (stdout);

	// Building list
	for(i = 0; i < 4; i++)
	{
		fprintf(stdout, "Test %d: Inserting %d before start of list ...\n", testno++, data[i]);
		ntmp     = mknode(data[i]);
		fprintf(stdout, " you have: "); 
		ltmp     = insert(ltmp, ltmp -> first, ntmp);
		displayf(ltmp, 0);
		fprintf(stdout, "should be: %s\n\n", output[num++]); 
		fflush(stdout);
	
		fprintf(stdout, "Test %d: Checking list quantity ...\n", testno++);
		fprintf(stdout, " you have: %lu\n", ltmp -> qty); 
		fprintf(stdout, "should be: %d\n\n", (i+1)); 
		fflush (stdout);
	}

	i = 4;

	fprintf(stdout, "Test %d: Inserting %d before end of list ...\n", testno++, data[i]);
	fprintf(stdout, " you have: ");
	ltmp         = insert(ltmp, ltmp -> last, mknode(data[i]));
	displayf(ltmp, 0);
	fprintf(stdout, "should be: %s\n\n", output[num++]); 
	fflush(stdout);
	i            = i + 1;
	
	fprintf(stdout, "Test %d: Checking list quantity ...\n", testno++);
	fprintf(stdout, " you have: %lu\n", ltmp -> qty); 
	fprintf(stdout, "should be: %d\n\n", i); 
	fflush (stdout);

	fprintf(stdout, "Test %d: Inserting %d before second to last node ...\n", testno++, data[i]);
	fprintf(stdout, " you have: ");
	ntmp         = setpos(ltmp, getpos(ltmp, ltmp -> last) - 1);
	ltmp         = insert(ltmp, ntmp, mknode(data[i]));
	displayf(ltmp, 0);
	fprintf(stdout, "should be: %s\n\n", output[num++]); 
	fflush(stdout);
	i            = i + 1;
	
	fprintf(stdout, "Test %d: Checking list quantity ...\n", testno++);
	fprintf(stdout, " you have: %lu\n", ltmp -> qty); 
	fprintf(stdout, "should be: %d\n\n", i); 
	fflush (stdout);

	fprintf(stdout, "Test %d: Inserting %d before third to last node ...\n", testno++, data[i]);
	fprintf(stdout, " you have: ");
	ntmp         = setpos(ltmp, getpos(ltmp, ltmp -> last) - 2);
	ltmp         = insert(ltmp, ntmp, mknode(data[i]));
	displayf(ltmp, 0);
	fprintf(stdout, "should be: %s\n\n", output[num++]); 
	fflush(stdout);
	i            = i + 1;
	
	fprintf(stdout, "Test %d: Checking list quantity ...\n", testno++);
	fprintf(stdout, " you have: %lu\n", ltmp -> qty); 
	fprintf(stdout, "should be: %d\n\n", i); 
	fflush (stdout);

	fprintf(stdout, "Test %d: Inserting %d before fifth to last node ...\n", testno++, data[i]);
	fprintf(stdout, " you have: ");
	ntmp         = setpos(ltmp, getpos(ltmp, ltmp -> last) - 4);
	ltmp         = insert(ltmp, ntmp, mknode(data[i]));
	displayf(ltmp, 0);
	fprintf(stdout, "should be: %s\n\n", output[num++]); 
	fflush(stdout);
	i            = i + 1;
	
	fprintf(stdout, "Test %d: Checking list quantity ...\n", testno++);
	fprintf(stdout, " you have: %lu\n", ltmp -> qty); 
	fprintf(stdout, "should be: %d\n\n", i); 
	fflush (stdout);

	fprintf(stdout, "Test %d: Inserting %d before 2nd node ...\n", testno++, data[i]);
	fprintf(stdout, " you have: ");
	ltmp         = insert(ltmp, ltmp -> first -> after, mknode(data[i]));
	displayf(ltmp, 0);
	fprintf(stdout, "should be: %s\n\n", output[num++]); 
	fflush(stdout);
	i            = i + 1;
	
	fprintf(stdout, "Test %d: Checking list quantity ...\n", testno++);
	fprintf(stdout, " you have: %lu\n", ltmp -> qty); 
	fprintf(stdout, "should be: %d\n\n", i); 
	fflush (stdout);

	return(0);
}
示例#29
0
MRESULT EXPENTRY scbProcedure(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
   switch(msg)
   {
   case WM_CREATE:
      create(hwnd,PVOIDFROMMP(mp2));
      return WinDefWindowProc(hwnd, msg, mp1, mp2);

   case 0x041E:
      selectBitmap(hwnd, BITMAP_MOUSEOVER);
      return WinDefWindowProc(hwnd, msg, mp1, mp2);

   case 0x041F:
      selectBitmap(hwnd, BITMAP_NORMAL);
      return WinDefWindowProc(hwnd, msg, mp1, mp2);

   case WM_BUTTON1DOWN:
      selectBitmap(hwnd, BITMAP_PRESS);
      break;

   case WM_BUTTON1UP:
      selectBitmap(hwnd, BITMAP_MOUSEOVER);
      break;

   case WM_DESTROY:
      destroy(hwnd); /* Limpa bitmaps */
      return WinDefWindowProc(hwnd, msg, mp1, mp2);

   case WM_PAINT:
      paint(hwnd);
      break;

   case WM_WINDOWPOSCHANGED:
      ajustBackground(hwnd,PVOIDFROMMP(mp1));
      return WinDefWindowProc(hwnd, msg, mp1, mp2);

   case WMSKN_AJUSTSIZEPOS:
      sizePos(hwnd,SHORT1FROMMP(mp1),SHORT2FROMMP(mp1),SHORT1FROMMP(mp2),SHORT2FROMMP(mp2));
      break;

   case WMSKN_QUERYPOS:
      return getpos(hwnd);

   case WMSKN_QUERYSIZE:
      return getsize(hwnd);

   case WMSKN_AJUSTPOS:
      reposic(hwnd,SHORT1FROMMP(mp1),SHORT2FROMMP(mp1));
      break;

   case WMSKN_SETIMAGE:                 /* MP1=XBITMAP, MP2=ID */
      loadImage(hwnd,SHORT1FROMMP(mp2),PVOIDFROMMP(mp1));
      break;

   case WMSKN_SETLIMITS:
      setLimits(hwnd,LONGFROMMP(mp1),LONGFROMMP(mp2));
      break;

   case WMSKN_SETVALUE:
      setValue(hwnd,LONGFROMMP(mp1));
      break;

   case WMSKN_UP:
      moveCursor(hwnd, -1);
      break;

   case WMSKN_DOWN:
      moveCursor(hwnd, 1);
      break;

   case WMSKN_CONNECT:
      doConnect(hwnd,LONGFROMMP(mp1),LONGFROMMP(mp2));
      break;

   case WM_BEGINDRAG:
      DBGMessage("Iniciou drag&drop");
      ((SLIDERDATA *) WinQueryWindowPtr(hwnd,0))->drag = TRUE;
      WinSetCapture(HWND_DESKTOP,hwnd);
      break;

   case WM_ENDDRAG:
      DBGMessage("Terminou drag&drop");
      ((SLIDERDATA *) WinQueryWindowPtr(hwnd,0))->drag = FALSE;
      WinSetCapture(HWND_DESKTOP,NULLHANDLE);
      break;

   case WM_MOUSEMOVE:
      if(((SLIDERDATA *) WinQueryWindowPtr(hwnd,0))->drag)
         mouseMove(hwnd, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1));
      break;

   default:
      return WinDefWindowProc(hwnd, msg, mp1, mp2);

   }
   return 0;
}
示例#30
0
文件: airlines.c 项目: clamiax/misc
int main()
{
   int positions[POS+1] = { 0 }; /* positions[0] do a lot of things :-) */
   int c; /* 1 = first class, 2 = economy. */

   srand( time(NULL) ); /* for the flight numbers ;) */

   /* available classes (2 + 1): ac[0] is not a class */
   int ac[3] = { 0, 1, 1 };

   int chclass = 0; /* for auto-change of class check */

   while(1) {

      if(!chclass) {
	 printf("\n"
		"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"
	        "American airlines international airport :-)\n"
	        "AIRLINES PRENOTATION SYSTEM! (C)Claudio M.\n"
		"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"
                "\nPlease type 1 for \"first class\"\n"
	        "Please type 2 for \"economy\"\n"
	        "Choose: ");
         scanf("%d", &c);
	 printf("\n");
      }
      else
	 --chclass;

      positions[0] = getpos(c, positions);

      if(positions[0] == -1) {
	 printf("The class %d is not exists, choose another class.\n", c);
	 continue;
      }
      else if(positions[0]) {
	 printf("<==================[ BOARDING PAPER ]==================>\n"
		"Class: %d\n"
		"Positions: %d\n"
		"Fly number: *%d\n\n"
		"Thank you for fly with us!\n"
		"Hope you enjoy with our company.\n"
	        "<==================[ BOARDING PAPER ]==================>\n"
		,c, positions[0], 6789 + rand() & 1000);
	 positions[positions[0]] = 1;

         printf("\nPress a key for reserve a flight.\n");
	 getchar(); /* ignore the newline */
         getchar(); /* wait for a key */
      }
      else { /* there are not positions available in the class */
	 ac[c] = 0; 

	 /* check if there is at least one available class */
	 for(ac[0] = 0, positions[0] = 1; positions[0] <= 2; positions[0]++)
	    ac[0] += ac[positions[0]];

	 if(!ac[0]) {
	    printf("Sorry! There are not classes available.\n");
	    printf("Take your car or run ;)\n");
	    break;
	 }

	 while( (positions[0] = getchar()) != 'n' && positions[0] != 'y') { 
	    printf("Class %d is full! Want you try to check class %d?\n"
	           "Choose (y / n): ", c, c == 1 ? 2 : 1);
         }

	 if(positions[0] == 'n') {
	    printf("Next flight leaves in 3 hours\n");
	    break;
	 }
	 c = c == 1 ? 2 : 1;
	 ++chclass;
      }
   } /* end while(1) */
	 
   return 0;
} /* E0F main */