Пример #1
0
int main(int argc, char **argv) {
  char *name = NULL;

  /*
   * check for valid argument number
   * don't forget: first argument is name of the file,
   * reason for the + 1 in the if
   */
  if (argc != (MAX_ARG + 1)) {
    printf ("Usage: program_name + <dirname> + <type>\n");
    return EXIT_FAILURE;
  }

  name = argv[1];

  if (argc == 2 && strncmp(argv[2], PRINT, strlen(PRINT)) == 0) {
    walkDir(name, printFileAttribute);
  } else if (argc == 3 && strncmp(argv[2], SEARCH, strlen(SEARCH)) == 0) {
    walkDir(name, printFileAttribute, argv[3]);
  } else {
    walkDir(name, printName);
  }

  return EXIT_SUCCESS;
}
Пример #2
0
int main(int argc, char *argv[])
{
  if (argc < 3) {
    printf("Invalid parameter\n");
    printf("Usage: %s dir function\n", argv[0]);
    printf("\tfunction -print: shows the files and details\n");
    printf("\tfunction -grep content: shows the files with the given content\n");
    return EXIT_SUCCESS;
  }

  if (strcmp(argv[2], "-print") == 0) {
    walkDir(argv[1], &print);
  }
  else if(strcmp(argv[2], "-grep") == 0) {
    if (argc < 4) {
        printf("Invalid parameter\n");
        printf("You have to give a search string\n");
        return EXIT_SUCCESS;
    }
    walkDir(argv[1], &grep, argv[3]);
  }
  else {
    printf("invalid function\n");
  }

  return EXIT_SUCCESS;
}
Пример #3
0
static void walkDir(char *dirName, Visitor visitor) {
  struct dirent *pDirent;
  DIR *pDir = NULL;
  int len = strlen(dirName);

  printf("directory %s\n", dirName);
  pDir = opendir(dirName);

  if (pDir == NULL) {
    printf("Cannot open directory %s\n", dirName);
    closedir(pDir);
    return;
  }

  pDirent = readdir(pDir);

  while(pDirent != NULL) {
    sprintf(&dirName[len], "/%s", pDirent->d_name);

    if (pDirent->d_type == DT_DIR) {
      if (strncmp(pDirent->d_name, ".", 1) != 0 &&
          strncmp(pDirent->d_name, "..", 2) != 0) {
        walkDir(dirName, visitor);
      }
    } else if (pDirent->d_type == DT_REG) {
      if (visitor != NULL) {
        visitor(dirName, NULL);
      }
    }
    pDirent = readdir(pDir);
  }

  closedir(pDir);
}
Пример #4
0
void walkDir(const char*path, char*table) {
    // find 
    DIR *root = opendir(path);
    char nextdir[256];
    char fullname[256];
    struct dirent *entry;
    if (root == NULL) {
        fprintf(stderr, "Failed to opendir(%s): %s\n\n", path, strerror(errno));
        exit(1);
    }
    while((entry = readdir(root)) != NULL) {
        if (entry->d_type == 4 && entry->d_name[0] != '.') {
            sprintf(nextdir, "%s/%s", path, entry->d_name);
            walkDir(nextdir, table);
        } else if (entry->d_type == 8 && entry->d_name[0] == 'r' && entry->d_name[1] == '.') {
            sprintf(fullname, "%s/%s", path, entry->d_name);
            fprintf(stderr, ".");
            fflush(stderr);
            readRegion(fullname, table);

        }

    }
    closedir(root);

}
Пример #5
0
// int doffire(unsigned int xmax=128, unsigned int ymax=128, unsigned int fmatch=125 unsigned short burnPropAge=400) {
// use simpler float nRand, nClust probabilities...
int doffire(unsigned tmax=1000000, int doSQL=1, unsigned short fMatch=200, float nRand=1, float nClust=0, int kmax=4, int sheepSpeed=1) {
	// burn toplolgy: do we nave nnn burning
	//
	std::string simName("ForestFire7d");
	std::string simPramComment("");
	//int fMatch = 250;
	//
	unsigned short rFire = 1;
	unsigned int nBurning = 0;
	unsigned short dnBurning = 0;
	int thisX, thisY, xFire, yFire; 
	//int *fireSquare = new int;
	int *fireSquare = NULL;
	unsigned int nBurnedTotal=0, nFires=0;  // number of elements burning, new Elements burning...
	//
	int burnPropAge=1;
	//
	//int *bigClustMaps = new int[(ymax+2)*(xmax+2)];
	int *grids = new int[(ymax+2)*(xmax+2)];
	int intKey;
	float aveRho, aveVol;
	int gridPos=0;
	//
	int rSeed=int(time(NULL));
	int drSeed = 0;
	srand(time(NULL));	
	Rand plantRandx(rSeed + drSeed);
		drSeed ++;
	Rand plantRandy(rSeed + drSeed);
		drSeed ++;
	Rand fireRandx(rSeed + drSeed);
		drSeed ++;
	Rand fireRandy(rSeed + drSeed);
		drSeed ++;
	Rand rfMatch(rSeed + drSeed);
		drSeed ++;
	Rand rcPlant(rSeed + drSeed);
		drSeed ++;
	Rand walkDir(rSeed + drSeed);
		drSeed ++;
	Rand sheepRand(rSeed + drSeed);
		drSeed ++;

	// initialize sheep:
	unsigned int sheepPos = (xmax+2) + 1 + sheepRand.nextInt(xmax) + (xmax+2)*sheepRand.nextInt(ymax);	// a little sloppy with the rand. numbs, but not important.

	// initialize the grid/cluster-grid with "rocks" around the border and in otherwise empty cells.
	// "cluster 0" will, for the time being, not participate in the simulation. just for posterity,
	// we will place "rocks" around the borders. initialize the interior of the grid with 0; we will
	// map the excluded areas via the clusters grid.
	for (unsigned int i = (xmax+2); i<(xmax+2)*(ymax+1); i++) {
		grids[i] = 0;
		//clustGrids[i] = 0;
		};
	for (unsigned int i=0; i<(xmax+2); i++) {
		grids[i] = rockAge;
		grids[(ymax+1)*(xmax+2) + i] = rockAge;
		//
		};
	for (unsigned int i=0; i<(ymax+2); i++) {
		grids[(xmax+2)*i] = rockAge;
		grids[(xmax+2)*i + xmax+1] = rockAge;
		//
		};
	//printf("the grid:\n");
	//printGrid(grids, 1, xmax, ymax);
	//
	// cluster map moved to a function:
//	unsigned int biggestFire = getClustMaps1(bigClustMaps);
	unsigned int biggestFire = xmax0*ymax0;
	// now, the cluster map is established. as we plant trees, we will plant against this grid.
	//
	// seed the grid with some trees:
	Rand treeSeedx(rSeed + drSeed);
		drSeed ++;
	Rand treeSeedy(rSeed + drSeed);
		drSeed ++;
	// particularly for dendritic models, how many seeds to we want? in the purest form, we want 1, but that will take a LONG time to get started.
	for (unsigned int i=0; i < xmax; i++) {
		// seed the grid with some trees
		//if (rand()%(xmax)==1 and i%(xmax+2)!=0 and (i+1)%(xmax+2)!=0 and i>(xmax+2) and i<((xmax+2)*(ymax+1)) ) grids[i]++;
		int thisX = treeSeedx.nextInt(xmax);
		int thisY = treeSeedy.nextInt(ymax);
		//thisClust = clustGrids[(xmax+2)*(thisY+1)+thisX+1];
		//grids[(xmax+2)*(thisY+1)+thisX+1] = thisClust;
		//thisClust = *(bigClustMaps + (xmax+2)*(thisY+1)+thisX+1);
		*(grids + (xmax+2)*(thisY+1)+thisX+1) = 1;		
		//yodapause();
		};
	//printf("random grid established...\n");
	//printGrid(&grids[0], 1, xmax, ymax);
	//
	char DB[]="ForestFire";
	char HOST[]="localhost";
	char USER[]="myoder";
	char PASSWORD[]="yoda";
	mysqlpp::Connection myconn(DB, HOST, USER, PASSWORD);
	mysqlpp::Query myquery=myconn.query();
	mysqlpp::Result res1;
	//int intKey;
	//unsigned int fcounts[xmax*ymax];
	//unsigned int *fcounts = new unsigned int[xmax*ymax];
	unsigned int *fcounts = new unsigned int[biggestFire];
		for (unsigned int i=0; i<biggestFire; i++) {
			//fcounts[i]=0;
			*(fcounts + i) = 0;
			};
	if (doSQL==1 or doSQL==5) {	
		//
		// insert a new row for this sim-run:
		myquery.reset();
		printf("insert simprams.\n");
		//myquery << "insert into ForestFire.SimPrams (SimName, SimSW, xmax, ymax, sparkInterval, sparkProb, burnAge, propAge, tmax, wrapX, wrapY, Comment) values (%0q, %1q, %2q, %3q, %4q, %5q, %6q, %7q, %8q, %9q, %10q, %11q )";
		myquery << "insert into ForestFire.SimPrams (SimName, SimSW, xmax, ymax, sparkInterval, tmax, nRand, nClust, kmax, Comment) values (%0q, %1q, %2q, %3q, %4q, %5q, %6q, %7q, %8q, %9q)";
		myquery.parse();
		// note: simIndex(auto-int) and dtTime (default TIMESTAMP) set automatically.
		myquery.execute(simName.c_str(), simName.c_str(), xmax, ymax, fMatch, tmax, nRand, nClust, kmax, simPramComment.c_str());
		//
		// now, get the integer key for this simulation:
		// note that this could be accomplished with one call (optimal if MySQL calls have high overhead)
		// by writing a SPROC on the MySQL side.
		// also see the mysql_insert_id() (C API) and LAST_INSERT_ID() (SQL) functions, by which we should be ablt to automatically retrieve the indexID.
		myquery.reset();
		printf("fetch simIndex.\n");
		myquery << "select max(simIndex) from ForestFire.SimPrams where simName=%0q and simSW=%1q";
		myquery.parse();
		res1 = myquery.store(simName.c_str(), simName.c_str());
		intKey = res1.at(0).at(0);
		}; // doSQL

/*
	if (doSQL==1 or doSQL==5) {	
		//
		// insert a new row for this sim-run:
		myquery.reset();
		printf("insert simprams.\n");
		myquery << "insert into ForestFire.SimPrams (SimName, SimSW, xmax, ymax, sparkInterval, sparkProb, burnAge, propAge, tmax, wrapX, wrapY, Comment) values (%0q, %1q, %2q, %3q, %4q, %5q, %6q, %7q, %8q, %9q, %10q, %11q )";
		myquery.parse();
		// note: simIndex(auto-int) and dtTime (default TIMESTAMP) set automatically.
		myquery.execute(simName.c_str(), simName.c_str(), xmax, ymax, fmatch, pMatch, burnAge, burnPropAge, tmax, wrapx1, wrapy1, simPramComment.c_str());
		//
		// now, get the integer key for this simulation:
		// note that this could be accomplished with one call (optimal if MySQL calls have high overhead)
		// by writing a SPROC on the MySQL side.
		// also see the mysql_insert_id() (C API) and LAST_INSERT_ID() (SQL) functions, by which we should be ablt to automatically retrieve the indexID.
		myquery.reset();
		printf("fetch simIndex.\n");
		myquery << "select max(simIndex) from ForestFire.SimPrams where simName=%0q and simSW=%1q";
		myquery.parse();
		res1 = myquery.store(simName.c_str(), simName.c_str());
		intKey = res1.at(0).at(0);
		}; // doSQL
*/
	//
	for (unsigned int i=0; i<=tmax; i++) {
		//
		// first do the sheep:
		// note, we can remove sheep by setting sheepSpeed=0
		for (unsigned short isheep = 0; isheep<sheepSpeed; isheep++) {
			switch (*(grids+sheepPos)) {
				case 0: case rockAge:
					// move:
					sheepPos = sheepPos + getRandDir((xmax+2), sheepRand);
					break;
				case 1:
					// eat:
					*(grids+sheepPos)=0;
					break;
				default:
					// nothing.
					break;
				};
			//
			// are we outside the grid or on an illegal spot?
			if (sheepPos<=(xmax+2) or sheepPos>((xmax+2)*(ymax+1)) or sheepPos%(xmax+2)==0 or sheepPos%(xmax+1)==0) {
				// we've wandered off the grid; get new sheep.
				sheepPos = (xmax+2) + 1 + sheepRand.nextInt(xmax) + (xmax+2)*sheepRand.nextInt(ymax);
				};
			}; // sheep-speed
		//
		//if (doSQL==5 or doSQL==6) if(i%1000000 == 0) printf("%d million\n", i/1000000);
		if (doSQL==6) if(i%1000000 == 0) printf("%d million\n", i/1000000);

		if (doSQL==16) {
			if(i%100000 == 0) {
				// printf("%d million\n", i/1000000);
				aveRho=0;
				aveVol=0;
				for (unsigned int k=0; k<(xmax+2)*(ymax+2); k++) {
					if (*(grids+k)>0 and *(grids+k)<rockAge) {
						aveRho = aveRho + 1;
						aveVol = aveVol + *(grids+k);
						};
					};
				//printf("mils,\t Rho,\t Vol,\t %d, %f, %f\n", i/1000000, float(aveRho)/float(xmax*ymax), float(aveVol)/float(xmax*ymax));
				printf("%d, %f, %f\n", i/1000000, float(aveRho)/float(xmax*ymax), float(aveVol)/float(xmax*ymax));
				};
			};
		//
		// PLANT A TREE:
		// select a grid for tree planting:
		// yoder, v7: introduce dendritic growth. we have two prams, nRand, nClst. define a P(rand)-> Pr, P(clust)->Pc: Pr=nRand/(nRand+nClust), etc.
		//for (unsigned int irp=0; irp<randPlant; irp++) {
		thisX = plantRandx.nextInt(xmax);
		thisY = plantRandy.nextInt(ymax);
		gridPos = (xmax+2)*(thisY+1)+1+thisX;
		//
		// what is the grid value? if it's empty, plant against P=nRand/(nRand+nClust); if it's a tree, plant each adjacent grid with nR/(nR+nC)
		switch (*(grids+gridPos)) {
			case 0:
				// planting stats:
				if (rcPlant.nextDouble() <= nRand) {
					*(grids+gridPos) = 1;
					};
				break;
			case 1:
				if (rcPlant.nextDouble() <= float(nClust)/float(nClust+nRand) and *(grids+gridPos + 1)==0) {
					*(grids+gridPos+1) = 1;
					};
				if (rcPlant.nextDouble() <= float(nClust)/float(nClust+nRand) and *(grids+gridPos - 1)==0) {
					*(grids+gridPos-1) = 1;
					};
				if (rcPlant.nextDouble() <= float(nClust)/float(nClust+nRand) and *(grids+gridPos + (xmax+2))==0) {
					*(grids+gridPos+(xmax+2)) = 1;
					};
				if (rcPlant.nextDouble() <= float(nClust)/float(nClust+nRand) and *(grids+gridPos - (xmax+2))==0) {
					*(grids+gridPos-(xmax+2)) = 1;
					};
				break;
			};
		//
// debug:
//		if (i%10000==0) {
//			plotGridSimple (grids, i, xmax, ymax);
//			};

	// we've planted a tree. do we throw a match?
	// a 1 in fMatch chance (use any value between 0 and fMatch)
		if (rfMatch.nextInt(fMatch) == 1) {
			//yodapause();
			// throw a match.
			xFire = fireRandx.nextInt(xmax) + 1;
			yFire = fireRandy.nextInt(ymax) + 1;
			//
			fireSquare = grids + (xmax+2)*yFire + xFire;
			//printf("match: (%d, %d) :: %d\n", xFire, yFire, *fireSquare);
			//yodapause();
			//
			if (*fireSquare > 0 and *fireSquare<rockAge) {
				// initiate a new fire.
				// start from the epicenter and work out in concentric rectangles (squares)
				// until there are no new fires.
				// note: we make two passes over each circle. for now, we assume all squares
				// continue to burn until the fire is over. this is a subtle consideration that
				// will not matter for simpler versions of the model, but if we introduce burn probabilities,
				// we will have to be more careful.

				//burningClust = clustGrids[(xmax+2)*yFire + xFire];
				//burningClust = *(bigClustMaps + (xmax+2)*yFire + xFire);
				*fireSquare=-(*fireSquare);	// the fire-square starts burning
				//
				rFire = 1;
				dnBurning = 1;
				//
				nBurning = dnBurning;
				int yFireMin = int(yodacode::greaterOf((yFire-rFire), 1));	// we always start with a 1 squar boundary. we might, however, encounter the edges.
				int yFireMax = int(yodacode::lesserOf((yFire+rFire), float(ymax)));
				int xFireMin = int(yodacode::greaterOf(float(xFire-rFire), 1));
				int xFireMax = int(yodacode::lesserOf(float(xFire+rFire), float(xmax)));
				//printf("fire range: %d, %d, %d, %d\n", yFireMin, yFireMax, xFireMin, xFireMax);
				//printf("preplot\n.");
				//
				//plotGrid(&grids[0],i, xmax, ymax);
				if (doSQL==0) {
					printGrid(grids, i, xmax, ymax);
					};
				//while (dnBurning > 0) {
				while (dnBurning > 0) {
					dnBurning=0;
					for (char doTwice = 0; doTwice <=1; doTwice++) {	// "char" is a 1 byte integer. we could also use a boolean to count to 2.
					for (int iy = (yFireMin); iy <= (yFireMax); iy++) {
						for (int ix = (xFireMin); ix <= (xFireMax); ix++) {
							// also note: Gelb is right. a recursive approach is faster, though this bredth-first appraoch is more like real fire propagation.
							// printf("try-burn: %d, %d\n", ix, iy);
							//plotGrid(&grids[0], xmax, ymax);
							//yodapause();
							//
							int * centerGrid = (grids + ix + (xmax+2)*iy);
							int cStat, uStat, dStat, lStat, rStat;
							//int ulStat, urStat, llStat, lrStat;	// diagonal elements.
							cStat = *centerGrid;
							//
							uStat = *(centerGrid + (xmax+2));
							dStat = *(centerGrid - (xmax+2));
							lStat = *(centerGrid - 1);
							rStat = *(centerGrid + 1);
							//
							// diagonal elements:
							//ulStat = getGridStatus(*(centerGrid + (xmax+2) - 1), i);
							//urStat = getGridStatus(*(centerGrid + (xmax+2) + 1), i);
							//llStat = getGridStatus(*(centerGrid - (xmax+2) - 1), i);
							//lrStat = getGridStatus(*(centerGrid - (xmax+2) + 1), i);
							//yodapause();
								//if (*centerGrid >= burnAge and (*leftGrid==-1 or *rightGrid==-1 or *upGrid==-1 or *downGrid==-1)) {
								//if (*centerGrid >= burnAge and (*leftGrid<=-burnPropAge or *rightGrid<=-burnPropAge or *upGrid<=-burnPropAge or *downGrid<=-burnPropAge)) {
								//if (cStat >= burnAge and cStat < rockAge and (lStat<=-burnPropAge or rStat<=-burnPropAge or uStat<=-burnPropAge or dStat<=-burnPropAge)) {
								//
							// no immunity:
							if (cStat >= 1 and cStat < rockAge 
								and (lStat<=-1 or rStat<=-1 or uStat<=-1 or dStat<=-1) )
								{
	//
	//						// next nearest neighbors:
	//						if (cStat >= burnAge and cStat < rockAge 
	//							and  ( (lStat<=-burnPropAge or rStat<=-burnPropAge or uStat<=-burnPropAge or dStat<=-burnPropAge)
	//								 or ( (ulStat<=-nnnAge or urStat<=-nnnAge  or llStat<=-nnnAge  or lrStat<=-nnnAge)
	//									 and (ulStat<=-burnPropAge or urStat<=-burnPropAge or llStat<=-burnPropAge  or lrStat<=-burnPropAge)
	//									 )
	//						 		)
	//							) {
								*centerGrid = -(*centerGrid);
								// age -> number of trees in that grid...
								dnBurning ++;
								//printf("[%d, %d] catches from [%d, %d]\n", ix, iy, xFire, yFire);
								};
							}; // ix
						}; // iy
						}; // doTwice	
						// plotGridSimple (grids, i, xmax, ymax);
						nBurning = nBurning + dnBurning;
						//yodapause();
					xFireMin = int(yodacode::greaterOf(1, float(xFireMin-1)));
					xFireMax = int(yodacode::lesserOf(float(xmax), xFireMax+1));
					yFireMin = int(yodacode::greaterOf(1, float(yFireMin-1)));
					yFireMax = int(yodacode::lesserOf(float(ymax), yFireMax+1));
					// g1.plot_xy(vfireX, vfireY, "");
					};	// end "while" fire still burining
				//
				nFires++;
				nBurnedTotal = nBurnedTotal + nBurning;
				fcounts[nBurning-1]++;
			//	plotGrid(&grids[0], xmax, ymax);
				if (doSQL==0) {
					printGrid(&grids[0], i, xmax, ymax);
					printf("fire size, vol, nFires, totalBurned, totalVol: (%d) (%d) (%d)\n", nBurning, nFires, nBurnedTotal);
					};
				// write fire to MySQL:
				if (doSQL==1) {
					printf("fire size, nFires, totalBurned: (%d) (%d) (%d)\n", nBurning, nFires, nBurnedTotal);
	//				myquery.reset();
	//				myquery << "insert into ForestFire.ForestFires (simIndex, t, xSpark, ySpark, AveTreeAge, nBurned) values (%0q, %1q, %2q, %3q, %4q, %5q) ";
	//				myquery.parse();
	//				myquery.execute(intKey, i, xFire, yFire, aveTreeAge, nBurning);
					};
				if (doSQL==3) {
					printf("fire (%d) at time %d\n",nBurning, i);
					if (nBurning>=10) plotGridSimple (grids, i, xmax, ymax);
					};
				if (doSQL==4) {
					if (nBurning>=10) plotGridImg (grids, i, xmax, ymax, burnPropAge);
					};
				//
				// fires finished burning; extinguish:
				for (int iy = (yFireMin); iy <= (yFireMax); iy++) {
					for (int ix = (xFireMin); ix <= (xFireMax); ix++) {
						// &grids[0] + ix + (xmax+2)*iy
						//if (grids[ix + (xmax+2)*iy] < 0) grids[ix + (xmax+2)*iy]=0;
						if (*(grids +ix + (xmax+2)*iy) < 0) *(grids +ix + (xmax+2)*iy)=0;
						};
					};
				}; //else printf("no tree at match point.\n");	// if match -> tree...
			}; // if match-time
		};	// end sim-steps.
	// end simulation.
	//printf("doSQL: %d\n", doSQL);
	// doSQL's:
	// 0: 'print-grid" fires
	// 1: full SQL: insert each forest fire data-set into ForestFires
	// 2: print summary to screen. use this for direct gnuplot calls, " plot '<./ffire4...'" 
	// 3: Print each fire to screen; "plotGrid" each fire nBurning>(25) print summary to screen at end
	// 4: plotGridImg each fire nBurning>(20); print summary to screen,
	// 5: SQL: insert just summary data to SQL; prints progress by million (will screw up plotting)
	// 6: report summary, progress by million.
	// 11: return to standard-output the last grid in full. use to make an image of the final grid.
	//
	// end-o-run summaries (print):
	if (doSQL==2 or doSQL==3 or doSQL==4 or doSQL==6) {
		for (unsigned int i=0; i<(biggestFire); i++) {
			//if (fcounts[i]!=0) printf("%d\t%d\n", i+1, fcounts[i]);
			if (*(fcounts + i) != 0) printf("%d\t%d\n", i+1, *(fcounts + i));
			//printf("%d,\t%d\n", i+1, fcounts[i]);
			};
		} else {
			//printf("finished.\nfire size, nFires, totalBurned: (%d) (%d) (%d)\n", nBurning, nFires, nBurnedTotal);
			};
	if (doSQL==5 ) { // no plots, just a summary -> SQL
		//
		for (unsigned int i=0; i<(biggestFire); i++) {
			// if (fcounts[i]!=0) printf("%d\t%d\n", i+1, fcounts[i]);
		//	printf ("sql bits: %d, %d, %d, %d\n", intKey, tmax, i+1, fcounts[i]);
			myquery.reset();
			myquery << "insert into ffcounts (simIndex, tmax, nBurned, nEvents) values (%0q, %1q, %2q, %3q)";
			myquery.parse();
			myquery.execute(intKey, tmax, i+1, fcounts[i]);
			//printf("%d,\t%d\n", i+1, fcounts[i]);
			};				
		};
	// return the final grid in full and give an average density at the end...?
	if (doSQL==11) {
		for (unsigned int i=0; i<(xmax+2)*(ymax+2); i++) {
			printf ("%d,\t%d,\t%d\n", i-int(i/(xmax+2))*(xmax+2), i/(xmax+2), getGridStatus(*(grids+i), tmax));
			};
		};

	//yodacode::yodapause();
	return 0;
	//return &grids[0];
	};
void btpCharacterController_c::update( const class vec3_c& dir )
{
	// set the forward direction of the character controller
	btVector3 walkDir( dir[0]*QIO_TO_BULLET, dir[1]*QIO_TO_BULLET, dir[2]*QIO_TO_BULLET );
	ch->setWalkDirection( walkDir );
}
Пример #7
0
int main(int argc, char **argv) {

    fprintf(stderr, "hello world\n");

    // this can hold blockcounts:
    //    uint64_t blockCounts[256];
    // We need 128 of these, hold block counts for each level
    const size_t toMalloc = 256*sizeof(uint64_t) * 128;
    //                      [ table size       ] * [num tables]
    fprintf(stderr, "mallocing %d bytes of memory to block tables... ", toMalloc);
    char * blockTable = (char*)malloc(toMalloc);
    fprintf(stderr, "ok.\n");
    fprintf(stderr, "clearing... ");
    memset(blockTable, 0, toMalloc);
    fprintf(stderr, "ok.\n");

    walkDir(argv[1], blockTable);


    fprintf(stderr, "\n-- REPORT --\n");
    //fprintf(stderr, "Read %u chunks\n", numChunks);

    printReport("data.js", blockTable); 

    free(blockTable);
    
    /*  Test code:  TODO, move this elsewhere

    printf("read in %d bytes: %d\n", r, (unsigned int)(*buf));

    char t[256] = "\x00\x00\x00\x01\x00\x09\x00\x05hello\x00\x00\x00\x06\x01\x02\x03\x04\x05\x06\x12"; 
    char *test = t;

    NBT_Int i(test);
    printf("int val=%d\n", i.getValue());
    assert(i.getValue() == 1);
    test += i.size;

    NBT_Short s(test);
    printf("short val=%d\n", s.getValue());
    assert(s.getValue() == 9);
    test+=s.size;

    NBT_String str(test);
    printf("str val=%s\n", str.getString().c_str());
    assert(strncmp(str.getString().c_str(), "hello", 5) == 0);
    test += str.size;
    assert(str.size == 7);

    NBT_Byte_Array ba(test);
    assert(ba.size == (4+6));
    assert(ba.length() == 6);
    assert(memcmp(ba.buff, "\x01\x02\x03\x04\x05\x06", 6) == 0);
    test += ba.size;
        
    NBT_Byte b(test);
    assert(b.getByte() == 0x12);
    assert(b.size == 1);
    test += b.size;


    char t2[256] = "\x09\x00\x06mylist\x02\x00\x00\x00\x04\x00\x01\x00\x02\x00\x03\x00\x04";

    test = t2;
    test += 1; 
    NBT_String t_name(test);
    test += t_name.size;

    printf("name: %s\n", t_name.getString().c_str());

    NBT_List l(test);
    assert(l.getListType() == TAG_Short);
    assert(l.getList().size() == 4);

    printf("start Compounttest:\n");

    char t3[256] = "\x01\x00\x04\x42yte\xab\x03\x00\x05myint\x00\x00\x00\x08\x02\x00\x07myshort\x00\xff\x00";
    test = t3;
    NBT_Compound cmp(test);


    printf("real data test\n----\n");

    test = buf;
    test++;
    NBT_String buf_string(test);
    test += buf_string.size;
    printf("compound name: %s\n", buf_string.getString().c_str());

    NBT_Compound buf_compound(test);
    buf_compound.name = buf_string.getString();
    printf("\n\n");

    buf_compound.print(0);

    list<NBT_Tag*> listlist = buf_compound.getList();


    //t->print();
    //free(testbuf);
    */
    return 0;
}