static void CL_Beams_SetupBuiltinTexture(void)
{
	// beam direction is horizontal in the lightning texture
	int texwidth = 128;
	int texheight = 64;
	float r, g, b, intensity, thickness = texheight * 0.25f, border = thickness + 2.0f, ithickness = 1.0f / thickness, center, n;
	int x, y;
	unsigned char *data;
	skinframe_t *skinframe;
	float centersamples[17][2];

	// make a repeating noise pattern for the beam path
	for (x = 0; x < 16; x++)
	{
		centersamples[x][0] = lhrandom(border, texheight - border);
		centersamples[x][1] = lhrandom(0.2f, 1.00f);
	}
	centersamples[16][0] = centersamples[0][0];
	centersamples[16][1] = centersamples[0][1];

	data = (unsigned char *)Mem_Alloc(tempmempool, texwidth * texheight * 4);

	// iterate by columns and draw the entire column of pixels
	for (x = 0; x < texwidth; x++)
	{
		r = x * 16.0f / texwidth;
		y = (int)r;
		g = r - y;
		center = centersamples[y][0] * (1.0f - g) + centersamples[y+1][0] * g;
		n = centersamples[y][1] * (1.0f - g) + centersamples[y + 1][1] * g;
		for (y = 0; y < texheight; y++)
		{
			intensity = 1.0f - fabs((y - center) * ithickness);
			if (intensity > 0)
			{
				intensity = pow(intensity * n, 2);
				r = intensity * 1.000f * 255.0f;
				g = intensity * 2.000f * 255.0f;
				b = intensity * 4.000f * 255.0f;
				data[(y * texwidth + x) * 4 + 2] = (unsigned char)(bound(0, r, 255));
				data[(y * texwidth + x) * 4 + 1] = (unsigned char)(bound(0, g, 255));
				data[(y * texwidth + x) * 4 + 0] = (unsigned char)(bound(0, b, 255));
			}
			else
				intensity = 0.0f;
			data[(y * texwidth + x) * 4 + 3] = (unsigned char)255;
		}
	}

	skinframe = R_SkinFrame_LoadInternalBGRA("lightningbeam", TEXF_FORCELINEAR, data, texwidth, texheight, 0, 0, 0, false);
	Mod_LoadCustomMaterial(r_main_mempool, &cl_beams_builtintexture, "cl_beams_builtintexture", 0, MATERIALFLAG_WALL | MATERIALFLAG_ADD | MATERIALFLAG_BLENDED | MATERIALFLAG_NOCULLFACE | MATERIALFLAG_VERTEXCOLOR | MATERIALFLAG_ALPHAGEN_VERTEX, skinframe);
	Mem_Free(data);
}
Exemple #2
0
void CDAudio_StartPlaylist(qboolean resume)
{
	const char *list;
	const char *t;
	int index;
	int current;
	int randomplay;
	int count;
	int listindex;
	float position;
	char trackname[MAX_QPATH];
	CDAudio_Stop();
	index = music_playlist_index.integer;
	if (index >= 0 && index < MAX_PLAYLISTS && bgmvolume.value > 0)
	{
		list = music_playlist_list[index].string;
		current = music_playlist_current[index].integer;
		randomplay = music_playlist_random[index].integer;
		position = music_playlist_sampleposition[index].value;
		count = 0;
		trackname[0] = 0;
		if (list && list[0])
		{
			for (t = list;;count++)
			{
				if (!COM_ParseToken_Console(&t))
					break;
				// if we don't find the desired track, use the first one
				if (count == 0)
					strlcpy(trackname, com_token, sizeof(trackname));
			}
		}
		if (count > 0)
		{
			// position < 0 means never resume track
			if (position < 0)
				position = 0;
			// advance to next track in playlist if the last one ended
			if (!resume)
			{
				position = 0;
				current++;
				if (randomplay)
					current = (int)lhrandom(0, count);
			}
			// wrap playlist position if needed
			if (current >= count)
				current = 0;
			// set current
			Cvar_SetValueQuick(&music_playlist_current[index], current);
			// get the Nth trackname
			if (current >= 0 && current < count)
			{
				for (listindex = 0, t = list;;listindex++)
				{
					if (!COM_ParseToken_Console(&t))
						break;
					if (listindex == current)
					{
						strlcpy(trackname, com_token, sizeof(trackname));
						break;
					}
				}
			}
			if (trackname[0])
			{
				CDAudio_Play_byName(trackname, false, false, position);
				if (faketrack != -1)
					music_playlist_active = index;
			}
		}
	}
	music_playlist_playing = music_playlist_active >= 0 ? 1 : -1;
}
Exemple #3
0
static void r_lightningbeams_setuptexture(void)
{
#if 0
#define BEAMWIDTH 128
#define BEAMHEIGHT 64
#define PATHPOINTS 8
	int i, j, px, py, nearestpathindex, imagenumber;
	float particlex, particley, particlexv, particleyv, dx, dy, s, maxpathstrength;
	unsigned char *pixels;
	int *image;
	struct lightningpathnode_s
	{
		float x, y, strength;
	}
	path[PATHPOINTS], temppath;

	image = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * sizeof(int));
	pixels = Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * sizeof(unsigned char[4]));

	for (imagenumber = 0, maxpathstrength = 0.0339476;maxpathstrength < 0.5;imagenumber++, maxpathstrength += 0.01)
	{
		for (i = 0;i < PATHPOINTS;i++)
		{
			path[i].x = lhrandom(0, 1);
			path[i].y = lhrandom(0.2, 0.8);
			path[i].strength = lhrandom(0, 1);
		}
		for (i = 0;i < PATHPOINTS;i++)
		{
			for (j = i + 1;j < PATHPOINTS;j++)
			{
				if (path[j].x < path[i].x)
				{
					temppath = path[j];
					path[j] = path[i];
					path[i] = temppath;
				}
			}
		}
		particlex = path[0].x;
		particley = path[0].y;
		particlexv = lhrandom(0, 0.02);
		particlexv = lhrandom(-0.02, 0.02);
		memset(image, 0, BEAMWIDTH * BEAMHEIGHT * sizeof(int));
		for (i = 0;i < 65536;i++)
		{
			for (nearestpathindex = 0;nearestpathindex < PATHPOINTS;nearestpathindex++)
				if (path[nearestpathindex].x > particlex)
					break;
			nearestpathindex %= PATHPOINTS;
			dx = path[nearestpathindex].x + lhrandom(-0.01, 0.01);dx = bound(0, dx, 1) - particlex;if (dx < 0) dx += 1;
			dy = path[nearestpathindex].y + lhrandom(-0.01, 0.01);dy = bound(0, dy, 1) - particley;
			s = path[nearestpathindex].strength / sqrt(dx*dx+dy*dy);
			particlexv = particlexv /* (1 - lhrandom(0.08, 0.12))*/ + dx * s;
			particleyv = particleyv /* (1 - lhrandom(0.08, 0.12))*/ + dy * s;
			particlex += particlexv * maxpathstrength;particlex -= (int) particlex;
			particley += particleyv * maxpathstrength;particley = bound(0, particley, 1);
			px = particlex * BEAMWIDTH;
			py = particley * BEAMHEIGHT;
			if (px >= 0 && py >= 0 && px < BEAMWIDTH && py < BEAMHEIGHT)
				image[py*BEAMWIDTH+px] += 16;
		}

		for (py = 0;py < BEAMHEIGHT;py++)
		{
			for (px = 0;px < BEAMWIDTH;px++)
			{
				pixels[(py*BEAMWIDTH+px)*4+2] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
				pixels[(py*BEAMWIDTH+px)*4+1] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
				pixels[(py*BEAMWIDTH+px)*4+0] = bound(0, image[py*BEAMWIDTH+px] * 1.0f, 255.0f);
				pixels[(py*BEAMWIDTH+px)*4+3] = 255;
			}
		}

		Image_WriteTGABGRA(va(vabuf, sizeof(vabuf), "lightningbeam%i.tga", imagenumber), BEAMWIDTH, BEAMHEIGHT, pixels);
	}

	r_lightningbeamtexture = R_LoadTexture2D(r_lightningbeamtexturepool, "lightningbeam", BEAMWIDTH, BEAMHEIGHT, pixels, TEXTYPE_BGRA, TEXF_FORCELINEAR, NULL);

	Mem_Free(pixels);
	Mem_Free(image);
#else
#define BEAMWIDTH 64
#define BEAMHEIGHT 128
	float r, g, b, intensity, fx, width, center;
	int x, y;
	unsigned char *data, *noise1, *noise2;

	data = (unsigned char *)Mem_Alloc(tempmempool, BEAMWIDTH * BEAMHEIGHT * 4);
	noise1 = (unsigned char *)Mem_Alloc(tempmempool, BEAMHEIGHT * BEAMHEIGHT);
	noise2 = (unsigned char *)Mem_Alloc(tempmempool, BEAMHEIGHT * BEAMHEIGHT);
	fractalnoise(noise1, BEAMHEIGHT, BEAMHEIGHT / 8);
	fractalnoise(noise2, BEAMHEIGHT, BEAMHEIGHT / 16);

	for (y = 0;y < BEAMHEIGHT;y++)
	{
		width = 0.15;//((noise1[y * BEAMHEIGHT] * (1.0f / 256.0f)) * 0.1f + 0.1f);
		center = (noise1[y * BEAMHEIGHT + (BEAMHEIGHT / 2)] / 256.0f) * (1.0f - width * 2.0f) + width;
		for (x = 0;x < BEAMWIDTH;x++, fx++)
		{
			fx = (((float) x / BEAMWIDTH) - center) / width;
			intensity = 1.0f - sqrt(fx * fx);
			if (intensity > 0)
				intensity = pow(intensity, 2) * ((noise2[y * BEAMHEIGHT + x] * (1.0f / 256.0f)) * 0.33f + 0.66f);
			intensity = bound(0, intensity, 1);
			r = intensity * 1.0f;
			g = intensity * 1.0f;
			b = intensity * 1.0f;
			data[(y * BEAMWIDTH + x) * 4 + 2] = (unsigned char)(bound(0, r, 1) * 255.0f);
			data[(y * BEAMWIDTH + x) * 4 + 1] = (unsigned char)(bound(0, g, 1) * 255.0f);
			data[(y * BEAMWIDTH + x) * 4 + 0] = (unsigned char)(bound(0, b, 1) * 255.0f);
			data[(y * BEAMWIDTH + x) * 4 + 3] = (unsigned char)255;
		}
	}

	r_lightningbeamtexture = R_SkinFrame_LoadInternalBGRA("lightningbeam", TEXF_FORCELINEAR, data, BEAMWIDTH, BEAMHEIGHT, false);
	Mem_Free(noise1);
	Mem_Free(noise2);
	Mem_Free(data);
#endif
}