Example #1
0
int write_C(char * file, char * argv[])
{
	FILE * o;
	char buf[SIZE];
	int l;

	sprintf(buf, "%s.x.c", file);
	o = fopen(buf, "w");
	if (!o)
		return -1;
	srand((unsigned)time(NULL));
	fprintf(o, "#if 0\n");
	fprintf(o, "\t%s %s, %s\n", my_name, version, subject);
	fprintf(o, "\t%s %s %s %s\n\n\t", cpright, author.f, author.s, author.e);
	for (l = 0; argv[l]; l++)
		fprintf(o, "%s ", argv[l]);
	fprintf(o, "\n#endif\n\n");
	fprintf(o, "static  long date = %ld;\n", date);
	fprintf(o, "static  char mail[] = \"%s\";\n", mail);
	fprintf(o, "static  int  relax = %d;\n", relax);
	l = noise(buf, 256, 256, 0);
	dump_array(o, buf, "pswd", l);
	state_0();
	key(buf, l);
	dump_array(o, strdup(shll), "shll", strlen(shll) + 1);
	dump_array(o, inlo, "inlo", strlen(inlo) + 1);
	dump_array(o, xecc, "xecc", strlen(xecc) + 1);
	dump_array(o, lsto, "lsto", strlen(lsto) + 1);
	l = noise(buf, 8, 8, 1);
	fprintf(o, "#define TEXT_%s	\"%s\"\n", "chk1", buf);
	dump_array(o, buf, "chk1", l + 1);
	if (!relax && key_with_file(shll)) {
		fprintf(stderr, "%s: invalid file name: %s", my_name, shll);
		perror("");
		exit(1);
	}
	dump_array(o, opts, "opts", strlen(opts) + 1);
	dump_array(o, text, "text", strlen(text) + 1);
	l = noise(buf, 8, 8, 1);
	fprintf(o, "#define TEXT_%s	\"%s\"\n", "chk2", buf);
	dump_array(o, buf, "chk2", l + 1);
	fprintf(o, "typedef char %s_t[%d];\n\n", "hide", 1<<12);
	fprintf(o, DEBUGEXEC_line, DEBUGEXEC_flag);
	fprintf(o, TRACEABLE_line, TRACEABLE_flag);
	for (l = 0; RTC[l]; l++)
		fprintf(o, "%s\n", RTC[l]);
	fflush(o);
	fclose(o);
	return 0;
}
Spacetime::Spacetime(void) 
{
	// Required physX runtime variable initializations
	gScene = NULL;
	gPhysics = NULL;
	gMaterial	= NULL;
	gFoundation = NULL;
	gDispatcher = NULL;
	gConnection	= NULL;
	deltaT = 1.0f / 600.0f;

	ANALYTIC = true;
	numTimeSteps = 10000;
	uThreshold = 10;

	initPhysics();

	state_0 = matrix<double>(DOF*joints.size()*2,1);
	state_d = matrix<double>(DOF*joints.size()*2,1);
		
	if (DOF == 1) {
		state_0(0,0) = -PxPi/4.0f;
		state_0(1,0) =  PxPi/4.0f;
		state_0(2,0) =  0.0f;
		state_0(3,0) =  0.0f;
		
		state_d(0,0) = 0.0f;
		state_d(1,0) = 0.0f;
		state_d(2,0) = 0.0f;
		state_d(3,0) = 0.0f;
	} 
	else if (DOF == 3) {
		state_0(0,0) = -PxPi/4.0f;
		state_0(1,0) =  0.0f;
		state_0(2,0) =  0.0f;
		state_0(3,0) =  PxPi/4.0f;
		state_0(4,0) =  0.0f;
		state_0(5,0) =  0.0f;
		state_0(6,0) =  0.0f;
		state_0(7,0) =  0.0f;
		state_0(8,0) =  0.0f;
		state_0(9,0) =  0.0f;
		state_0(10,0) = 0.0f;
		state_0(11,0) = 0.0f;

		state_d(0,0) = 0.0f;
		state_d(1,0) = 0.0f;
		state_d(2,0) = 0.0f;
		state_d(3,0) = 0.0f;
		state_d(4,0) = 0.0f;
		state_d(5,0) = 0.0f;
		state_d(6,0) = 0.0f;
		state_d(7,0) = 0.0f;
		state_d(8,0) = 0.0f;
		state_d(9,0) = 0.0f;
		state_d(10,0) = 0.0f;
		state_d(11,0) = 0.0f;
	}
}
Example #3
0
int main(void) {
	while (1) {
		state = 0;
		int setTime = 15;
		numPlayers = 2;
		initScreen();
		clearScreen();
		initCharBuffer();
		clean_up();
		initKeyboard();
		initState0();
		initAI();


		//Bypass the menu system for testing
		if (IORD(keys,0) == 8) {
			initPlayer(pOne, MARIO, "pOne", 50, 100, HUMAN);
			initPlayer(pTwo, LUIGI, "pTwo", 50, 100, COMPUTER);
			state = 2;
		} else {
			while (state == 0) {
				decode_scancode(ps2, &decode_mode, buf, &ascii);
				state_0(decode_mode, buf[0]);
			};
			initState1(pOne);
			if(aOn)file_handle = initAudio(fname);
			if(aOn)alt_irq_register(AUDIO_0_IRQ, &ab, (alt_isr_func) write_fifo);
			if(aOn)		alt_up_audio_enable_write_interrupt(ab->audio);
			while (state == 1) {
				decode_scancode(ps2, &decode_mode, buf, &ascii);
				state_1(decode_mode, buf[0], ascii);
				if(aOn)loop_audio(file_handle, fname, ab);
			};
		}

		//clean_up();
		clearCharBuffer();
		clearScreen();

		//enable keyboard IRQ
		void* keyboard_control_register_ptr = (void*) (KEYBOARD_BASE + 4);
		alt_irq_register(KEYBOARD_IRQ, keyboard_control_register_ptr,
				keyboard_ISR);
		alt_up_ps2_enable_read_interrupt(ps2);

		//Draw field and UI to both buffers
		initField();

		updateField();
		drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name);
		drawGas(p[pOne].gas);
		drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp);
		drawBullet(p[pOne].bulletType);
		//drawWindIndicator(1);
		updateScreen();

		updateField();
		drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name);
		drawGas(p[pOne].gas);
		drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp);
		drawBullet(p[pOne].bulletType);
		//drawWindIndicator(1);

		float time;
		alt_timestamp_start();


		int start_timer_flag = 1;
		//printf("NUM PLAYERA %i\n", numPlayers);
		int i;
		while (state == 2) {
			int fallFlag = 1;

			//Checks to see if any players are falling
			while (fallFlag == 1) {
				fallFlag = 0;
				for (i = 0; i < numPlayers; i++) {
					if (p[i].alive) {
						if (p[i].y + TANK_HEIGHT >= SCREEN_HEIGHT-1) {
							p[i].hp = 0;
							p[i].alive = DEAD;
						}
						checkPlayerFalling(i);
						if (p[i].isFalling) {
							undrawPlayer(i);
							updatePlayer(i);
							fallFlag = 1;
						}
					}
				}
				if (fallFlag == 1) {
					updateScreen();
				}
			}

			if(start_timer_flag){
				start_time = (float) alt_timestamp() / (float) alt_timestamp_freq();
				start_timer_flag = 0;
			}
			time = (float) alt_timestamp() / (float) alt_timestamp_freq()-start_time;
			if (time >= setTime) {
				setPlayerTurn();
			}
			if (p[turn].type == HUMAN) {
				runGame();

			} else {
				p[turn].deg = 0;
				aiMain(turn);
				setPlayerTurn();
			}
			printTimer(setTime - time);
			int deadCount = 0;
			for (i = 0; i < numPlayers; i++) {
				if (p[i].alive == DEAD)
					deadCount++;
			}
			if (deadCount == numPlayers - 1) {
				usleep(500000);
				state = 3;
			}
		}

		alt_up_ps2_disable_read_interrupt(ps2);
		if(aOn)alt_up_audio_disable_write_interrupt(ab->audio);

		GameOverScreen();
	}
}