Example #1
0
void Draw_Point(const int x, const int y, color_t c)
{
	Uint32 *screen = gGraphicsDevice.buf;
	int idx = PixelIndex(
		x,
		y,
		gGraphicsDevice.cachedConfig.Res.x,
		gGraphicsDevice.cachedConfig.Res.y);
	if (x < gGraphicsDevice.clipping.left ||
		x > gGraphicsDevice.clipping.right ||
		y < gGraphicsDevice.clipping.top ||
		y > gGraphicsDevice.clipping.bottom)
	{
		return;
	}
	if (c.a == 255)
	{
		screen[idx] = COLOR2PIXEL(c);
	}
	else
	{
		const color_t existing = PIXEL2COLOR(screen[idx]);
		screen[idx] = COLOR2PIXEL(ColorAlphaBlend(existing, c));
	}
}
Example #2
0
void PicLoad(
	Pic *p, const Vec2i size, const Vec2i offset, const SDL_Surface *image)
{
	p->size = size;
	p->offset = Vec2iZero();
	CMALLOC(p->Data, size.x * size.y * sizeof *((Pic *)0)->Data);
	// Manually copy the pixels and replace the alpha component,
	// since our gfx device format has no alpha
	int srcI = offset.y*image->w + offset.x;
	for (int i = 0; i < size.x * size.y; i++, srcI++)
	{
		const Uint32 pixel = ((Uint32 *)image->pixels)[srcI];
		color_t c;
		SDL_GetRGBA(pixel, image->format, &c.r, &c.g, &c.b, &c.a);
		// If completely transparent, replace rgb with black (0) too
		// This is because transparency blitting checks entire pixel
		if (c.a == 0)
		{
			p->Data[i] = 0;
		}
		else
		{
			p->Data[i] = COLOR2PIXEL(c);
		}
		if ((i + 1) % size.x == 0)
		{
			srcI += image->w - size.x;
		}
	}
}
Example #3
0
void ClearScreen(GraphicsDevice *g)
{
	color_t color = { 32, 32, 60, 255 };
	const Uint32 pixel = COLOR2PIXEL(color);
	for (int i = 0; i < GraphicsGetScreenSize(&g->cachedConfig); i++)
	{
		g->buf[i] = pixel;
	}
}
Example #4
0
void DrawCross(GraphicsDevice *device, int x, int y, color_t color)
{
	Uint32 *screen = device->buf;
	const Uint32 pixel = COLOR2PIXEL(color);
	screen += x;
	screen += y * gGraphicsDevice.cachedConfig.Res.x;
	*screen = pixel;
	*(screen - 1) = pixel;
	*(screen + 1) = pixel;
	*(screen - gGraphicsDevice.cachedConfig.Res.x) = pixel;
	*(screen + gGraphicsDevice.cachedConfig.Res.x) = pixel;
}
Example #5
0
void PicFromPicPaletted(Pic *pic, const PicPaletted *picP)
{
	pic->size = Vec2iNew(picP->w, picP->h);
	pic->offset = Vec2iZero();
	CMALLOC(pic->Data, pic->size.x * pic->size.y * sizeof *pic->Data);
	for (int i = 0; i < pic->size.x * pic->size.y; i++)
	{
		unsigned char palette = *(picP->data + i);
		pic->Data[i] = COLOR2PIXEL(PaletteToColor(palette));
		// Special case: if the palette colour is 0, it's transparent
		if (palette == 0)
		{
			pic->Data[i] = 0;
		}
	}
}
Example #6
0
void DrawPointTint(GraphicsDevice *device, Vec2i pos, HSV tint)
{
	Uint32 *screen = device->buf;
	int idx = PixelIndex(
		pos.x, pos.y,
		device->cachedConfig.Res.x,
		device->cachedConfig.Res.y);
	color_t c;
	if (pos.x < device->clipping.left || pos.x > device->clipping.right ||
		pos.y < device->clipping.top || pos.y > device->clipping.bottom)
	{
		return;
	}
	c = PIXEL2COLOR(screen[idx]);
	c = ColorTint(c, tint);
	screen[idx] = COLOR2PIXEL(c);
}
Example #7
0
void DrawPointMask(GraphicsDevice *device, Vec2i pos, color_t mask)
{
	Uint32 *screen = device->buf;
	int idx = PixelIndex(
		pos.x, pos.y,
		device->cachedConfig.Res.x,
		device->cachedConfig.Res.y);
	color_t c;
	if (pos.x < gGraphicsDevice.clipping.left ||
		pos.x > gGraphicsDevice.clipping.right ||
		pos.y < gGraphicsDevice.clipping.top ||
		pos.y > gGraphicsDevice.clipping.bottom)
	{
		return;
	}
	c = PIXEL2COLOR(screen[idx]);
	c = ColorMult(c, mask);
	screen[idx] = COLOR2PIXEL(c);
}
Example #8
0
void CameraDraw(
	Camera *camera, const input_device_e pausingDevice,
	const bool controllerUnplugged)
{
	Vec2i centerOffset = Vec2iZero();
	const int numLocalPlayersAlive =
		GetNumPlayers(PLAYER_ALIVE_OR_DYING, false, true);
	const int numLocalPlayers = GetNumPlayers(PLAYER_ANY, false, true);
	const int w = gGraphicsDevice.cachedConfig.Res.x;
	const int h = gGraphicsDevice.cachedConfig.Res.y;

	for (int i = 0; i < GraphicsGetScreenSize(&gGraphicsDevice.cachedConfig); i++)
	{
		gGraphicsDevice.buf[i] = COLOR2PIXEL(colorBlack);
	}

	const Vec2i noise = ScreenShakeGetDelta(camera->shake);

	GraphicsResetBlitClip(&gGraphicsDevice);
	if (numLocalPlayersAlive == 0)
	{
		// Count the number of local players with lives left
		// If there are none, then try to spectate if there are remote players
		int firstRemotePlayerUID = -1;
		bool hasLocalPlayerLives = false;
		CA_FOREACH(const PlayerData, p, gPlayerDatas)
			if (p->Lives > 0)
			{
				if (p->IsLocal)
				{
					hasLocalPlayerLives = true;
					break;
				}
				else
				{
					firstRemotePlayerUID = p->UID;
				}
			}
		CA_FOREACH_END()
		if (!hasLocalPlayerLives)
		{
			if (camera->spectateMode == SPECTATE_NONE)
			{
				// Enter spectator mode
				// If there are remote players, follow them
				if (firstRemotePlayerUID != -1)
				{
					camera->spectateMode = SPECTATE_FOLLOW;
					camera->FollowPlayerUID = firstRemotePlayerUID;
				}
				else
				{
					// Free-look mode
					camera->spectateMode = SPECTATE_FREE;
				}
			}
		}
		else
		{
			// Don't spectate
			camera->spectateMode = SPECTATE_NONE;
		}
		if (camera->spectateMode == SPECTATE_FOLLOW)
		{
			FollowPlayer(&camera->lastPosition, camera->FollowPlayerUID);
		}
		DoBuffer(
			&camera->Buffer,
			camera->lastPosition,
			X_TILES, noise, centerOffset);
		SoundSetEars(camera->lastPosition);
	}