Exemple #1
0
int AA_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
	int keyboard;
	int i;

	/* Initialize all variables that we clean on shutdown */
	for ( i=0; i<SDL_NUMMODES; ++i ) {
		SDL_modelist[i] = SDL_malloc(sizeof(SDL_Rect));
		SDL_modelist[i]->x = SDL_modelist[i]->y = 0;
	}
	/* Modes sorted largest to smallest */
	SDL_modelist[0]->w = 1024; SDL_modelist[0]->h = 768;
	SDL_modelist[1]->w = 800; SDL_modelist[1]->h = 600;
	SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480;
	SDL_modelist[3]->w = 320; SDL_modelist[3]->h = 400;
	SDL_modelist[4]->w = 320; SDL_modelist[4]->h = 240;
	SDL_modelist[5]->w = 320; SDL_modelist[5]->h = 200;
	SDL_modelist[6] = NULL;

	/* Initialize the library */

	AA_mutex = SDL_CreateMutex();

	aa_parseoptions (NULL, NULL, NULL, NULL);

	AA_context = aa_autoinit(&aa_defparams);
	if ( ! AA_context ) {
		SDL_SetError("Unable to initialize AAlib");
		return(-1);
	}

	/* Enable mouse and keyboard support */

	if ( ! aa_autoinitkbd (AA_context, AA_SENDRELEASE) ) {
		SDL_SetError("Unable to initialize AAlib keyboard");
		return(-1);
	}
	if ( ! aa_autoinitmouse (AA_context, AA_SENDRELEASE) ) {
		fprintf(stderr,"Warning: Unable to initialize AAlib mouse");
	}
	AA_rparams = aa_getrenderparams();

	local_this = this;

	aa_resizehandler(AA_context, AA_ResizeHandler);

	fprintf(stderr,"Using AAlib driver: %s (%s)\n", AA_context->driver->name, AA_context->driver->shortname);

	AA_in_x11 = (SDL_strcmp(AA_context->driver->shortname,"X11") == 0);
	/* Determine the screen depth (use default 8-bit depth) */
	vformat->BitsPerPixel = 8;
	vformat->BytesPerPixel = 1;

	/* We're done! */
	return(0);
}
Exemple #2
0
static gboolean
gst_aasink_open (GstAASink * aasink)
{
  if (!aasink->context) {
    aa_recommendhidisplay (aa_drivers[aasink->aa_driver]->shortname);

    aasink->context = aa_autoinit (&aasink->ascii_surf);
    if (aasink->context == NULL) {
      GST_ELEMENT_ERROR (GST_ELEMENT (aasink), LIBRARY, TOO_LAZY, (NULL),
          ("error opening aalib context"));
      return FALSE;
    }
    aa_autoinitkbd (aasink->context, 0);
    aa_resizehandler (aasink->context, (void *) aa_resize);
  }
  return TRUE;
}
Exemple #3
0
int main(int argc, char **argv) {
	int help_flag = 0;
	int aahelp_flag = 0;
	int justoutput_flag = 0;
	int loadavg_flag = 0;
	int ipc_flag = 0;
	int port_num = DEFPORT;
	int max_iterations = 0;
	int delay = 0;
	int normal_load;
	int socket_fd = -1;
	float randomizestyletime = 0;
	float randomizesitetime  = 0;
	char *endptr;

	setlocale(LC_ALL, "");
	bindtextdomain("aajm", LOCALEDIR);
	textdomain("aajm");

	char options[] = "aljhip:n:d:m:t:s:T:S:";
	static struct option long_options[] =
        {
		{"help", no_argument, &help_flag, 1},
		{"aahelp", no_argument, &aahelp_flag, 1},
		{"justoutput", no_argument, &justoutput_flag, 1},
		{"ipc", no_argument, &ipc_flag, 1},
		{"loadavg", no_argument, &loadavg_flag, 1},
		{"maxiterations", required_argument, 0, 'm'},
		{"port", required_argument, 0, 'p'},
		{"normalload", required_argument, 0, 'n'},
		{"delay", required_argument, 0, 'd'},
		{"siteswap", required_argument, 0, 's'},
		{"style", required_argument, 0, 't'},
		{"rstyle", required_argument, 0, 'S'},
		{"rsiteswap", required_argument, 0, 'T'},
		{0,0,0,0}
	};

	normal_load = (int)(DEFLOAD * 100);
	char optch;
	int option_index = 0;

	//jmlib = new JMLib(errorCB);
    jmlib = JMLib::alloc();
	jmlib->setPatternDefault();
	jmlib->setStyleDefault();
	jmlib->startJuggle();

	aa_parseoptions(NULL, NULL, &argc, argv);

	while( (optch = getopt_long(argc,argv,options,
			long_options,&option_index)) != -1)
		switch(optch) {
			case 's':
				jmlib->setPattern("Something",optarg,
					HR_DEF, DR_DEF);
				break;
			case 't':
				jmlib->setStyle(optarg);
				break;
			case 'S':
				randomizesitetime = strtod(optarg, &endptr);
				if (endptr==optarg || *endptr != 0) {
						randomizesitetime = DEFRANDOMSITETIME;
				}
				break;
			case 'T':
				randomizestyletime = strtod(optarg, &endptr);
				if (endptr==optarg || *endptr != 0) {
						randomizestyletime = DEFRANDOMSTYLETIME;
				}
				break;
			case 'h':
				help_flag=1;
				break;
			case 'a':
				aahelp_flag=1;
				break;
			case 'j':
				justoutput_flag=1;
				break;
			case 'm':
				max_iterations = atoi(optarg);
				break;
			case 'd':
				delay = atoi(optarg);
				break;
			case 'l':
				loadavg_flag=1;
				break;
			case 'n':
				normal_load = (int)(100*atof(optarg));
				break;
			case 'i':
				ipc_flag=1;
				break;
			case 'p':
				port_num=atoi(optarg);
				break;
		}

	if(aahelp_flag || help_flag) {
		printf(gettext("AAJM, An ASCII Art Juggling program\n"));
		printf(gettext("Usage: %s [OPTIONS]\n"),argv[0]);
	}
	if(help_flag) {
		printf(gettext("Jugglemaster Options:\n"));
		printf(gettext("  -s, --siteswap=XX          show siteswap XX (3)\n"));
		printf(gettext("  -t, --style=XX             use style XX (\"Normal\")\n"));
		printf(gettext("  -S, --rsiteswap=XX         Randomize siteswap every XX seconds (%f)\n"), DEFRANDOMSITETIME);
		printf(gettext("  -T, --rstyle=XX            Randomize style every XX seconds (%f)\n"), DEFRANDOMSTYLETIME);
		printf(gettext("  -d, --delay=XX             delay XX ms between frames (%i)\n"), (int)DEFSPEED/1000);
		printf(gettext("  -m, --maxiterations=XX     do at most XX iterations\n"));
		printf(gettext("  -j, --justoutput           only output [don't init kb or mouse]\n"));
		printf(gettext("  -i, --ipc                  enable IPC\n"));
		printf(gettext("  -p, --port=XX              use port XX for IPC (%i)\n"),DEFPORT);
		printf(gettext("  -l, --loadavg              change speed based on load average\n"));
		printf(gettext("  -n, --normalload=XX        a normal load average for your machine (%2.2f)\n"),DEFLOAD);
		printf(gettext("  -h, --help                 get help [this screen]\n"));
		printf(gettext("  -a, --aahelp               get help on AA options\n\n"));
	}
	if(aahelp_flag) {
		printf(gettext("AALib Options:\n%s\n\n"),aa_help);
	}
	if(aahelp_flag || help_flag) {
		return 0;
	}


	context = aa_autoinit(&aa_defparams);
	if (context == NULL) {
		printf(gettext("Failed to initialize aalib\n"));
		exit(1);
	}

	if(!justoutput_flag) {
		aa_autoinitkbd(context, 0);
		aa_hidecursor(context);
	}
	params = aa_getrenderparams();
	jmlib->setWindowSize(aa_imgwidth(context),aa_imgheight(context));
	jmlib->startJuggle();

	aa_resizehandler(context, resizehandler);

	if(loadavg_flag) {
		/* If we're doing that thing where we care, then this
			can go down to as-low-as-possible priority */
		nice(19);
	}

	if(ipc_flag) {
		socket_fd = startlistening(port_num);
	}

	main_loop(max_iterations,delay,loadavg_flag,normal_load, socket_fd,
                  randomizestyletime, randomizesitetime);

	if(socket_fd > 0) {
		stoplistening(socket_fd);
	}
	aa_close(context);

	delete jmlib;
	return 1;
}