Skip to content

Commit

Permalink
Texture render actors (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Feb 22, 2018
1 parent a3426e7 commit e92db9c
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 171 deletions.
63 changes: 15 additions & 48 deletions src/cdogs/blit.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2013-2017 Cong Xu
Copyright (c) 2013-2018 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -232,54 +232,10 @@ void BlitMasked(
}
}
}
void BlitCharMultichannel(
GraphicsDevice *device,
const Pic *pic,
const struct vec2i pos,
const CharColors *masks)
CharColors CharColorsFromOneColor(const color_t color)
{
Uint32 *current = pic->Data;
struct vec2i v = svec2i_add(pos, pic->offset);
for (int i = 0; i < pic->size.y; i++)
{
int yoff = i + v.y;
if (yoff > device->clipping.bottom)
{
break;
}
if (yoff < device->clipping.top)
{
current += pic->size.x;
continue;
}
yoff *= device->cachedConfig.Res.x;
for (int j = 0; j < pic->size.x; j++)
{
Uint32 *target;
const int xoff = j + v.x;
if (xoff < device->clipping.left)
{
current++;
continue;
}
if (xoff > device->clipping.right)
{
current += pic->size.x - j;
break;
}
if (*current == 0)
{
current++;
continue;
}
target = device->buf + yoff + xoff;
const color_t color = PIXEL2COLOR(*current);
*target = PixelMult(
*current,
COLOR2PIXEL(CharColorsGetChannelMask(masks, color.a)));
current++;
}
}
CharColors c = { color, color, color, color, color };
return c;
}
color_t CharColorsGetChannelMask(
const CharColors *c, const uint8_t alpha)
Expand All @@ -297,6 +253,17 @@ color_t CharColorsGetChannelMask(
return colorWhite;
}
}
void CharColorsGetMaskedName(char *buf, const char *base, const CharColors *c)
{
char bufSkin[16], bufArms[16], bufBody[16], bufLegs[16], bufHair[16];
ColorStr(bufSkin, c->Skin);
ColorStr(bufArms, c->Arms);
ColorStr(bufBody, c->Body);
ColorStr(bufLegs, c->Legs);
ColorStr(bufHair, c->Hair);
sprintf(buf, "%s/%s/%s/%s/%s/%s", base,
bufSkin, bufArms, bufBody, bufLegs, bufHair);
}
void BlitBlend(
GraphicsDevice *g, const Pic *pic, struct vec2i pos, const color_t blend)
{
Expand Down
9 changes: 3 additions & 6 deletions src/cdogs/blit.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
This file incorporates work covered by the following copyright and
permission notice:
Copyright (c) 2013-2014, 2016-2017 Cong Xu
Copyright (c) 2013-2014, 2016-2018 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -80,11 +80,6 @@ void BlitMasked(
struct vec2i pos,
color_t mask,
int isTransparent);
void BlitCharMultichannel(
GraphicsDevice *device,
const Pic *pic,
const struct vec2i pos,
const CharColors *masks);
void BlitBlend(
GraphicsDevice *g, const Pic *pic, struct vec2i pos, const color_t blend);
void BlitPicHighlight(
Expand All @@ -93,7 +88,9 @@ void BlitClearBuf(GraphicsDevice *g);
void BlitUpdateFromBuf(GraphicsDevice *g, SDL_Texture *t);

Uint32 PixelMult(const Uint32 p, const Uint32 m);
CharColors CharColorsFromOneColor(const color_t color);
color_t CharColorsGetChannelMask(const CharColors *c, const uint8_t alpha);
void CharColorsGetMaskedName(char *buf, const char *base, const CharColors *c);

#define BLIT_BRIGHTNESS_MIN (-10)
#define BLIT_BRIGHTNESS_MAX 10
4 changes: 3 additions & 1 deletion src/cdogs/character_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ static void LoadCharacterClass(CharacterClass *c, json_t *node)
{
memset(c, 0, sizeof *c);
c->Name = GetString(node, "Name");
CPicLoadJSON(&c->HeadPics, json_find_first_label(node, "HeadPics")->child);
// TODO: allow non-directional head sprites?
json_t *headPics = json_find_first_label(node, "HeadPics")->child;
c->HeadSprites = GetString(headPics, "Sprites");
// TODO: custom character sprites
c->Sprites = StrCharSpriteClass("base");

Expand Down
4 changes: 2 additions & 2 deletions src/cdogs/character_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2016-2017 Cong Xu
Copyright (c) 2016-2018 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -37,7 +37,7 @@
typedef struct
{
char *Name;
CPic HeadPics;
char *HeadSprites;
const CharSprites *Sprites;
struct
{
Expand Down
3 changes: 2 additions & 1 deletion src/cdogs/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ color_t ColorMult(color_t c, color_t m)
c.r = (uint8_t)((int)c.r * m.r / 255);
c.g = (uint8_t)((int)c.g * m.g / 255);
c.b = (uint8_t)((int)c.b * m.b / 255);
c.a = (uint8_t)((int)c.a * m.a / 255);
return c;
}
color_t ColorAlphaBlend(color_t a, color_t b)
Expand Down Expand Up @@ -233,5 +234,5 @@ color_t StrColor(const char *s)
}
void ColorStr(char *s, const color_t c)
{
sprintf(s, "%02x%02x%02x", c.r, c.g, c.b);
sprintf(s, "%02x%02x%02x%02x", c.r, c.g, c.b, c.a);
}
Loading

0 comments on commit e92db9c

Please sign in to comment.