示例#1
0
int main(int argc, char *argv[])
{
	initTracer();
	scene *curscene = sceneLoad();
	TGAFILE *tga = openTGA(curscene);

	clock_t start = clock();

	int i, j;

	for (j = 0; j < (int)curscene->resolution; j++)
	{
		printf("Scanning horizontal line %d.\n", j);

		for (i = 0; i < (int)curscene->resolution; i++)
		{
			vector color = pixelraytrace(curscene, i, j);
			writeTGAColor(tga, curscene, i, j, color.x, color.y, color.z);
		}
	}

	clock_t end = clock();

	printf("Entire process took %.4f seconds.\n", ((double)(end - start)) / CLOCKS_PER_SEC);

	sceneFree(curscene);
	closeTGA(tga);

	return 0;
}
示例#2
0
int main(int argc, char *argv[])
{
	initTracer();

	int i;
	int rank, size;
	scene *curscene;
	int res;
	TGAFILE* tga = NULL;
	vector *scanline;
	MPI_Status status;

	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &size);

	if (rank == 0) {
		curscene = sceneLoad();
		tga = openTGA(curscene);
	} else
		curscene = calloc(1, sizeof(scene));

	MPI_Bcast((void*)curscene, sizeof(scene) / sizeof(float), MPI_FLOAT, 0, MPI_COMM_WORLD);

	res = sceneResolution(curscene);
	scanline = calloc(res, sizeof(vector));
	int line = 0;
	float aaweight = 1.0f / size;

	for (line = 0; line < res; line++) {
		if (rank == size - 1) {
			printf("Starting scan of horizontal line %d.\n", line);
		} else {
			MPI_Recv(scanline, (sizeof(vector) / sizeof(float)) * res, MPI_FLOAT, rank + 1, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
		}

		for (i = 0; i <res; i++)
		{
			if (rank == size - 1)
				scanline[i] = smul(pixelraytraceaa(curscene, line, i, rank), aaweight);
			else
				scanline[i] = add(scanline[i], smul(pixelraytraceaa(curscene, line, i, rank), aaweight));
		}

		if (rank == 0) {
			for (i = 0; i < res; i++)
				writeTGAColor(tga, curscene, line, i, scanline[i].x, scanline[i].y, scanline[i].z);
		} else {
			MPI_Send(scanline, (sizeof(vector) / sizeof(float)) * res, MPI_FLOAT, rank - 1, 0, MPI_COMM_WORLD);
		}
	}

	free(curscene);

	MPI_Finalize();

	return 0;
}
示例#3
0
void menu_update() {
	if (scene.tempo <= 0) {
		if (input.escape->press) exitGame();
		if (input.up->repeat && selection > 0) {
			selection--;
			menu_sound(false);
		}
		if (input.down->repeat && selection < 2) {
			selection++;
			menu_sound(false);
		}
		if (input.enter->press) switch (selection) {
			case 0: sceneLoad(LEVEL);
			case 1: sceneLoad(SETTINGS);
			default: exitGame();
			menu_sound(true);
		}
	}
	animTempo += game.delta*.25;
}
示例#4
0
void level_update() {
	if (scene.tempo <= 0) {
		if (input.backspace->press) {
			sceneLoad(MENU);
		}
		if (input.enter->press && !input.captureText && !input.captureFinish) {
			showTextbox();
		}
		if (input.captureFinish) {
			hideTextbox();
		}
		if (input.textUpdate) {
			calculatePoints(false);
		}
		if (input.tab->press) {
			setDir(-functionDir);
			calculatePoints(true);
		}
	}
	if (zeroHeightTempo > 0) {
		zeroHeightTempo -= game.delta*3;
		if (zeroHeightTempo < 0) {
			zeroHeightTempo = 0;
		}
	}
	dottedTempo += game.delta*3;
	while (dottedTempo >= 1) {
		dottedTempo -= 1;
	}
	if (functionPlot) {
		if (weightTempo < 1) {
			weightTempo += game.delta*8;
			if (weightTempo > 1) weightTempo = 1;
		}
	} else {
		if (weightTempo > 0) {
			weightTempo -= game.delta*2;
			if (weightTempo < 0) weightTempo = 0;
		}
	}
	if (plotTempo > 0) {
		if (weightTempo > 0) {
			plotTempo -= game.delta*8;
			if (plotTempo < 0) plotTempo = 0;
		} else {
			plotTempo = 0;
		}
	}
}
示例#5
0
bool updatePause(bool ingame) {
	animTempo += game.delta*.25;
	if (confirm) {
		if (confirmTempo < 1) {
			confirmTempo += game.delta*8;
			if (confirmTempo > 1) confirmTempo = 1;
		}
	} else {
		if (confirmTempo > 0) {
			confirmTempo -= game.delta*8;
			if (confirmTempo < 0) confirmTempo = 0;
		}
	}
	if (unpausing) {
		if (pauseTempo > 0) {
			pauseTempo -= game.delta*4;
			if (pauseTempo <= 0) {
				pauseTempo = 0;
				return true;
			}
		}
		return false;
	} else if (ingame) {
		if (pauseTempo < 1) {
			pauseTempo += game.delta*4;
			if (pauseTempo > 1) {
				pauseTempo = 1;
			}
		}
	}
	if (scene.tempo <= 0) {
		if (confirm) {
			if (input.up->repeat && selection2 > 0) {
				selection2--;
				settings_sound(false);
			}
			if (input.down->repeat && selection2 < 1) {
				selection2++;
				settings_sound(false);
			}
			if (input.enter->press) {
				if (selection2 == 0) {
					unpausing = true;
					confirm = false;
					sceneLoad(MENU);
				} else {
					confirm = false;
				}
				settings_sound(true);
			} else if (input.escape->press) {
				confirm = false;
				settings_sound(true);
			}
			return false;
		}
		if (input.up->repeat && selection > (ingame?-1:0)) {
			selection--;
			settings_sound(false);
		}
		if (input.down->repeat && selection < 3) {
			selection++;
			settings_sound(false);
		}
		if ((selection == (ingame?-1:3) && input.enter->press) || input.escape->press) {
			settings_sound(true);
			if (ingame) {
				unpausing = true;
				return false;
			}
			sceneLoad(MENU);
		}
		if (selection == 0) {
			updateSlider(&game.volumeBgm);
		} else if (selection == 1) {
			updateSlider(&game.volumeSfx);
		} else if (selection == 2) {
			if (input.enter->press) {
				game.showPopups = !game.showPopups;
				settings_sound(true);
			}
		} else if (ingame && selection == 3) {
			if (input.enter->press) {
				confirm = true;
				selection2 = 1;
				settings_sound(true);
			}
		}
	}
	return false;
}
示例#6
0
int main(int argc, char *argv[])
{
	initTracer();

	int i, p;
	int rank, size;
	scene *curscene;
	int res;
	TGAFILE* tga = NULL;
	vector *scanline;
	MPI_Status status;

	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &size);

	if (rank == 0) {
		curscene = sceneLoad();
		tga = openTGA(curscene);
	} else
		curscene = calloc(1, sizeof(scene));

	double start, end;
	start = MPI_Wtime();

	MPI_Bcast((void*)curscene, sizeof(scene) / sizeof(float), MPI_FLOAT, 0, MPI_COMM_WORLD);

	res = sceneResolution(curscene);
	scanline = calloc(res, sizeof(vector));

	if (rank == 0) {
		int lastline = 0;
		int waiting = res;

		for (lastline = 0; lastline < size - 1; lastline++) {
			MPI_Send(&lastline, 1, MPI_INT, lastline + 1, 0, MPI_COMM_WORLD);
		}

		int flag;

		while(1) {
			if (waiting == 0)
				break;

			MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
			if (flag) {
				MPI_Recv(scanline, (sizeof(vector) / sizeof(float)) * res, MPI_FLOAT, status.MPI_SOURCE, status.MPI_TAG, MPI_COMM_WORLD, &status);

				if (lastline < res) {
					MPI_Send(&lastline, 1, MPI_INT, status.MPI_SOURCE, 0, MPI_COMM_WORLD);
					lastline++;
				}

				for (i = 0; i < res; i++)
					writeTGAColor(tga, curscene, status.MPI_TAG, i, scanline[i].x, scanline[i].y, scanline[i].z);

				waiting--;
			}
		}

		flag = -1;
		for (p = 1; p < size; p++) {
			MPI_Send(&flag, 1, MPI_INT, p, 0, MPI_COMM_WORLD);
		}

	} else {
		int line;

		while(1) {
			MPI_Recv(&line, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);

			if (line < 0) {
				break;
			}

			printf("Process %d scanning horizontal line %d.\n", rank, line);

			for (i = 0; i < res; i++)
				scanline[i] = pixelraytrace(curscene, line, i);

			MPI_Send(scanline, (sizeof(vector) / sizeof(float)) * res, MPI_FLOAT, 0, line, MPI_COMM_WORLD);
		}
	}

	free(curscene);

	end = MPI_Wtime();

	if (rank == 0)
		printf("Entire process took %.4f seconds.\n", end - start);

	MPI_Finalize();

	return 0;
}