Skip to content

Commit

Permalink
Remove renderToTex (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Feb 7, 2018
1 parent b0d25ee commit 8b2149d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 87 deletions.
9 changes: 7 additions & 2 deletions src/cdogs/camera.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2013-2017 Cong Xu
Copyright (c) 2013-2018 Cong Xu
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -31,6 +31,7 @@
#include "draw/drawtools.h"
#include "events.h"
#include "font.h"
#include "log.h"
#include "los.h"
#include "player.h"

Expand All @@ -41,7 +42,11 @@ void CameraInit(Camera *camera)
{
memset(camera, 0, sizeof *camera);
DrawBufferInit(
&camera->Buffer, svec2i(X_TILES, Y_TILES), &gGraphicsDevice, false);
&camera->Buffer, svec2i(X_TILES, Y_TILES), &gGraphicsDevice);
if (SDL_SetRenderTarget(gGraphicsDevice.gameWindow.renderer, NULL) != 0)
{
LOG(LM_MAIN, LL_ERROR, "cannot set render target: %s", SDL_GetError());
}
camera->lastPosition = svec2_zero();
HUDInit(&camera->HUD, &gGraphicsDevice, &gMission);
camera->shake = ScreenShakeZero();
Expand Down
17 changes: 5 additions & 12 deletions src/cdogs/draw/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,9 @@ static void DrawFloor(DrawBuffer *b, struct vec2i offset)
{
continue;
}
if (b->renderToTex)
{
BlitMasked(&gGraphicsDevice, &pic->pic, pos, mask, false);
}
else
{
PicRender(
&pic->pic, gGraphicsDevice.gameWindow.renderer,
pos, mask);
}
PicRender(
&pic->pic, gGraphicsDevice.gameWindow.renderer,
pos, mask);
}
}
tile += X_TILES - b->Size.x;
Expand Down Expand Up @@ -305,7 +298,7 @@ static void DrawThing(DrawBuffer *b, const TTileItem *t, const struct vec2i offs

if (!svec2i_is_zero(t->ShadowSize))
{
DrawShadow(&gGraphicsDevice, picPos, t->ShadowSize, b->renderToTex);
DrawShadow(&gGraphicsDevice, picPos, t->ShadowSize);
}

if (t->CPicFunc)
Expand All @@ -322,7 +315,7 @@ static void DrawThing(DrawBuffer *b, const TTileItem *t, const struct vec2i offs
{
TActor *a = CArrayGet(&gActors, t->id);
ActorPics pics = GetCharacterPicsFromActor(a);
DrawActorPics(&pics, picPos, b->renderToTex);
DrawActorPics(&pics, picPos);
// Draw weapon indicators
DrawLaserSight(&pics, a, picPos);
}
Expand Down
7 changes: 3 additions & 4 deletions src/cdogs/draw/draw_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ static Character *ActorGetCharacterMutable(TActor *a)

static void DrawDyingBody(
GraphicsDevice *g, const ActorPics *pics, const struct vec2i pos);
void DrawActorPics(
const ActorPics *pics, const struct vec2i pos, const bool renderToTex)
void DrawActorPics(const ActorPics *pics, const struct vec2i pos)
{
if (pics->IsDead)
{
Expand All @@ -260,7 +259,7 @@ void DrawActorPics(
// Draw shadow
if (!pics->IsTransparent)
{
DrawShadow(&gGraphicsDevice, pos, svec2i(8, 6), renderToTex);
DrawShadow(&gGraphicsDevice, pos, svec2i(8, 6));
}
for (int i = 0; i < BODY_PART_COUNT; i++)
{
Expand Down Expand Up @@ -460,7 +459,7 @@ void DrawCharacterSimple(
ActorPics pics = GetCharacterPics(
c, d, ACTORANIMATION_IDLE, 0, NULL, GUNSTATE_READY,
false, NULL, NULL, 0);
DrawActorPics(&pics, pos, true);
DrawActorPics(&pics, pos);
if (hilite)
{
FontCh('>', svec2i_add(pos, svec2i(-8, -16)));
Expand Down
3 changes: 1 addition & 2 deletions src/cdogs/draw/draw_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ ActorPics GetCharacterPics(
const bool isTransparent, HSV *tint, color_t *mask,
const int deadPic);
ActorPics GetCharacterPicsFromActor(TActor *a);
void DrawActorPics(
const ActorPics *pics, const struct vec2i pos, const bool renderToTex);
void DrawActorPics(const ActorPics *pics, const struct vec2i pos);
void DrawLaserSight(
const ActorPics *pics, const TActor *a, const struct vec2i picPos);
void DrawActorHighlight(
Expand Down
5 changes: 1 addition & 4 deletions src/cdogs/draw/draw_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
#include "los.h"


void DrawBufferInit(
DrawBuffer *b, struct vec2i size, GraphicsDevice *g,
const bool renderToTex)
void DrawBufferInit(DrawBuffer *b, struct vec2i size, GraphicsDevice *g)
{
b->OrigSize = size;
CMALLOC(b->tiles, size.x * sizeof *b->tiles);
Expand All @@ -68,7 +66,6 @@ void DrawBufferInit(
b->g = g;
CArrayInit(&b->displaylist, sizeof(const TTileItem *));
CArrayReserve(&b->displaylist, 32);
b->renderToTex = renderToTex;
}
void DrawBufferTerminate(DrawBuffer *b)
{
Expand Down
5 changes: 1 addition & 4 deletions src/cdogs/draw/draw_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ typedef struct
struct vec2i Size; // size in tiles
Tile **tiles;
CArray displaylist; // of const TTileItem *, to determine draw order
bool renderToTex;
} DrawBuffer;

void DrawBufferInit(
DrawBuffer *b, struct vec2i size, GraphicsDevice *g,
const bool renderToTex);
void DrawBufferInit(DrawBuffer *b, struct vec2i size, GraphicsDevice *g);
void DrawBufferTerminate(DrawBuffer *b);

void DrawBufferSetFromMap(
Expand Down
60 changes: 6 additions & 54 deletions src/cdogs/draw/drawtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,63 +255,15 @@ void DrawCross(GraphicsDevice *device, int x, int y, color_t color)
}

// Note: size is half-size
void DrawShadow(
GraphicsDevice *g, struct vec2i pos, struct vec2i size,
const bool renderToTex)
void DrawShadow(GraphicsDevice *g, struct vec2i pos, struct vec2i size)
{
if (!ConfigGetBool(&gConfig, "Graphics.Shadows"))
{
return;
}
if (renderToTex)
{
struct vec2i drawPos;
for (drawPos.y = pos.y - size.y;
drawPos.y < pos.y + size.y;
drawPos.y++)
{
if (drawPos.y >= g->clipping.bottom)
{
break;
}
if (drawPos.y < g->clipping.top)
{
continue;
}
for (drawPos.x = pos.x - size.x;
drawPos.x < pos.x + size.x;
drawPos.x++)
{
// Calculate value tint based on distance from center
struct vec2i scaledPos;
int distance2;
if (drawPos.x >= g->clipping.right)
{
break;
}
if (drawPos.x < g->clipping.left)
{
continue;
}
scaledPos.x = drawPos.x;
scaledPos.y = (drawPos.y - pos.y) * size.x / size.y + pos.y;
distance2 = svec2i_distance_squared(scaledPos, pos);
// Maximum distance is x, so scale distance squared by x squared
const HSV tint =
{
-1.0, 1.0,
CLAMP(distance2 * 1.0 / (size.x*size.x), 0.0, 1.0)
};
DrawPointTint(g, drawPos, tint);
}
}
}
else
{
const Pic *shadow = PicManagerGetPic(&gPicManager, "shadow");
const Rect2i dest =
Rect2iNew(svec2i_subtract(pos, size), svec2i_scale(size, 2));
TextureRender(
shadow->Tex, g->gameWindow.renderer, dest, colorTransparent);
}
const Pic *shadow = PicManagerGetPic(&gPicManager, "shadow");
const Rect2i dest =
Rect2iNew(svec2i_subtract(pos, size), svec2i_scale(size, 2));
TextureRender(
shadow->Tex, g->gameWindow.renderer, dest, colorTransparent);
}
4 changes: 1 addition & 3 deletions src/cdogs/draw/drawtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,4 @@ void DrawRectangle(
// *
void DrawCross(GraphicsDevice *device, int x, int y, color_t color);

void DrawShadow(
GraphicsDevice *g, struct vec2i pos, struct vec2i size,
const bool renderToTex);
void DrawShadow(GraphicsDevice *g, struct vec2i pos, struct vec2i size);
13 changes: 11 additions & 2 deletions src/cdogs/grafx_bg.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void GrafxMakeRandomBackground(
rand() * 360.0 / RAND_MAX, rand() * 1.0 / RAND_MAX, 0.5
};
DrawBuffer buffer;
DrawBufferInit(&buffer, svec2i(X_TILES, Y_TILES), device, true);
DrawBufferInit(&buffer, svec2i(X_TILES, Y_TILES), device);
co->MissionIndex = 0;
GrafxMakeBackground(
device, &buffer, co, mo, map, tint, false, svec2_zero(), NULL);
Expand All @@ -65,8 +65,17 @@ void GrafxDrawBackground(
GraphicsDevice *g, DrawBuffer *buffer,
const HSV tint, const struct vec2 pos, GrafxDrawExtra *extra)
{
if (SDL_SetRenderTarget(g->gameWindow.renderer, g->bkg) != 0)
{
LOG(LM_MAIN, LL_ERROR, "cannot set render target: %s", SDL_GetError());
}
if (g->cachedConfig.SecondWindow)
{
if (SDL_SetRenderTarget(g->gameWindow.renderer, g->bkg2) != 0)
{
LOG(LM_MAIN, LL_ERROR, "cannot set render target: %s",
SDL_GetError());
}
DrawBackground(
g, g->bkg, buffer, &gMap, tint,
svec2(pos.x - g->cachedConfig.Res.x / 2, pos.y), extra);
Expand Down Expand Up @@ -99,7 +108,7 @@ void GrafxRedrawBackground(GraphicsDevice *g, const struct vec2 pos)
{
memset(g->buf, 0, GraphicsGetMemSize(&g->cachedConfig));
DrawBuffer buffer;
DrawBufferInit(&buffer, svec2i(X_TILES, Y_TILES), g, true);
DrawBufferInit(&buffer, svec2i(X_TILES, Y_TILES), g);
const HSV tint = {
rand() * 360.0 / RAND_MAX, rand() * 1.0 / RAND_MAX, 0.5
};
Expand Down

0 comments on commit 8b2149d

Please sign in to comment.