Beispiel #1
0
/* generates object names, if they are missing */
static int generate_names(DATAFILE *dat, int n)
{
   int i;

   while (dat->type != DAT_END) {
      if (!*get_datafile_property(dat, DAT_NAME)) {
	 char tmp[32];

	 sprintf(tmp, "%03d_%c%c%c%c", n++,
			(dat->type>>24)&0xFF, (dat->type>>16)&0xFF,
			(dat->type>>8)&0xFF, dat->type&0xFF);

	 for (i=4; tmp[i]; i++) {
	    if (((tmp[i] < '0') || (tmp[i] > '9')) &&
		((tmp[i] < 'A') || (tmp[i] > 'Z')) &&
		((tmp[i] < 'a') || (tmp[i] > 'z')))
	       tmp[i] = 0;
	 }

	 datedit_set_property(dat, DAT_NAME, tmp);
      }

      if (dat->type == DAT_FILE)
	 n = generate_names((DATAFILE *)dat->dat, n);

      dat++;
   }
Beispiel #2
0
// create a (huge) triangle Mesh with a cube map
GObject *CreateSkybox(char *sbname,
					  char *dirname) {

	static const int A = 1000.0;
	float A2 = 0.5f * A;
	TriangleMesh *mesh;
	Texture *ctex;
	GObject *gobj;
	int len;
	char **names;

	mesh = CreateVoidTriangleMesh();

	AddPointTMesh(mesh, -A, -A2, A);  // P0
	AddPointTMesh(mesh,  A, -A2, A);  // P1
	AddPointTMesh(mesh,  A, A2, A);  // P2
	AddPointTMesh(mesh, -A, A2, A);  // P3
	AddPointTMesh(mesh, -A, -A2,  -A);  // P4
	AddPointTMesh(mesh,  A, -A2,  -A);  // P5
	AddPointTMesh(mesh,  A, A2,  -A);  // P6
	AddPointTMesh(mesh, -A, A2,  -A);  // P7

	// front
	AddTriangleTMesh(mesh, 0, 1, 2); // P0 - P1 - P2
	AddTriangleTMesh(mesh, 2, 3, 0); // P2 - P3 - P0
	// back
	AddTriangleTMesh(mesh, 5, 4, 7);
	AddTriangleTMesh(mesh, 7, 6, 5);
	// left
	AddTriangleTMesh(mesh, 4, 0, 3);
	AddTriangleTMesh(mesh, 3, 7, 4);
	// right
	AddTriangleTMesh(mesh, 1, 5, 6);
	AddTriangleTMesh(mesh, 6, 2, 1);
	// top
	AddTriangleTMesh(mesh, 3, 2, 6);
	AddTriangleTMesh(mesh, 6, 7, 3);
	// bottom
	AddTriangleTMesh(mesh, 4, 5, 1);
	AddTriangleTMesh(mesh, 1, 0, 4);

	// Create cube map texture and assign.

	names = generate_names(dirname);
	ctex = SceneRegisterCubeMapTexture(sbname,
									   names[0], names[1],
									   names[2], names[3],
									   names[4], names[5]);
	SetTextureMaterial(mesh->materialFront, ctex);
	gobj = SceneRegisterVoidGObject("SKYBOX/", sbname);
	AddPatchGObject(gobj, mesh);
	return gobj;
}
int main(int argc, char *argv[])
{
	struct option long_option[] =
	{
		{"help", 0, NULL, 'h'},
		{"file", 1, NULL, 'f'},
		{"force", 0, NULL, 'F'},
		{"debug", 0, NULL, 'd'},
		{"version", 0, NULL, 'v'},
		{NULL, 0, NULL, 0},
	};
	char *cfgfile = SYS_ASOUNDRC;
	int res;

	command = argv[0];
	while (1) {
		int c;

		if ((c = getopt_long(argc, argv, "hf:Fdv", long_option, NULL)) < 0)
			break;
		switch (c) {
		case 'h':
			help();
			return EXIT_SUCCESS;
		case 'f':
			cfgfile = optarg;
			break;
		case 'F':
			force_restore = 1;
			break;
		case 'd':
			debugflag = 1;
			break;
		case 'v':
			printf("alsactl version " SND_UTIL_VERSION_STR "\n");
			return EXIT_SUCCESS;
		case '?':		// error msg already printed
			help();
			return EXIT_FAILURE;
			break;
		default:		// should never happen
			fprintf(stderr, 
			"Invalid option '%c' (%d) not handled??\n", c, c);
		}
	}
	if (argc - optind <= 0) {
		fprintf(stderr, "alsactl: Specify command...\n");
		return 0;
	}

	if (!strcmp(argv[optind], "store")) {
		res =  save_state(cfgfile,
		   argc - optind > 1 ? argv[optind + 1] : NULL);
	} else if (!strcmp(argv[optind], "restore")) {
		res = load_state(cfgfile, 
		   argc - optind > 1 ? argv[optind + 1] : NULL);
	} else if (!strcmp(argv[optind], "names")) {
		if (!strcmp(cfgfile, SYS_ASOUNDRC))
			cfgfile = SYS_ASOUNDNAMES;
		res = generate_names(cfgfile);
	} else {
		fprintf(stderr, "alsactl: Unknown command '%s'...\n", 
			argv[optind]);
		res = -ENODEV;
	}

	return res < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}